public class DBEventSource extends AbstractEventSource<ResultSetEvent> implements PollingSource<ResultSetEvent>, ResultSetSource
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.
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
dataSource
The simple instance name of the data source which to poll for the event.
|
protected DefaultEventManager |
eventManager
The event manager of this data source providing the connection to the data
source.
|
protected java.lang.String |
jdbcConnectionURL
The URL to connect to the database.
|
protected java.lang.String |
jdbcDriver
The fully-qualified name of the class of the JDBC-driver.
|
protected java.lang.String |
jdbcPassword
The password to log on a the database with.
|
protected java.lang.String |
jdbcUserName
The name of the user to log on at the database with.
|
protected java.lang.Boolean |
notifyEmptyOnly
Whether the event should be produced in case the result set is empty.
|
protected java.lang.Long |
pollTime
The time in milliseconds this event source polls its data source.
|
protected java.lang.String |
selectStatement
The statement which is executed and provides the result set for the event.
|
protected java.lang.Long |
startTime
The start point (in milliseconds) this event should start polling.
|
eventType, handlerList, id, lock, logger, sourceType, thread, threadLockCONF_POLL_TIME, CONF_START_TIMECONF_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 and Description |
|---|
DBEventSource(Configuration conf,
DefaultEventManager eventManager,
Registry registry)
Default constructor for a plugin of the
DefaultEventManager
called by a service registry. |
| Modifier and Type | Method and Description |
|---|---|
void |
checkForAndHandleEvent()
Checks for an event and handles it (usually by using
AbstractEventSource.forwardEvent(Event, boolean, boolean)). |
protected ResultSetEvent |
createResultSetEvent(java.sql.ResultSet resultSet)
Creates a
ResultSetEvent for the designated result set. |
long |
getPollTime()
Gets the time in milliseconds this event source polls, more precisely, the
time span between two polls.
|
long |
getStartTime()
Gets the absolute time in milliseconds since midnight, January 1, 1970 UTC
when this polling source should start polling.
|
void |
init()
Initialises this polling source.
|
protected boolean |
nextHandler(ResultSetEvent event,
boolean consumed,
boolean concurrent)
This method is called right before an event is offered to the next handler.
|
protected void |
setConfiguration(Configuration conf,
boolean completed)
Sets the internal fields according to the values of the designated
configuration.
|
void |
setConfiguration(Configuration conf,
java.lang.String id)
Sets the (additional) configuration of this event source and its ID.
|
void |
terminate()
Terminates this polling source.
|
protected void |
verifyConfigurationValues()
This method verifies whether the required configuration values and the data
context have been set yet.
|
addAll, addedHandlerLocked, addedHandlerLocked, addHandler, createPattern, forwardEvent, getEventHandler, getHierarchicalSourceName, getID, getType, maskedInterrupt, maskInterrupt, removeHandler, removingHandlerLocked, replaceValueParams, run, unmaskInterruptclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddAll, addHandler, getEventHandler, getHierarchicalSourceName, getID, getType, removeHandlerprotected java.lang.Long pollTime
protected java.lang.Long startTime
protected java.lang.String dataSource
protected java.lang.String jdbcDriver
protected java.lang.String jdbcConnectionURL
protected java.lang.String jdbcUserName
protected java.lang.String jdbcPassword
protected java.lang.String selectStatement
protected java.lang.Boolean notifyEmptyOnly
protected final DefaultEventManager eventManager
public DBEventSource(Configuration conf, DefaultEventManager eventManager, Registry registry) throws ConfigurationException
DefaultEventManager
called by a service registry.
Note that this constructor calls
setConfiguration(Configuration, boolean); subclasses may not be
fully initialised at this point.
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.ConfigurationException - If the configuration is not valid for a
ResultSetSource, a ConfigurationException
will be thrown.protected void setConfiguration(Configuration conf, boolean completed) throws ConfigurationException
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.ConfigurationException - If there are problems with the
configuration, for instance the configuration does not provide
required values, a ConfigurationException may be
thrown.protected void verifyConfigurationValues()
throws ConfigurationException
ConfigurationException will be
thrown.ConfigurationException - If there are problems with the
configuration, for instance the configuration does not provide
required values or the data context is not set, a
ConfigurationException may be thrown.public void setConfiguration(Configuration conf, java.lang.String id) throws ConfigurationException
EventSourceRunnable.run().setConfiguration in interface EventSource<ResultSetEvent>setConfiguration in class AbstractEventSource<ResultSetEvent>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.public long getPollTime()
PollingSourcePollingSource.init() and PollingSource.terminate() will be called.getPollTime in interface PollingSource<ResultSetEvent>public long getStartTime()
PollingSourcePollingSource.getPollTime().getStartTime in interface PollingSource<ResultSetEvent>public void init()
PollingSourceinit in interface PollingSource<ResultSetEvent>public void checkForAndHandleEvent()
AbstractEventSourceAbstractEventSource.forwardEvent(Event, boolean, boolean)).checkForAndHandleEvent in class AbstractEventSource<ResultSetEvent>public void terminate()
PollingSourceterminate in interface PollingSource<ResultSetEvent>protected ResultSetEvent createResultSetEvent(java.sql.ResultSet resultSet)
ResultSetEvent for the designated result set.resultSet - The result set for which to create a
ResultSetEvent.ResultSetEvent created for the designated result
set.protected boolean nextHandler(ResultSetEvent event, boolean consumed, boolean concurrent)
AbstractEventSourcenextHandler in class AbstractEventSource<ResultSetEvent>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.