org.ikasan.framework.initiator
Class AbstractInitiator

java.lang.Object
  extended by org.ikasan.framework.initiator.AbstractInitiator
All Implemented Interfaces:
Initiator
Direct Known Subclasses:
EventDrivenInitiatorImpl, JmsMessageDrivenInitiatorImpl, JmsMessageDrivenInitiatorImpl, QuartzStatefulScheduledDrivenInitiator, SimpleInitiator

public abstract class AbstractInitiator
extends Object
implements Initiator

Abstract base class for all existing Initiator implementations Provides implementations for the common Initiator functionality:

Author:
Ikasan Development Team

Field Summary
protected  boolean error
          Flag indicating a stoppage in error
protected  ErrorLoggingService errorLoggingService
          Service for logging errors in a heavyweight fashion
static String EXCEPTION_ACTION_IMPLIED_ROLLBACK
          Exception action is an implied rollback message
protected  IkasanExceptionHandler exceptionHandler
          Handler for exceptions
protected  ExcludedEventService excludedEventService
          Service for excluding events
protected  Set<String> exclusions
          Set of ids for Events that will be immediately excluded when next encountered
protected  Flow flow
          Flow to be invoked by this initiator
protected  String moduleName
          Name of the module
protected  List<MonitorListener> monitorListeners
          Monitor listeners for the initiator
protected  String name
          Name of the initiator
protected  Integer retryCount
          Count of how many times this Initiator has retried
protected  boolean stopping
          Flag indicating that the initiator has received a stop call
static String UNSUPPORTED_EXCLUDE_ENCONTERED
          Exception action is an implied rollback message
 
Constructor Summary
AbstractInitiator(String moduleName, String name, Flow flow, IkasanExceptionHandler exceptionHandler)
          Constructor
 
Method Summary
 void addListener(MonitorListener monitorListener)
          Adds a MonitorListener to this Initiator
protected abstract  void cancelRetryCycle()
          Cancels retry activity
protected abstract  void completeRetryCycle()
          Cancel the retry activity, and resume any business as usual activity
protected  void continueRetryCycle(long delay)
          Template method for subclasses to selectively override
 IkasanExceptionHandler getExceptionHandler()
          Accessor for exceptionHandler
 Set<String> getExclusions()
          Accessor for exclusions
 Flow getFlow()
          Returns the flow that this invokes
 long getHandledEventCount()
           
 Date getLastEventTime()
           
protected abstract  org.apache.log4j.Logger getLogger()
          Provides access to the implementation class specific logger instance
 String getModuleName()
          Accessor for moduleName
 List<MonitorListener> getMonitorListeners()
          Accessor for monitorListeners
 String getName()
          The flow initiator's name.
 Integer getRetryCount()
          Accessor for retryCount
 InitiatorState getState()
          Returns the current state of the Initiator
protected  void handleAction(IkasanExceptionAction action, String eventId)
          Handle the returned action from the flow invocation
protected  void handleRetry(Integer maxAttempts, long delay)
          Handle an IkasanExceptionAction 'retry'
protected  void invokeFlow(Event event)
          Invoke the flow with a single Event
protected  void invokeFlow(List<Event> events)
          Invoke the flow with all available Events, handing exception actions as we go
 boolean isError()
          Is this initiator in an error state.
 boolean isStopping()
          Accessor for stopping flag
protected  void logError(Event event, Throwable throwable, String componentName, IkasanExceptionAction exceptionAction)
          Logs errors in a heavy weight fashion using an ErrorLoggingService if available
protected  void notifyMonitorListeners()
          Notification to all registered MonitorListener of the current state of the Initiator
 void removeListener(MonitorListener monitorListener)
          Removes a specified MonitorListener from this Initiator This method has no effect if the specified MonitorListener is not currently a registered listener
protected  void resume()
          Returns the Initiator to normal running, completes recovering if necessary
 void setErrorLoggingService(ErrorLoggingService errorLoggingService)
          Setter for optional ErrorLoggingService
 void setExcludedEventService(ExcludedEventService excludedEventService)
           
 void start()
          Start this initiator.
protected abstract  void startInitiator()
          Only the extending class knows how to start the initiator.
protected abstract  void startRetryCycle(Integer maxAttempts, long delay)
          Initiator needs to start a retry cycle due to an exception action.
 void stop()
          Stop this initiator.
protected  void stopInError()
          Sets the error flag before stopping the initiator by normal means
protected abstract  void stopInitiator()
          Only the extending class knows how to stop the initiator.
 boolean supportsExclusions()
          Returns true if an excludedEventService is present, and thus supports exclusions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.ikasan.framework.initiator.Initiator
getType, isRecovering, isRunning
 

Field Detail

EXCEPTION_ACTION_IMPLIED_ROLLBACK

public static final String EXCEPTION_ACTION_IMPLIED_ROLLBACK
Exception action is an implied rollback message

See Also:
Constant Field Values

UNSUPPORTED_EXCLUDE_ENCONTERED

public static final String UNSUPPORTED_EXCLUDE_ENCONTERED
Exception action is an implied rollback message

See Also:
Constant Field Values

monitorListeners

protected List<MonitorListener> monitorListeners
Monitor listeners for the initiator


moduleName

protected String moduleName
Name of the module


name

protected String name
Name of the initiator


flow

protected Flow flow
Flow to be invoked by this initiator


error

protected boolean error
Flag indicating a stoppage in error


stopping

protected boolean stopping
Flag indicating that the initiator has received a stop call


retryCount

protected Integer retryCount
Count of how many times this Initiator has retried


exceptionHandler

protected IkasanExceptionHandler exceptionHandler
Handler for exceptions


errorLoggingService

protected ErrorLoggingService errorLoggingService
Service for logging errors in a heavyweight fashion


excludedEventService

protected ExcludedEventService excludedEventService
Service for excluding events


exclusions

protected Set<String> exclusions
Set of ids for Events that will be immediately excluded when next encountered

Constructor Detail

AbstractInitiator

public AbstractInitiator(String moduleName,
                         String name,
                         Flow flow,
                         IkasanExceptionHandler exceptionHandler)
Constructor

Parameters:
moduleName - The name of the module
name - The name of this initiator
flow - The name of the flow it starts
exceptionHandler -
Method Detail

addListener

public void addListener(MonitorListener monitorListener)
Adds a MonitorListener to this Initiator

Parameters:
monitorListener -

removeListener

public void removeListener(MonitorListener monitorListener)
Removes a specified MonitorListener from this Initiator This method has no effect if the specified MonitorListener is not currently a registered listener

Parameters:
monitorListener - - listener to remove

notifyMonitorListeners

protected void notifyMonitorListeners()
Notification to all registered MonitorListener of the current state of the Initiator


getExceptionHandler

public IkasanExceptionHandler getExceptionHandler()
Description copied from interface: Initiator
Accessor for exceptionHandler

Specified by:
getExceptionHandler in interface Initiator
Returns:
ExceptionHandler if any

getMonitorListeners

public List<MonitorListener> getMonitorListeners()
Accessor for monitorListeners

Returns:
List of all MonitorListeners registered with this Initiator

getState

public InitiatorState getState()
Description copied from interface: Initiator
Returns the current state of the Initiator

Specified by:
getState in interface Initiator
Returns:
InitiatorState representing the current state of the Initiators

start

public void start()
           throws InitiatorOperationException
Description copied from interface: Initiator
Start this initiator.

Specified by:
start in interface Initiator
Throws:
InitiatorOperationException - Exception if we cannot start the Initiator

stop

public void stop()
          throws InitiatorOperationException
Description copied from interface: Initiator
Stop this initiator.

Specified by:
stop in interface Initiator
Throws:
InitiatorOperationException - Exception if we cannot stop the Initiator

invokeFlow

protected void invokeFlow(List<Event> events)
Invoke the flow with all available Events, handing exception actions as we go

Parameters:
events -

logError

protected void logError(Event event,
                        Throwable throwable,
                        String componentName,
                        IkasanExceptionAction exceptionAction)
Logs errors in a heavy weight fashion using an ErrorLoggingService if available

Parameters:
event -
throwable -
componentName -

invokeFlow

protected void invokeFlow(Event event)
Invoke the flow with a single Event

Parameters:
event -

handleAction

protected void handleAction(IkasanExceptionAction action,
                            String eventId)
Handle the returned action from the flow invocation

Parameters:
action - IkasanExceptionAction to deal with

handleRetry

protected void handleRetry(Integer maxAttempts,
                           long delay)
                    throws InitiatorOperationException
Handle an IkasanExceptionAction 'retry'

Parameters:
maxAttempts - - maximum number of times to retry
delay - - time to delay between retries
Throws:
InitiatorOperationException - Exception to throw if we cannot retry

resume

protected void resume()
               throws InitiatorOperationException
Returns the Initiator to normal running, completes recovering if necessary

Throws:
InitiatorOperationException

stopInError

protected void stopInError()
Sets the error flag before stopping the initiator by normal means


getModuleName

public String getModuleName()
Accessor for moduleName

Returns:
name of the module

getRetryCount

public Integer getRetryCount()
Accessor for retryCount

Specified by:
getRetryCount in interface Initiator
Returns:

getName

public String getName()
Description copied from interface: Initiator
The flow initiator's name.

Specified by:
getName in interface Initiator
Returns:
name

getFlow

public Flow getFlow()
Description copied from interface: Initiator
Returns the flow that this invokes

Specified by:
getFlow in interface Initiator
Returns:
Flow

isError

public boolean isError()
Description copied from interface: Initiator
Is this initiator in an error state. This error state also denotes this initiator as stopped.

Specified by:
isError in interface Initiator
Returns:
boolean

isStopping

public boolean isStopping()
Accessor for stopping flag

Returns:
stopping flag

setErrorLoggingService

public void setErrorLoggingService(ErrorLoggingService errorLoggingService)
Setter for optional ErrorLoggingService

Parameters:
errorLoggingService -

getLogger

protected abstract org.apache.log4j.Logger getLogger()
Provides access to the implementation class specific logger instance

Returns:
Logger instance for the extending class

completeRetryCycle

protected abstract void completeRetryCycle()
Cancel the retry activity, and resume any business as usual activity


cancelRetryCycle

protected abstract void cancelRetryCycle()
Cancels retry activity


startInitiator

protected abstract void startInitiator()
                                throws InitiatorOperationException
Only the extending class knows how to start the initiator.

Throws:
InitiatorOperationException - Exception if we cannot start initiator

stopInitiator

protected abstract void stopInitiator()
                               throws InitiatorOperationException
Only the extending class knows how to stop the initiator.

Throws:
InitiatorOperationException - Excetpion if we cannot stop initiator

startRetryCycle

protected abstract void startRetryCycle(Integer maxAttempts,
                                        long delay)
                                 throws InitiatorOperationException
Initiator needs to start a retry cycle due to an exception action. Only the extending class has the knowledge to start a retry cycle.

Parameters:
maxAttemptss - The number of retries we allow
delay - The delay in milliseconds before we perform a retry
Throws:
InitiatorOperationException

continueRetryCycle

protected void continueRetryCycle(long delay)
Template method for subclasses to selectively override

Parameters:
delay -

setExcludedEventService

public void setExcludedEventService(ExcludedEventService excludedEventService)
Parameters:
excludedEventService - to set

supportsExclusions

public boolean supportsExclusions()
Returns true if an excludedEventService is present, and thus supports exclusions

Returns:
true if exclusions are supported by this Initiator

getExclusions

public Set<String> getExclusions()
Accessor for exclusions

Returns:
set of eventIds noted for exclusion when next encountered

getHandledEventCount

public long getHandledEventCount()
Specified by:
getHandledEventCount in interface Initiator

getLastEventTime

public Date getLastEventTime()
Specified by:
getLastEventTime in interface Initiator


Copyright © 2007-2012 Ikasan. All Rights Reserved.