@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;
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;
log
Constructor and Description |
---|
RetryingServiceWrapper() |
Modifier and Type | Method and 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 component
|
Service[] |
wrappedServices()
Return all the services that are wrapped by this service.
|
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
continueOnFailure, isBranching, setUniqueId
createName, createQualifier, isTrackingEndpoint
changeState, requestClose, requestInit, requestStart, requestStop, retrieveComponentState
getUniqueId
close, init
public void doService(AdaptrisMessage msg) throws ServiceException
Service
Apply the service to the message.
doService
in interface Service
msg
- the AdaptrisMessage
to processServiceException
- wrapping any underlying Exception
spublic void prepare() throws CoreException
ComponentLifecycleExtension
prepare
in interface ComponentLifecycleExtension
CoreException
protected void initService() throws CoreException
initService
in class ServiceImp
CoreException
protected void closeService()
closeService
in class ServiceImp
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 ComponentLifecycle
start
in class ServiceImp
CoreException
- wrapping any underlying Exception
spublic 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
stop
in class ServiceImp
public Service getService()
public void setService(Service service)
public java.lang.Integer getNumRetries()
public void setNumRetries(java.lang.Integer numRetries)
public TimeInterval getDelayBetweenRetries()
public void setDelayBetweenRetries(TimeInterval delayBetweenRetries)
public boolean isRestartOnFailure()
public void setRestartOnFailure(java.lang.Boolean restartOnFailure)
public java.lang.Boolean getRestartOnFailure()
public void registerEventHandler(EventHandler eh)
EventHandlerAware
registerEventHandler
in interface EventHandlerAware
eh
- the event handler currently in use.public Service[] wrappedServices()
ServiceWrapper
wrappedServices
in interface ServiceWrapper