Class DBEventSource
java.lang.Object
de.aristaflow.adept2.core.eventmanager.common.AbstractEventSource<ResultSetEvent>
de.aristaflow.adept2.core.eventmanager.dbevents.DBEventSource
- All Implemented Interfaces:
EventSource<ResultSetEvent>,PollingSource<ResultSetEvent>,ResultSetSource,Runnable
- Direct Known Subclasses:
DBActivityEventSource,ReadOnlyRSEventSource
public class DBEventSource
extends AbstractEventSource<ResultSetEvent>
implements PollingSource<ResultSetEvent>, ResultSetSource
A source for events based on SQL statements, that is a SQL statement is
executed regularly and the result set (if one exists) is notified as event to
the corresponding event handler.
This event source terminates as soon as an event has been handled by all registered handler.
This event source terminates as soon as an event has been handled by all registered handler.
To simplify events caused by non-existence, the event source can be configured to send the event only if the result set is empty. In this case the empty result set will be attached to the event.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe simple instance name of the data source which to poll for the event.protected final DefaultEventManagerThe event manager of this data source providing the connection to the data source.protected StringThe URL to connect to the database.protected StringThe fully-qualified name of the class of the JDBC-driver.protected StringThe password to log on a the database with.protected StringThe name of the user to log on at the database with.protected BooleanWhether the event should be produced in case the result set is empty.protected LongThe time in milliseconds this event source polls its data source.protected StringThe statement which is executed and provides the result set for the event.protected LongThe start point (in milliseconds) this event should start polling.Fields inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventSource
eventType, handlerList, id, lock, logger, sourceType, thread, threadLockFields inherited from interface de.aristaflow.adept2.model.events.sources.PollingSource
CONF_POLL_TIME, CONF_START_TIMEFields inherited from interface de.aristaflow.adept2.model.events.sources.ResultSetSource
CONF_DATA_SOURCE_NAME, CONF_JDBC_CONNECTION_URL, CONF_JDBC_DRIVER, CONF_JDBC_PASSWORD, CONF_JDBC_USER_NAME, CONF_NOTIFY_EMPTY_ONLY, CONF_SELECT_STATEMENT -
Constructor Summary
ConstructorsConstructorDescriptionDBEventSource(Configuration conf, DefaultEventManager eventManager, Registry registry) Default constructor for a plugin of theDefaultEventManagercalled by a service registry. -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks for an event and handles it (usually by usingAbstractEventSource.forwardEvent(Event, boolean, boolean)).protected ResultSetEventcreateResultSetEvent(ResultSet resultSet) Creates aResultSetEventfor the designated result set.longGets the time in milliseconds this event source polls, more precisely, the time span between two polls.longGets the absolute time in milliseconds since midnight, January 1, 1970 UTC when this polling source should start polling.protected booleannextHandler(ResultSetEvent event, boolean consumed, boolean concurrent) This method is called right before an event is offered to the next handler.protected voidsetConfiguration(Configuration conf, boolean completed) Sets the internal fields according to the values of the designated configuration.voidsetConfiguration(Configuration conf, String id) Sets the (additional) configuration of this event source and its ID.protected voidThis method verifies whether the required configuration values and the data context have been set yet.Methods inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventSource
addAll, addedHandlerLocked, addedHandlerLocked, addHandler, createPattern, forwardEvent, getEventHandler, getHierarchicalSourceName, getID, getType, maskedInterrupt, maskInterrupt, removeHandler, removingHandlerLocked, replaceValueParams, run, unmaskInterruptMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface de.aristaflow.adept2.model.events.sources.EventSource
addAll, addHandler, getEventHandler, getHierarchicalSourceName, getID, getType, removeHandlerMethods inherited from interface de.aristaflow.adept2.model.events.sources.PollingSource
init, terminate
-
Field Details
-
pollTime
The time in milliseconds this event source polls its data source. -
startTime
The start point (in milliseconds) this event should start polling. -
dataSource
The simple instance name of the data source which to poll for the event. This is not required if the driver, the connection URL, the user name and the password are provided instead. If all are provided, the data source will be used. -
jdbcDriver
The fully-qualified name of the class of the JDBC-driver. This is only required if no data source is provided. -
jdbcConnectionURL
The URL to connect to the database. This is only required if no data source is provided. -
jdbcUserName
The name of the user to log on at the database with. This is only required if no data source is provided. -
jdbcPassword
The password to log on a the database with. This is only required if no data source is provided. -
selectStatement
The statement which is executed and provides the result set for the event. -
notifyEmptyOnly
Whether the event should be produced in case the result set is empty. -
eventManager
The event manager of this data source providing the connection to the data source.
-
-
Constructor Details
-
DBEventSource
public DBEventSource(Configuration conf, DefaultEventManager eventManager, Registry registry) throws ConfigurationException Default constructor for a plugin of theDefaultEventManagercalled by a service registry.Note that this constructor calls
setConfiguration(Configuration, boolean); subclasses may not be fully initialised at this point.- Parameters:
conf- The configuration as provided from the registry.eventManager- The event manager this event source is a plugin of.registry- The registry of this plugin.- Throws:
ConfigurationException- If the configuration is not valid for aResultSetSource, aConfigurationExceptionwill be thrown.
-
-
Method Details
-
setConfiguration
protected void setConfiguration(Configuration conf, boolean completed) throws ConfigurationException Sets the internal fields according to the values of the designated configuration. Note that this method is called from the constructor and therefore this object may not be fully initialised!- Parameters:
conf- The configuration from which to get the configuration values.completed- Whether the configuration is complete after this setting and therefore the values should be verified.- Throws:
ConfigurationException- If there are problems with the configuration, for instance the configuration does not provide required values, aConfigurationExceptionmay be thrown.
-
verifyConfigurationValues
This method verifies whether the required configuration values and the data context have been set yet. If configuration values or the data context are missing or inappropriate, aConfigurationExceptionwill be thrown.- Throws:
ConfigurationException- If there are problems with the configuration, for instance the configuration does not provide required values or the data context is not set, aConfigurationExceptionmay be thrown.
-
setConfiguration
Description 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 interfaceEventSource<ResultSetEvent>- Overrides:
setConfigurationin classAbstractEventSource<ResultSetEvent>- 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 benulldepends on the implementation of the event source.id- The ID of this event source. This must not benullnor the empty string.- Throws:
ConfigurationException- If there are problems with the designated configuration (configuration isnullalthough this is not allowed, a required configuration value is missing, ...), aConfigurationExceptionwill be thrown.
-
getPollTime
public long getPollTime()Description copied from interface:PollingSourceGets the time in milliseconds this event source polls, more precisely, the time span between two polls. If this is 0 or negative, no polling will apply. However,PollingSource.init()andPollingSource.terminate()will be called.- Specified by:
getPollTimein interfacePollingSource<ResultSetEvent>- Returns:
- The time in milliseconds this event source polls (> 0).
-
getStartTime
public long getStartTime()Description copied from interface:PollingSourceGets the absolute time in milliseconds since midnight, January 1, 1970 UTC when this polling source should start polling. This is used for calculating the first poll time by adding the time span defined inPollingSource.getPollTime().- Specified by:
getStartTimein interfacePollingSource<ResultSetEvent>- Returns:
- The absolute time in milliseconds since midnight, January 1, 1970 UTC when this polling source should start polling.
-
checkForAndHandleEvent
public void checkForAndHandleEvent()Description copied from class:AbstractEventSourceChecks for an event and handles it (usually by usingAbstractEventSource.forwardEvent(Event, boolean, boolean)).- Specified by:
checkForAndHandleEventin classAbstractEventSource<ResultSetEvent>
-
createResultSetEvent
Creates aResultSetEventfor the designated result set.- Parameters:
resultSet- The result set for which to create aResultSetEvent.- Returns:
- The
ResultSetEventcreated for the designated result set.
-
nextHandler
Description copied from class:AbstractEventSourceThis 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.- Specified by:
nextHandlerin classAbstractEventSource<ResultSetEvent>- 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.
-