Class MessageDispatchInterceptor
java.lang.Object
org.apache.catalina.tribes.group.ChannelInterceptorBase
org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor
- All Implemented Interfaces:
ChannelInterceptor
,MessageDispatchInterceptorMBean
,Heartbeat
,MembershipListener
public class MessageDispatchInterceptor
extends ChannelInterceptorBase
implements MessageDispatchInterceptorMBean
The message dispatcher is a way to enable asynchronous communication through a channel. The dispatcher will look for
the
Channel.SEND_OPTIONS_ASYNCHRONOUS
flag to be set, if it is, it will queue the message for delivery
and immediately return to the sender.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.catalina.tribes.ChannelInterceptor
ChannelInterceptor.InterceptorEvent
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected final AtomicLong
protected ExecutorService
protected long
protected long
protected int
protected int
protected boolean
protected static final StringManager
protected boolean
Fields inherited from class org.apache.catalina.tribes.group.ChannelInterceptorBase
optionFlag
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionlong
addAndGetCurrentSize
(long inc) boolean
addToQueue
(ChannelMessage msg, Member[] destination, InterceptorPayload payload) int
Return the current number of threads that are in use.long
Return the total number of tasks that have completed execution by the pool.long
long
long
int
int
int
Return the current number of threads that are managed by the pool.long
Return the total number of tasks that have ever been scheduled for execution by the pool.boolean
boolean
protected void
sendAsyncData
(ChannelMessage msg, Member[] destination, InterceptorPayload payload) void
sendMessage
(Member[] destination, ChannelMessage msg, InterceptorPayload payload) ThesendMessage
method is called when a message is being sent to one more destinations.void
setAlwaysSend
(boolean alwaysSend) long
setAndGetCurrentSize
(long value) void
setKeepAliveTime
(long keepAliveTime) void
setMaxQueueSize
(long maxQueueSize) void
setMaxSpareThreads
(int maxSpareThreads) void
setMaxThreads
(int maxThreads) void
setOptionFlag
(int flag) Sets the option flagvoid
setUseDeepClone
(boolean useDeepClone) void
start
(int svc) Starts up the channel.void
void
stop
(int svc) Shuts down the channel.void
Methods inherited from class org.apache.catalina.tribes.group.ChannelInterceptorBase
fireInterceptorEvent, getChannel, getLocalMember, getMember, getMembers, getNext, getOptionFlag, getPrevious, hasMembers, heartbeat, memberAdded, memberDisappeared, messageReceived, okToProcess, setChannel, setNext, setPrevious
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptorMBean
getOptionFlag
-
Field Details
-
sm
-
maxQueueSize
protected long maxQueueSize -
run
protected volatile boolean run -
useDeepClone
protected boolean useDeepClone -
alwaysSend
protected boolean alwaysSend -
currentSize
-
executor
-
maxThreads
protected int maxThreads -
maxSpareThreads
protected int maxSpareThreads -
keepAliveTime
protected long keepAliveTime
-
-
Constructor Details
-
MessageDispatchInterceptor
public MessageDispatchInterceptor()
-
-
Method Details
-
sendMessage
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException Description copied from interface:ChannelInterceptor
ThesendMessage
method is called when a message is being sent to one more destinations. The interceptor can modify any of the parameters and then pass on the message down the stack by invokinggetNext().sendMessage(destination,msg,payload)
.Alternatively the interceptor can stop the message from being sent by not invoking
getNext().sendMessage(destination,msg,payload)
.If the message is to be sent asynchronous the application can be notified of completion and errors by passing in an error handler attached to a payload object.
The ChannelMessage.getAddress contains Channel.getLocalMember, and can be overwritten to simulate a message sent from another node.
- Specified by:
sendMessage
in interfaceChannelInterceptor
- Overrides:
sendMessage
in classChannelInterceptorBase
- Parameters:
destination
- Member[] - the destination for this messagemsg
- ChannelMessage - the message to be sentpayload
- InterceptorPayload - the payload, carrying an error handler and future useful data, can be null- Throws:
ChannelException
- if a serialization error happens.- See Also:
-
addToQueue
-
startQueue
public void startQueue() -
stopQueue
public void stopQueue() -
setOptionFlag
public void setOptionFlag(int flag) Description copied from interface:ChannelInterceptor
Sets the option flag- Specified by:
setOptionFlag
in interfaceChannelInterceptor
- Overrides:
setOptionFlag
in classChannelInterceptorBase
- Parameters:
flag
- int- See Also:
-
setMaxQueueSize
public void setMaxQueueSize(long maxQueueSize) -
setUseDeepClone
public void setUseDeepClone(boolean useDeepClone) -
getMaxQueueSize
public long getMaxQueueSize()- Specified by:
getMaxQueueSize
in interfaceMessageDispatchInterceptorMBean
-
getUseDeepClone
public boolean getUseDeepClone() -
getCurrentSize
public long getCurrentSize()- Specified by:
getCurrentSize
in interfaceMessageDispatchInterceptorMBean
-
addAndGetCurrentSize
public long addAndGetCurrentSize(long inc) -
setAndGetCurrentSize
public long setAndGetCurrentSize(long value) -
getKeepAliveTime
public long getKeepAliveTime()- Specified by:
getKeepAliveTime
in interfaceMessageDispatchInterceptorMBean
-
getMaxSpareThreads
public int getMaxSpareThreads()- Specified by:
getMaxSpareThreads
in interfaceMessageDispatchInterceptorMBean
-
getMaxThreads
public int getMaxThreads()- Specified by:
getMaxThreads
in interfaceMessageDispatchInterceptorMBean
-
setKeepAliveTime
public void setKeepAliveTime(long keepAliveTime) -
setMaxSpareThreads
public void setMaxSpareThreads(int maxSpareThreads) -
setMaxThreads
public void setMaxThreads(int maxThreads) -
isAlwaysSend
public boolean isAlwaysSend()- Specified by:
isAlwaysSend
in interfaceMessageDispatchInterceptorMBean
-
setAlwaysSend
public void setAlwaysSend(boolean alwaysSend) - Specified by:
setAlwaysSend
in interfaceMessageDispatchInterceptorMBean
-
start
Description copied from interface:ChannelInterceptor
Starts up the channel. This can be called multiple times for individual services to start The svc parameter can be the logical or value of any constants- Specified by:
start
in interfaceChannelInterceptor
- Overrides:
start
in classChannelInterceptorBase
- Parameters:
svc
- one of:- Channel.DEFAULT - will start all services
- Channel.MBR_RX_SEQ - starts the membership receiver
- Channel.MBR_TX_SEQ - starts the membership broadcaster
- Channel.SND_TX_SEQ - starts the replication transmitter
- Channel.SND_RX_SEQ - starts the replication receiver
- Throws:
ChannelException
- if a startup error occurs or the service is already started.- See Also:
-
stop
Description copied from interface:ChannelInterceptor
Shuts down the channel. This can be called multiple times for individual services to shutdown The svc parameter can be the logical or value of any constants- Specified by:
stop
in interfaceChannelInterceptor
- Overrides:
stop
in classChannelInterceptorBase
- Parameters:
svc
- one of:- Channel.DEFAULT - will shutdown all services
- Channel.MBR_RX_SEQ - stops the membership receiver
- Channel.MBR_TX_SEQ - stops the membership broadcaster
- Channel.SND_TX_SEQ - stops the replication transmitter
- Channel.SND_RX_SEQ - stops the replication receiver
- Throws:
ChannelException
- if a startup error occurs or the service is already started.- See Also:
-
sendAsyncData
-
getPoolSize
public int getPoolSize()Return the current number of threads that are managed by the pool.- Specified by:
getPoolSize
in interfaceMessageDispatchInterceptorMBean
- Returns:
- the current number of threads that are managed by the pool
-
getActiveCount
public int getActiveCount()Return the current number of threads that are in use.- Specified by:
getActiveCount
in interfaceMessageDispatchInterceptorMBean
- Returns:
- the current number of threads that are in use
-
getTaskCount
public long getTaskCount()Return the total number of tasks that have ever been scheduled for execution by the pool.- Specified by:
getTaskCount
in interfaceMessageDispatchInterceptorMBean
- Returns:
- the total number of tasks that have ever been scheduled for execution by the pool
-
getCompletedTaskCount
public long getCompletedTaskCount()Return the total number of tasks that have completed execution by the pool.- Specified by:
getCompletedTaskCount
in interfaceMessageDispatchInterceptorMBean
- Returns:
- the total number of tasks that have completed execution by the pool
-