/** * Gets the CoAP endpoint that should be used to communicate with a given client. * * @param registration the client * @return the CoAP endpoint bound to the same network address and port that the client connected to during * registration. If no such CoAP endpoint is available, the first CoAP endpoint from the list of registered * endpoints is returned */ private Endpoint getEndpointForClient(Registration registration) { for (Endpoint ep : endpoints) { InetSocketAddress endpointAddress = ep.getAddress(); if (endpointAddress.equals(registration.getRegistrationEndpointAddress())) { return ep; } } throw new IllegalStateException( "can't find the client endpoint for address : " + registration.getRegistrationEndpointAddress()); } }
o.add("regDate", r.getRegistrationDate().getTime()); o.add("identity", IdentitySerDes.serialize(r.getIdentity())); o.add("regAddr", r.getRegistrationEndpointAddress().getHostString()); o.add("regPort", r.getRegistrationEndpointAddress().getPort()); o.add("lt", r.getLifeTimeInSec()); if (r.getSmsNumber() != null) {
o.add("regDate", r.getRegistrationDate().getTime()); o.add("identity", IdentitySerDes.serialize(r.getIdentity())); o.add("regAddr", r.getRegistrationEndpointAddress().getHostString()); o.add("regPort", r.getRegistrationEndpointAddress().getPort()); o.add("lt", r.getLifeTimeInSec()); if (r.getSmsNumber() != null) {
/** * Returns an updated version of the registration. * * @param registration the registration to update * @return the updated registration */ public Registration update(Registration registration) { Identity identity = this.identity != null ? this.identity : registration.getIdentity(); Link[] linkObject = this.objectLinks != null ? this.objectLinks : registration.getObjectLinks(); long lifeTimeInSec = this.lifeTimeInSec != null ? this.lifeTimeInSec : registration.getLifeTimeInSec(); BindingMode bindingMode = this.bindingMode != null ? this.bindingMode : registration.getBindingMode(); String smsNumber = this.smsNumber != null ? this.smsNumber : registration.getSmsNumber(); Map<String, String> additionalAttributes = this.additionalAttributes.isEmpty() ? registration.getAdditionalRegistrationAttributes() : updateAdditionalAttributes(registration.getAdditionalRegistrationAttributes()); // this needs to be done in any case, even if no properties have changed, in order // to extend the client registration time-to-live period ... Date lastUpdate = new Date(); Registration.Builder builder = new Registration.Builder(registration.getId(), registration.getEndpoint(), identity, registration.getRegistrationEndpointAddress()); builder.lwM2mVersion(registration.getLwM2mVersion()).lifeTimeInSec(lifeTimeInSec).smsNumber(smsNumber) .bindingMode(bindingMode).objectLinks(linkObject).registrationDate(registration.getRegistrationDate()) .lastUpdate(lastUpdate).additionalRegistrationAttributes(additionalAttributes); return builder.build(); }