Class InMemoryObservationStore
java.lang.Object
org.eclipse.californium.core.observe.InMemoryObservationStore
- All Implemented Interfaces:
ObservationStore
An observation store that keeps all observations in-memory.
-
Constructor Summary
ConstructorDescriptionInMemoryObservationStore
(org.eclipse.californium.elements.config.Configuration config) -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all observations from this store.Gets the observation initiated by the request with the given token.int
getSize()
Gets the number of observations currently held in this store.boolean
isEmpty()
Checks if this store is empty.put
(Token key, Observation obs) Adds an observation to the store using the provided token.putIfAbsent
(Token key, Observation obs) Adds an observation to the store using the provided token, if not already added with that token.void
Removes the observation initiated by the request with the given token.void
setContext
(Token token, org.eclipse.californium.elements.EndpointContext ctx) Sets the endpoint context on the observation initiated by the request with the given token.void
setExecutor
(ScheduledExecutorService executor) Set executor for this store.void
start()
void
stop()
-
Constructor Details
-
InMemoryObservationStore
public InMemoryObservationStore(org.eclipse.californium.elements.config.Configuration config)
-
-
Method Details
-
setExecutor
Description copied from interface:ObservationStore
Set executor for this store. Executor is not managed by the store, it must be shutdown externally, if the resource should be freed.- Specified by:
setExecutor
in interfaceObservationStore
- Parameters:
executor
- intended to be used for rare executing timers (e.g. cleanup tasks).
-
putIfAbsent
Description copied from interface:ObservationStore
Adds an observation to the store using the provided token, if not already added with that token. Preserve previous stored observation with that token.- Specified by:
putIfAbsent
in interfaceObservationStore
- Parameters:
key
- unique token to add the provided observation.obs
- The observation to add.- Returns:
- the previous value associated with the specified key, or
null
if there was no mapping for the key.
-
put
Description copied from interface:ObservationStore
Adds an observation to the store using the provided token. Potentially replaces previous stored observation with that token.- Specified by:
put
in interfaceObservationStore
- Parameters:
key
- unique token to add the provided observation.obs
- The observation to add.- Returns:
- the previous value associated with the specified key, or
null
if there was no mapping for the key.
-
get
Description copied from interface:ObservationStore
Gets the observation initiated by the request with the given token.- Specified by:
get
in interfaceObservationStore
- Parameters:
token
- The token of the initiating request.- Returns:
- The corresponding observation or
null
if no observation is registered for the given token.
-
remove
Description copied from interface:ObservationStore
Removes the observation initiated by the request with the given token.- Specified by:
remove
in interfaceObservationStore
- Parameters:
token
- The token of the observation to remove.
-
isEmpty
public boolean isEmpty()Checks if this store is empty.- Returns:
true
if this store does not contain any observations.
-
getSize
public int getSize()Gets the number of observations currently held in this store.- Returns:
- The number of observations.
-
clear
public void clear()Removes all observations from this store. -
setContext
Description copied from interface:ObservationStore
Sets the endpoint context on the observation initiated by the request with the given token.This method is necessary because the endpoint context may not be known when the observation is originally registered. This is due to the fact that the information contained in the endpoint context is gathered by the transport layer when the request establishing the observation is sent to the peer.
- Specified by:
setContext
in interfaceObservationStore
- Parameters:
token
- The token of the observation to set the context on.ctx
- The context to set.
-
start
public void start()- Specified by:
start
in interfaceObservationStore
-
stop
public void stop()- Specified by:
stop
in interfaceObservationStore
-