Class StandaloneConsumer
- java.lang.Object
-
- com.adaptris.core.StandaloneConsumer
-
- All Implemented Interfaces:
AdaptrisComponent
,AdaptrisMessageConsumer
,AdaptrisMessageWorker
,ComponentLifecycle
,ComponentLifecycleExtension
,MessageEventGenerator
,StateManagedComponent
@ComponentProfile(summary="Standalone wrapper for a consumer and connection", tag="consumer,base") public class StandaloneConsumer extends java.lang.Object implements AdaptrisMessageConsumer, StateManagedComponent, ComponentLifecycleExtension
Wrapper class for a
AdaptrisMessageConsumer
and aAdaptrisConnection
. ImplementsAdaptrisMessageConsumer
and delegates all method calls to the underlying consumer.In the adapter configuration file this class is aliased as standalone-consumer which is the preferred alternative to the fully qualified classname when building your configuration.
-
-
Constructor Summary
Constructors Constructor Description StandaloneConsumer()
Creates a new instance.StandaloneConsumer(AdaptrisConnection c)
StandaloneConsumer(AdaptrisConnection c, AdaptrisMessageConsumer amc)
StandaloneConsumer(AdaptrisMessageConsumer consumer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
changeState(ComponentState newState)
Updates the state for the componentComponentState
.void
close()
Closes the component.java.lang.String
createName()
Create a name for anyMleMarker
that is generated.java.lang.String
createQualifier()
Create a qualifier for anyMleMarker
that is generated.AdaptrisMessage
decode(byte[] bytes)
Decodes the passed byte[] using the configuredAdaptrisMessageEncoder
.byte[]
encode(AdaptrisMessage msg)
Encode the passed message using the configuredAdaptrisMessageEncoder
.AdaptrisConnection
getConnection()
Get the connection to be used.AdaptrisMessageConsumer
getConsumer()
Returns the underlyingAdaptrisMessageConsumer
.AdaptrisMessageEncoder
getEncoder()
Returns theAdaptrisMessageEncoder
to use.java.lang.Boolean
getIsTrackingEndpoint()
AdaptrisMessageFactory
getMessageFactory()
java.lang.String
getUniqueId()
Get the unique-id that is associated with this component.void
handleConnectionException()
Called if a connection exception is encountered.void
init()
Initialises the component.boolean
isTrackingEndpoint()
Returns true if this should be considered an 'end-point' for tracking purposes, otherwise false.void
prepare()
Prepare for initialisation.void
registerAdaptrisMessageListener(AdaptrisMessageListener l)
Sets theAdaptrisMessageListener
to use.void
registerConnection(AdaptrisConnection conn)
Sets theAdaptrisConnection
to use.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.ComponentState
retrieveComponentState()
Returns the last recordeComponentState
.<T> T
retrieveConnection(java.lang.Class<T> type)
Return this components underlying connection.void
setConnection(AdaptrisConnection conn)
Set the connection to be used.void
setConsumer(AdaptrisMessageConsumer cons)
Sets the underlyingAdaptrisMessageConsumer
.void
setEncoder(AdaptrisMessageEncoder encoder)
Sets theAdaptrisMessageEncoder
to use.void
setIsTrackingEndpoint(java.lang.Boolean b)
void
setMessageFactory(AdaptrisMessageFactory f)
Set the message factory used when creating AdaptrisMessage instances.void
start()
Starts the component.void
stop()
Stop the component-
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.AdaptrisMessageConsumer
consumeLocationKey
-
-
-
-
Constructor Detail
-
StandaloneConsumer
public StandaloneConsumer()
Creates a new instance.
-
StandaloneConsumer
public StandaloneConsumer(AdaptrisMessageConsumer consumer)
-
StandaloneConsumer
public StandaloneConsumer(AdaptrisConnection c)
-
StandaloneConsumer
public StandaloneConsumer(AdaptrisConnection c, AdaptrisMessageConsumer amc)
-
-
Method Detail
-
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()
-
retrieveConnection
public <T> T retrieveConnection(java.lang.Class<T> type)
Description copied from interface:AdaptrisMessageWorker
Return this components underlying connection.- Specified by:
retrieveConnection
in interfaceAdaptrisMessageWorker
- Parameters:
type
- the type of connection to cast to.- Returns:
- the connection
-
createQualifier
public java.lang.String createQualifier()
Description copied from interface:MessageEventGenerator
Create a qualifier for anyMleMarker
that is generated.The default implementation is to return the unique-id of the component in question, or the empty string if not configured
- Specified by:
createQualifier
in interfaceMessageEventGenerator
- Returns:
- the qualifier for any
MleMarker
that is generated.
-
getUniqueId
public java.lang.String getUniqueId()
Description copied from interface:AdaptrisComponent
Get the unique-id that is associated with this component.- Specified by:
getUniqueId
in interfaceAdaptrisComponent
- Returns:
- the unique-id
-
getConnection
public AdaptrisConnection getConnection()
Get the connection to be used.As this class is designed to be marshalled to XML, the getter and setter for the connection is required to be present, and simply proxies the underlying AdaptrisMessageWorker implementation.
- Returns:
- the connection
-
setConnection
public void setConnection(AdaptrisConnection conn)
Set the connection to be used.As this class is designed to be marshalled to XML, the getter and setter for the connection is required to be present, and simply proxies the underlying AdaptrisMessageWorker implementation.
- Parameters:
conn
- the connection- See Also:
AdaptrisMessageWorker.registerConnection(AdaptrisConnection)
-
registerConnection
public void registerConnection(AdaptrisConnection conn)
Sets the
AdaptrisConnection
to use. May not be null.- Specified by:
registerConnection
in interfaceAdaptrisMessageWorker
- Parameters:
conn
- theAdaptrisConnection
to use
-
getConsumer
public AdaptrisMessageConsumer getConsumer()
Returns the underlying
AdaptrisMessageConsumer
.- Returns:
- the underlying
AdaptrisMessageConsumer
-
setConsumer
public void setConsumer(AdaptrisMessageConsumer cons)
Sets the underlying
AdaptrisMessageConsumer
. May not be null.- Parameters:
cons
- the underlyingAdaptrisMessageConsumer
-
registerAdaptrisMessageListener
public void registerAdaptrisMessageListener(AdaptrisMessageListener l)
Description copied from interface:AdaptrisMessageConsumer
Sets the
AdaptrisMessageListener
to use.- Specified by:
registerAdaptrisMessageListener
in interfaceAdaptrisMessageConsumer
- Parameters:
l
- theAdaptrisMessageListener
to use- See Also:
#registerAdaptrisMessageListener(com.adaptris.core.AdaptrisMessageListener)
-
getEncoder
public AdaptrisMessageEncoder getEncoder()
Description copied from interface:AdaptrisMessageWorker
Returns the
AdaptrisMessageEncoder
to use.- Specified by:
getEncoder
in interfaceAdaptrisMessageWorker
- Returns:
- the
AdaptrisMessageEncoder
to use - See Also:
AdaptrisMessageWorker.getEncoder()
-
setEncoder
public void setEncoder(AdaptrisMessageEncoder encoder)
Description copied from interface:AdaptrisMessageWorker
Sets the
AdaptrisMessageEncoder
to use.- Specified by:
setEncoder
in interfaceAdaptrisMessageWorker
- Parameters:
encoder
- theAdaptrisMessageEncoder
to use- See Also:
(com.adaptris.core.AdaptrisMessageEncoder)
-
handleConnectionException
public void handleConnectionException() throws CoreException
Description copied from interface:AdaptrisMessageWorker
Called if a connection exception is encountered. Generally this will be when a polling consumer fails to obtain input, when a producer fails to produce or when some third party thread such as JMS exception listener is invoked.
- Specified by:
handleConnectionException
in interfaceAdaptrisMessageWorker
- Throws:
CoreException
- wrapping underlying Exceptions- See Also:
AdaptrisMessageWorker.handleConnectionException()
-
encode
public byte[] encode(AdaptrisMessage msg) throws CoreException
Description copied from interface:AdaptrisMessageWorker
Encode the passed message using the configured
AdaptrisMessageEncoder
. If no AME is configured implementations should returnmsg.getBytes()
.- Specified by:
encode
in interfaceAdaptrisMessageWorker
- Parameters:
msg
- theAdaptrisMessage
to encode- Returns:
- the
AdaptrisMessage
encoded as a byte[] - Throws:
CoreException
- wrapping any that occur- See Also:
(com.adaptris.core.AdaptrisMessage)
-
decode
public AdaptrisMessage decode(byte[] bytes) throws CoreException
Description copied from interface:AdaptrisMessageWorker
Decodes the passed byte[] using the configured
AdaptrisMessageEncoder
. If no AME is configured, implementations should just set the byte[] as the payload of a new message.- Specified by:
decode
in interfaceAdaptrisMessageWorker
- Parameters:
bytes
- the byte[] to decode- Returns:
- an
AdaptrisMessage
- Throws:
CoreException
- wrapping any that occur- See Also:
AdaptrisMessageWorker.decode(byte[])
-
prepare
public void prepare() throws CoreException
Description copied from interface:ComponentLifecycleExtension
Prepare for initialisation.- Specified by:
prepare
in interfaceComponentLifecycleExtension
- Throws:
CoreException
-
createName
public java.lang.String createName()
Description copied from interface:MessageEventGenerator
Create a name for anyMleMarker
that is generated.The default implementation is to return the classname of the component in question.
* @return the name for anyMleMarker
that is generated.- Specified by:
createName
in interfaceMessageEventGenerator
- See Also:
MessageEventGenerator.createName()
-
getIsTrackingEndpoint
public java.lang.Boolean getIsTrackingEndpoint()
-
setIsTrackingEndpoint
public void setIsTrackingEndpoint(java.lang.Boolean b)
-
isTrackingEndpoint
public boolean isTrackingEndpoint()
Description copied from interface:MessageEventGenerator
Returns true if this should be considered an 'end-point' for tracking purposes, otherwise false.
- Specified by:
isTrackingEndpoint
in interfaceMessageEventGenerator
- Returns:
- true if this should be considered an 'end-point' for tracking purposes, otherwise false
- See Also:
MessageEventGenerator.isTrackingEndpoint()
-
getMessageFactory
public AdaptrisMessageFactory getMessageFactory()
- Specified by:
getMessageFactory
in interfaceAdaptrisMessageWorker
- Returns:
- the messageFactory
- See Also:
AdaptrisMessageWorker.getMessageFactory()
-
setMessageFactory
public void setMessageFactory(AdaptrisMessageFactory f)
Description copied from interface:AdaptrisMessageWorker
Set the message factory used when creating AdaptrisMessage instances.- Specified by:
setMessageFactory
in interfaceAdaptrisMessageWorker
- Parameters:
f
- the messageFactory to set- See Also:
AdaptrisMessageWorker.setMessageFactory(AdaptrisMessageFactory)
-
changeState
public void changeState(ComponentState newState)
Description copied from interface:StateManagedComponent
Updates the state for the component
ComponentState
.- Specified by:
changeState
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
-
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
-
-