use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class RedisRegistrationStore method removeObservations.
@Override
public Collection<Observation> removeObservations(String registrationId) {
try (Jedis j = pool.getResource()) {
// check registration exists
Registration registration = getRegistration(j, registrationId);
if (registration == null)
return Collections.emptyList();
// get endpoint and create lock
String endpoint = registration.getEndpoint();
byte[] lockValue = null;
byte[] lockKey = toKey(LOCK_EP, endpoint);
try {
lockValue = RedisLock.acquire(j, lockKey);
return unsafeRemoveAllObservations(j, registrationId);
} finally {
RedisLock.release(j, lockKey, lockValue);
}
}
}
use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class QueueModeIntegrationTestHelper method createServer.
public void createServer(int clientAwakeTime) {
server = createServerBuilder(clientAwakeTime).build();
awakeNotifications.set(0);
server.getPresenceService().addListener(new PresenceListener() {
@Override
public void onAwake(Registration registration) {
if (registration.getEndpoint().equals(currentEndpointIdentifier.get())) {
awakeNotifications.addAndGet(1);
}
}
@Override
public void onSleeping(Registration registration) {
awakeNotifications.set(0);
awakeLatch.countDown();
}
});
// monitor client registration
setupRegistrationMonitoring();
}
use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class IntegrationTestHelper method setupRegistrationMonitoring.
protected void setupRegistrationMonitoring() {
resetLatch();
server.getRegistrationService().addListener(new RegistrationListener() {
@Override
public void updated(RegistrationUpdate update, Registration updatedRegistration, Registration previousRegistration) {
if (updatedRegistration.getEndpoint().equals(currentEndpointIdentifier.get())) {
updateLatch.countDown();
}
}
@Override
public void unregistered(Registration registration, Collection<Observation> observations, boolean expired, Registration newReg) {
if (registration.getEndpoint().equals(currentEndpointIdentifier.get())) {
deregisterLatch.countDown();
}
}
@Override
public void registered(Registration registration, Registration previousReg, Collection<Observation> previousObsersations) {
if (registration.getEndpoint().equals(currentEndpointIdentifier.get())) {
last_registration = registration;
registerLatch.countDown();
}
}
});
}
use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class CaliforniumLwM2mBootstrapRequestSender method send.
@Override
public <T extends LwM2mResponse> void send(final String endpointName, final Identity destination, final DownlinkRequest<T> request, final long timeout, ResponseCallback<T> responseCallback, ErrorCallback errorCallback) {
// Create the CoAP request from LwM2m request
CoapRequestBuilder coapClientRequestBuilder = new CoapRequestBuilder(destination, model, encoder);
request.accept(coapClientRequestBuilder);
final Request coapRequest = coapClientRequestBuilder.getRequest();
// Add CoAP request callback
MessageObserver obs = new AsyncRequestObserver<T>(coapRequest, responseCallback, errorCallback, timeout) {
@Override
public T buildResponse(Response coapResponse) {
// TODO we need to fix that by removing the Client dependency from LwM2MResponseBuilder or by creating a
// LwM2mBootstrapResponseBuilder
Registration registration = new Registration.Builder("fakeregistrationid", endpointName, destination, destination.isSecure() ? secureEndpoint.getAddress() : nonSecureEndpoint.getAddress()).build();
// Build LwM2m response
LwM2mResponseBuilder<T> lwm2mResponseBuilder = new LwM2mResponseBuilder<>(coapRequest, coapResponse, registration, model, null, decoder);
request.accept(lwm2mResponseBuilder);
return lwm2mResponseBuilder.getResponse();
}
};
coapRequest.addMessageObserver(obs);
// Send CoAP request asynchronously
if (destination.isSecure())
secureEndpoint.sendRequest(coapRequest);
else
nonSecureEndpoint.sendRequest(coapRequest);
}
use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class InMemoryRegistrationStoreTest method update_registration_keeps_properties_unchanged.
@Test
public void update_registration_keeps_properties_unchanged() {
givenASimpleRegistration(lifetime);
store.addRegistration(registration);
RegistrationUpdate update = new RegistrationUpdate(registrationId, Identity.unsecure(address, port), null, null, null, null, null);
UpdatedRegistration updatedRegistration = store.updateRegistration(update);
Assert.assertEquals(lifetime, updatedRegistration.getUpdatedRegistration().getLifeTimeInSec());
Assert.assertSame(binding, updatedRegistration.getUpdatedRegistration().getBindingMode());
Assert.assertEquals(sms, updatedRegistration.getUpdatedRegistration().getSmsNumber());
Assert.assertEquals(registration, updatedRegistration.getPreviousRegistration());
Registration reg = store.getRegistrationByEndpoint(ep);
Assert.assertEquals(lifetime, reg.getLifeTimeInSec());
Assert.assertSame(binding, reg.getBindingMode());
Assert.assertEquals(sms, reg.getSmsNumber());
}
Aggregations