Class Channel
- java.lang.Object
-
- com.adaptris.core.Channel
-
- All Implemented Interfaces:
AdaptrisComponent
,ComponentLifecycle
,ComponentLifecycleExtension
,ConfigComment
,EventHandlerAware
,StateManagedComponent
,StateManagedComponentContainer
@ComponentProfile(summary="Channels bind two connections together for workflows to do their work", tag="base") public class Channel extends java.lang.Object implements ComponentLifecycleExtension, StateManagedComponentContainer, EventHandlerAware, ConfigComment
Links two
AdaptrisConnection
implementations and has aWorkflowList
In the adapter configuration file this class is aliased as channel which is the preferred alternative to the fully qualified classname when building your configuration.
-
-
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
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
changeState(ComponentState s)
Updates the state for the componentComponentState
.void
close()
Closes the component.java.lang.Boolean
getAutoStart()
java.lang.String
getComments()
AdaptrisConnection
getConsumeConnection()
Returns theAdaptrisConnection
used for consuming.ProcessingExceptionHandler
getMessageErrorHandler()
Returns theMessageErrorHandler
to use.AdaptrisConnection
getProduceConnection()
Returns theAdaptrisConnection
used for producing.java.lang.String
getUniqueId()
Get the unique id of this channel.WorkflowList
getWorkflowList()
Returns theWorkflowList
to use.boolean
hasUniqueId()
Check if this channel has a unique Id.void
init()
Initialises the component.boolean
isAvailable()
Returnstrue
if thisChannel
is available.java.util.Date
lastStartTime()
Get the last time this channel was startedjava.util.Date
lastStopTime()
Get the last time this channel was stopped.void
prepare()
Prepare for initialisation.void
registerActiveMsgErrorHandler(ProcessingExceptionHandler m)
Register the activeMessageErrorHandler
for this Channel.void
registerEventHandler(EventHandler eh)
Register the current event handler against this component.void
requestChildClose()
Close any independent sub components.void
requestChildInit()
Initialise any independent sub-components.void
requestChildStart()
Start any independent sub components.void
requestChildStop()
Stop any independent sub components.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.ProcessingExceptionHandler
retrieveActiveMsgErrorHandler()
Return the activeMessageErrorHandler
for this Channel.ComponentState
retrieveComponentState()
This method is notsynchronized
and returns the 'last recorded' state of this object.void
setAutoStart(java.lang.Boolean autoStart)
Specify whether or not to auto-start the channel.void
setComments(java.lang.String s)
void
setConsumeConnection(AdaptrisConnection connection)
Sets theAdaptrisConnection
to use for consuming.void
setMessageErrorHandler(ProcessingExceptionHandler errorHandler)
Sets theMessageErrorHandler
to use.void
setProduceConnection(AdaptrisConnection connection)
Sets theAdaptrisConnection
to use for producing.void
setUniqueId(java.lang.String string)
Set the unique id of this channel.void
setWorkflowList(WorkflowList workflows)
Sets theWorkflowList
to use.boolean
shouldStart()
void
start()
Starts the component.void
stop()
Stop the componentvoid
toggleAvailability(boolean b)
Set whether thisChannel
is available.
-
-
-
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
-
prepare
public void prepare() throws CoreException
Description copied from interface:ComponentLifecycleExtension
Prepare for initialisation.- Specified by:
prepare
in interfaceComponentLifecycleExtension
- Throws:
CoreException
-
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.
-
changeState
public void changeState(ComponentState s)
Description copied from interface:StateManagedComponent
Updates the state for the component
ComponentState
.- Specified by:
changeState
in interfaceStateManagedComponent
-
init
public void init() throws CoreException
Description copied from interface:ComponentLifecycle
Initialises the component.Component initialisation includes config verification, creation of connections etc.
- Specified by:
init
in interfaceComponentLifecycle
- Throws:
CoreException
- wrapping any underlyingException
s- See Also:
ComponentLifecycle.init()
-
start
public void start() throws CoreException
Description copied from interface:ComponentLifecycle
Starts the component.Once a component is started it should be ready to process messages. In the case of
AdaptrisMessageConsumer
, calling start will begin message delivery.- Specified by:
start
in interfaceComponentLifecycle
- Throws:
CoreException
- wrapping any underlyingException
s- See Also:
ComponentLifecycle.start()
-
stop
public void stop()
Description copied from interface:ComponentLifecycle
Stop the componentA stopped component is not expected to be ready to process messages. In the case of
AdaptrisMessageConsumer
, calling stop will pause message delivery. Throwing aRuntimeException
may cause unintended consequences- Specified by:
stop
in interfaceComponentLifecycle
- See Also:
ComponentLifecycle.stop()
-
close
public void close()
Description copied from interface:ComponentLifecycle
Closes the component.A closed component should release any connections it uses, etc. and clean up completely. Throwing a
RuntimeException
may cause unintended consequences- Specified by:
close
in interfaceComponentLifecycle
- See Also:
ComponentLifecycle.close()
-
setConsumeConnection
public void setConsumeConnection(AdaptrisConnection connection)
Sets the
AdaptrisConnection
to use for consuming.- Parameters:
connection
- theAdaptrisConnection
to use for consuming, may not be null
-
getConsumeConnection
public AdaptrisConnection getConsumeConnection()
Returns the
AdaptrisConnection
used for consuming.- Returns:
- the
AdaptrisConnection
used for consuming
-
setProduceConnection
public void setProduceConnection(AdaptrisConnection connection)
Sets the
AdaptrisConnection
to use for producing.- Parameters:
connection
- theAdaptrisConnection
to use for producing, may not be null
-
getProduceConnection
public AdaptrisConnection getProduceConnection()
Returns the
AdaptrisConnection
used for producing.- Returns:
- the
AdaptrisConnection
used for producing
-
setWorkflowList
public void setWorkflowList(WorkflowList workflows)
Sets the
WorkflowList
to use.- Parameters:
workflows
- theWorkflowList
to use, may not be null
-
getWorkflowList
public WorkflowList getWorkflowList()
Returns the
WorkflowList
to use.- Returns:
- the
WorkflowList
to use
-
setMessageErrorHandler
public void setMessageErrorHandler(ProcessingExceptionHandler errorHandler)
Sets the
MessageErrorHandler
to use.- Parameters:
errorHandler
- theMessageErrorHandler
to use, may not be null
-
getMessageErrorHandler
public ProcessingExceptionHandler getMessageErrorHandler()
Returns the
MessageErrorHandler
to use.- Returns:
- the
MessageErrorHandler
to use
-
isAvailable
public boolean isAvailable()
Returns
true
if thisChannel
is available. AChannel
is available if i) it is not in the process of being rebooted or ii) it has not failed to reboot.- Returns:
true
if thisChannel
is available
-
toggleAvailability
public void toggleAvailability(boolean b)
Set whether this
Channel
is available.- Parameters:
b
- whether thisChannel
is available
-
registerActiveMsgErrorHandler
public void registerActiveMsgErrorHandler(ProcessingExceptionHandler m)
Register the activeMessageErrorHandler
for this Channel.- Parameters:
m
- the activeMessageErrorHandler
-
retrieveActiveMsgErrorHandler
public ProcessingExceptionHandler retrieveActiveMsgErrorHandler()
Return the activeMessageErrorHandler
for this Channel.- Returns:
- the active
MessageErrorHandler
-
getUniqueId
public java.lang.String getUniqueId()
Get the unique id of this channel.
- Specified by:
getUniqueId
in interfaceAdaptrisComponent
- Returns:
- the unique id
-
setUniqueId
public void setUniqueId(java.lang.String string)
Set the unique id of this channel. The channel's unique id allows it to be individually controlled, either by an event or by the Adapter container.
- Parameters:
string
- the unique id
-
hasUniqueId
public boolean hasUniqueId()
Check if this channel has a unique Id.
- Returns:
- true if the unique id is non-null and non- empty
-
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- See Also:
StateManagedComponent.requestInit()
-
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- See Also:
StateManagedComponent.requestStart()
-
requestStop
public void requestStop()
Description copied from interface:StateManagedComponent
Request this component is stopped.
- Specified by:
requestStop
in interfaceStateManagedComponent
- See Also:
StateManagedComponent.requestStop()
-
requestClose
public void requestClose()
Description copied from interface:StateManagedComponent
Request this component is closed.
- Specified by:
requestClose
in interfaceStateManagedComponent
- See Also:
StateManagedComponent.requestClose()
-
retrieveComponentState
public ComponentState retrieveComponentState()
This method is not
synchronized
and returns the 'last recorded' state of this object.- Specified by:
retrieveComponentState
in interfaceStateManagedComponent
- Returns:
- the current
ComponentState
- See Also:
StateManagedComponent.retrieveComponentState()
-
requestChildInit
public void requestChildInit() throws CoreException
Description copied from interface:StateManagedComponentContainer
Initialise any independent sub-components.- Specified by:
requestChildInit
in interfaceStateManagedComponentContainer
- Throws:
CoreException
- wrapping any underlying Exceptions- See Also:
StateManagedComponentContainer.requestChildInit()
-
requestChildStart
public void requestChildStart() throws CoreException
Description copied from interface:StateManagedComponentContainer
Start any independent sub components.- Specified by:
requestChildStart
in interfaceStateManagedComponentContainer
- Throws:
CoreException
- wrapping any underlying Exceptions- See Also:
StateManagedComponentContainer.requestChildStart()
-
requestChildStop
public void requestChildStop()
Description copied from interface:StateManagedComponentContainer
Stop any independent sub components.- Specified by:
requestChildStop
in interfaceStateManagedComponentContainer
- See Also:
StateManagedComponentContainer.requestChildStop()
-
requestChildClose
public void requestChildClose()
Description copied from interface:StateManagedComponentContainer
Close any independent sub components.- Specified by:
requestChildClose
in interfaceStateManagedComponentContainer
- See Also:
StateManagedComponentContainer.requestChildClose()
-
getAutoStart
public java.lang.Boolean getAutoStart()
-
setAutoStart
public void setAutoStart(java.lang.Boolean autoStart)
Specify whether or not to auto-start the channel.If auto-start is set to false, then this channel is not started. This behaviour only occurs if the channel has a non-null/empty unique-id as otherwise you will not be able to start the channel through the standard JMX controls
- Parameters:
autoStart
- default is true.
-
shouldStart
public boolean shouldStart()
-
lastStartTime
public java.util.Date lastStartTime()
Get the last time this channel was started- Returns:
- channel 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.- Returns:
- channel stop time
-
setComments
public void setComments(java.lang.String s)
- Specified by:
setComments
in interfaceConfigComment
-
getComments
public java.lang.String getComments()
- Specified by:
getComments
in interfaceConfigComment
-
-