Class AbstractEventSource<T extends Event>
- java.lang.Object
- 
- de.aristaflow.adept2.core.eventmanager.common.AbstractEventSource<T>
 
- 
- Type Parameters:
- T- The type of events this event source creates.
 - All Implemented Interfaces:
- EventSource<T>,- Runnable
 - Direct Known Subclasses:
- AbstractSharingActEventSource,- DBEventSource,- FileEventSource,- MailEventSource
 
 public abstract class AbstractEventSource<T extends Event> extends Object implements EventSource<T> This abstract class provides the means for managing the handler registered for an event source.- Author:
- Ulrich Kreher
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected StringeventTypeThe ID (name) of the events this event source produces.protected List<EventHandler>handlerListAll handler registered for this event source.protected StringidThe ID of this event source.protected ReadWriteLocklockThe lock for synchronising accesses to the list of handler.protected LoggerloggerThe logger for exceptions that occur when handling an event.protected StringsourceTypeThe type of this event source.protected ThreadthreadThe thread currently running,nullif no thread is running.protected ReadWriteLockthreadLockThe lock for synchronising access to the thread and the interrupt handling.
 - 
Constructor SummaryConstructors Constructor Description AbstractEventSource(Registry registry, String eventType)Creates a new event source providing the management of registered event handler.AbstractEventSource(String sourceType, String eventType)Creates a new event source providing the management of registered event handler.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddAll(List<EventHandler> handler)Adds the designated event handler in the designated order to the list of the handler that are already registered.protected voidaddedHandlerLocked(int index, EventHandler handler)Signals subclasses that the designated event handler has been added to this event source at the designated index.protected voidaddedHandlerLocked(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.voidaddHandler(EventHandler handler, int index)Adds the designated handler at the designated position (0-based) to the list of registered handler.protected abstract voidcheckForAndHandleEvent()Checks for an event and handles it (usually by usingforwardEvent(Event, boolean, boolean)).protected PatterncreatePattern(String filter)Creates a pattern for the designated filter.
 NOTE: This method is used by filtered event sources.protected booleanforwardEvent(T event, boolean consumed, boolean concurrent)Sends the designated event to all registered event handler.List<EventHandler>getEventHandler()Gets the event handler that have been registered for this event source.StringgetHierarchicalSourceName()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.StringgetID()Gets the ID of this source.StringgetType()Gets the type of this source.protected voidmaskedInterrupt()Interrupts the current thread if there is one.protected voidmaskInterrupt()Masks interrupts that occur after calling this method.protected abstract booleannextHandler(T event, boolean consumed, boolean concurrent)This method is called right before an event is offered to the next handler.EventHandlerremoveHandler(String handlerID)Removes the handler with the designated ID from the list and returns it.protected voidremovingHandlerLocked(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 StringreplaceValueParams(String value, InputDataContext dataContext)WrapsParamRefTools#replaceParams(String, InputDataContext)by allowing fornulland the empty string as value.voidrun()This method tracks the running state of this source and delegates to subclasses for checking for an event and handling it appropriately.voidsetConfiguration(org.apache.commons.configuration2.Configuration conf, String id)Sets the (additional) configuration of this event source and its ID.protected booleanunmaskInterrupt()Unmasks the interrupt once.
 
- 
- 
- 
Field Detail- 
loggerprotected final Logger logger The logger for exceptions that occur when handling an event.
 - 
sourceTypeprotected final String sourceType The type of this event source.
 - 
idprotected String id The ID of this event source.
 - 
eventTypeprotected final String eventType The ID (name) of the events this event source produces.
 - 
lockprotected final ReadWriteLock lock The lock for synchronising accesses to the list of handler.
 - 
handlerListprotected final List<EventHandler> handlerList All handler registered for this event source.
 - 
threadprotected volatile Thread thread The thread currently running,nullif no thread is running. This allows to prevent concurrent runs and interrupting runs.
 Synchronise access to this field viathreadLock.
 - 
threadLockprotected final ReadWriteLock threadLock The lock for synchronising access to the thread and the interrupt handling.
 
- 
 - 
Constructor Detail- 
AbstractEventSourcepublic AbstractEventSource(String sourceType, String eventType) Creates a new event source providing the management of registered event handler.- Parameters:
- sourceType- The type of this event source.
- eventType- The ID (name) of the events this event source produces.
 
 - 
AbstractEventSourcepublic AbstractEventSource(Registry registry, String eventType) Creates a new event source providing the management of registered event handler.- Parameters:
- registry- The registry providing the source type of this event source.
- eventType- The ID (name) of the events this event source produces.
 
 
- 
 - 
Method Detail- 
getTypepublic String getType() Description copied from interface:EventSourceGets the type of this source. This is usually the simple instance name of the plugin, if the event source has been loaded as plugin.- Specified by:
- getTypein interface- EventSource<T extends Event>
- Returns:
- The type of this source.
 
 - 
getIDpublic String getID() Description copied from interface:EventSourceGets the ID of this source. Until separatelysetthis ID is arbitrary and may even benull.- Specified by:
- getIDin interface- EventSource<T extends Event>
- Returns:
- The ID of this source.
 
 - 
getHierarchicalSourceNamepublic String getHierarchicalSourceName() Description copied from interface:EventSourceGets 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.- Specified by:
- getHierarchicalSourceNamein interface- EventSource<T extends Event>
- Returns:
- The hierarchical name of this source, that is the event type, the source type and the source ID.
 
 - 
setConfigurationpublic void setConfiguration(org.apache.commons.configuration2.Configuration conf, String id) throws ConfigurationExceptionDescription copied from interface:EventSourceSets the (additional) configuration of this event source and its ID. The configuration is additional with respect to the configuration provided by the plugin load mechanism, if the event source is loaded as plugin.
 It is ensured that this method will be called beforeRunnable.run().- Specified by:
- setConfigurationin interface- EventSource<T extends Event>
- Parameters:
- 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- nulldepends on the implementation of the event source.
- id- The ID of this event source. This must not be- nullnor the empty string.
- Throws:
- ConfigurationException- If there are problems with the designated configuration (configuration is- nullalthough this is not allowed, a required configuration value is missing, ...), a- ConfigurationExceptionwill be thrown.
 
 - 
createPatternprotected Pattern createPattern(String filter) Creates a pattern for the designated filter.
 NOTE: This method is used by filtered event sources.- Parameters:
- filter- The filter as string which to transform to a pattern.
- Returns:
- The pattern for the designated filter or nullin case the filter isnullor the empty string.
 
 - 
replaceValueParamsprotected String replaceValueParams(String value, InputDataContext dataContext) throws ConfigurationException WrapsParamRefTools#replaceParams(String, InputDataContext)by allowing fornulland the empty string as value. In this casenullwill be returned.
 NOTE: This method is used by filtered event activity sources.- Parameters:
- value- The configuration value in which to replace parameter references.
- dataContext- The data context with which to replace parameter references.
- Returns:
- A string having all parameter references in the value replaced or
         null.
- Throws:
- ConfigurationException- If a parameter in the value cannot be replaced with the designated data context, a- ConfigurationExceptionwill be thrown.
 
 - 
getEventHandlerpublic List<EventHandler> getEventHandler() Description copied from interface:EventSourceGets the event handler that have been registered for this event source. These handler are notified about an event in the designated order.- Specified by:
- getEventHandlerin interface- EventSource<T extends Event>
- Returns:
- The event handler that have been registered for this event source.
 
 - 
addHandlerpublic void addHandler(EventHandler handler, int index) Description copied from interface:EventSourceAdds the designated handler at the designated position (0-based) to the list of registered handler. It is not checked, whether the handler is already registered.- Specified by:
- addHandlerin interface- EventSource<T extends Event>
- Parameters:
- handler- The handler which to add.
- index- The index (0-based) at which to add the handler in the list.
 
 - 
addedHandlerLockedprotected void addedHandlerLocked(int index, EventHandler handler)Signals subclasses that the designated event handler has been added to this event source at the designated index. The write lock for adding is still held.
 This implementation does nothing as default. - Parameters:
- 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.
- See Also:
- addHandler(EventHandler, int)
 
 - 
addAllpublic void addAll(List<EventHandler> handler) Description copied from interface:EventSourceAdds the designated event handler in the designated order to the list of the handler that are already registered. It is not checked whether a handler is already registered (and neither whether a handler is several times in the designated list.- Specified by:
- addAllin interface- EventSource<T extends Event>
- Parameters:
- handler- The handler to register in the designated order. They are added at the end of the list of handler that are already registered.
 
 - 
addedHandlerLockedprotected void addedHandlerLocked(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. The write lock for adding is still held.
 This implementation does nothing as default. - Parameters:
- handlers- The event handlers which have been added to this event source.
- See Also:
- addAll(List)
 
 - 
removeHandlerpublic EventHandler removeHandler(String handlerID) Description copied from interface:EventSourceRemoves the handler with the designated ID from the list and returns it. If there is no handler registered with the designated ID,nullwill be returned.- Specified by:
- removeHandlerin interface- EventSource<T extends Event>
- Parameters:
- handlerID- The ID of the handler which to remove.
- Returns:
- The removed handler or nullin case no handler with the designated ID has been registered.
 
 - 
removingHandlerLockedprotected 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. The write lock for removing is still held.This implementation does nothing as default. - Parameters:
- 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.
- See Also:
- removeHandler(String)
 
 - 
runpublic final void run() This method tracks the running state of this source and delegates to subclasses for checking for an event and handling it appropriately. It is ensured that it is not run concurrently on an event source instance. Additionally the handler list will be read locked.
 - 
checkForAndHandleEventprotected abstract void checkForAndHandleEvent() Checks for an event and handles it (usually by usingforwardEvent(Event, boolean, boolean)).
 - 
forwardEventprotected boolean forwardEvent(T event, boolean consumed, boolean concurrent) throws EventHandlingException Sends the designated event to all registered event handler. Concurrent event handling is done if the caller of this method allows it and there are appropriate event handler. Exceptions from the event handling will be logged and handling will continue. However, the first occurredEventHandlingExceptionwill be rethrown.
 Depending on whether the handler is interruptible or not, while event handling interrupts will be masked. If a masked interrupt occurs, the interrupt flag will be set and this method will return early, that is before all event handler have been notified.- Parameters:
- 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.
- Returns:
- Whether the event has been consumed by one of the registered handler.
- Throws:
- EventHandlingException- The critical exception that occurred when handling the designated event having other occurred non-critical exceptions as suppressed ones.
 
 - 
nextHandlerprotected abstract boolean nextHandler(T event, boolean consumed, boolean concurrent) This method is called right before an event is offered to the next handler. In case of concurrent handling, this method will only be called once for all concurrent handling but this will be indicated by the corresponding parameter.- Parameters:
- 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.
- Returns:
- Whether the event handling may continue. In case of serious
         problems preventing further event handling, return
         falsehere.
 
 - 
maskInterruptprotected void maskInterrupt() Masks interrupts that occur after calling this method. This is reentrant, that is masking is totalled.
 - 
unmaskInterruptprotected boolean unmaskInterrupt() Unmasks the interrupt once. If there are no more masks and an interrupt occurred while being masked,truewill be returned.
 Note that a pending interrupt will be set as interrupt in the thread but just as return value of this method.- Returns:
- Whether an interrupt occurred while being masked but only if no more masks are left.
 
 - 
maskedInterruptprotected void maskedInterrupt() Interrupts the current thread if there is one. If the current thread masks its interrupts, the interrupt will remain pending until the thread has unmasked completely.
 
- 
 
-