Class RetryingServiceWrapper
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.services.RetryingServiceWrapper
-
- All Implemented Interfaces:
AdaptrisComponent
,ComponentLifecycle
,ComponentLifecycleExtension
,EventHandlerAware
,MessageEventGenerator
,Service
,ServiceWrapper
,StateManagedComponent
@ComponentProfile(summary="Retry a message periodically if the wrapped service fails", tag="service") public class RetryingServiceWrapper extends ServiceImp implements EventHandlerAware, ServiceWrapper
This service wrapper, will attempt to run the wrapped service and should the service fail with a
ServiceException
we will attempt to retry the service according to your configuration.You can control then retrying behaviour with the following two configurable options;
- num-retries
- delay-between-retries
A value of zero for num-retries will retry the wrapped service infinitely. The default value if not set is 10.
The delay-between-retries is of type
TimeInterval
. The default value if not set is 10 seconds.You may also force the wrapped service to be restarted upon each retry by setting restart-on-failure to true;
-
-
Field Summary
-
Fields inherited from class com.adaptris.core.ServiceImp
log
-
-
Constructor Summary
Constructors Constructor Description RetryingServiceWrapper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closeService()
void
doService(AdaptrisMessage msg)
Apply the service to the message.TimeInterval
getDelayBetweenRetries()
java.lang.Integer
getNumRetries()
java.lang.Boolean
getRestartOnFailure()
Service
getService()
protected void
initService()
boolean
isRestartOnFailure()
void
prepare()
Prepare for initialisation.void
registerEventHandler(EventHandler eh)
Register the current event handler against this component.void
setDelayBetweenRetries(TimeInterval delayBetweenRetries)
void
setNumRetries(java.lang.Integer numRetries)
void
setRestartOnFailure(java.lang.Boolean restartOnFailure)
void
setService(Service service)
void
start()
Starts the component.void
stop()
Stop the componentService[]
wrappedServices()
Return all the services that are wrapped by this service.-
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId
-
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.AdaptrisComponent
getUniqueId
-
Methods inherited from interface com.adaptris.core.ComponentLifecycle
close, init
-
Methods inherited from interface com.adaptris.core.MessageEventGenerator
createName, createQualifier, isTrackingEndpoint
-
Methods inherited from interface com.adaptris.core.Service
continueOnFailure, isBranching, setUniqueId
-
Methods inherited from interface com.adaptris.core.StateManagedComponent
changeState, requestClose, requestInit, requestStart, requestStop, retrieveComponentState
-
-
-
-
Method Detail
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
Description copied from interface:Service
Apply the service to the message.
- Specified by:
doService
in interfaceService
- Parameters:
msg
- theAdaptrisMessage
to process- Throws:
ServiceException
- wrapping any underlyingException
s
-
prepare
public void prepare() throws CoreException
Description copied from interface:ComponentLifecycleExtension
Prepare for initialisation.- Specified by:
prepare
in interfaceComponentLifecycleExtension
- Throws:
CoreException
-
initService
protected void initService() throws CoreException
- Specified by:
initService
in classServiceImp
- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeService
in classServiceImp
-
start
public void start() throws CoreException
Description copied from interface:ComponentLifecycle
Starts 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:
start
in interfaceComponentLifecycle
- Overrides:
start
in classServiceImp
- Throws:
CoreException
- wrapping any underlyingException
s
-
stop
public void stop()
Description copied from interface:ComponentLifecycle
Stop 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 aRuntimeException
may cause unintended consequences- Specified by:
stop
in interfaceComponentLifecycle
- Overrides:
stop
in classServiceImp
-
getService
public Service getService()
-
setService
public void setService(Service service)
-
getNumRetries
public java.lang.Integer getNumRetries()
-
setNumRetries
public void setNumRetries(java.lang.Integer numRetries)
-
getDelayBetweenRetries
public TimeInterval getDelayBetweenRetries()
-
setDelayBetweenRetries
public void setDelayBetweenRetries(TimeInterval delayBetweenRetries)
-
isRestartOnFailure
public boolean isRestartOnFailure()
-
setRestartOnFailure
public void setRestartOnFailure(java.lang.Boolean restartOnFailure)
-
getRestartOnFailure
public java.lang.Boolean getRestartOnFailure()
-
registerEventHandler
public void registerEventHandler(EventHandler eh)
Description copied from interface:EventHandlerAware
Register the current event handler against this component.- Specified by:
registerEventHandler
in interfaceEventHandlerAware
- Parameters:
eh
- the event handler currently in use.
-
wrappedServices
public Service[] wrappedServices()
Description copied from interface:ServiceWrapper
Return all the services that are wrapped by this service.- Specified by:
wrappedServices
in interfaceServiceWrapper
- Returns:
- an array of wrapped services.
-
-