Package org.apache.camel.component.netty
Class TimeoutCorrelationManagerSupport
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.component.netty.TimeoutCorrelationManagerSupport
-
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.CamelContextAware
,NettyCamelStateCorrelationManager
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
public abstract class TimeoutCorrelationManagerSupport extends org.apache.camel.support.service.ServiceSupport implements org.apache.camel.CamelContextAware, NettyCamelStateCorrelationManager
A base class for usingNettyCamelStateCorrelationManager
that supports timeout.
-
-
Constructor Summary
Constructors Constructor Description TimeoutCorrelationManagerSupport()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
doShutdown()
protected void
doStart()
protected void
doStop()
org.apache.camel.CamelContext
getCamelContext()
abstract String
getRequestCorrelationId(Object request)
Implement this method to extract the correlation id from the request message body.abstract String
getResponseCorrelationId(Object response)
Implement this method to extract the correlation id from the response message body.NettyCamelState
getState(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.Channel channel, Object msg)
Gets the state when a response message has been received.NettyCamelState
getState(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.Channel channel, Throwable cause)
Gets the state when some internal error occurred.long
getTimeout()
long
getTimeoutChecker()
org.apache.camel.LoggingLevel
getTimeoutLoggingLevel()
String
getTimeoutResponse(String correlationId, Object request)
Override this to implement a custom timeout response message.ExecutorService
getWorkerPool()
void
putState(io.netty.channel.Channel channel, NettyCamelState state)
Puts the state.void
removeState(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.Channel channel)
Removes the state when the channel is inactive.void
setCamelContext(org.apache.camel.CamelContext camelContext)
void
setTimeout(long timeout)
Sets timeout value in millis seconds.void
setTimeoutChecker(long timeoutChecker)
Time in millis how frequent to check for timeouts.void
setTimeoutLoggingLevel(org.apache.camel.LoggingLevel timeoutLoggingLevel)
Sets the logging level to use when a timeout was hit.void
setWorkerPool(ExecutorService workerPool)
To use a shared worker pool for processing timed out requests.-
Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doInit, doLifecycleChange, doResume, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Method Detail
-
getCamelContext
public org.apache.camel.CamelContext getCamelContext()
- Specified by:
getCamelContext
in interfaceorg.apache.camel.CamelContextAware
-
setCamelContext
public void setCamelContext(org.apache.camel.CamelContext camelContext)
- Specified by:
setCamelContext
in interfaceorg.apache.camel.CamelContextAware
-
getTimeout
public long getTimeout()
-
setTimeout
public void setTimeout(long timeout)
Sets timeout value in millis seconds. The default value is 30000 (30 seconds).
-
getTimeoutChecker
public long getTimeoutChecker()
-
setTimeoutChecker
public void setTimeoutChecker(long timeoutChecker)
Time in millis how frequent to check for timeouts. Set this to a lower value if you want to react faster upon timeouts. The default value is 1000.
-
getTimeoutLoggingLevel
public org.apache.camel.LoggingLevel getTimeoutLoggingLevel()
-
setTimeoutLoggingLevel
public void setTimeoutLoggingLevel(org.apache.camel.LoggingLevel timeoutLoggingLevel)
Sets the logging level to use when a timeout was hit.
-
getWorkerPool
public ExecutorService getWorkerPool()
-
setWorkerPool
public void setWorkerPool(ExecutorService workerPool)
To use a shared worker pool for processing timed out requests.
-
getRequestCorrelationId
public abstract String getRequestCorrelationId(Object request)
Implement this method to extract the correlation id from the request message body.
-
getResponseCorrelationId
public abstract String getResponseCorrelationId(Object response)
Implement this method to extract the correlation id from the response message body.
-
getTimeoutResponse
public String getTimeoutResponse(String correlationId, Object request)
Override this to implement a custom timeout response message.- Parameters:
correlationId
- the correlation idrequest
- the request message- Returns:
- the response message or null to use an
ExchangeTimedOutException
exception.
-
putState
public void putState(io.netty.channel.Channel channel, NettyCamelState state)
Description copied from interface:NettyCamelStateCorrelationManager
Puts the state. You can get access to the Camel message from theNettyCamelState
instance.- Specified by:
putState
in interfaceNettyCamelStateCorrelationManager
- Parameters:
channel
- the channelstate
- the Camel state to be stored
-
removeState
public void removeState(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.Channel channel)
Description copied from interface:NettyCamelStateCorrelationManager
Removes the state when the channel is inactive.- Specified by:
removeState
in interfaceNettyCamelStateCorrelationManager
- Parameters:
ctx
- netty channel handler contextchannel
- the channel
-
getState
public NettyCamelState getState(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.Channel channel, Object msg)
Description copied from interface:NettyCamelStateCorrelationManager
Gets the state when a response message has been received. If the implementation stores the state temporary in for example aMap
instance then this method should remove the state from the map as its no longer needed. In other words use theMap.remove(Object)
to get and remove the state.- Specified by:
getState
in interfaceNettyCamelStateCorrelationManager
- Parameters:
ctx
- netty channel handler contextchannel
- the channelmsg
- the response message
-
getState
public NettyCamelState getState(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.Channel channel, Throwable cause)
Description copied from interface:NettyCamelStateCorrelationManager
Gets the state when some internal error occurred.- Specified by:
getState
in interfaceNettyCamelStateCorrelationManager
- Parameters:
ctx
- netty channel handler contextchannel
- the channelcause
- the error
-
doStart
protected void doStart() throws Exception
- Overrides:
doStart
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
doStop
protected void doStop() throws Exception
- Overrides:
doStop
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
-