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, ComponentLifecycleExtensionWrapper class for a
AdaptrisMessageConsumerand aAdaptrisConnection. ImplementsAdaptrisMessageConsumerand 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 voidchangeState(ComponentState newState)Updates the state for the componentComponentState.voidclose()Closes the component.java.lang.StringcreateName()Create a name for anyMleMarkerthat is generated.java.lang.StringcreateQualifier()Create a qualifier for anyMleMarkerthat is generated.AdaptrisMessagedecode(byte[] bytes)Decodes the passed byte[] using the configuredAdaptrisMessageEncoder.byte[]encode(AdaptrisMessage msg)Encode the passed message using the configuredAdaptrisMessageEncoder.AdaptrisConnectiongetConnection()Get the connection to be used.AdaptrisMessageConsumergetConsumer()Returns the underlyingAdaptrisMessageConsumer.AdaptrisMessageEncodergetEncoder()Returns theAdaptrisMessageEncoderto use.java.lang.BooleangetIsTrackingEndpoint()AdaptrisMessageFactorygetMessageFactory()java.lang.StringgetUniqueId()Get the unique-id that is associated with this component.voidhandleConnectionException()Called if a connection exception is encountered.voidinit()Initialises the component.booleanisTrackingEndpoint()Returns true if this should be considered an 'end-point' for tracking purposes, otherwise false.voidprepare()Prepare for initialisation.voidregisterAdaptrisMessageListener(AdaptrisMessageListener l)Sets theAdaptrisMessageListenerto use.voidregisterConnection(AdaptrisConnection conn)Sets theAdaptrisConnectionto use.voidrequestClose()Request this component is closed.voidrequestInit()Request this component is init'd.voidrequestStart()Request this component is started.voidrequestStop()Request this component is stopped.ComponentStateretrieveComponentState()Returns the last recordeComponentState.<T> TretrieveConnection(java.lang.Class<T> type)Return this components underlying connection.voidsetConnection(AdaptrisConnection conn)Set the connection to be used.voidsetConsumer(AdaptrisMessageConsumer cons)Sets the underlyingAdaptrisMessageConsumer.voidsetEncoder(AdaptrisMessageEncoder encoder)Sets theAdaptrisMessageEncoderto use.voidsetIsTrackingEndpoint(java.lang.Boolean b)voidsetMessageFactory(AdaptrisMessageFactory f)Set the message factory used when creating AdaptrisMessage instances.voidstart()Starts the component.voidstop()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 CoreExceptionDescription copied from interface:ComponentLifecycleInitialises the component.Component initialisation includes config verification, creation of connections etc.
- Specified by:
initin interfaceComponentLifecycle- Throws:
CoreException- wrapping any underlyingExceptions- See Also:
ComponentLifecycle.init()
-
start
public void start() throws CoreExceptionDescription copied from interface:ComponentLifecycleStarts 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:
startin interfaceComponentLifecycle- Throws:
CoreException- wrapping any underlyingExceptions- See Also:
ComponentLifecycle.start()
-
stop
public void stop()
Description copied from interface:ComponentLifecycleStop 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 aRuntimeExceptionmay cause unintended consequences- Specified by:
stopin interfaceComponentLifecycle- See Also:
ComponentLifecycle.stop()
-
close
public void close()
Description copied from interface:ComponentLifecycleCloses the component.A closed component should release any connections it uses, etc. and clean up completely. Throwing a
RuntimeExceptionmay cause unintended consequences- Specified by:
closein interfaceComponentLifecycle- See Also:
ComponentLifecycle.close()
-
retrieveConnection
public <T> T retrieveConnection(java.lang.Class<T> type)
Description copied from interface:AdaptrisMessageWorkerReturn this components underlying connection.- Specified by:
retrieveConnectionin interfaceAdaptrisMessageWorker- Parameters:
type- the type of connection to cast to.- Returns:
- the connection
-
createQualifier
public java.lang.String createQualifier()
Description copied from interface:MessageEventGeneratorCreate a qualifier for anyMleMarkerthat 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:
createQualifierin interfaceMessageEventGenerator- Returns:
- the qualifier for any
MleMarkerthat is generated.
-
getUniqueId
public java.lang.String getUniqueId()
Description copied from interface:AdaptrisComponentGet the unique-id that is associated with this component.- Specified by:
getUniqueIdin 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
AdaptrisConnectionto use. May not be null.- Specified by:
registerConnectionin interfaceAdaptrisMessageWorker- Parameters:
conn- theAdaptrisConnectionto 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:AdaptrisMessageConsumerSets the
AdaptrisMessageListenerto use.- Specified by:
registerAdaptrisMessageListenerin interfaceAdaptrisMessageConsumer- Parameters:
l- theAdaptrisMessageListenerto use- See Also:
#registerAdaptrisMessageListener(com.adaptris.core.AdaptrisMessageListener)
-
getEncoder
public AdaptrisMessageEncoder getEncoder()
Description copied from interface:AdaptrisMessageWorkerReturns the
AdaptrisMessageEncoderto use.- Specified by:
getEncoderin interfaceAdaptrisMessageWorker- Returns:
- the
AdaptrisMessageEncoderto use - See Also:
AdaptrisMessageWorker.getEncoder()
-
setEncoder
public void setEncoder(AdaptrisMessageEncoder encoder)
Description copied from interface:AdaptrisMessageWorkerSets the
AdaptrisMessageEncoderto use.- Specified by:
setEncoderin interfaceAdaptrisMessageWorker- Parameters:
encoder- theAdaptrisMessageEncoderto use- See Also:
(com.adaptris.core.AdaptrisMessageEncoder)
-
handleConnectionException
public void handleConnectionException() throws CoreExceptionDescription copied from interface: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.
- Specified by:
handleConnectionExceptionin interfaceAdaptrisMessageWorker- Throws:
CoreException- wrapping underlying Exceptions- See Also:
AdaptrisMessageWorker.handleConnectionException()
-
encode
public byte[] encode(AdaptrisMessage msg) throws CoreException
Description copied from interface:AdaptrisMessageWorkerEncode the passed message using the configured
AdaptrisMessageEncoder. If no AME is configured implementations should returnmsg.getBytes().- Specified by:
encodein interfaceAdaptrisMessageWorker- Parameters:
msg- theAdaptrisMessageto encode- Returns:
- the
AdaptrisMessageencoded 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:AdaptrisMessageWorkerDecodes 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:
decodein 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 CoreExceptionDescription copied from interface:ComponentLifecycleExtensionPrepare for initialisation.- Specified by:
preparein interfaceComponentLifecycleExtension- Throws:
CoreException
-
createName
public java.lang.String createName()
Description copied from interface:MessageEventGeneratorCreate a name for anyMleMarkerthat is generated.The default implementation is to return the classname of the component in question.
* @return the name for anyMleMarkerthat is generated.- Specified by:
createNamein 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:MessageEventGeneratorReturns true if this should be considered an 'end-point' for tracking purposes, otherwise false.
- Specified by:
isTrackingEndpointin 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:
getMessageFactoryin interfaceAdaptrisMessageWorker- Returns:
- the messageFactory
- See Also:
AdaptrisMessageWorker.getMessageFactory()
-
setMessageFactory
public void setMessageFactory(AdaptrisMessageFactory f)
Description copied from interface:AdaptrisMessageWorkerSet the message factory used when creating AdaptrisMessage instances.- Specified by:
setMessageFactoryin interfaceAdaptrisMessageWorker- Parameters:
f- the messageFactory to set- See Also:
AdaptrisMessageWorker.setMessageFactory(AdaptrisMessageFactory)
-
changeState
public void changeState(ComponentState newState)
Description copied from interface:StateManagedComponentUpdates the state for the component
ComponentState.- Specified by:
changeStatein interfaceStateManagedComponent
-
retrieveComponentState
public ComponentState retrieveComponentState()
Description copied from interface:StateManagedComponentReturns the last recorde
ComponentState.- Specified by:
retrieveComponentStatein interfaceStateManagedComponent- Returns:
- the current
ComponentState
-
requestInit
public void requestInit() throws CoreExceptionDescription copied from interface:StateManagedComponentRequest this component is init'd.
- Specified by:
requestInitin interfaceStateManagedComponent- Throws:
CoreException- wrapping any underlying Exceptions
-
requestStart
public void requestStart() throws CoreExceptionDescription copied from interface:StateManagedComponentRequest this component is started.
- Specified by:
requestStartin interfaceStateManagedComponent- Throws:
CoreException- wrapping any underlying Exceptions
-
requestStop
public void requestStop()
Description copied from interface:StateManagedComponentRequest this component is stopped.
- Specified by:
requestStopin interfaceStateManagedComponent
-
requestClose
public void requestClose()
Description copied from interface:StateManagedComponentRequest this component is closed.
- Specified by:
requestClosein interfaceStateManagedComponent
-
-