org.jboss.soa.esb.listeners
Class GpListener

java.lang.Object
  extended by org.jboss.soa.esb.listeners.GpListener
All Implemented Interfaces:
java.lang.Runnable

public class GpListener
extends java.lang.Object
implements java.lang.Runnable

Controlling class that will launch listener child threads for supported transport listener classes, as indicated in the configuration XML tree pointed by arg[0]

Can be launched as uppermost controller (it has a main(args) method)

Also implements Runnable, and can thus be launched in a child thread from an upper controlling process

Listens on a JMS queue (with an optional message selector) for commands (e.g. Quiesce, Reload Parameters, Set End Time, etc.)

Parameter reloading can also be set using the PARM_RELOAD_SECS attribute

End time for this instance can also be set using the PARM_END_TIME attribute

Author:
Esteban

Nested Class Summary
static class GpListener.State
           
 
Field Summary
static java.lang.String CHLD_EMAIL_PARMS
           
static java.lang.String COMMAND_CONN_FACTORY
           
static java.lang.String COMMAND_IS_TOPIC
           
static java.lang.String COMMAND_JNDI_NAME
           
static java.lang.String COMMAND_JNDI_TYPE
           
static java.lang.String COMMAND_JNDI_URL
           
static java.lang.String COMMAND_MSG_SELECTOR
           
protected  int m_iDfltReloadMillis
           
static java.lang.String PARM_ACTION_CLASS
           
static java.lang.String PARM_END_TIME
           
static java.lang.String PARM_LISTENER_CLASS
           
static java.lang.String PARM_MAX_THREADS
           
static java.lang.String PARM_RELOAD_SECS
           
static java.text.SimpleDateFormat s_oDateParse
           
 
Constructor Summary
GpListener(java.lang.String p_sParameterName)
           
 
Method Summary
protected static java.lang.Class checkActionClass(java.lang.String p_sName)
          Check to see if an object of the class (arg 0) can be instantiated in this context
 void checkParms(DomElement p_oP)
          Check to see if all needed parameters are there, and assign default values to some of them
 boolean continueLooping()
          Helper accessor for child processes that provides info to determine if they can continue with yet another execution cycle
 boolean endNotRequested()
          Accessor to determine if execution time is not expired, and no shutdown request received
 boolean endRequested()
          Accessor to determine if execution time is expired or shutdown requested
static java.lang.Class[] getActionClassArgs()
           
 java.util.Map<java.lang.String,java.lang.Object> getControllerAttributes()
          Obtain a shallow copy of needed atributes in this object's last loaded parameter tree

The local bject is cloned so child threads can use it as they choose to without interfering with the environment

Listener processes controlled by this object should keep a reference to this object at construction time, and not call this method again unless they specifically need updated values.

protected static InotificationHandler getNotifHandler()
          Lazy instantiator of a InotificationHandler
 GpListener.State getState()
           
static void main(java.lang.String[] args)
           
static void notifyError(DomElement p_oP, java.lang.Exception p_e, java.io.Serializable p_oSer)
          Find child nodes named "NotificationList" that contain an attribute 'type' that starts with "err" (case insensitive) or no 'type' attribute set
static void notifyOK(DomElement p_oP, java.io.Serializable p_oSer)
          Find child nodes named "NotificationList" that contain an attribute 'type' that starts with "ok" (case insensitive)
 void run()
          Main execution loop

Will continue to run until either

a) run time is expired

b) quiesce command is received in command queue

For every child element that contains a PARM_LISTENER_CLASS attribute, this method will try to launch a child thread instantiating an object of that class, and will call it's run() method

Once all child processes are trigered, the main thread will either

1) wait for a message in the command queue (if one was configured) until next reload or end of run period expired

or 2) Just sleep if there's no command queue to listen on

 boolean timeToReload()
          Provide a common accessor to determine if parameters have to be reloaded

For child threads this means thread execution has to end

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_iDfltReloadMillis

protected int m_iDfltReloadMillis

COMMAND_CONN_FACTORY

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

COMMAND_JNDI_TYPE

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

COMMAND_JNDI_URL

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

COMMAND_IS_TOPIC

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

COMMAND_JNDI_NAME

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

COMMAND_MSG_SELECTOR

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

PARM_RELOAD_SECS

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

PARM_END_TIME

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

PARM_LISTENER_CLASS

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

PARM_ACTION_CLASS

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

PARM_MAX_THREADS

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

CHLD_EMAIL_PARMS

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

s_oDateParse

public static final java.text.SimpleDateFormat s_oDateParse
Constructor Detail

GpListener

public GpListener(java.lang.String p_sParameterName)
           throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

getControllerAttributes

public java.util.Map<java.lang.String,java.lang.Object> getControllerAttributes()
Obtain a shallow copy of needed atributes in this object's last loaded parameter tree

The local bject is cloned so child threads can use it as they choose to without interfering with the environment

Listener processes controlled by this object should keep a reference to this object at construction time, and not call this method again unless they specifically need updated values. Parameter reload could have happened since last call

Returns:
Map - a shallow copy of the attributes Map

getState

public GpListener.State getState()

checkParms

public void checkParms(DomElement p_oP)
                throws java.lang.Exception
Check to see if all needed parameters are there, and assign default values to some of them

Parameters:
p_oP - DomElement - Where to look for the mandatory/optional configuration attributes
Throws:
java.lang.Exception - - If attributes are wrong or not enough for a proper runtime configuration

run

public void run()
Main execution loop

Will continue to run until either

a) run time is expired

b) quiesce command is received in command queue

For every child element that contains a PARM_LISTENER_CLASS attribute, this method will try to launch a child thread instantiating an object of that class, and will call it's run() method

Once all child processes are trigered, the main thread will either

1) wait for a message in the command queue (if one was configured) until next reload or end of run period expired

or 2) Just sleep if there's no command queue to listen on

Specified by:
run in interface java.lang.Runnable

endRequested

public boolean endRequested()
Accessor to determine if execution time is expired or shutdown requested

Returns:
boolean if processing has to stop (all child threads will be allowed to finish)

endNotRequested

public boolean endNotRequested()
Accessor to determine if execution time is not expired, and no shutdown request received

Returns:
boolean - true if run time has not expired and quiesce has not been requested

timeToReload

public boolean timeToReload()
Provide a common accessor to determine if parameters have to be reloaded

For child threads this means thread execution has to end

Child processes should only call this method when they are idle (as opposed to in the middle of executing a unit of work)

Returns:
boolean - true if it's time to reload parameters

continueLooping

public boolean continueLooping()
Helper accessor for child processes that provides info to determine if they can continue with yet another execution cycle

Returns:
boolean - true if runtime is not expired and not time yet to reload parameters

getActionClassArgs

public static java.lang.Class[] getActionClassArgs()

checkActionClass

protected static java.lang.Class checkActionClass(java.lang.String p_sName)
                                           throws java.lang.Exception
Check to see if an object of the class (arg 0) can be instantiated in this context

Parameters:
p_sName - String - class name to instantiate - Must implement org.jboss.soa.esb.listeners.AbstractActionClass
Returns:
Class -
Throws:
java.lang.Exception - - if class not found in path or no appropriate constructor

notifyOK

public static void notifyOK(DomElement p_oP,
                            java.io.Serializable p_oSer)
Find child nodes named "NotificationList" that contain an attribute 'type' that starts with "ok" (case insensitive)

Parameters:
p_oP - - DomElement to search for "NotificationList" child Elements
p_oSer - Serializable - Will constitute the body of the notification

notifyError

public static void notifyError(DomElement p_oP,
                               java.lang.Exception p_e,
                               java.io.Serializable p_oSer)
Find child nodes named "NotificationList" that contain an attribute 'type' that starts with "err" (case insensitive) or no 'type' attribute set

Parameters:
p_oP - - DomElement to search for "NotificationList" child Elements
p_e - - Exception if not null, will be appended to the body
p_oSer - Serializable - Will be included at the beginning of the body of the notification

getNotifHandler

protected static InotificationHandler getNotifHandler()
Lazy instantiator of a InotificationHandler

Returns:
- a reference to an implementation of the interface or null if it can't be instantiated