@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.
| 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. |
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 |
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, waitconsumeLocationKeypublic StandaloneConsumer()
Creates a new instance.
public StandaloneConsumer(AdaptrisMessageConsumer consumer)
public StandaloneConsumer(AdaptrisConnection c)
public StandaloneConsumer(AdaptrisConnection c, AdaptrisMessageConsumer amc)
public void init()
throws CoreException
ComponentLifecycleComponent initialisation includes config verification, creation of connections etc.
init in interface ComponentLifecycleCoreException - wrapping any underlying ExceptionsComponentLifecycle.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 ComponentLifecycleCoreException - wrapping any underlying ExceptionsComponentLifecycle.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 ComponentLifecycleComponentLifecycle.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 ComponentLifecycleComponentLifecycle.close()public <T> T retrieveConnection(java.lang.Class<T> type)
AdaptrisMessageWorkerretrieveConnection in interface AdaptrisMessageWorkertype - the type of connection to cast to.public java.lang.String createQualifier()
MessageEventGeneratorMleMarker 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 MessageEventGeneratorMleMarker that is generated.public java.lang.String getUniqueId()
AdaptrisComponentgetUniqueId in interface AdaptrisComponentpublic 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 AdaptrisMessageWorkerconn - the AdaptrisConnection to usepublic AdaptrisMessageConsumer getConsumer()
Returns the underlying AdaptrisMessageConsumer.
AdaptrisMessageConsumerpublic void setConsumer(AdaptrisMessageConsumer cons)
Sets the underlying AdaptrisMessageConsumer. May not be null.
cons - the underlying AdaptrisMessageConsumerpublic void registerAdaptrisMessageListener(AdaptrisMessageListener l)
AdaptrisMessageConsumer
Sets the AdaptrisMessageListener to use.
registerAdaptrisMessageListener in interface AdaptrisMessageConsumerl - the AdaptrisMessageListener to use#registerAdaptrisMessageListener(com.adaptris.core.AdaptrisMessageListener)public AdaptrisMessageEncoder getEncoder()
AdaptrisMessageWorker
Returns the AdaptrisMessageEncoder to use.
getEncoder in interface AdaptrisMessageWorkerAdaptrisMessageEncoder to useAdaptrisMessageWorker.getEncoder()public void setEncoder(AdaptrisMessageEncoder encoder)
AdaptrisMessageWorker
Sets the AdaptrisMessageEncoder to use.
setEncoder in interface AdaptrisMessageWorkerencoder - the AdaptrisMessageEncoder to use(com.adaptris.core.AdaptrisMessageEncoder)public void handleConnectionException()
throws CoreException
AdaptrisMessageWorkerCalled 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 AdaptrisMessageWorkerCoreException - 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 AdaptrisMessageWorkermsg - 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 AdaptrisMessageWorkerbytes - the byte[] to decodeAdaptrisMessageCoreException - wrapping any that occurAdaptrisMessageWorker.decode(byte[])public void prepare()
throws CoreException
ComponentLifecycleExtensionprepare in interface ComponentLifecycleExtensionCoreExceptionpublic java.lang.String createName()
MessageEventGeneratorMleMarker 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 MessageEventGeneratorMessageEventGenerator.createName()public java.lang.Boolean getIsTrackingEndpoint()
public void setIsTrackingEndpoint(java.lang.Boolean b)
public boolean isTrackingEndpoint()
MessageEventGeneratorReturns true if this should be considered an 'end-point' for tracking purposes, otherwise false.
isTrackingEndpoint in interface MessageEventGeneratorMessageEventGenerator.isTrackingEndpoint()public AdaptrisMessageFactory getMessageFactory()
getMessageFactory in interface AdaptrisMessageWorkerAdaptrisMessageWorker.getMessageFactory()public void setMessageFactory(AdaptrisMessageFactory f)
AdaptrisMessageWorkersetMessageFactory in interface AdaptrisMessageWorkerf - the messageFactory to setAdaptrisMessageWorker.setMessageFactory(AdaptrisMessageFactory)public void changeState(ComponentState newState)
StateManagedComponent
Updates the state for the component ComponentState.
changeState in interface StateManagedComponentpublic ComponentState retrieveComponentState()
StateManagedComponent
Returns the last recorde ComponentState.
retrieveComponentState in interface StateManagedComponentComponentStatepublic void requestInit()
throws CoreException
StateManagedComponentRequest this component is init'd.
requestInit in interface StateManagedComponentCoreException - wrapping any underlying Exceptionspublic void requestStart()
throws CoreException
StateManagedComponentRequest this component is started.
requestStart in interface StateManagedComponentCoreException - wrapping any underlying Exceptionspublic void requestStop()
StateManagedComponentRequest this component is stopped.
requestStop in interface StateManagedComponentpublic void requestClose()
StateManagedComponentRequest this component is closed.
requestClose in interface StateManagedComponent