Skip to content

Commit

Permalink
Remove addObservation from the ObservationRegistry API
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Sangoi authored and msangoi committed Dec 21, 2016
1 parent 64b2776 commit daa5e4a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 59 deletions.

This file was deleted.

Expand Up @@ -38,7 +38,6 @@
import org.eclipse.leshan.core.response.ResponseCallback;
import org.eclipse.leshan.server.client.Registration;
import org.eclipse.leshan.server.model.LwM2mModelProvider;
import org.eclipse.leshan.server.observation.ObservationRegistry;
import org.eclipse.leshan.server.request.LwM2mRequestSender;
import org.eclipse.leshan.server.response.ResponseListener;
import org.eclipse.leshan.server.response.ResponseProcessingTask;
Expand All @@ -48,7 +47,7 @@
public class CaliforniumLwM2mRequestSender implements LwM2mRequestSender {

private final Set<Endpoint> endpoints;
private final ObservationRegistry observationRegistry;
private final CaliforniumObservationRegistryImpl observationRegistry;
private final LwM2mModelProvider modelProvider;
private final LwM2mNodeDecoder decoder;
private final LwM2mNodeEncoder encoder;
Expand All @@ -64,8 +63,9 @@ public class CaliforniumLwM2mRequestSender implements LwM2mRequestSender {
* @param observationRegistry the registry for keeping track of observed resources
* @param modelProvider provides the supported objects definitions
*/
public CaliforniumLwM2mRequestSender(final Set<Endpoint> endpoints, final ObservationRegistry observationRegistry,
LwM2mModelProvider modelProvider, LwM2mNodeEncoder encoder, LwM2mNodeDecoder decoder) {
public CaliforniumLwM2mRequestSender(final Set<Endpoint> endpoints,
final CaliforniumObservationRegistryImpl observationRegistry, LwM2mModelProvider modelProvider,
LwM2mNodeEncoder encoder, LwM2mNodeDecoder decoder) {
Validate.notNull(endpoints);
Validate.notNull(observationRegistry);
Validate.notNull(modelProvider);
Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.californium.core.coap.Request;
import org.eclipse.californium.core.coap.Response;
import org.eclipse.californium.core.network.Endpoint;
import org.eclipse.californium.core.observe.NotificationListener;
import org.eclipse.californium.core.observe.ObservationStore;
import org.eclipse.leshan.ResponseCode;
import org.eclipse.leshan.core.model.LwM2mModel;
Expand All @@ -39,23 +40,23 @@
import org.eclipse.leshan.core.observation.Observation;
import org.eclipse.leshan.core.request.ContentFormat;
import org.eclipse.leshan.core.response.ObserveResponse;
import org.eclipse.leshan.server.californium.CaliforniumObservationRegistry;
import org.eclipse.leshan.server.californium.CaliforniumRegistrationStore;
import org.eclipse.leshan.server.client.Registration;
import org.eclipse.leshan.server.model.LwM2mModelProvider;
import org.eclipse.leshan.server.observation.ObservationRegistry;
import org.eclipse.leshan.server.observation.ObservationRegistryListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Implementation of the {@link CaliforniumObservationRegistry} accessing the persisted observation via the provided
* Implementation of the {@link ObservationRegistry} accessing the persisted observation via the provided
* {@link LwM2mObservationStore}.
*
* When a new observation is added or changed or canceled, the registered listeners are notified.
*/
public class CaliforniumObservationRegistryImpl implements CaliforniumObservationRegistry {
public class CaliforniumObservationRegistryImpl implements ObservationRegistry, NotificationListener {

private final Logger LOG = LoggerFactory.getLogger(CaliforniumObservationRegistry.class);
private final Logger LOG = LoggerFactory.getLogger(CaliforniumObservationRegistryImpl.class);

private final CaliforniumRegistrationStore registrationStore;
private final LwM2mModelProvider modelProvider;
Expand All @@ -72,14 +73,13 @@ public class CaliforniumObservationRegistryImpl implements CaliforniumObservatio
* @param modelProvider instance of {@link LwM2mModelProvider}
* @param decoder instance of {@link LwM2mNodeDecoder}
*/
public CaliforniumObservationRegistryImpl(CaliforniumRegistrationStore store,
LwM2mModelProvider modelProvider, LwM2mNodeDecoder decoder) {
public CaliforniumObservationRegistryImpl(CaliforniumRegistrationStore store, LwM2mModelProvider modelProvider,
LwM2mNodeDecoder decoder) {
this.registrationStore = store;
this.modelProvider = modelProvider;
this.decoder = decoder;
}

@Override
public void addObservation(Observation observation) {
// cancel any other observation for the same path and registration id.
// delegate this to the observation store to avoid race conditions on add/cancel?
Expand All @@ -96,12 +96,10 @@ public void addObservation(Observation observation) {
}
}

@Override
public void setNonSecureEndpoint(Endpoint endpoint) {
nonSecureEndpoint = endpoint;
}

@Override
public void setSecureEndpoint(Endpoint endpoint) {
secureEndpoint = endpoint;
}
Expand Down Expand Up @@ -186,7 +184,9 @@ private Set<Observation> getObservations(String registrationId, String resourceP
return result;
}

@Override
/**
* @return the Californium {@link ObservationStore}
*/
public ObservationStore getObservationStore() {
return registrationStore;
}
Expand Down
Expand Up @@ -45,13 +45,12 @@
import org.eclipse.leshan.server.LwM2mServer;
import org.eclipse.leshan.server.Startable;
import org.eclipse.leshan.server.Stoppable;
import org.eclipse.leshan.server.californium.CaliforniumObservationRegistry;
import org.eclipse.leshan.server.californium.CaliforniumRegistrationStore;
import org.eclipse.leshan.server.californium.LeshanServerBuilder;
import org.eclipse.leshan.server.client.Registration;
import org.eclipse.leshan.server.client.RegistrationUpdate;
import org.eclipse.leshan.server.client.RegistrationListener;
import org.eclipse.leshan.server.client.RegistrationService;
import org.eclipse.leshan.server.client.RegistrationUpdate;
import org.eclipse.leshan.server.impl.RegistrationServiceImpl;
import org.eclipse.leshan.server.model.LwM2mModelProvider;
import org.eclipse.leshan.server.observation.ObservationRegistry;
Expand Down Expand Up @@ -87,7 +86,7 @@ public class LeshanServer implements LwM2mServer {

private final RegistrationServiceImpl registrationService;

private final CaliforniumObservationRegistry observationRegistry;
private final CaliforniumObservationRegistryImpl observationRegistry;

private final SecurityRegistry securityRegistry;

Expand Down
Expand Up @@ -54,7 +54,6 @@
import org.eclipse.leshan.core.response.WriteAttributesResponse;
import org.eclipse.leshan.core.response.WriteResponse;
import org.eclipse.leshan.server.client.Registration;
import org.eclipse.leshan.server.observation.ObservationRegistry;
import org.eclipse.leshan.util.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -66,7 +65,7 @@ public class LwM2mResponseBuilder<T extends LwM2mResponse> implements DownlinkRe
private LwM2mResponse lwM2mresponse;
private final Request coapRequest;
private final Response coapResponse;
private final ObservationRegistry observationRegistry;
private final CaliforniumObservationRegistryImpl observationRegistry;
private final Registration registration;
private final LwM2mModel model;
private final LwM2mNodeDecoder decoder;
Expand Down Expand Up @@ -106,7 +105,8 @@ public static ResponseCode fromCoapCode(final int code) {
}

public LwM2mResponseBuilder(final Request coapRequest, final Response coapResponse, final Registration registration,
final LwM2mModel model, final ObservationRegistry observationRegistry, final LwM2mNodeDecoder decoder) {
final LwM2mModel model, final CaliforniumObservationRegistryImpl observationRegistry,
final LwM2mNodeDecoder decoder) {
this.coapRequest = coapRequest;
this.coapResponse = coapResponse;
this.observationRegistry = observationRegistry;
Expand Down
Expand Up @@ -26,7 +26,6 @@
import org.eclipse.leshan.core.node.LwM2mPath;
import org.eclipse.leshan.core.node.codec.DefaultLwM2mNodeDecoder;
import org.eclipse.leshan.core.observation.Observation;
import org.eclipse.leshan.server.californium.CaliforniumObservationRegistry;
import org.eclipse.leshan.server.californium.CaliforniumRegistrationStore;
import org.eclipse.leshan.server.client.Registration;
import org.eclipse.leshan.server.model.StandardModelProvider;
Expand All @@ -38,7 +37,7 @@ public class CaliforniumObservationTest {

Request coapRequest;
LwM2mPath target;
CaliforniumObservationRegistry registry;
CaliforniumObservationRegistryImpl registry;
CaliforniumRegistrationStore store;

private CaliforniumTestSupport support = new CaliforniumTestSupport();
Expand Down
Expand Up @@ -26,13 +26,6 @@
*/
public interface ObservationRegistry {

/**
* Adds an observation of resource(s) to the registry.
*
* @param observation the observation
*/
void addObservation(Observation observation);

/**
* Cancels all active observations of resource(s) implemented by a particular LWM2M registration.
*
Expand Down

0 comments on commit daa5e4a

Please sign in to comment.