org.jboss.soa.esb.listeners.old
Class SqlTablePoller

java.lang.Object
  extended by org.jboss.soa.esb.listeners.old.AbstractListener
      extended by org.jboss.soa.esb.listeners.old.AbstractPoller
          extended by org.jboss.soa.esb.listeners.old.SqlTablePoller
All Implemented Interfaces:
java.lang.Runnable

public class SqlTablePoller
extends AbstractPoller

SqlTablePoller class The SQL table that is polled should have 1) a unique key (see "keyFields" parameter) that will be used to update status 2) a column to indicate the "processing status" of this trigger row (see ROW_STATE enum) Each retrieved row (see OPTIONAL_ATT.whereCondition) should be considered as a trigger that is intended to instantiate an object of "actionClass". The new instance will receive the full ConfigTree (level 1 for each child group)

Author:
Esteban Schifman

Nested Class Summary
static class SqlTablePoller.OPTIONAL_ATT
          Optional fields that can be included in your parameter tree as attributes in the upper Element 1) 4 character long String that indicate status of each row for this poller 1st: Character that indicates "Pending" state = available for processing 2nd: "Working" : some poller is working on the row (or ab-ended while working) 3rd: "Error" : some poller tried to process, and found an error during processing 4th: "Done" : this row has already been processed successfully 2) if you wish to further filter your ResultSet, you can add an optional list of conditions that will be included in the "scan" SQL statement (without "where") 3) Comma separated list of fields to order ResultSet (without "order by")
static class SqlTablePoller.ROW_STATE
          First character of these values are the default states of a table row trigger the "inProcessVals" parameter can override these (if that were ever necessary) this is why the default value for that parameter is "PWED" (see below) The poller will only process rows that have the "inProcessField" first character equal to the first character of whatever the "Pending" state is (typically "P")
static class SqlTablePoller.TABLE_ATT
          Mandatory attributes needed for SqlTablePoller 1) Table name 2) Comma separated list of fields needed in the ResultSet 3) Comma separated list of fields that constitute a unique ID of the working row all fields in this list MUST also be in the "selectFields" list these fields will be used in the "where" clause of update statements 4) Name of table field used as indicator/semaphore to avoid concurrent update
 
Nested classes/interfaces inherited from class org.jboss.soa.esb.listeners.old.AbstractListener
AbstractListener.ActionProcessingPipeline
 
Field Summary
static java.lang.String DEFAULT_STATES
           
protected  java.util.Map<java.lang.String,java.lang.String> m_oVals
           
protected  java.lang.String[] m_saCols
           
protected  java.lang.String[] m_saKeys
           
protected  java.lang.String m_sUpdStates
           
 
Fields inherited from class org.jboss.soa.esb.listeners.old.AbstractPoller
m_iDfltPollMillis, m_iMinPollMillis, m_iPollMillis, PARM_POLL_LTCY
 
Fields inherited from class org.jboss.soa.esb.listeners.old.AbstractListener
listenerConfig, logger, m_iMaxThr, m_iQthr, m_iSleepForThreads, m_iUpperThreadLimit, m_oActionDefinitionFactory, m_oActions, m_oDad, m_oMsgFactory, m_oThrGrp, MESSAGE_PROCESSING_ACTIONS_LIST
 
Constructor Summary
SqlTablePoller(GpListener p_oDad, ConfigTree p_oParms, ActionDefinitionFactory actionDefinitionFactory)
          In this constructor you can override default values for the following protected base class values:

m_iMinPollMillis : minimum polling interval (default 3000)
m_iDfltPollMillis : default polling interval (default 20000)
m_iSleepForThreads : how long to sleep if all configured threads are in use (default 3000)
m_iUpperThreadLimit : max number of threads allowed (default 10)

 
Method Summary
protected  void checkMyParms()
           
protected  void close()
          Close the listener implemenation.
protected  JdbcCleanConn newDbConn()
          Obtain a new database connection with parameter info
protected  java.util.List<java.lang.Object> pollForCandidates()
          Poll for message objects.
protected  java.lang.Object preProcess(java.lang.Object p_o)
          Preprocess the message object before returning for pipeline processing.
protected  void processingComplete(java.lang.Object initialMessage)
          Called on the listener implementation when pipeline processing of a message is complete.
protected  void processingError(java.lang.Object initialMessage, ActionProcessor processor, java.lang.Throwable error)
          Called on the listener implementation when pipeline processing error has occured.
protected  java.lang.String scanStatement()
          Assemble the SQL statement to scan (poll) the table
protected  java.lang.String selectForUpdStatement()
          Assemble the SQL "select for update" statement for the "inProcessField" parameter in the table row uniquely identified by the list of fields in the "keyFields" parameter
protected  java.lang.String updateStatement()
          Assemble the SQL statement to update the field in the "inProcessField" parameter in the table row uniquely identified by the list of fields in the "keyFields" parameter
 
Methods inherited from class org.jboss.soa.esb.listeners.old.AbstractPoller
receive
 
Methods inherited from class org.jboss.soa.esb.listeners.old.AbstractListener
run
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_STATES

public static final java.lang.String DEFAULT_STATES
See Also:
Constant Field Values

m_oVals

protected java.util.Map<java.lang.String,java.lang.String> m_oVals

m_saCols

protected java.lang.String[] m_saCols

m_saKeys

protected java.lang.String[] m_saKeys

m_sUpdStates

protected java.lang.String m_sUpdStates
Constructor Detail

SqlTablePoller

public SqlTablePoller(GpListener p_oDad,
                      ConfigTree p_oParms,
                      ActionDefinitionFactory actionDefinitionFactory)
               throws java.lang.Exception
In this constructor you can override default values for the following protected base class values:

m_iMinPollMillis : minimum polling interval (default 3000)
m_iDfltPollMillis : default polling interval (default 20000)
m_iSleepForThreads : how long to sleep if all configured threads are in use (default 3000)
m_iUpperThreadLimit : max number of threads allowed (default 10)

Parameters:
p_oDad - GpListener - The controlling process
p_oParms - ConfigTree - Sub tree that corresponds to this instance
Throws:
java.lang.Exception
Method Detail

checkMyParms

protected void checkMyParms()
                     throws java.lang.Exception
Throws:
java.lang.Exception

preProcess

protected java.lang.Object preProcess(java.lang.Object p_o)
Description copied from class: AbstractPoller
Preprocess the message object before returning for pipeline processing.

Specified by:
preProcess in class AbstractPoller
Parameters:
p_o - Message object for preprocessing.
Returns:
The preprocessed message object, or the supplied message unmodified.

pollForCandidates

protected java.util.List<java.lang.Object> pollForCandidates()
Description copied from class: AbstractPoller
Poll for message objects.

Specified by:
pollForCandidates in class AbstractPoller
Returns:
A list of message objects, or an empty list if there are no message objects.

newDbConn

protected JdbcCleanConn newDbConn()
                           throws java.lang.Exception
Obtain a new database connection with parameter info

Returns:
A new connection
Throws:
java.lang.Exception - - if problems are encountered

scanStatement

protected java.lang.String scanStatement()
Assemble the SQL statement to scan (poll) the table

Returns:
- The resulting SQL statement

updateStatement

protected java.lang.String updateStatement()
Assemble the SQL statement to update the field in the "inProcessField" parameter in the table row uniquely identified by the list of fields in the "keyFields" parameter

Returns:
- The resulting SQL statement

selectForUpdStatement

protected java.lang.String selectForUpdStatement()
Assemble the SQL "select for update" statement for the "inProcessField" parameter in the table row uniquely identified by the list of fields in the "keyFields" parameter

Returns:
- The resulting SQL statement

close

protected void close()
Description copied from class: AbstractListener
Close the listener implemenation.

Allows the listener to perform relevant close/cleanup tasks.

Specified by:
close in class AbstractListener

processingError

protected void processingError(java.lang.Object initialMessage,
                               ActionProcessor processor,
                               java.lang.Throwable error)
Description copied from class: AbstractListener
Called on the listener implementation when pipeline processing error has occured.

Specified by:
processingError in class AbstractListener
Parameters:
initialMessage - The message that was initialy supplied to the pipeline.
processor - The processor that raised the error. Can be null where the error was raised before pipeline processing of the message.
error - The error. Can be null.

processingComplete

protected void processingComplete(java.lang.Object initialMessage)
Description copied from class: AbstractListener
Called on the listener implementation when pipeline processing of a message is complete.

Specified by:
processingComplete in class AbstractListener
Parameters:
initialMessage - The message that was initialy supplied to the pipeline.