@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 a AdaptrisConnection
. Implements
AdaptrisMessageConsumer
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.
CONFIRMATION_ID_KEY
Constructor and Description |
---|
StandaloneConsumer()
Creates a new instance.
|
StandaloneConsumer(AdaptrisConnection c) |
StandaloneConsumer(AdaptrisConnection c,
AdaptrisMessageConsumer amc) |
StandaloneConsumer(AdaptrisMessageConsumer consumer) |
Modifier and Type | Method and Description |
---|---|
void |
changeState(ComponentState newState)
Updates the state for the component
ComponentState . |
void |
close()
Closes the component.
|
java.lang.String |
createName()
Create a name for any
MleMarker that is generated. |
java.lang.String |
createQualifier()
Create a qualifier for any
MleMarker that is generated. |
AdaptrisMessage |
decode(byte[] bytes)
Decodes the passed byte[] using the configured
AdaptrisMessageEncoder . |
byte[] |
encode(AdaptrisMessage msg)
Encode the passed message using the configured
AdaptrisMessageEncoder . |
AdaptrisConnection |
getConnection()
Get the connection to be used.
|
AdaptrisMessageConsumer |
getConsumer()
Returns the underlying
AdaptrisMessageConsumer . |
ConsumeDestination |
getDestination()
Returns the
ConsumeDestination to use. |
AdaptrisMessageEncoder |
getEncoder()
Returns the
AdaptrisMessageEncoder 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 the
AdaptrisMessageListener to use. |
void |
registerConnection(AdaptrisConnection conn)
Sets the
AdaptrisConnection 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 recorde
ComponentState . |
<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 underlying
AdaptrisMessageConsumer . |
void |
setDestination(ConsumeDestination destination)
Sets the
ConsumeDestination to use. |
void |
setEncoder(AdaptrisMessageEncoder encoder)
Sets the
AdaptrisMessageEncoder 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
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
consumeLocationKey
public StandaloneConsumer()
Creates a new instance.
public StandaloneConsumer(AdaptrisMessageConsumer consumer)
public StandaloneConsumer(AdaptrisConnection c)
public StandaloneConsumer(AdaptrisConnection c, AdaptrisMessageConsumer amc)
public void init() throws CoreException
ComponentLifecycle
Component initialisation includes config verification, creation of connections etc.
init
in interface ComponentLifecycle
CoreException
- wrapping any underlying Exception
sComponentLifecycle.init()
public void start() throws CoreException
ComponentLifecycle
Once a component is started it should be ready to process messages. In the case of AdaptrisMessageConsumer
, calling start
will begin message delivery.
start
in interface ComponentLifecycle
CoreException
- wrapping any underlying Exception
sComponentLifecycle.start()
public void stop()
ComponentLifecycle
A stopped component is not expected to be ready to process messages. In the case of AdaptrisMessageConsumer
, calling stop
will pause message delivery. Throwing a RuntimeException
may cause unintended consequences
stop
in interface ComponentLifecycle
ComponentLifecycle.stop()
public void close()
ComponentLifecycle
A closed component should release any connections it uses, etc. and clean up completely. Throwing a RuntimeException
may
cause unintended consequences
close
in interface ComponentLifecycle
ComponentLifecycle.close()
public <T> T retrieveConnection(java.lang.Class<T> type)
AdaptrisMessageWorker
retrieveConnection
in interface AdaptrisMessageWorker
type
- the type of connection to cast to.public java.lang.String createQualifier()
MessageEventGenerator
MleMarker
that is generated.
The default implementation is to return the unique-id of the component in question, or the empty string if not configured
createQualifier
in interface MessageEventGenerator
MleMarker
that is generated.public java.lang.String getUniqueId()
AdaptrisComponent
getUniqueId
in interface AdaptrisComponent
public AdaptrisConnection getConnection()
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.
public void setConnection(AdaptrisConnection conn)
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.
conn
- the connectionAdaptrisMessageWorker.registerConnection(AdaptrisConnection)
public void registerConnection(AdaptrisConnection conn)
Sets the AdaptrisConnection
to use. May not be null.
registerConnection
in interface AdaptrisMessageWorker
conn
- the AdaptrisConnection
to usepublic AdaptrisMessageConsumer getConsumer()
Returns the underlying AdaptrisMessageConsumer
.
AdaptrisMessageConsumer
public void setConsumer(AdaptrisMessageConsumer cons)
Sets the underlying AdaptrisMessageConsumer
. May not be null.
cons
- the underlying AdaptrisMessageConsumer
public void registerAdaptrisMessageListener(AdaptrisMessageListener l)
AdaptrisMessageConsumer
Sets the AdaptrisMessageListener
to use.
registerAdaptrisMessageListener
in interface AdaptrisMessageConsumer
l
- the AdaptrisMessageListener
to use#registerAdaptrisMessageListener(com.adaptris.core.AdaptrisMessageListener)
public ConsumeDestination getDestination()
AdaptrisMessageConsumer
Returns the ConsumeDestination
to use.
getDestination
in interface AdaptrisMessageConsumer
Object
's ConsumeDestination
AdaptrisMessageConsumer.getDestination()
public void setDestination(ConsumeDestination destination)
AdaptrisMessageConsumer
Sets the ConsumeDestination
to use.
setDestination
in interface AdaptrisMessageConsumer
destination
- the name of the destination#setDestination(com.adaptris.core.ConsumeDestination)
public AdaptrisMessageEncoder getEncoder()
AdaptrisMessageWorker
Returns the AdaptrisMessageEncoder
to use.
getEncoder
in interface AdaptrisMessageWorker
AdaptrisMessageEncoder
to useAdaptrisMessageWorker.getEncoder()
public void setEncoder(AdaptrisMessageEncoder encoder)
AdaptrisMessageWorker
Sets the AdaptrisMessageEncoder
to use.
setEncoder
in interface AdaptrisMessageWorker
encoder
- the AdaptrisMessageEncoder
to use(com.adaptris.core.AdaptrisMessageEncoder)
public void handleConnectionException() throws CoreException
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.
handleConnectionException
in interface AdaptrisMessageWorker
CoreException
- wrapping underlying ExceptionsAdaptrisMessageWorker.handleConnectionException()
public byte[] encode(AdaptrisMessage msg) throws CoreException
AdaptrisMessageWorker
Encode the passed message using the configured
AdaptrisMessageEncoder
. If no AME is configured
implementations should return msg.getBytes()
.
encode
in interface AdaptrisMessageWorker
msg
- the AdaptrisMessage
to encodeAdaptrisMessage
encoded as a byte[]CoreException
- wrapping any that occur(com.adaptris.core.AdaptrisMessage)
public AdaptrisMessage decode(byte[] bytes) throws CoreException
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.
decode
in interface AdaptrisMessageWorker
bytes
- the byte[] to decodeAdaptrisMessage
CoreException
- wrapping any that occurAdaptrisMessageWorker.decode(byte[])
public void prepare() throws CoreException
ComponentLifecycleExtension
prepare
in interface ComponentLifecycleExtension
CoreException
public java.lang.String createName()
MessageEventGenerator
MleMarker
that is generated.
The default implementation is to return the classname of the component in question.
* @return the name for anyMleMarker
that is generated.createName
in interface MessageEventGenerator
MessageEventGenerator.createName()
public java.lang.Boolean getIsTrackingEndpoint()
public void setIsTrackingEndpoint(java.lang.Boolean b)
public boolean isTrackingEndpoint()
MessageEventGenerator
Returns true if this should be considered an 'end-point' for tracking purposes, otherwise false.
isTrackingEndpoint
in interface MessageEventGenerator
MessageEventGenerator.isTrackingEndpoint()
public AdaptrisMessageFactory getMessageFactory()
getMessageFactory
in interface AdaptrisMessageWorker
AdaptrisMessageWorker.getMessageFactory()
public void setMessageFactory(AdaptrisMessageFactory f)
AdaptrisMessageWorker
setMessageFactory
in interface AdaptrisMessageWorker
f
- the messageFactory to setAdaptrisMessageWorker.setMessageFactory(AdaptrisMessageFactory)
public void changeState(ComponentState newState)
StateManagedComponent
Updates the state for the component ComponentState
.
changeState
in interface StateManagedComponent
public ComponentState retrieveComponentState()
StateManagedComponent
Returns the last recorde ComponentState
.
retrieveComponentState
in interface StateManagedComponent
ComponentState
public void requestInit() throws CoreException
StateManagedComponent
Request this component is init'd.
requestInit
in interface StateManagedComponent
CoreException
- wrapping any underlying Exceptionspublic void requestStart() throws CoreException
StateManagedComponent
Request this component is started.
requestStart
in interface StateManagedComponent
CoreException
- wrapping any underlying Exceptionspublic void requestStop()
StateManagedComponent
Request this component is stopped.
requestStop
in interface StateManagedComponent
public void requestClose()
StateManagedComponent
Request this component is closed.
requestClose
in interface StateManagedComponent