congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
Registration.getId
Code IndexAdd Tabnine to your IDE (free)

How to use
getId
method
in
org.eclipse.leshan.server.registration.Registration

Best Java code snippets using org.eclipse.leshan.server.registration.Registration.getId (Showing top 20 results out of 315)

origin: eclipse/leshan

@Override
public int cancelObservations(Registration registration, String resourcepath) {
  if (registration == null || registration.getId() == null || resourcepath == null || resourcepath.isEmpty())
    return 0;
  Set<Observation> observations = getObservations(registration.getId(), resourcepath);
  for (Observation observation : observations) {
    cancelObservation(observation);
  }
  return observations.size();
}
origin: eclipse/leshan

@Override
public void sendCoapRequest(final Registration destination, final Request coapRequest, long timeout,
    CoapResponseCallback responseCallback, ErrorCallback errorCallback) {
  // Define destination
  EndpointContext context = EndpointContextUtil.extractContext(destination.getIdentity());
  coapRequest.setDestinationContext(context);
  // Add CoAP request callback
  MessageObserver obs = new CoapAsyncRequestObserver(coapRequest, responseCallback, errorCallback, timeout);
  coapRequest.addMessageObserver(obs);
  // Store pending request to cancel it on de-registration
  addPendingRequest(destination.getId(), coapRequest);
  // Send CoAP request asynchronously
  Endpoint endpoint = getEndpointForClient(destination);
  endpoint.sendRequest(coapRequest);
}
origin: eclipse/leshan

  @Override
  public JsonElement serialize(Registration src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject element = new JsonObject();

    element.addProperty("endpoint", src.getEndpoint());
    element.addProperty("registrationId", src.getId());
    element.add("registrationDate", context.serialize(src.getRegistrationDate()));
    element.add("lastUpdate", context.serialize(src.getLastUpdate()));
    element.addProperty("address", src.getAddress().getHostAddress() + ":" + src.getPort());
    element.addProperty("smsNumber", src.getSmsNumber());
    element.addProperty("lwM2mVersion", src.getLwM2mVersion());
    element.addProperty("lifetime", src.getLifeTimeInSec());
    element.addProperty("bindingMode", src.getBindingMode().toString());
    element.add("rootPath", context.serialize(src.getRootPath()));
    element.add("objectLinks", context.serialize(src.getSortedObjectLinks()));
    element.add("secure", context.serialize(src.getIdentity().isSecure()));
    element.add("additionalRegistrationAttributes", context.serialize(src.getAdditionalRegistrationAttributes()));

    if (src.usesQueueMode()) {
      element.add("sleeping", context.serialize(!presenceService.isClientAwake(src)));
    }

    return element;
  }
}
origin: eclipse/leshan

@Override
public Set<Observation> getObservations(Registration registration) {
  return getObservations(registration.getId());
}
origin: eclipse/leshan

@Override
public Response sendCoapRequest(final Registration destination, final Request coapRequest, long timeout)
    throws InterruptedException {
  // Define destination
  EndpointContext context = EndpointContextUtil.extractContext(destination.getIdentity());
  coapRequest.setDestinationContext(context);
  // Send CoAP request synchronously
  CoapSyncRequestObserver syncMessageObserver = new CoapSyncRequestObserver(coapRequest, timeout);
  coapRequest.addMessageObserver(syncMessageObserver);
  // Store pending request to cancel it on de-registration
  addPendingRequest(destination.getId(), coapRequest);
  // Send CoAP request asynchronously
  Endpoint endpoint = getEndpointForClient(destination);
  endpoint.sendRequest(coapRequest);
  // Wait for response, then return it
  return syncMessageObserver.waitForCoapResponse();
}
origin: eclipse/leshan

@Override
public int cancelObservations(Registration registration) {
  // check registration id
  String registrationId = registration.getId();
  if (registrationId == null)
    return 0;
  Collection<Observation> observations = registrationStore.removeObservations(registrationId);
  if (observations == null)
    return 0;
  for (Observation observation : observations) {
    cancel(observation);
  }
  return observations.size();
}
origin: eclipse/leshan

@Override
public <T extends LwM2mResponse> void send(final Registration destination, final DownlinkRequest<T> request,
    long timeout, ResponseCallback<T> responseCallback, ErrorCallback errorCallback) {
  // Retrieve the objects definition
  final LwM2mModel model = modelProvider.getObjectModel(destination);
  // Create the CoAP request from LwM2m request
  CoapRequestBuilder coapRequestBuilder = new CoapRequestBuilder(destination.getIdentity(),
      destination.getRootPath(), destination.getId(), destination.getEndpoint(), model, encoder);
  request.accept(coapRequestBuilder);
  final Request coapRequest = coapRequestBuilder.getRequest();
  // Add CoAP request callback
  MessageObserver obs = new AsyncRequestObserver<T>(coapRequest, responseCallback, errorCallback, timeout) {
    @Override
    public T buildResponse(Response coapResponse) {
      // Build LwM2m response
      LwM2mResponseBuilder<T> lwm2mResponseBuilder = new LwM2mResponseBuilder<>(coapRequest, coapResponse,
          destination, model, observationService, decoder);
      request.accept(lwm2mResponseBuilder);
      return lwm2mResponseBuilder.getResponse();
    }
  };
  coapRequest.addMessageObserver(obs);
  // Store pending request to cancel it on de-registration
  addPendingRequest(destination.getId(), coapRequest);
  // Send CoAP request asynchronously
  Endpoint endpoint = getEndpointForClient(destination);
  endpoint.sendRequest(coapRequest);
}
origin: eclipse/leshan

@Override
public Deregistration addRegistration(Registration registration) {
  try {
    lock.writeLock().lock();
    Registration registrationRemoved = regsByEp.put(registration.getEndpoint(), registration);
    regsByRegId.put(registration.getId(), registration);
    // If a registration is already associated to this address we don't care as we only want to keep the most
    // recent binding.
    regsByAddr.put(registration.getSocketAddress(), registration);
    if (registrationRemoved != null) {
      Collection<Observation> observationsRemoved = unsafeRemoveAllObservations(registrationRemoved.getId());
      if (!registrationRemoved.getSocketAddress().equals(registration.getSocketAddress())) {
        removeFromMap(regsByAddr, registrationRemoved.getSocketAddress(), registrationRemoved);
      }
      if (!registrationRemoved.getId().equals(registration.getId())) {
        removeFromMap(regsByRegId, registrationRemoved.getId(), registrationRemoved);
      }
      return new Deregistration(registrationRemoved, observationsRemoved);
    }
  } finally {
    lock.writeLock().unlock();
  }
  return null;
}
origin: eclipse/leshan

@Override
public <T extends LwM2mResponse> T send(final Registration destination, final DownlinkRequest<T> request,
    long timeout) throws InterruptedException {
  // Retrieve the objects definition
  final LwM2mModel model = modelProvider.getObjectModel(destination);
  // Create the CoAP request from LwM2m request
  CoapRequestBuilder coapRequestBuilder = new CoapRequestBuilder(destination.getIdentity(),
      destination.getRootPath(), destination.getId(), destination.getEndpoint(), model, encoder);
  request.accept(coapRequestBuilder);
  final Request coapRequest = coapRequestBuilder.getRequest();
  // Send CoAP request synchronously
  SyncRequestObserver<T> syncMessageObserver = new SyncRequestObserver<T>(coapRequest, timeout) {
    @Override
    public T buildResponse(Response coapResponse) {
      // Build LwM2m response
      LwM2mResponseBuilder<T> lwm2mResponseBuilder = new LwM2mResponseBuilder<>(coapRequest, coapResponse,
          destination, model, observationService, decoder);
      request.accept(lwm2mResponseBuilder);
      return lwm2mResponseBuilder.getResponse();
    }
  };
  coapRequest.addMessageObserver(syncMessageObserver);
  // Store pending request to cancel it on de-registration
  addPendingRequest(destination.getId(), coapRequest);
  // Send CoAP request asynchronously
  Endpoint endpoint = getEndpointForClient(destination);
  endpoint.sendRequest(coapRequest);
  // Wait for response, then return it
  return syncMessageObserver.waitForResponse();
}
origin: eclipse/leshan

  @Override
  public void run() {
    try {
      Collection<Registration> allRegs = new ArrayList<>();
      try {
        lock.readLock().lock();
        allRegs.addAll(regsByEp.values());
      } finally {
        lock.readLock().unlock();
      }
      for (Registration reg : allRegs) {
        if (!reg.isAlive()) {
          // force de-registration
          Deregistration removedRegistration = removeRegistration(reg.getId());
          expirationListener.registrationExpired(removedRegistration.getRegistration(),
              removedRegistration.getObservations());
        }
      }
    } catch (Exception e) {
      LOG.warn("Unexpected Exception while registration cleaning", e);
    }
  }
}
origin: eclipse/leshan

/**
 * 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();
}
origin: eclipse/leshan

@Override
public Deregistration removeRegistration(String registrationId) {
  try {
    lock.writeLock().lock();
    Registration registration = getRegistration(registrationId);
    if (registration != null) {
      Collection<Observation> observationsRemoved = unsafeRemoveAllObservations(registration.getId());
      regsByEp.remove(registration.getEndpoint());
      removeFromMap(regsByAddr, registration.getSocketAddress(), registration);
      removeFromMap(regsByRegId, registration.getId(), registration);
      return new Deregistration(registration, observationsRemoved);
    }
    return null;
  } finally {
    lock.writeLock().unlock();
  }
}
origin: eclipse/leshan

public void addObservation(Registration registration, Observation observation) {
  for (Observation existing : registrationStore.addObservation(registration.getId(), observation)) {
    cancel(existing);
  }
  for (ObservationListener listener : listeners) {
    listener.newObservation(observation, registration);
  }
}
origin: eclipse/leshan

@Override
public void cancelPendingRequests(Registration registration) {
  Validate.notNull(registration);
  String registrationId = registration.getId();
  SortedMap<String, Request> requests = pendingRequests.subMap(getFloorKey(registrationId),
      getCeilingKey(registrationId));
  for (Request coapRequest : requests.values()) {
    coapRequest.cancel();
  }
  requests.clear();
}
origin: eclipse/leshan

@Override
public UpdatedRegistration updateRegistration(RegistrationUpdate update) {
  try {
    lock.writeLock().lock();
    Registration registration = getRegistration(update.getRegistrationId());
    if (registration == null) {
      return null;
    } else {
      Registration updatedRegistration = update.update(registration);
      regsByEp.put(updatedRegistration.getEndpoint(), updatedRegistration);
      // If registration is already associated to this address we don't care as we only want to keep the most
      // recent binding.
      regsByAddr.put(updatedRegistration.getSocketAddress(), updatedRegistration);
      if (!registration.getSocketAddress().equals(updatedRegistration.getSocketAddress())) {
        removeFromMap(regsByAddr, registration.getSocketAddress(), registration);
      }
      regsByRegId.put(updatedRegistration.getId(), updatedRegistration);
      return new UpdatedRegistration(registration, updatedRegistration);
    }
  } finally {
    lock.writeLock().unlock();
  }
}
origin: eclipse/leshan

  @Override
  public void run() {
    try (Jedis j = pool.getResource()) {
      Set<byte[]> endpointsExpired = j.zrangeByScore(EXP_EP, Double.NEGATIVE_INFINITY,
          System.currentTimeMillis(), 0, cleanLimit);
      for (byte[] endpoint : endpointsExpired) {
        Registration r = deserializeReg(j.get(toEndpointKey(endpoint)));
        if (!r.isAlive(gracePeriod)) {
          Deregistration dereg = removeRegistration(j, r.getId(), true);
          if (dereg != null)
            expirationListener.registrationExpired(dereg.getRegistration(), dereg.getObservations());
        }
      }
    } catch (Exception e) {
      LOG.warn("Unexpected Exception while registration cleaning", e);
    }
  }
}
origin: org.eclipse.leshan/leshan-server-cluster

  @Override
  public void run() {
    try (Jedis j = pool.getResource()) {
      Set<byte[]> endpointsExpired = j.zrangeByScore(EXP_EP, Double.NEGATIVE_INFINITY,
          System.currentTimeMillis(), 0, cleanLimit);
      for (byte[] endpoint : endpointsExpired) {
        Registration r = deserializeReg(j.get(toEndpointKey(endpoint)));
        if (!r.isAlive(gracePeriod)) {
          Deregistration dereg = removeRegistration(j, r.getId(), true);
          if (dereg != null)
            expirationListener.registrationExpired(dereg.getRegistration(), dereg.getObservations());
        }
      }
    } catch (Exception e) {
      LOG.warn("Unexpected Exception while registration cleaning", e);
    }
  }
}
origin: eclipse/leshan

long nbRemoved = j.del(toRegIdKey(r.getId()));
if (nbRemoved > 0) {
  j.del(toEndpointKey(r.getEndpoint()));
  Collection<Observation> obsRemoved = unsafeRemoveAllObservations(j, r.getId());
  removeAddrIndex(j, r);
  removeExpiration(j, r);
origin: eclipse/leshan

public SendableResponse<DeregisterResponse> deregister(Identity sender, DeregisterRequest deregisterRequest) {
  // We must check if the client is using the right identity.
  Registration registration = registrationService.getById(deregisterRequest.getRegistrationId());
  if (registration == null) {
    return new SendableResponse<>(DeregisterResponse.notFound());
  }
  if (authorizer.isAuthorized(deregisterRequest, registration, sender) == null) {
    // TODO replace by Forbidden if https://github.com/OpenMobileAlliance/OMA_LwM2M_for_Developers/issues/181 is
    // closed.
    return new SendableResponse<>(DeregisterResponse.badRequest("forbidden"));
  }
  final Deregistration deregistration = registrationService.getStore()
      .removeRegistration(deregisterRequest.getRegistrationId());
  if (deregistration != null) {
    LOG.debug("Deregistered client: {}", deregistration.getRegistration());
    // Create callback to notify new de-registration
    Runnable whenSent = new Runnable() {
      @Override
      public void run() {
        registrationService.fireUnregistered(deregistration.getRegistration(),
            deregistration.getObservations(), null);
      };
    };
    return new SendableResponse<>(DeregisterResponse.success(), whenSent);
  } else {
    LOG.debug("Invalid deregistration :  registration {} not found", registration.getId());
    return new SendableResponse<>(DeregisterResponse.notFound());
  }
}
origin: eclipse/leshan

  LOG.debug("Invalid update:  registration {} not found", registration.getId());
  return new SendableResponse<>(UpdateResponse.notFound());
} else {
org.eclipse.leshan.server.registrationRegistrationgetId

Javadoc

Gets the clients identity.

Popular methods of Registration

  • getEndpoint
  • getIdentity
  • getAdditionalRegistrationAttributes
  • getBindingMode
  • getLifeTimeInSec
  • getLwM2mVersion
  • getRegistrationDate
  • getRegistrationEndpointAddress
  • getRootPath
  • getSmsNumber
  • isAlive
  • usesQueueMode
  • isAlive,
  • usesQueueMode,
  • getExpirationTimeStamp,
  • getLastUpdate,
  • getObjectLinks,
  • getSocketAddress,
  • <init>,
  • getAddress,
  • getPort

Popular in Java

  • Finding current android device location
  • onCreateOptionsMenu (Activity)
  • getSupportFragmentManager (FragmentActivity)
  • onRequestPermissionsResult (Fragment)
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
  • 21 Best IntelliJ Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now