T - The type of events this event source creates.public abstract class AbstractEventSource<T extends Event> extends java.lang.Object implements EventSource<T>
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
eventType
The ID (name) of the events this event source produces.
|
protected java.util.List<EventHandler> |
handlerList
All handler registered for this event source.
|
protected java.lang.String |
id
The ID of this event source.
|
protected java.util.concurrent.locks.ReadWriteLock |
lock
The lock for synchronising accesses to the list of handler.
|
protected java.util.logging.Logger |
logger
The logger for exceptions that occur when handling an event.
|
protected java.lang.String |
sourceType
The type of this event source.
|
protected java.lang.Thread |
thread
The thread currently running,
null if no thread is running. |
protected java.util.concurrent.locks.ReadWriteLock |
threadLock
The lock for synchronising access to the thread and the interrupt handling.
|
| Constructor and Description |
|---|
AbstractEventSource(Registry registry,
java.lang.String eventType)
Creates a new event source providing the management of registered event
handler.
|
AbstractEventSource(java.lang.String sourceType,
java.lang.String eventType)
Creates a new event source providing the management of registered event
handler.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAll(java.util.List<EventHandler> handler)
Adds the designated event handler in the designated order to the list of
the handler that are already registered.
|
protected void |
addedHandlerLocked(int index,
EventHandler handler)
Signals subclasses that the designated event handler has been added to this event source at the
designated index.
|
protected void |
addedHandlerLocked(java.util.List<EventHandler> handlers)
Signals subclasses that the designated event handlers have been added to this event source at
the end of the list of event handlers.
|
void |
addHandler(EventHandler handler,
int index)
Adds the designated handler at the designated position (0-based) to the
list of registered handler.
|
protected abstract void |
checkForAndHandleEvent()
Checks for an event and handles it (usually by using
forwardEvent(Event, boolean, boolean)). |
protected java.util.regex.Pattern |
createPattern(java.lang.String filter)
Creates a pattern for the designated filter.
|
protected boolean |
forwardEvent(T event,
boolean consumed,
boolean concurrent)
Sends the designated event to all registered event handler.
|
java.util.List<EventHandler> |
getEventHandler()
Gets the event handler that have been registered for this event source.
|
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.
|
java.lang.String |
getType()
Gets the type of this source.
|
protected void |
maskedInterrupt()
Interrupts the current thread if there is one.
|
protected void |
maskInterrupt()
Masks interrupts that occur after calling this method.
|
protected abstract boolean |
nextHandler(T event,
boolean consumed,
boolean concurrent)
This method is called right before an event is offered to the next handler.
|
EventHandler |
removeHandler(java.lang.String handlerID)
Removes the handler with the designated ID from the list and returns it.
|
protected void |
removingHandlerLocked(int index,
EventHandler handler)
Signals subclasses that the designated event handler is about to be removed from the designated
index of the handler list of this event source.
|
protected java.lang.String |
replaceValueParams(java.lang.String value,
InputDataContext dataContext)
Wraps
ParamRefTools#replaceParams(String, InputDataContext) by allowing for
null and the empty string as value. |
void |
run()
This method tracks the running state of this source and delegates to
subclasses for checking for an event and handling it appropriately.
|
void |
setConfiguration(Configuration conf,
java.lang.String id)
Sets the (additional) configuration of this event source and its ID.
|
protected boolean |
unmaskInterrupt()
Unmasks the interrupt once.
|
protected final java.util.logging.Logger logger
protected final java.lang.String sourceType
protected java.lang.String id
protected final java.lang.String eventType
protected final java.util.concurrent.locks.ReadWriteLock lock
protected final java.util.List<EventHandler> handlerList
protected volatile java.lang.Thread thread
null if no thread is running.
This allows to prevent concurrent runs and interrupting runs. threadLock.protected final java.util.concurrent.locks.ReadWriteLock threadLock
public AbstractEventSource(java.lang.String sourceType,
java.lang.String eventType)
sourceType - The type of this event source.eventType - The ID (name) of the events this event source produces.public AbstractEventSource(Registry registry, java.lang.String eventType)
registry - The registry providing the source type of this event
source.eventType - The ID (name) of the events this event source produces.public java.lang.String getType()
EventSourcegetType in interface EventSource<T extends Event>public java.lang.String getID()
EventSourceset this ID is arbitrary
and may even be null.getID in interface EventSource<T extends Event>public java.lang.String getHierarchicalSourceName()
EventSourcegetHierarchicalSourceName in interface EventSource<T extends Event>public void setConfiguration(Configuration conf, java.lang.String id) throws ConfigurationException
EventSourceRunnable.run().setConfiguration in interface EventSource<T 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 java.util.regex.Pattern createPattern(java.lang.String filter)
filter - The filter as string which to transform to a pattern.null in case
the filter is null or the empty string.protected java.lang.String replaceValueParams(java.lang.String value,
InputDataContext dataContext)
throws ConfigurationException
ParamRefTools#replaceParams(String, InputDataContext) by allowing for
null and the empty string as value. In this case
null will be returned.value - The configuration value in which to replace parameter
references.dataContext - The data context with which to replace parameter
references.null.ConfigurationException - If a parameter in the value cannot be
replaced with the designated data context, a
ConfigurationException will be thrown.public java.util.List<EventHandler> getEventHandler()
EventSourcegetEventHandler in interface EventSource<T extends Event>public void addHandler(EventHandler handler, int index)
EventSourceaddHandler in interface EventSource<T extends Event>handler - The handler which to add.index - The index (0-based) at which to add the handler in the list.protected void addedHandlerLocked(int index,
EventHandler handler)
This implementation does nothing as default.
index - The index (position in the list of all handlers) at which the designated handler
has been added to this event source.handler - The event handler which has been added to this event source.addHandler(EventHandler, int)public void addAll(java.util.List<EventHandler> handler)
EventSourceaddAll in interface EventSource<T extends Event>handler - The handler to register in the designated order. They are
added at the end of the list of handler that are already
registered.protected void addedHandlerLocked(java.util.List<EventHandler> handlers)
This implementation does nothing as default.
handlers - The event handlers which have been added to this event source.addAll(List)public EventHandler removeHandler(java.lang.String handlerID)
EventSourcenull
will be returned.removeHandler in interface EventSource<T extends Event>handlerID - The ID of the handler which to remove.null in case no handler with
the designated ID has been registered.protected void removingHandlerLocked(int index,
EventHandler handler)
This implementation does nothing as default.
index - The index (position in the list of all handlers) from which the designated handler
will be removed from this event source.handler - The event handler which is about to be removed from this event source.removeHandler(String)public final void run()
run in interface java.lang.Runnableprotected abstract void checkForAndHandleEvent()
forwardEvent(Event, boolean, boolean)).protected boolean forwardEvent(T event, boolean consumed, boolean concurrent) throws EventHandlingException
EventHandlingException will be rethrown. event - The event to be handled by the registered handler.consumed - Whether the event has been consumed yet.concurrent - Whether the event can be handled concurrently.EventHandlingException - The first exception that occurred when
handling the designated event.protected abstract boolean nextHandler(T event, boolean consumed, boolean concurrent)
event - The event which is about to be handled by the next registered
handler.consumed - Whether the event has been consumed yet.concurrent - Whether the next event handling is concurrent and thus
the event will be offered to several event handler concurrently.false here.protected void maskInterrupt()
protected boolean unmaskInterrupt()
true will be returned. protected void maskedInterrupt()