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 ChannelInterceptor
ChannelInterceptor.InterceptorEvent -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanWhether to always send.protected final AtomicLongCurrent queue size.protected ExecutorServiceThe executor service.protected longKeep alive time.protected longMaximum queue size.protected intMaximum number of spare threads.protected intMaximum number of threads.protected booleanWhether the queue is running.protected static final StringManagerThe string manager for this class.protected booleanWhether to use deep clone.Fields inherited from class ChannelInterceptorBase
optionFlag -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongaddAndGetCurrentSize(long inc) Add to the current size and return the new value.booleanaddToQueue(ChannelMessage msg, Member[] destination, InterceptorPayload payload) Add a message to the queue.intReturn the current number of threads that are in use.longReturn the total number of tasks that have completed execution by the pool.longGet the current queue size.longGet the keep alive time.longGet the maximum queue size.intGet the maximum spare threads.intGet the maximum threads.intReturn the current number of threads that are managed by the pool.longReturn the total number of tasks that have ever been scheduled for execution by the pool.booleanGet whether deep clone is used.booleanCheck if always send is enabled.protected voidsendAsyncData(ChannelMessage msg, Member[] destination, InterceptorPayload payload) Send async data.voidsendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) ThesendMessagemethod is called when a message is being sent to one more destinations.voidsetAlwaysSend(boolean alwaysSend) Set always send.longsetAndGetCurrentSize(long value) Set the current size and return the value.voidsetKeepAliveTime(long keepAliveTime) Set the keep alive time.voidsetMaxQueueSize(long maxQueueSize) Set the maximum queue size.voidsetMaxSpareThreads(int maxSpareThreads) Set the maximum spare threads.voidsetMaxThreads(int maxThreads) Set the maximum threads.voidsetOptionFlag(int flag) Sets the option flagvoidsetUseDeepClone(boolean useDeepClone) Set whether to use deep clone.voidstart(int svc) Starts up the channel.voidStart the dispatch queue.voidstop(int svc) Shuts down the channel.voidStop the dispatch queue.Methods inherited from class ChannelInterceptorBase
fireInterceptorEvent, getChannel, getLocalMember, getMember, getMembers, getNext, getOptionFlag, getPrevious, hasMembers, heartbeat, memberAdded, memberDisappeared, messageReceived, okToProcess, setChannel, setNext, setPreviousMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface MessageDispatchInterceptorMBean
getOptionFlag
-
Field Details
-
sm
The string manager for this class. -
maxQueueSize
protected long maxQueueSizeMaximum queue size. -
run
protected volatile boolean runWhether the queue is running. -
useDeepClone
protected boolean useDeepCloneWhether to use deep clone. -
alwaysSend
protected boolean alwaysSendWhether to always send. -
currentSize
Current queue size. -
executor
The executor service. -
maxThreads
protected int maxThreadsMaximum number of threads. -
maxSpareThreads
protected int maxSpareThreadsMaximum number of spare threads. -
keepAliveTime
protected long keepAliveTimeKeep alive time.
-
-
Constructor Details
-
MessageDispatchInterceptor
public MessageDispatchInterceptor()Default constructor.
-
-
Method Details
-
sendMessage
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException Description copied from interface:ChannelInterceptorThesendMessagemethod 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:
sendMessagein interfaceChannelInterceptor- Overrides:
sendMessagein 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
Add a message to the queue.- Parameters:
msg- the messagedestination- the destinationpayload- the payload- Returns:
- true if added
-
startQueue
public void startQueue()Start the dispatch queue. -
stopQueue
public void stopQueue()Stop the dispatch queue. -
setOptionFlag
public void setOptionFlag(int flag) Description copied from interface:ChannelInterceptorSets the option flag- Specified by:
setOptionFlagin interfaceChannelInterceptor- Overrides:
setOptionFlagin classChannelInterceptorBase- Parameters:
flag- int- See Also:
-
setMaxQueueSize
public void setMaxQueueSize(long maxQueueSize) Set the maximum queue size.- Parameters:
maxQueueSize- the maximum queue size
-
setUseDeepClone
public void setUseDeepClone(boolean useDeepClone) Set whether to use deep clone.- Parameters:
useDeepClone- whether to use deep clone
-
getMaxQueueSize
public long getMaxQueueSize()Description copied from interface:MessageDispatchInterceptorMBeanGet the maximum queue size.- Specified by:
getMaxQueueSizein interfaceMessageDispatchInterceptorMBean- Returns:
- the maximum queue size
-
getUseDeepClone
public boolean getUseDeepClone()Get whether deep clone is used.- Returns:
- whether deep clone is used
-
getCurrentSize
public long getCurrentSize()Description copied from interface:MessageDispatchInterceptorMBeanGet the current queue size.- Specified by:
getCurrentSizein interfaceMessageDispatchInterceptorMBean- Returns:
- the current queue size
-
addAndGetCurrentSize
public long addAndGetCurrentSize(long inc) Add to the current size and return the new value.- Parameters:
inc- the increment- Returns:
- the new size
-
setAndGetCurrentSize
public long setAndGetCurrentSize(long value) Set the current size and return the value.- Parameters:
value- the value- Returns:
- the value
-
getKeepAliveTime
public long getKeepAliveTime()Description copied from interface:MessageDispatchInterceptorMBeanGet the keep alive time.- Specified by:
getKeepAliveTimein interfaceMessageDispatchInterceptorMBean- Returns:
- the keep alive time
-
getMaxSpareThreads
public int getMaxSpareThreads()Description copied from interface:MessageDispatchInterceptorMBeanGet the maximum spare threads.- Specified by:
getMaxSpareThreadsin interfaceMessageDispatchInterceptorMBean- Returns:
- the maximum spare threads
-
getMaxThreads
public int getMaxThreads()Description copied from interface:MessageDispatchInterceptorMBeanGet the maximum threads.- Specified by:
getMaxThreadsin interfaceMessageDispatchInterceptorMBean- Returns:
- the maximum threads
-
setKeepAliveTime
public void setKeepAliveTime(long keepAliveTime) Set the keep alive time.- Parameters:
keepAliveTime- the keep alive time
-
setMaxSpareThreads
public void setMaxSpareThreads(int maxSpareThreads) Set the maximum spare threads.- Parameters:
maxSpareThreads- the maximum spare threads
-
setMaxThreads
public void setMaxThreads(int maxThreads) Set the maximum threads.- Parameters:
maxThreads- the maximum threads
-
isAlwaysSend
public boolean isAlwaysSend()Description copied from interface:MessageDispatchInterceptorMBeanCheck if always send is enabled.- Specified by:
isAlwaysSendin interfaceMessageDispatchInterceptorMBean- Returns:
- whether always send is enabled
-
setAlwaysSend
public void setAlwaysSend(boolean alwaysSend) Description copied from interface:MessageDispatchInterceptorMBeanSet always send.- Specified by:
setAlwaysSendin interfaceMessageDispatchInterceptorMBean- Parameters:
alwaysSend- whether to always send
-
start
Description copied from interface:ChannelInterceptorStarts 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:
startin interfaceChannelInterceptor- Overrides:
startin 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:ChannelInterceptorShuts down the channel. This can be called multiple times for individual services to shut down. The svc parameter can be the logical or value of any constants- Specified by:
stopin interfaceChannelInterceptor- Overrides:
stopin classChannelInterceptorBase- Parameters:
svc- one of:- Channel.DEFAULT - will shut down 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
Send async data.- Parameters:
msg- the messagedestination- the destinationpayload- the payload
-
getPoolSize
public int getPoolSize()Return the current number of threads that are managed by the pool.- Specified by:
getPoolSizein 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:
getActiveCountin 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:
getTaskCountin 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:
getCompletedTaskCountin interfaceMessageDispatchInterceptorMBean- Returns:
- the total number of tasks that have completed execution by the pool
-