Class WorkflowImp
- java.lang.Object
-
- com.adaptris.core.WorkflowImp
-
- All Implemented Interfaces:
AdaptrisComponent
,AdaptrisMessageListener
,ComponentLifecycle
,ComponentLifecycleExtension
,ConfigComment
,EventHandlerAware
,StateManagedComponent
,Workflow
- Direct Known Subclasses:
StandardWorkflowImpl
,WorkflowWithObjectPool
public abstract class WorkflowImp extends java.lang.Object implements Workflow
Partial implementation ofWorkflow
.- See Also:
StandardWorkflow
,PoolingWorkflow
-
-
Field Summary
Fields Modifier and Type Field Description protected EventHandler
eventHandler
protected org.slf4j.Logger
log
protected java.util.Date
startTime
protected java.util.Date
stopTime
-
Fields inherited from interface com.adaptris.core.Workflow
PREVIOUS_GUID_KEY, WORKFLOW_ID_KEY
-
-
Constructor Summary
Constructors Constructor Description WorkflowImp()
Creates a new instance with defaults to prevent NullPointerExceptions.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected AdaptrisMessage
addConsumeLocation(AdaptrisMessage msg)
void
addInterceptor(WorkflowInterceptor wi)
void
changeState(ComponentState s)
Updates the state for the componentComponentState
.long
channelUnavailableWait()
void
close()
Close this component.protected abstract void
closeWorkflow()
Close the workflow.protected AdaptrisMessage
copyExceptionHeaders(AdaptrisMessage workingCopy, AdaptrisMessage orig)
boolean
disableMessageCount()
Whether or not message-counts should be disabled on this workflow.void
doProduce(AdaptrisMessage msg)
This method contains the behaviour that varies between standard and request -reply workflows.java.lang.String
friendlyName()
Get the friendly name for this component.TimeInterval
getChannelUnavailableWaitInterval()
java.lang.String
getComments()
AdaptrisMessageConsumer
getConsumer()
Returns theAdaptrisMessageConsumer
to use.java.lang.Boolean
getDisableDefaultMessageCount()
java.util.List<WorkflowInterceptor>
getInterceptors()
Return all the configured interceptors.ProcessingExceptionHandler
getMessageErrorHandler()
Returns theMessageErrorHandler
to use.MessageLogger
getMessageLogger()
ProduceExceptionHandler
getProduceExceptionHandler()
Returns produceExceptionHandler.AdaptrisMessageProducer
getProducer()
Returns theAdaptrisMessageProducer
to use.java.lang.Boolean
getSendEvents()
Return whether events should be sent.ServiceCollection
getServiceCollection()
Returns theServiceCollection
to use.java.lang.String
getUniqueId()
Returns any configured unique-id.void
handleBadMessage(AdaptrisMessage msg)
Handle a 'bad' message.protected void
handleBadMessage(java.lang.String logMsg, java.lang.Exception e, AdaptrisMessage msg)
protected void
handleChannelUnavailable(AdaptrisMessage msg)
Allows common functionality when the channel is unavailable.void
handleProduceException()
Handle anException
encountered producing a message.void
init()
Because the order in which concrete workflows may need to init their components, this method simply ensures that theMessageErrorHandler
is inited, and then delegates all other init requirements to the concrete implementation.protected abstract void
initialiseWorkflow()
Initialise the workflow.java.util.Date
lastStartTime()
Get the last time this workflow was startedjava.util.Date
lastStopTime()
Get the last time this channel was stopped.protected void
logSuccess(AdaptrisMessage msg, long start)
MessageLogger
messageLogger()
Channel
obtainChannel()
Returns a reference to thisWorkflow
'sChannel
.java.lang.String
obtainWorkflowId()
Returns what the workflow considers to be it's unique ID of the workflow.void
prepare()
Prepare for initialisation.protected abstract void
prepareWorkflow()
protected void
processingStart(AdaptrisMessage msg)
Mark the workflow having started processing a message.void
registerActiveMsgErrorHandler(ProcessingExceptionHandler meh)
Sets theMessageErrorHandler
to use for handling error messages.void
registerChannel(Channel ch)
Sets a reference to thisWorkflow
'sChannel
.void
registerEventHandler(EventHandler eh)
Register the current event handler against this component.void
requestClose()
Request this component is closed.void
requestInit()
Request this component is init'd.void
requestStart()
Request this component is started.void
requestStop()
Request this component is stopped.protected abstract void
resubmitMessage(AdaptrisMessage msg)
Resubmit a message upon the channel becoming available again.protected ProcessingExceptionHandler
retrieveActiveMsgErrorHandler()
Accessor to allow sub-classes access to theMessageErrorHandler
that is in use.ComponentState
retrieveComponentState()
Returns the last recordeComponentState
.boolean
sendEvents()
protected void
sendMessageLifecycleEvent(AdaptrisMessage wip)
void
setChannelUnavailableWaitInterval(TimeInterval channelUnavailableWaitInterval)
void
setComments(java.lang.String s)
void
setConsumer(AdaptrisMessageConsumer param)
Sets theAdaptrisMessageConsumer
to use.void
setDisableDefaultMessageCount(java.lang.Boolean b)
Disable the defaultMessageMetricsInterceptor
that keeps a message count.void
setInterceptors(java.util.List<WorkflowInterceptor> list)
void
setMessageErrorHandler(ProcessingExceptionHandler errorHandler)
Sets a configuredMessageErrorHandler
.void
setMessageLogger(MessageLogger ml)
void
setProduceExceptionHandler(ProduceExceptionHandler p)
Sets produceExceptionHandler.void
setProducer(AdaptrisMessageProducer param)
Sets theAdaptrisMessageProducer
to use.void
setSendEvents(java.lang.Boolean events)
Sets whether events should be sent.void
setServiceCollection(ServiceCollection services)
Sets theServiceCollection
to use.void
setUniqueId(java.lang.String id)
void
start()
Start this component.protected abstract void
startWorkflow()
Start the workflow.void
stop()
Stop this component.protected abstract void
stopWorkflow()
Stop the workflow.protected void
workflowEnd(AdaptrisMessage input, AdaptrisMessage output)
Mark the workflow as finished on this message.protected void
workflowStart(AdaptrisMessage msg)
Mark the workflow having accepted a message.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.adaptris.core.AdaptrisMessageListener
onAdaptrisMessage, onAdaptrisMessage, onAdaptrisMessage
-
-
-
-
Field Detail
-
log
protected transient org.slf4j.Logger log
-
eventHandler
protected transient EventHandler eventHandler
-
startTime
protected transient java.util.Date startTime
-
stopTime
protected transient java.util.Date stopTime
-
-
Method Detail
-
registerActiveMsgErrorHandler
public void registerActiveMsgErrorHandler(ProcessingExceptionHandler meh)
Sets the
MessageErrorHandler
to use for handling error messages. This may be configured at the Workflow, Channel or Adapter level. May not be null.- Specified by:
registerActiveMsgErrorHandler
in interfaceWorkflow
- Parameters:
meh
- theMessageErrorHandler
to use
-
registerEventHandler
public void registerEventHandler(EventHandler eh)
Description copied from interface:EventHandlerAware
Register the current event handler against this component.- Specified by:
registerEventHandler
in interfaceEventHandlerAware
- Parameters:
eh
- the event handler currently in use.
-
prepare
public final void prepare() throws CoreException
Description copied from interface:ComponentLifecycleExtension
Prepare for initialisation.- Specified by:
prepare
in interfaceComponentLifecycleExtension
- Throws:
CoreException
-
prepareWorkflow
protected abstract void prepareWorkflow() throws CoreException
- Throws:
CoreException
-
init
public final void init() throws CoreException
Because the order in which concrete workflows may need to init their components, this method simply ensures that the
MessageErrorHandler
is inited, and then delegates all other init requirements to the concrete implementation.- Specified by:
init
in interfaceComponentLifecycle
- Throws:
CoreException
- encapsulating any underlying Exception- See Also:
ComponentLifecycle.init()
,initialiseWorkflow()
-
initialiseWorkflow
protected abstract void initialiseWorkflow() throws CoreException
Initialise the workflow.- Throws:
CoreException
- encapsulating any underlying Exception
-
start
public final void start() throws CoreException
Start this component.Because the order in which concrete workflows may need to start their components, this method simply ensures that the
MessageErrorHandler
is started, and then delegates to the concrete imp.- Specified by:
start
in interfaceComponentLifecycle
- Throws:
CoreException
- encapsulating any underlying Exception- See Also:
ComponentLifecycle.start()
,startWorkflow()
-
startWorkflow
protected abstract void startWorkflow() throws CoreException
Start the workflow.- Throws:
CoreException
- encapsulating any underlying Exception- See Also:
ComponentLifecycle.start()
-
stop
public final void stop()
Stop this component.Because the order in which concrete workflows may need to stop their components, this method simply uses
stopWorkflow
to stop the concrete workflow, and then ensures that the MessageErrorHandler is closed.- Specified by:
stop
in interfaceComponentLifecycle
- See Also:
ComponentLifecycle.stop()
,stopWorkflow()
-
stopWorkflow
protected abstract void stopWorkflow()
Stop the workflow.
-
close
public final void close()
Close this component.Because the order in which concrete workflows may need to close their components, this method delegates all other close requirements to the concrete implementation, after the concrete workflow has performed its close it ensures that the
MessageErrorHandler
is closed.- Specified by:
close
in interfaceComponentLifecycle
- See Also:
ComponentLifecycle.close()
,closeWorkflow()
-
closeWorkflow
protected abstract void closeWorkflow()
Close the workflow.
-
changeState
public void changeState(ComponentState s)
Description copied from interface:StateManagedComponent
Updates the state for the component
ComponentState
.- Specified by:
changeState
in interfaceStateManagedComponent
-
requestInit
public void requestInit() throws CoreException
Description copied from interface:StateManagedComponent
Request this component is init'd.
- Specified by:
requestInit
in interfaceStateManagedComponent
- Throws:
CoreException
- wrapping any underlying Exceptions
-
requestStart
public void requestStart() throws CoreException
Description copied from interface:StateManagedComponent
Request this component is started.
- Specified by:
requestStart
in interfaceStateManagedComponent
- Throws:
CoreException
- wrapping any underlying Exceptions
-
requestStop
public void requestStop()
Description copied from interface:StateManagedComponent
Request this component is stopped.
- Specified by:
requestStop
in interfaceStateManagedComponent
-
requestClose
public void requestClose()
Description copied from interface:StateManagedComponent
Request this component is closed.
- Specified by:
requestClose
in interfaceStateManagedComponent
-
retrieveComponentState
public ComponentState retrieveComponentState()
Description copied from interface:StateManagedComponent
Returns the last recorde
ComponentState
.- Specified by:
retrieveComponentState
in interfaceStateManagedComponent
- Returns:
- the current
ComponentState
-
retrieveActiveMsgErrorHandler
protected ProcessingExceptionHandler retrieveActiveMsgErrorHandler()
Accessor to allow sub-classes access to theMessageErrorHandler
that is in use.- Returns:
- the message error handler in use.
-
handleChannelUnavailable
protected void handleChannelUnavailable(AdaptrisMessage msg)
Allows common functionality when the channel is unavailable.- Parameters:
msg
- the current message.
-
resubmitMessage
protected abstract void resubmitMessage(AdaptrisMessage msg)
Resubmit a message upon the channel becoming available again.- Parameters:
msg
- the AdaptrisMessage.
-
handleProduceException
public void handleProduceException()
Description copied from interface:Workflow
Handle an
Exception
encountered producing a message.- Specified by:
handleProduceException
in interfaceWorkflow
- See Also:
Workflow.handleProduceException()
-
doProduce
public void doProduce(AdaptrisMessage msg) throws ServiceException, ProduceException
This method contains the behaviour that varies between standard and request -reply workflows. It is overridden in
RequestReplyWorkflow
.- Specified by:
doProduce
in interfaceWorkflow
- Parameters:
msg
- the message to process- Throws:
ProduceException
- if any occurServiceException
- not thrown by this implementation
-
handleBadMessage
public void handleBadMessage(AdaptrisMessage msg)
Description copied from interface:Workflow
Handle a 'bad' message. A bad message is one which has caused an
Exception
in theServceCollection
orAdaptrisMessageProducer
.- Specified by:
handleBadMessage
in interfaceWorkflow
- Parameters:
msg
- the original version of the 'bad' message- See Also:
Workflow.handleBadMessage(AdaptrisMessage)
-
sendMessageLifecycleEvent
protected void sendMessageLifecycleEvent(AdaptrisMessage wip)
-
obtainWorkflowId
public java.lang.String obtainWorkflowId()
Description copied from interface:Workflow
Returns what the workflow considers to be it's unique ID of the workflow.
This may differ from any 'unique-id' element that has been set.
- Specified by:
obtainWorkflowId
in interfaceWorkflow
- Returns:
- the unique ID
-
friendlyName
public java.lang.String friendlyName()
Description copied from interface:AdaptrisMessageListener
Get the friendly name for this component.- Specified by:
friendlyName
in interfaceAdaptrisMessageListener
- Returns:
- the friendly name.
-
setServiceCollection
public void setServiceCollection(ServiceCollection services)
Sets the
ServiceCollection
to use. May not be null.- Parameters:
services
- theServiceCollection
to use
-
getServiceCollection
public ServiceCollection getServiceCollection()
Returns the
ServiceCollection
to use.- Returns:
- the
ServiceCollection
to use
-
setConsumer
public void setConsumer(AdaptrisMessageConsumer param)
Sets the
AdaptrisMessageConsumer
to use. May not be null. Sets the unique ID of this Workflow based on the consumer's destination's unique ID. If there is no destination (e.g. from aNullMessageConsumer
) , ID is set to "default".- Parameters:
param
- theAdaptrisMessageConsumer
to use
-
getConsumer
public AdaptrisMessageConsumer getConsumer()
Returns the
AdaptrisMessageConsumer
to use.- Specified by:
getConsumer
in interfaceWorkflow
- Returns:
- the
AdaptrisMessageConsumer
to use
-
setProducer
public void setProducer(AdaptrisMessageProducer param)
Sets the
AdaptrisMessageProducer
to use. May not be null.- Parameters:
param
- theAdaptrisMessagePRoducer
to use
-
getProducer
public AdaptrisMessageProducer getProducer()
Returns the
AdaptrisMessageProducer
to use.- Specified by:
getProducer
in interfaceWorkflow
- Returns:
- the
AdaptrisMessageProducer
to use
-
setMessageErrorHandler
public void setMessageErrorHandler(ProcessingExceptionHandler errorHandler)
Sets a configured
MessageErrorHandler
. Will over-ride any MEH configured at the Channel or Workflow level. May be null.- Parameters:
errorHandler
- the configuredMessageErrorHandler
-
getMessageErrorHandler
public ProcessingExceptionHandler getMessageErrorHandler()
Returns the
MessageErrorHandler
to use.- Specified by:
getMessageErrorHandler
in interfaceWorkflow
- Returns:
- the
MessageErrorHandler
to use
-
setSendEvents
public void setSendEvents(java.lang.Boolean events)
Sets whether events should be sent.
- Parameters:
events
- whether events should be sent; default is null (true).
-
getSendEvents
public java.lang.Boolean getSendEvents()
Return whether events should be sent.
- Returns:
- whether events should be sent
-
sendEvents
public boolean sendEvents()
-
obtainChannel
public Channel obtainChannel()
Description copied from interface:Workflow
Returns a reference to this
Workflow
'sChannel
.- Specified by:
obtainChannel
in interfaceWorkflow
- Returns:
- a reference to this
Workflow
'sChannel
- See Also:
Workflow.obtainChannel()
-
registerChannel
public void registerChannel(Channel ch) throws CoreException
Description copied from interface:Workflow
Sets a reference to this
Workflow
'sChannel
.- Specified by:
registerChannel
in interfaceWorkflow
- Parameters:
ch
- thisWorkflow
'sChannel
- Throws:
CoreException
- See Also:
Workflow.registerChannel(com.adaptris.core.Channel)
-
getChannelUnavailableWaitInterval
public TimeInterval getChannelUnavailableWaitInterval()
-
setChannelUnavailableWaitInterval
public void setChannelUnavailableWaitInterval(TimeInterval channelUnavailableWaitInterval)
Sets the time the
Workflow
implementation will wait if its parentChannel
is unavailable before resubmitting the message.- Parameters:
channelUnavailableWaitInterval
- the time
-
channelUnavailableWait
public long channelUnavailableWait()
-
getProduceExceptionHandler
public ProduceExceptionHandler getProduceExceptionHandler()
Returns produceExceptionHandler.
- Returns:
- produceExceptionHandler
-
setProduceExceptionHandler
public void setProduceExceptionHandler(ProduceExceptionHandler p)
Sets produceExceptionHandler.
- Parameters:
p
- the produceExceptionHandler to set
-
getUniqueId
public java.lang.String getUniqueId()
Description copied from interface:Workflow
Returns any configured unique-id.
- Specified by:
getUniqueId
in interfaceAdaptrisComponent
- Specified by:
getUniqueId
in interfaceWorkflow
- Returns:
- the unique ID
-
setUniqueId
public void setUniqueId(java.lang.String id)
-
getInterceptors
public java.util.List<WorkflowInterceptor> getInterceptors()
Description copied from interface:Workflow
Return all the configured interceptors.- Specified by:
getInterceptors
in interfaceWorkflow
- Returns:
- all the configured interceptors.
-
setInterceptors
public void setInterceptors(java.util.List<WorkflowInterceptor> list)
-
addInterceptor
public void addInterceptor(WorkflowInterceptor wi)
-
workflowStart
protected void workflowStart(AdaptrisMessage msg)
Mark the workflow having accepted a message.- Parameters:
msg
- the input message- See Also:
WorkflowInterceptor
-
processingStart
protected void processingStart(AdaptrisMessage msg)
Mark the workflow having started processing a message.- Parameters:
msg
- the input message- See Also:
WorkflowInterceptor
-
workflowEnd
protected void workflowEnd(AdaptrisMessage input, AdaptrisMessage output)
Mark the workflow as finished on this message.- Parameters:
input
- the input messageoutput
- the message that was produced.- See Also:
WorkflowInterceptor
-
copyExceptionHeaders
protected AdaptrisMessage copyExceptionHeaders(AdaptrisMessage workingCopy, AdaptrisMessage orig)
-
handleBadMessage
protected void handleBadMessage(java.lang.String logMsg, java.lang.Exception e, AdaptrisMessage msg)
-
logSuccess
protected void logSuccess(AdaptrisMessage msg, long start)
-
lastStartTime
public java.util.Date lastStartTime()
Get the last time this workflow was started- Specified by:
lastStartTime
in interfaceWorkflow
- Returns:
- workflow start time
-
lastStopTime
public java.util.Date lastStopTime()
Get the last time this channel was stopped. This is set when the channel is initialised so it may have been subsequently started.- Specified by:
lastStopTime
in interfaceWorkflow
- Returns:
- channel stop time
-
getDisableDefaultMessageCount
public java.lang.Boolean getDisableDefaultMessageCount()
-
setDisableDefaultMessageCount
public void setDisableDefaultMessageCount(java.lang.Boolean b)
Disable the defaultMessageMetricsInterceptor
that keeps a message count.If the workflow has a unique-id, and there are no
MessageMetricsInterceptor
instances configured on the workflow, one is created with the same name as the workflow with a default configuredMetricsInterceptorImpl.setTimesliceDuration(com.adaptris.util.TimeInterval)
of 1 minute- Parameters:
b
- true to disable, default null (false);- Since:
- 3.0.3
-
disableMessageCount
public boolean disableMessageCount()
Description copied from interface:Workflow
Whether or not message-counts should be disabled on this workflow.- Specified by:
disableMessageCount
in interfaceWorkflow
-
getMessageLogger
public MessageLogger getMessageLogger()
-
setMessageLogger
public void setMessageLogger(MessageLogger ml)
-
setComments
public void setComments(java.lang.String s)
- Specified by:
setComments
in interfaceConfigComment
-
getComments
public java.lang.String getComments()
- Specified by:
getComments
in interfaceConfigComment
-
messageLogger
public MessageLogger messageLogger()
-
addConsumeLocation
protected AdaptrisMessage addConsumeLocation(AdaptrisMessage msg)
-
-