E - The type of the event.S - The type of the SharingSource.public abstract class AbstractSharedEventSource<E extends Event,S extends SharingSource<E>> extends java.lang.Object implements SharedPollingSource<E>
This way, sharing event sources do not need to poll separately but can share the same resources when checking for their respective event.
| Modifier and Type | Field and Description |
|---|---|
protected DefaultEventManager |
eventManager
The event manager of this event source providing the connection to the event source.
|
protected java.lang.String |
eventType
The event type, cf
Event.getEventType(). |
protected Configuration |
initConf
The configuration of this event source that is shared by all sharing sources.
|
protected java.util.logging.Logger |
logger
The logger for exceptions that occur when handling an event.
|
protected java.lang.Class<S> |
sharingSourceClass
The
SharingSource type this event source is using. |
protected java.util.concurrent.locks.ReadWriteLock |
sourceLock
|
protected java.util.Map<java.util.List<java.io.Serializable>,java.util.List<S>> |
sources
All sharing sources registered at this shared source, indexed by their identifying values and
in the order they have been added to this sharing event source.
|
protected java.lang.String |
sourceType
The type of this shared DB event source.
|
CONF_POLL_TIME, CONF_START_TIME| Constructor and Description |
|---|
AbstractSharedEventSource(Configuration conf,
DefaultEventManager eventManager,
Registry registry,
java.lang.Class<S> sharingSourceClass,
java.lang.String eventType,
java.lang.String sourceType)
Default constructor for a plugin of the
DefaultEventManager called by a service
registry. |
| Modifier and Type | Method and Description |
|---|---|
void |
addAll(java.util.List<EventHandler> handlers)
Adds the designated event handler in the designated order to the list of
the handler that are already registered.
|
protected boolean |
addedSharingSourceLocked(java.util.List<java.io.Serializable> sourceKeys,
S source)
Signals subclasses that the designated sharing source has been added to this shared source.
|
void |
addHandler(EventHandler handler,
int index)
Adds the designated handler at the designated position (0-based) to the
list of registered handler.
|
boolean |
addSharingSource(SharingSource<?> source)
Adds the designated sharing source at this shared source.
|
java.util.List<EventHandler> |
getEventHandler()
Gets the event handler that have been registered for this event source.
|
protected java.lang.String |
getEventType()
Gets the type of the events, this shared event source generates.
|
java.lang.String |
getHierarchicalSourceName()
Gets the hierarchical name of this source, that is the event type, the
source type and the source ID for usage in log messages and alike.
|
java.lang.String |
getID()
Gets the ID of this source.
|
protected abstract java.util.List<java.io.Serializable> |
getSourceKeys(S source)
Gets the data (key values) that identifies the designated sharing event source.
|
java.lang.String |
getType()
Gets the type of this source.
|
void |
init()
Initialises this polling source.
|
protected void |
parseConfiguration(Configuration conf)
Parses the designated (initial) configuration.
|
EventHandler |
removeHandler(java.lang.String handlerID)
Removes the handler with the designated ID from the list and returns it.
|
boolean |
removeSharingSource(SharingSource<?> source)
Removes the designated sharing source from this shared source.
|
protected void |
removingSharingSourceLocked(java.util.List<java.io.Serializable> sourceKeys,
SharingSource<?> source)
Signals subclasses that the designated sharing source is about to be removed from this shared
source.
|
void |
setConfiguration(Configuration conf,
java.lang.String id)
Sets the (additional) configuration of this event source and its ID.
|
boolean |
supportsSharingSource(SharingSource<?> source)
Gets whether this shared source can handle the designated sharing source
and combine it with the already registered sharing sources.
|
void |
terminate()
Terminates this polling source.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetPollTime, getStartTimeprotected final java.util.logging.Logger logger
protected final java.lang.Class<S extends SharingSource<E>> sharingSourceClass
SharingSource type this event source is using.protected final java.lang.String eventType
Event.getEventType().protected final java.lang.String sourceType
protected Configuration initConf
setConfiguration(Configuration, String).protected final java.util.concurrent.locks.ReadWriteLock sourceLock
protected final java.util.Map<java.util.List<java.io.Serializable>,java.util.List<S extends SharingSource<E>>> sources
protected final DefaultEventManager eventManager
public AbstractSharedEventSource(Configuration conf, DefaultEventManager eventManager, Registry registry, java.lang.Class<S> sharingSourceClass, java.lang.String eventType, java.lang.String sourceType)
DefaultEventManager called by a service
registry.conf - The configuration as provided from the registry. Since this is a shared event
source, the configuration will be ignored and only the
explicitly set configuration will be
used. This is usually a configuration of a/all sharing event sources.eventManager - The event manager this event source is a plugin of.registry - The registry of this plugin.sharingSourceClass - The class of S, used for type checks.eventType - The event type, cf. Event.getEventType().sourceType - The name of the source type.protected java.lang.String getEventType()
Event.getEventType()public java.lang.String getType()
EventSourcegetType in interface EventSource<E extends Event>public java.lang.String getID()
EventSourceset this ID is arbitrary
and may even be null.getID in interface EventSource<E extends Event>public java.lang.String getHierarchicalSourceName()
EventSourcegetHierarchicalSourceName in interface EventSource<E extends Event>public void setConfiguration(Configuration conf, java.lang.String id) throws ConfigurationException
EventSourceRunnable.run().setConfiguration in interface EventSource<E extends Event>conf - The configuration of this event source. This adheres (and
overwrites) the configuration provided by the plugin loading, if
this event source has been loaded as plugin. Whether this is
allowed to be null depends on the implementation of
the event source.id - The ID of this event source. This must not be null
nor the empty string.ConfigurationException - If there are problems with the designated
configuration (configuration is null although this
is not allowed, a required configuration value is missing, ...),
a ConfigurationException will be thrown.protected void parseConfiguration(Configuration conf) throws ConfigurationException
This implementation does nothing as default.
conf - The configuration to parse the required configuration values from.ConfigurationException - If there are problems with the designated configuration, for
instance the configuration does not provide required values, a
ConfigurationException may be thrown.public java.util.List<EventHandler> getEventHandler()
EventSourcegetEventHandler in interface EventSource<E extends Event>public void addHandler(EventHandler handler, int index)
EventSourceaddHandler in interface EventSource<E extends Event>handler - The handler which to add.index - The index (0-based) at which to add the handler in the list.public void addAll(java.util.List<EventHandler> handlers)
EventSourceaddAll in interface EventSource<E extends Event>handlers - The handler to register in the designated order. They are
added at the end of the list of handler that are already
registered.public EventHandler removeHandler(java.lang.String handlerID)
EventSourcenull
will be returned.removeHandler in interface EventSource<E extends Event>handlerID - The ID of the handler which to remove.null in case no handler with
the designated ID has been registered.public void init()
PollingSourceinit in interface PollingSource<E extends Event>public void terminate()
PollingSourceterminate in interface PollingSource<E extends Event>public boolean supportsSharingSource(SharingSource<?> source)
supportsSharingSource in interface SharedPollingSource<E extends Event>source - The source that wants to share a source for polling.public boolean addSharingSource(SharingSource<?> source)
SharedPollingSourceaddSharingSource in interface SharedPollingSource<E extends Event>source - The source that wants to share a source for polling.SharedPollingSource.supportsSharingSource(SharingSource).protected boolean addedSharingSourceLocked(java.util.List<java.io.Serializable> sourceKeys,
S source)
false. In
this case the sharing source will be removed from this shared source. supportsSharingSource(SharingSource) has already been called before calling
this method.
This implementation does nothing as default.
sourceKeys - The data (key values) of the designated source which also identify it.source - The sharing source which has been added and should be added to this shared
source.addSharingSource(SharingSource)public boolean removeSharingSource(SharingSource<?> source)
SharedPollingSourceremoveSharingSource in interface SharedPollingSource<E extends Event>source - The source that does no longer want to share a source for
polling.protected void removingSharingSourceLocked(java.util.List<java.io.Serializable> sourceKeys,
SharingSource<?> source)
This implementation does nothing as default.
sourceKeys - The data (key values) of the designated source which also identify it.source - The sharing source which is about to be removed from this shared source.removeSharingSource(SharingSource)protected abstract java.util.List<java.io.Serializable> getSourceKeys(S source) throws InvalidDataTypeException, NoSuchParameterException
source - The sharing event source for which to retrieve the key values identifying it.InvalidDataTypeException - If a parameter reference identifying the designated sharing
event source has not the same data type as in the data context, an
InvalidDataTypeException will be thrown.NoSuchParameterException - If a parameter reference identifying the designated sharing
event source is not in the data context, an InvalidDataTypeException
will be thrown.