org.flexiblepower.observation.ext
T - The type of the observations that this SimpleObservationProvider can send.public class SimpleObservationProvider<T> extends AbstractObservationProvider<T> implements java.io.Closeable
SimpleObservationProvider is used for objects that won't need to implement the
ObservationProvider itself. This helper object can be used as the service that keeps track of connected
ObservationConsumers and can easily send them the Observation through the
AbstractObservationProvider.publish(Observation) method.
The way to using this is using its SimpleObservationProvider.Builder. E.g.:
SimpleObservationProvider<State> provider = SimpleObservationProvider.create(this, State.class)
.observationOf("dishwasher")
.build();
// Now the provider has been registered in the service repository as an ObservationProvider
provider.publish(state);
// When the provider is no longer of use, close it down!
provider.close();
| Modifier and Type | Class and Description |
|---|---|
static class |
SimpleObservationProvider.Builder<T>
This
SimpleObservationProvider.Builder is a helper class to create SimpleObservationProvider. |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
static <T> SimpleObservationProvider.Builder<T> |
create(java.lang.Object source,
java.lang.Class<T> observationType)
This helper method makes it easier to create new
SimpleObservationProvider. |
getLastObservation, publish, subscribe, unsubscribepublic static <T> SimpleObservationProvider.Builder<T> create(java.lang.Object source, java.lang.Class<T> observationType)
SimpleObservationProvider. You just provider the source
object (usually 'this') and the class of the observations that you want to publish here.T - The type of the observations that the SimpleObservationProvider can send.source - The source object that does the observations. This is used to fill the 'observedBy' field.observationType - The class of observations that will be done.SimpleObservationProvider.Builder that can be used to finish upSimpleObservationProvider.Builderpublic void close()
close in interface java.io.Closeable