Class AdaptrisConnectionImp
- java.lang.Object
-
- com.adaptris.core.AdaptrisConnectionImp
-
- All Implemented Interfaces:
AdaptrisComponent,AdaptrisConnection,ComponentLifecycle,ComponentLifecycleExtension,StateManagedComponent
- Direct Known Subclasses:
AllowsRetriesConnection,CacheConnection,EmbeddedConnection,JettyConnection,NoOpConnection
public abstract class AdaptrisConnectionImp extends java.lang.Object implements AdaptrisConnection, StateManagedComponent
Contains behaviour common to implementations of
AdaptrisConnection.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Loggerlog
-
Constructor Summary
Constructors Constructor Description AdaptrisConnectionImp()Created a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddExceptionListener(StateManagedComponent c)Add a component that will be notified upon exception.voidaddMessageConsumer(AdaptrisMessageConsumer consumer)Adds aAdaptrisMessageConsumerto this connection's internal store of message consumers.voidaddMessageProducer(AdaptrisMessageProducer producer)Adds aAdaptrisMessageProducerto this connection's internal store of message producers.voidchangeState(ComponentState s)Updates the state for the componentComponentState.AdaptrisConnectioncloneForTesting()Make a copy of this object for test purposes.voidclose()Closes the component.protected abstract voidcloseConnection()Close the underlying connection.ConnectionErrorHandlerconnectionErrorHandler()Returns the currently activeConnectionErrorHandlerConnectionErrorHandlergetConnectionErrorHandler()Returns the configuredConnectionErrorHandler.java.lang.StringgetUniqueId()Get the unique-id that is associated with this component.java.lang.BooleangetWorkersFirstOnShutdown()voidinit()Initialises the component.protected abstract voidinitConnection()Initialise the underlying connection.voidprepare()Prepare for initialisation.protected abstract voidprepareConnection()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 the connection as represented by this connectionjava.util.Set<StateManagedComponent>retrieveExceptionListeners()Return a collection of components that need to be restarted on exception.java.util.Set<AdaptrisMessageConsumer>retrieveMessageConsumers()Returns aListof this connection'sAdaptrisMessageConsumers.java.util.Set<AdaptrisMessageProducer>retrieveMessageProducers()Returns aListof this connection'sAdaptrisMessageProducers.voidsetConnectionErrorHandler(ConnectionErrorHandler handler)Sets theConnectionErrorHandlerto use.voidsetUniqueId(java.lang.String s)voidsetWorkersFirstOnShutdown(java.lang.Boolean b)Perform consumer and producer lifecycle shutdown prior to connection shutdown.voidstart()Starts the component.protected abstract voidstartConnection()Start the underlying connection.voidstop()Stop the componentprotected abstract voidstopConnection()Stop the underlying connection.booleanworkersFirstOnShutdown()
-
-
-
Method Detail
-
init
public final 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()
-
prepare
public final void prepare() throws CoreExceptionDescription copied from interface:ComponentLifecycleExtensionPrepare for initialisation.- Specified by:
preparein interfaceComponentLifecycleExtension- Throws:
CoreException
-
prepareConnection
protected abstract void prepareConnection() throws CoreException- Throws:
CoreException
-
start
public final 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()
-
close
public final 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()
-
stop
public final 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()
-
initConnection
protected abstract void initConnection() throws CoreExceptionInitialise the underlying connection.- Throws:
CoreException- wrapping any exception.
-
startConnection
protected abstract void startConnection() throws CoreExceptionStart the underlying connection.- Throws:
CoreException- wrapping any exception.
-
stopConnection
protected abstract void stopConnection()
Stop the underlying connection.
-
closeConnection
protected abstract void closeConnection()
Close the underlying connection.
-
addExceptionListener
public void addExceptionListener(StateManagedComponent c)
Description copied from interface:AdaptrisConnectionAdd a component that will be notified upon exception.- Specified by:
addExceptionListenerin interfaceAdaptrisConnection- Parameters:
c- the component that will be notified.
-
retrieveExceptionListeners
public java.util.Set<StateManagedComponent> retrieveExceptionListeners()
Description copied from interface:AdaptrisConnectionReturn a collection of components that need to be restarted on exception.- Specified by:
retrieveExceptionListenersin interfaceAdaptrisConnection- Returns:
- a list of Components that need to be restarted of any exceptions.
- See Also:
ConnectionErrorHandler
-
addMessageProducer
public void addMessageProducer(AdaptrisMessageProducer producer) throws CoreException
Description copied from interface:AdaptrisConnectionAdds a
AdaptrisMessageProducerto this connection's internal store of message producers.- Specified by:
addMessageProducerin interfaceAdaptrisConnection- Parameters:
producer- theAdaptrisMessageProducerto add- Throws:
CoreException- wrapping any underlyingExceptions- See Also:
#addMessageProducer(com.adaptris.core.AdaptrisMessageProducer)
-
retrieveMessageProducers
public java.util.Set<AdaptrisMessageProducer> retrieveMessageProducers()
Description copied from interface:AdaptrisConnectionReturns a
Listof this connection'sAdaptrisMessageProducers.- Specified by:
retrieveMessageProducersin interfaceAdaptrisConnection- Returns:
- a
Listof this connection'sAdaptrisMessageProducers - See Also:
AdaptrisConnection.retrieveMessageProducers()
-
addMessageConsumer
public void addMessageConsumer(AdaptrisMessageConsumer consumer) throws CoreException
Description copied from interface:AdaptrisConnectionAdds a
AdaptrisMessageConsumerto this connection's internal store of message consumers.- Specified by:
addMessageConsumerin interfaceAdaptrisConnection- Parameters:
consumer- theAdaptrisMessageConsumerto add- Throws:
CoreException- wrapping any underlyingExceptions- See Also:
#addMessageConsumer(com.adaptris.core.AdaptrisMessageConsumer)
-
retrieveMessageConsumers
public java.util.Set<AdaptrisMessageConsumer> retrieveMessageConsumers()
Description copied from interface:AdaptrisConnectionReturns a
Listof this connection'sAdaptrisMessageConsumers.- Specified by:
retrieveMessageConsumersin interfaceAdaptrisConnection- Returns:
- a
Listof this connection'sAdaptrisMessageConsumers - See Also:
AdaptrisConnection.retrieveMessageConsumers()
-
setConnectionErrorHandler
public void setConnectionErrorHandler(ConnectionErrorHandler handler)
Description copied from interface:AdaptrisConnectionSets theConnectionErrorHandlerto use.- Specified by:
setConnectionErrorHandlerin interfaceAdaptrisConnection- See Also:
#setConnectionErrorHandler(com.adaptris.core.ConnectionErrorHandler)
-
getConnectionErrorHandler
public ConnectionErrorHandler getConnectionErrorHandler()
Description copied from interface:AdaptrisConnectionReturns the configuredConnectionErrorHandler.- Specified by:
getConnectionErrorHandlerin interfaceAdaptrisConnection- See Also:
AdaptrisConnection.getConnectionErrorHandler()
-
connectionErrorHandler
public ConnectionErrorHandler connectionErrorHandler()
Description copied from interface:AdaptrisConnectionReturns the currently activeConnectionErrorHandler- Specified by:
connectionErrorHandlerin interfaceAdaptrisConnection- Returns:
- the active
ConnectionErrorHandler, which may not be the same as the configured...
-
getWorkersFirstOnShutdown
public java.lang.Boolean getWorkersFirstOnShutdown()
- Returns:
- the workerLifecycleFirstOnShutdown
-
workersFirstOnShutdown
public boolean workersFirstOnShutdown()
- Returns:
- the workerLifecycleFirstOnShutdown
-
setWorkersFirstOnShutdown
public void setWorkersFirstOnShutdown(java.lang.Boolean b)
Perform consumer and producer lifecycle shutdown prior to connection shutdown.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.
- Parameters:
b- true to shutdown workers prior to connection shutdown, default is false.
-
retrieveConnection
public <T> T retrieveConnection(java.lang.Class<T> type)
Return the connection as represented by this connection- Specified by:
retrieveConnectionin interfaceAdaptrisConnection- Parameters:
type- the type of connection- Returns:
- the connection
-
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
-
setUniqueId
public void setUniqueId(java.lang.String s)
-
changeState
public void changeState(ComponentState s)
Description copied from interface:StateManagedComponentUpdates the state for the component
ComponentState.- Specified by:
changeStatein interfaceStateManagedComponent
-
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- See Also:
StateManagedComponent.requestInit()
-
requestStart
public void requestStart() throws CoreExceptionDescription copied from interface:StateManagedComponentRequest this component is started.
- Specified by:
requestStartin interfaceStateManagedComponent- Throws:
CoreException- wrapping any underlying Exceptions- See Also:
StateManagedComponent.requestStart()
-
requestStop
public void requestStop()
Description copied from interface:StateManagedComponentRequest this component is stopped.
- Specified by:
requestStopin interfaceStateManagedComponent- See Also:
StateManagedComponent.requestStop()
-
requestClose
public void requestClose()
Description copied from interface:StateManagedComponentRequest this component is closed.
- Specified by:
requestClosein interfaceStateManagedComponent- See Also:
StateManagedComponent.requestClose()
-
retrieveComponentState
public ComponentState retrieveComponentState()
Description copied from interface:StateManagedComponentReturns the last recorde
ComponentState.- Specified by:
retrieveComponentStatein interfaceStateManagedComponent- Returns:
- the current
ComponentState
-
cloneForTesting
public AdaptrisConnection cloneForTesting() throws CoreException
Description copied from interface:AdaptrisConnectionMake a copy of this object for test purposes.- Specified by:
cloneForTestingin interfaceAdaptrisConnection- Returns:
- a copy of this object
- Throws:
CoreException- wrapping any exceptions
-
-