Package org.apache.catalina.tribes.group
Class GroupChannel
- java.lang.Object
-
- org.apache.catalina.tribes.group.ChannelInterceptorBase
-
- org.apache.catalina.tribes.group.GroupChannel
-
- All Implemented Interfaces:
javax.management.MBeanRegistration,Channel,ChannelInterceptor,GroupChannelMBean,Heartbeat,JmxChannel,ManagedChannel,MembershipListener
public class GroupChannel extends ChannelInterceptorBase implements ManagedChannel, JmxChannel, GroupChannelMBean
The default implementation of a Channel.
The GroupChannel manages the replication channel. It coordinates message being sent and received with membership announcements. The channel has a chain of interceptors that can modify the message or perform other logic.
It manages a complete group, both membership and replication.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classGroupChannel.HeartbeatRunnableTitle: Internal heartbeat runnablestatic classGroupChannel.InterceptorIteratorAn iterator to loop through the interceptors in a channel.-
Nested classes/interfaces inherited from interface org.apache.catalina.tribes.ChannelInterceptor
ChannelInterceptor.InterceptorEvent
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<ChannelListener>channelListenersA list of channel listeners that subscribe to incoming messagesprotected ChannelCoordinatorcoordinatorTheChannelCoordinatorcoordinates the bottom layer components:
- MembershipService
- ChannelSender
- ChannelReceiverprotected booleanheartbeatFlag to determine if the channel manages its own heartbeat If set to true, the channel will start a local thread for the heart beat.protected java.util.concurrent.ScheduledFuture<?>heartbeatFutureInternal heartbeat futureprotected longheartbeatSleeptimeIfheartbeat == truethen how often do we want this heartbeat to run.protected ChannelInterceptorinterceptorsThe first interceptor in the interceptor stack.protected java.util.List<MembershipListener>membershipListenersA list of membership listeners that subscribe to membership announcementsprotected java.util.concurrent.ScheduledFuture<?>monitorFutureprotected java.lang.Stringnamethe name of this channel.protected booleanoptionCheckIf set to true, the GroupChannel will check to make sure thatprotected booleanownExecutorprotected static StringManagersmprotected java.util.concurrent.ScheduledExecutorServiceutilityExecutorExecutor service.-
Fields inherited from class org.apache.catalina.tribes.group.ChannelInterceptorBase
optionFlag
-
Fields inherited from interface org.apache.catalina.tribes.Channel
DEFAULT, MBR_RX_SEQ, MBR_TX_SEQ, SEND_OPTIONS_ASYNCHRONOUS, SEND_OPTIONS_BYTE_MESSAGE, SEND_OPTIONS_DEFAULT, SEND_OPTIONS_MULTICAST, SEND_OPTIONS_SECURE, SEND_OPTIONS_SYNCHRONIZED_ACK, SEND_OPTIONS_UDP, SEND_OPTIONS_USE_ACK, SND_RX_SEQ, SND_TX_SEQ
-
-
Constructor Summary
Constructors Constructor Description GroupChannel()Creates a GroupChannel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChannelListener(ChannelListener channelListener)Add a channel listener, this is a callback object when messages are received.voidaddInterceptor(ChannelInterceptor interceptor)Adds an interceptor to the stack for message processing.voidaddMembershipListener(MembershipListener membershipListener)Add a membership listener, will get notified when a new member joins, leaves or crashes.protected voidcheckOptionFlags()Validates the option flags that each interceptor is using and reports an error if two interceptor share the same flag.ChannelReceivergetChannelReceiver()returns the channel receiverChannelSendergetChannelSender()returns the channel senderChannelInterceptorgetFirstInterceptor()Returns the first interceptor of the stack.booleangetHeartbeat()longgetHeartbeatSleeptime()java.util.Iterator<ChannelInterceptor>getInterceptors()Returns the interceptor stackjava.lang.StringgetJmxDomain()Return the jmx domain which this channel is registered.java.lang.StringgetJmxPrefix()Return the jmx prefix which will be used with channel ObjectName.MembershipServicegetMembershipService()Returns the membership servicejava.lang.StringgetName()Return the name of this channel.booleangetOptionCheck()java.util.concurrent.ScheduledExecutorServicegetUtilityExecutor()Return executor that can be used for utility tasks.voidheartbeat()Sends a heartbeat through the interceptor stack.
Invoke this method from the application on a periodic basis if you have turned off internal heartbeatschannel.setHeartbeat(false)booleanisJmxEnabled()If set to true, this channel is registered with jmx.voidmemberAdded(Member member)memberAdded gets invoked by the interceptor below the channel and the channel will broadcast it to the membership listenersvoidmemberDisappeared(Member member)memberDisappeared gets invoked by the interceptor below the channel and the channel will broadcast it to the membership listenersvoidmessageReceived(ChannelMessage msg)Callback from the interceptor stack.voidpostDeregister()voidpostRegister(java.lang.Boolean registrationDone)voidpreDeregister()javax.management.ObjectNamepreRegister(javax.management.MBeanServer server, javax.management.ObjectName name)voidremoveChannelListener(ChannelListener channelListener)Remove a channel listener, listeners are removed based onObject.hashCode()andObject.equals(Object).voidremoveMembershipListener(MembershipListener membershipListener)Remove a membership listener, listeners are removed based onObject.hashCode()andObject.equals(Object).UniqueIdsend(Member[] destination, java.io.Serializable msg, int options)Send a message to one or more members in the clusterUniqueIdsend(Member[] destination, java.io.Serializable msg, int options, ErrorHandler handler)Send a message to one or more members in the clusterprotected voidsendNoRpcChannelReply(RpcMessage msg, Member destination)Sends aNoRpcChannelReplymessage to a member
This method gets invoked by the channel if an RPC message comes in and no channel listener accepts the message.voidsetChannelReceiver(ChannelReceiver clusterReceiver)Sets the channel receivervoidsetChannelSender(ChannelSender clusterSender)Sets the channel sendervoidsetHeartbeat(boolean heartbeat)Enables or disables local heartbeat. ifsetHeartbeat(true)is invoked then the channel will start an internal thread to invokeChannel.heartbeat()everygetHeartbeatSleeptimemillisecondsvoidsetHeartbeatSleeptime(long heartbeatSleeptime)Configure local heartbeat sleep time
Only used whengetHeartbeat()==truevoidsetJmxDomain(java.lang.String jmxDomain)Set the jmx domain which this channel should be registered.voidsetJmxEnabled(boolean jmxEnabled)If set to true, this channel is registered with jmx.voidsetJmxPrefix(java.lang.String jmxPrefix)Set the jmx prefix which will be used with channel ObjectName.voidsetMembershipService(MembershipService membershipService)Sets the membership servicevoidsetName(java.lang.String name)Set the name of this channelvoidsetOptionCheck(boolean optionCheck)Enables/disables the option check
Setting this to true, will make the GroupChannel perform a conflict check on the interceptors.protected voidsetupDefaultStack()Sets up the default implementation interceptor stack if no interceptors have been addedvoidsetUtilityExecutor(java.util.concurrent.ScheduledExecutorService utilityExecutor)Set the executor that can be used for utility tasks.voidstart(int svc)Starts up the channel.protected voidstartHeartbeat()voidstop(int svc)Shuts down the channel.-
Methods inherited from class org.apache.catalina.tribes.group.ChannelInterceptorBase
fireInterceptorEvent, getChannel, getLocalMember, getMember, getMembers, getNext, getOptionFlag, getPrevious, hasMembers, okToProcess, sendMessage, setChannel, setNext, setOptionFlag, 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.Channel
getLocalMember, getMember, getMembers, hasMembers
-
Methods inherited from interface org.apache.catalina.tribes.group.GroupChannelMBean
getLocalMember, getMembers, hasMembers
-
-
-
-
Field Detail
-
sm
protected static final StringManager sm
-
heartbeat
protected boolean heartbeat
Flag to determine if the channel manages its own heartbeat If set to true, the channel will start a local thread for the heart beat.
-
heartbeatSleeptime
protected long heartbeatSleeptime
Ifheartbeat == truethen how often do we want this heartbeat to run. The default value is 5000 milliseconds.
-
heartbeatFuture
protected java.util.concurrent.ScheduledFuture<?> heartbeatFuture
Internal heartbeat future
-
monitorFuture
protected java.util.concurrent.ScheduledFuture<?> monitorFuture
-
coordinator
protected final ChannelCoordinator coordinator
TheChannelCoordinatorcoordinates the bottom layer components:
- MembershipService
- ChannelSender
- ChannelReceiver
-
interceptors
protected ChannelInterceptor interceptors
The first interceptor in the interceptor stack. The interceptors are chained in a linked list, so we only need a reference to the first one
-
membershipListeners
protected final java.util.List<MembershipListener> membershipListeners
A list of membership listeners that subscribe to membership announcements
-
channelListeners
protected final java.util.List<ChannelListener> channelListeners
A list of channel listeners that subscribe to incoming messages
-
optionCheck
protected boolean optionCheck
If set to true, the GroupChannel will check to make sure that
-
name
protected java.lang.String name
the name of this channel.
-
utilityExecutor
protected java.util.concurrent.ScheduledExecutorService utilityExecutor
Executor service.
-
ownExecutor
protected boolean ownExecutor
-
-
Method Detail
-
addInterceptor
public void addInterceptor(ChannelInterceptor interceptor)
Description copied from interface:ChannelAdds an interceptor to the stack for message processing. Interceptors are ordered in the way they are added.
Will result in an interceptor stack like this:channel.addInterceptor(A); channel.addInterceptor(C); channel.addInterceptor(B);A -> C -> BThe complete stack will look like this:
Channel -> A -> C -> B -> ChannelCoordinator- Specified by:
addInterceptorin interfaceChannel- Parameters:
interceptor- ChannelInterceptorBase
-
heartbeat
public void heartbeat()
Sends a heartbeat through the interceptor stack.
Invoke this method from the application on a periodic basis if you have turned off internal heartbeatschannel.setHeartbeat(false)- Specified by:
heartbeatin interfaceChannel- Specified by:
heartbeatin interfaceChannelInterceptor- Specified by:
heartbeatin interfaceHeartbeat- Overrides:
heartbeatin classChannelInterceptorBase- See Also:
Channel.setHeartbeat(boolean)
-
send
public UniqueId send(Member[] destination, java.io.Serializable msg, int options) throws ChannelException
Description copied from interface:ChannelSend a message to one or more members in the cluster- Specified by:
sendin interfaceChannel- Specified by:
sendin interfaceGroupChannelMBean- Parameters:
destination- Member[] - the destinations, cannot be null or zero length, the reason for that is that a membership change can occur and at that time the application is uncertain what group the message actually got sent to.msg- Serializable - the message to send, has to be serializable, or aByteMessageto send a pure byte arrayoptions- int - sender options, see class documentation for each interceptor that is configured in order to trigger interceptors- Returns:
- a unique Id that identifies the message that is sent
- Throws:
ChannelException- if a serialization error happens.- See Also:
ByteMessage,Channel.SEND_OPTIONS_USE_ACK,Channel.SEND_OPTIONS_ASYNCHRONOUS,Channel.SEND_OPTIONS_SYNCHRONIZED_ACK
-
send
public UniqueId send(Member[] destination, java.io.Serializable msg, int options, ErrorHandler handler) throws ChannelException
Description copied from interface:ChannelSend a message to one or more members in the cluster- Specified by:
sendin interfaceChannel- Specified by:
sendin interfaceGroupChannelMBean- Parameters:
destination- Member[] - the destinations, null or zero length means allmsg- ClusterMessage - the message to sendoptions- int - sender options, see class documentationhandler- ErrorHandler - handle errors through a callback, rather than throw it- Returns:
- a unique Id that identifies the message that is sent
- Throws:
ChannelException- - if a serialization error happens.
-
messageReceived
public void messageReceived(ChannelMessage msg)
Callback from the interceptor stack.
When a message is received from a remote node, this method will be invoked by the previous interceptor.
This method can also be used to send a message to other components within the same application, but it's an extreme case, and you're probably better off doing that logic between the applications itself.- Specified by:
messageReceivedin interfaceChannelInterceptor- Overrides:
messageReceivedin classChannelInterceptorBase- Parameters:
msg- ChannelMessage
-
sendNoRpcChannelReply
protected void sendNoRpcChannelReply(RpcMessage msg, Member destination)
Sends aNoRpcChannelReplymessage to a member
This method gets invoked by the channel if an RPC message comes in and no channel listener accepts the message. This avoids timeout- Parameters:
msg- RpcMessagedestination- Member - the destination for the reply
-
memberAdded
public void memberAdded(Member member)
memberAdded gets invoked by the interceptor below the channel and the channel will broadcast it to the membership listeners- Specified by:
memberAddedin interfaceMembershipListener- Overrides:
memberAddedin classChannelInterceptorBase- Parameters:
member- Member - the new member
-
memberDisappeared
public void memberDisappeared(Member member)
memberDisappeared gets invoked by the interceptor below the channel and the channel will broadcast it to the membership listeners- Specified by:
memberDisappearedin interfaceMembershipListener- Overrides:
memberDisappearedin classChannelInterceptorBase- Parameters:
member- Member - the member that left or crashed- See Also:
Member.SHUTDOWN_PAYLOAD
-
setupDefaultStack
protected void setupDefaultStack() throws ChannelExceptionSets up the default implementation interceptor stack if no interceptors have been added- Throws:
ChannelException- Cluster error
-
checkOptionFlags
protected void checkOptionFlags() throws ChannelExceptionValidates the option flags that each interceptor is using and reports an error if two interceptor share the same flag.- Throws:
ChannelException- Error with option flag
-
start
public void start(int svc) throws ChannelExceptionDescription 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 interfaceChannel- Specified by:
startin interfaceChannelInterceptor- Specified by:
startin interfaceGroupChannelMBean- 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:
Channel
-
startHeartbeat
protected void startHeartbeat()
-
stop
public void stop(int svc) throws ChannelExceptionDescription 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 interfaceChannel- Specified by:
stopin interfaceChannelInterceptor- Specified by:
stopin interfaceGroupChannelMBean- 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:
Channel
-
getFirstInterceptor
public ChannelInterceptor getFirstInterceptor()
Returns the first interceptor of the stack. Useful for traversal.- Returns:
- ChannelInterceptor
-
getUtilityExecutor
public java.util.concurrent.ScheduledExecutorService getUtilityExecutor()
Description copied from interface:ChannelReturn executor that can be used for utility tasks.- Specified by:
getUtilityExecutorin interfaceChannel- Returns:
- the executor
-
setUtilityExecutor
public void setUtilityExecutor(java.util.concurrent.ScheduledExecutorService utilityExecutor)
Description copied from interface:ChannelSet the executor that can be used for utility tasks.- Specified by:
setUtilityExecutorin interfaceChannel- Parameters:
utilityExecutor- the executor
-
getChannelReceiver
public ChannelReceiver getChannelReceiver()
Description copied from interface:ManagedChannelreturns the channel receiver- Specified by:
getChannelReceiverin interfaceManagedChannel- Returns:
- ChannelReceiver
- See Also:
ChannelReceiver
-
getChannelSender
public ChannelSender getChannelSender()
Description copied from interface:ManagedChannelreturns the channel sender- Specified by:
getChannelSenderin interfaceManagedChannel- Returns:
- ChannelSender
- See Also:
ChannelSender
-
getMembershipService
public MembershipService getMembershipService()
Description copied from interface:ManagedChannelReturns the membership service- Specified by:
getMembershipServicein interfaceManagedChannel- Returns:
- MembershipService
- See Also:
MembershipService
-
setChannelReceiver
public void setChannelReceiver(ChannelReceiver clusterReceiver)
Description copied from interface:ManagedChannelSets the channel receiver- Specified by:
setChannelReceiverin interfaceManagedChannel- Parameters:
clusterReceiver- ChannelReceiver- See Also:
ChannelReceiver
-
setChannelSender
public void setChannelSender(ChannelSender clusterSender)
Description copied from interface:ManagedChannelSets the channel sender- Specified by:
setChannelSenderin interfaceManagedChannel- Parameters:
clusterSender- ChannelSender- See Also:
ChannelSender
-
setMembershipService
public void setMembershipService(MembershipService membershipService)
Description copied from interface:ManagedChannelSets the membership service- Specified by:
setMembershipServicein interfaceManagedChannel- Parameters:
membershipService- MembershipService- See Also:
MembershipService
-
addMembershipListener
public void addMembershipListener(MembershipListener membershipListener)
Description copied from interface:ChannelAdd a membership listener, will get notified when a new member joins, leaves or crashes.If the membership listener implements the Heartbeat interface the
heartbeat()method will be invoked when the heartbeat runs on the channel- Specified by:
addMembershipListenerin interfaceChannel- Specified by:
addMembershipListenerin interfaceGroupChannelMBean- Parameters:
membershipListener- MembershipListener- See Also:
MembershipListener
-
removeMembershipListener
public void removeMembershipListener(MembershipListener membershipListener)
Description copied from interface:ChannelRemove a membership listener, listeners are removed based onObject.hashCode()andObject.equals(Object).- Specified by:
removeMembershipListenerin interfaceChannel- Specified by:
removeMembershipListenerin interfaceGroupChannelMBean- Parameters:
membershipListener- MembershipListener- See Also:
MembershipListener
-
addChannelListener
public void addChannelListener(ChannelListener channelListener)
Description copied from interface:ChannelAdd a channel listener, this is a callback object when messages are received.If the channel listener implements the Heartbeat interface the
heartbeat()method will be invoked when the heartbeat runs on the channel- Specified by:
addChannelListenerin interfaceChannel- Specified by:
addChannelListenerin interfaceGroupChannelMBean- Parameters:
channelListener- ChannelListener- See Also:
ChannelListener,Heartbeat
-
removeChannelListener
public void removeChannelListener(ChannelListener channelListener)
Description copied from interface:ChannelRemove a channel listener, listeners are removed based onObject.hashCode()andObject.equals(Object).- Specified by:
removeChannelListenerin interfaceChannel- Specified by:
removeChannelListenerin interfaceGroupChannelMBean- Parameters:
channelListener- ChannelListener- See Also:
ChannelListener
-
getInterceptors
public java.util.Iterator<ChannelInterceptor> getInterceptors()
Description copied from interface:ManagedChannelReturns the interceptor stack- Specified by:
getInterceptorsin interfaceManagedChannel- Returns:
- Iterator
- See Also:
Channel.addInterceptor(ChannelInterceptor)
-
setOptionCheck
public void setOptionCheck(boolean optionCheck)
Enables/disables the option check
Setting this to true, will make the GroupChannel perform a conflict check on the interceptors. If two interceptors are using the same option flag and throw an error upon start.- Parameters:
optionCheck- boolean
-
setHeartbeatSleeptime
public void setHeartbeatSleeptime(long heartbeatSleeptime)
Configure local heartbeat sleep time
Only used whengetHeartbeat()==true- Parameters:
heartbeatSleeptime- long - time in milliseconds to sleep between heartbeats
-
setHeartbeat
public void setHeartbeat(boolean heartbeat)
Enables or disables local heartbeat. ifsetHeartbeat(true)is invoked then the channel will start an internal thread to invokeChannel.heartbeat()everygetHeartbeatSleeptimemilliseconds- Specified by:
setHeartbeatin interfaceChannel- Parameters:
heartbeat- boolean- See Also:
Channel.heartbeat()
-
getOptionCheck
public boolean getOptionCheck()
- Specified by:
getOptionCheckin interfaceGroupChannelMBean
-
getHeartbeat
public boolean getHeartbeat()
- Specified by:
getHeartbeatin interfaceGroupChannelMBean
-
getHeartbeatSleeptime
public long getHeartbeatSleeptime()
- Specified by:
getHeartbeatSleeptimein interfaceGroupChannelMBean- Returns:
- the sleep time in milliseconds that the internal heartbeat will sleep in between invocations of
Channel.heartbeat()
-
getName
public java.lang.String getName()
Description copied from interface:ChannelReturn the name of this channel.
-
setName
public void setName(java.lang.String name)
Description copied from interface:ChannelSet the name of this channel
-
isJmxEnabled
public boolean isJmxEnabled()
Description copied from interface:JmxChannelIf set to true, this channel is registered with jmx.- Specified by:
isJmxEnabledin interfaceJmxChannel- Returns:
- true if this channel will be registered with jmx.
-
setJmxEnabled
public void setJmxEnabled(boolean jmxEnabled)
Description copied from interface:JmxChannelIf set to true, this channel is registered with jmx.- Specified by:
setJmxEnabledin interfaceJmxChannel- Parameters:
jmxEnabled- set to true if this channel should be registered with jmx.
-
getJmxDomain
public java.lang.String getJmxDomain()
Description copied from interface:JmxChannelReturn the jmx domain which this channel is registered.- Specified by:
getJmxDomainin interfaceJmxChannel- Returns:
- jmxDomain
-
setJmxDomain
public void setJmxDomain(java.lang.String jmxDomain)
Description copied from interface:JmxChannelSet the jmx domain which this channel should be registered.- Specified by:
setJmxDomainin interfaceJmxChannel- Parameters:
jmxDomain- The jmx domain which this channel should be registered.
-
getJmxPrefix
public java.lang.String getJmxPrefix()
Description copied from interface:JmxChannelReturn the jmx prefix which will be used with channel ObjectName.- Specified by:
getJmxPrefixin interfaceJmxChannel- Returns:
- jmxPrefix
-
setJmxPrefix
public void setJmxPrefix(java.lang.String jmxPrefix)
Description copied from interface:JmxChannelSet the jmx prefix which will be used with channel ObjectName.- Specified by:
setJmxPrefixin interfaceJmxChannel- Parameters:
jmxPrefix- The jmx prefix which will be used with channel ObjectName.
-
preRegister
public javax.management.ObjectName preRegister(javax.management.MBeanServer server, javax.management.ObjectName name) throws java.lang.Exception- Specified by:
preRegisterin interfacejavax.management.MBeanRegistration- Throws:
java.lang.Exception
-
postRegister
public void postRegister(java.lang.Boolean registrationDone)
- Specified by:
postRegisterin interfacejavax.management.MBeanRegistration
-
preDeregister
public void preDeregister() throws java.lang.Exception- Specified by:
preDeregisterin interfacejavax.management.MBeanRegistration- Throws:
java.lang.Exception
-
postDeregister
public void postDeregister()
- Specified by:
postDeregisterin interfacejavax.management.MBeanRegistration
-
-