public abstract class AdaptrisConnectionImp extends java.lang.Object implements AdaptrisConnection, StateManagedComponent
Contains behaviour common to implementations of AdaptrisConnection
.
Modifier and Type | Field and Description |
---|---|
protected org.slf4j.Logger |
log |
Constructor and Description |
---|
AdaptrisConnectionImp()
Created a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addExceptionListener(StateManagedComponent c)
Add a component that will be notified upon exception.
|
void |
addMessageConsumer(AdaptrisMessageConsumer consumer)
Adds a
AdaptrisMessageConsumer to this connection's
internal store of message consumers. |
void |
addMessageProducer(AdaptrisMessageProducer producer)
Adds a
AdaptrisMessageProducer to this connection's
internal store of message producers. |
void |
changeState(ComponentState s)
Updates the state for the component
ComponentState . |
AdaptrisConnection |
cloneForTesting()
Make a copy of this object for test purposes.
|
void |
close()
Closes the component.
|
protected abstract void |
closeConnection()
Close the underlying connection.
|
ConnectionErrorHandler |
connectionErrorHandler()
Returns the currently active
ConnectionErrorHandler |
ConnectionErrorHandler |
getConnectionErrorHandler()
Returns the configured
ConnectionErrorHandler . |
java.lang.String |
getLookupName()
Returns the exact name to bind this object to our
Context . |
java.lang.String |
getUniqueId()
Get the unique-id that is associated with this component.
|
java.lang.Boolean |
getWorkersFirstOnShutdown() |
void |
init()
Initialises the component.
|
protected abstract void |
initConnection()
Initialise the underlying connection.
|
void |
prepare()
Prepare for initialisation.
|
protected abstract void |
prepareConnection() |
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 the connection as represented by this connection
|
java.util.Set<StateManagedComponent> |
retrieveExceptionListeners()
Return a collection of components that need to be restarted on exception.
|
java.util.Set<AdaptrisMessageConsumer> |
retrieveMessageConsumers()
Returns a
List of this connection's
AdaptrisMessageConsumer s. |
java.util.Set<AdaptrisMessageProducer> |
retrieveMessageProducers()
Returns a
List of this connection's
AdaptrisMessageProducer s. |
void |
setConnectionErrorHandler(ConnectionErrorHandler handler)
Sets the
ConnectionErrorHandler to use. |
void |
setLookupName(java.lang.String jndiName) |
void |
setUniqueId(java.lang.String s) |
void |
setWorkersFirstOnShutdown(java.lang.Boolean b)
Perform consumer and producer lifecycle shutdown prior to connection shutdown.
|
void |
start()
Starts the component.
|
protected abstract void |
startConnection()
Start the underlying connection.
|
void |
stop()
Stop the component
|
protected abstract void |
stopConnection()
Stop the underlying connection.
|
boolean |
workersFirstOnShutdown() |
public final 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 final void prepare() throws CoreException
ComponentLifecycleExtension
prepare
in interface ComponentLifecycleExtension
CoreException
protected abstract void prepareConnection() throws CoreException
CoreException
public final 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 final 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 final 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()
protected abstract void initConnection() throws CoreException
CoreException
- wrapping any exception.protected abstract void startConnection() throws CoreException
CoreException
- wrapping any exception.protected abstract void stopConnection()
protected abstract void closeConnection()
public void addExceptionListener(StateManagedComponent c)
AdaptrisConnection
addExceptionListener
in interface AdaptrisConnection
c
- the component that will be notified.public java.util.Set<StateManagedComponent> retrieveExceptionListeners()
AdaptrisConnection
retrieveExceptionListeners
in interface AdaptrisConnection
ConnectionErrorHandler
public void addMessageProducer(AdaptrisMessageProducer producer) throws CoreException
AdaptrisConnection
Adds a AdaptrisMessageProducer
to this connection's
internal store of message producers.
addMessageProducer
in interface AdaptrisConnection
producer
- the AdaptrisMessageProducer
to addCoreException
- wrapping any underlying Exception
s#addMessageProducer(com.adaptris.core.AdaptrisMessageProducer)
public java.util.Set<AdaptrisMessageProducer> retrieveMessageProducers()
AdaptrisConnection
Returns a List
of this connection's
AdaptrisMessageProducer
s.
retrieveMessageProducers
in interface AdaptrisConnection
List
of this connection's
AdaptrisMessageProducer
sAdaptrisConnection.retrieveMessageProducers()
public void addMessageConsumer(AdaptrisMessageConsumer consumer) throws CoreException
AdaptrisConnection
Adds a AdaptrisMessageConsumer
to this connection's
internal store of message consumers.
addMessageConsumer
in interface AdaptrisConnection
consumer
- the AdaptrisMessageConsumer
to addCoreException
- wrapping any underlying Exception
s#addMessageConsumer(com.adaptris.core.AdaptrisMessageConsumer)
public java.util.Set<AdaptrisMessageConsumer> retrieveMessageConsumers()
AdaptrisConnection
Returns a List
of this connection's
AdaptrisMessageConsumer
s.
retrieveMessageConsumers
in interface AdaptrisConnection
List
of this connection's
AdaptrisMessageConsumer
sAdaptrisConnection.retrieveMessageConsumers()
public void setConnectionErrorHandler(ConnectionErrorHandler handler)
AdaptrisConnection
ConnectionErrorHandler
to use.setConnectionErrorHandler
in interface AdaptrisConnection
#setConnectionErrorHandler(com.adaptris.core.ConnectionErrorHandler)
public ConnectionErrorHandler getConnectionErrorHandler()
AdaptrisConnection
ConnectionErrorHandler
.getConnectionErrorHandler
in interface AdaptrisConnection
AdaptrisConnection.getConnectionErrorHandler()
public ConnectionErrorHandler connectionErrorHandler()
AdaptrisConnection
ConnectionErrorHandler
connectionErrorHandler
in interface AdaptrisConnection
ConnectionErrorHandler
, which may not be the same as the configured...public java.lang.Boolean getWorkersFirstOnShutdown()
public boolean workersFirstOnShutdown()
public void setWorkersFirstOnShutdown(java.lang.Boolean b)
When set to true, this method forces the AdaptrisConnection to stop and close any registered MessageConsumer and MessageProducer implementations before attempting to stop and close the underlying Connection. This is useful in cases where shutting down the Connection blocks until all attached workers are manually closed (WebsphereMQ)
When set to false, existing behaviour is preserved, and the consumers and producers are shutdown as part of the normal workflow lifecycle.
b
- true to shutdown workers prior to connection shutdown, default is false.public <T> T retrieveConnection(java.lang.Class<T> type)
retrieveConnection
in interface AdaptrisConnection
type
- the type of connectionpublic java.lang.String getUniqueId()
AdaptrisComponent
getUniqueId
in interface AdaptrisComponent
public void setUniqueId(java.lang.String s)
public void changeState(ComponentState s)
StateManagedComponent
Updates the state for the component ComponentState
.
changeState
in interface StateManagedComponent
public void requestInit() throws CoreException
StateManagedComponent
Request this component is init'd.
requestInit
in interface StateManagedComponent
CoreException
- wrapping any underlying ExceptionsStateManagedComponent.requestInit()
public void requestStart() throws CoreException
StateManagedComponent
Request this component is started.
requestStart
in interface StateManagedComponent
CoreException
- wrapping any underlying ExceptionsStateManagedComponent.requestStart()
public void requestStop()
StateManagedComponent
Request this component is stopped.
requestStop
in interface StateManagedComponent
StateManagedComponent.requestStop()
public void requestClose()
StateManagedComponent
Request this component is closed.
requestClose
in interface StateManagedComponent
StateManagedComponent.requestClose()
public ComponentState retrieveComponentState()
StateManagedComponent
Returns the last recorde ComponentState
.
retrieveComponentState
in interface StateManagedComponent
ComponentState
public java.lang.String getLookupName()
JndiBindable
Context
.
Specifying a lookupName will not be modified at all when binding to jndi. Therefore you may want to prepend your own chosen subcontexts in this name e.g. "comp/env/"
getLookupName
in interface JndiBindable
public void setLookupName(java.lang.String jndiName)
public AdaptrisConnection cloneForTesting() throws CoreException
AdaptrisConnection
cloneForTesting
in interface AdaptrisConnection
CoreException
- wrapping any exceptions