Search in sources :

Example 21 with Registration

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);
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) UpdatedRegistration(org.eclipse.leshan.server.registration.UpdatedRegistration) Registration(org.eclipse.leshan.server.registration.Registration)

Example 22 with Registration

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();
}
Also used : PresenceListener(org.eclipse.leshan.server.queue.PresenceListener) Registration(org.eclipse.leshan.server.registration.Registration)

Example 23 with Registration

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();
            }
        }
    });
}
Also used : RegistrationListener(org.eclipse.leshan.server.registration.RegistrationListener) Registration(org.eclipse.leshan.server.registration.Registration) Observation(org.eclipse.leshan.core.observation.Observation) RegistrationUpdate(org.eclipse.leshan.server.registration.RegistrationUpdate)

Example 24 with Registration

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);
}
Also used : Response(org.eclipse.californium.core.coap.Response) LwM2mResponse(org.eclipse.leshan.core.response.LwM2mResponse) MessageObserver(org.eclipse.californium.core.coap.MessageObserver) Registration(org.eclipse.leshan.server.registration.Registration) Request(org.eclipse.californium.core.coap.Request) DownlinkRequest(org.eclipse.leshan.core.request.DownlinkRequest) AsyncRequestObserver(org.eclipse.leshan.core.californium.AsyncRequestObserver)

Example 25 with Registration

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());
}
Also used : UpdatedRegistration(org.eclipse.leshan.server.registration.UpdatedRegistration) Registration(org.eclipse.leshan.server.registration.Registration) UpdatedRegistration(org.eclipse.leshan.server.registration.UpdatedRegistration) RegistrationUpdate(org.eclipse.leshan.server.registration.RegistrationUpdate) Test(org.junit.Test)

Aggregations

Registration (org.eclipse.leshan.server.registration.Registration)44 Test (org.junit.Test)19 ObserveRequest (org.eclipse.leshan.core.request.ObserveRequest)15 Request (org.eclipse.californium.core.coap.Request)14 CreateRequest (org.eclipse.leshan.core.request.CreateRequest)13 DeleteRequest (org.eclipse.leshan.core.request.DeleteRequest)13 DiscoverRequest (org.eclipse.leshan.core.request.DiscoverRequest)13 ExecuteRequest (org.eclipse.leshan.core.request.ExecuteRequest)13 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)13 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)13 WriteAttributesRequest (org.eclipse.leshan.core.request.WriteAttributesRequest)12 Observation (org.eclipse.leshan.core.observation.Observation)10 UpdatedRegistration (org.eclipse.leshan.server.registration.UpdatedRegistration)10 InetSocketAddress (java.net.InetSocketAddress)7 Jedis (redis.clients.jedis.Jedis)6 RegistrationUpdate (org.eclipse.leshan.server.registration.RegistrationUpdate)5 Deregistration (org.eclipse.leshan.server.registration.Deregistration)4 ContentFormat (org.eclipse.leshan.core.request.ContentFormat)3 LwM2mResponse (org.eclipse.leshan.core.response.LwM2mResponse)3 ObserveResponse (org.eclipse.leshan.core.response.ObserveResponse)3