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 an chain of interceptors that can modify the message or perform other logic.
 It manages a complete group, both membership and replication.
- 
- 
Nested Class SummaryNested 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.ChannelInterceptorChannelInterceptor.InterceptorEvent
 
- 
 - 
Field SummaryFields 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.ChannelInterceptorBaseoptionFlag
 - 
Fields inherited from interface org.apache.catalina.tribes.ChannelDEFAULT, 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 SummaryConstructors Constructor Description GroupChannel()Creates a GroupChannel.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChannelListener(ChannelListener channelListener)Adds a channel listener to the channel.
 Channel listeners are uniquely identified using the equals(Object) methodvoidaddInterceptor(ChannelInterceptor interceptor)Adds an interceptor to the stack for message processing
 Interceptors are ordered in the way they are added.
 channel.addInterceptor(A);
 channel.addInterceptor(C);
 channel.addInterceptor(B);
 Will result in an interceptor stack like this:
 A -> C -> B
 The complete stack will look like this:
 Channel -> A -> C -> B -> ChannelCoordinatorvoidaddMembershipListener(MembershipListener membershipListener)Adds a membership listener to the channel.
 Membership listeners are uniquely identified using the equals(Object) methodprotected 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 receiver componentChannelSendergetChannelSender()Returns the channel sender componentChannelInterceptorgetFirstInterceptor()Returns the first interceptor of the stack.booleangetHeartbeat()longgetHeartbeatSleeptime()Returns the sleep time in milliseconds that the internal heartbeat will sleep in between invocations ofChannel.heartbeat()java.util.Iterator<ChannelInterceptor>getInterceptors()Returns an iterator of all the interceptors in this 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 service componentjava.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)Removes a channel listener from the channel.
 Channel listeners are uniquely identified using the equals(Object) methodvoidremoveMembershipListener(MembershipListener membershipListener)Removes a membership listener from the channel.
 Membership listeners are uniquely identified using the equals(Object) methodUniqueIdsend(Member[] destination, java.io.Serializable msg, int options)Send a message to the destinations specifiedUniqueIdsend(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 receiver componentvoidsetChannelSender(ChannelSender clusterSender)Sets the channel sender componentvoidsetHeartbeat(boolean heartbeat)Enables or disables local heartbeat.voidsetHeartbeatSleeptime(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 componentvoidsetName(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 the channel.protected voidstartHeartbeat()voidstop(int svc)Stops the channel.- 
Methods inherited from class org.apache.catalina.tribes.group.ChannelInterceptorBasefireInterceptorEvent, getChannel, getLocalMember, getMember, getMembers, getNext, getOptionFlag, getPrevious, hasMembers, okToProcess, sendMessage, setChannel, setNext, setOptionFlag, setPrevious
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.apache.catalina.tribes.ChannelgetLocalMember, getMember, getMembers, hasMembers
 - 
Methods inherited from interface org.apache.catalina.tribes.group.GroupChannelMBeangetLocalMember, getMembers, hasMembers
 
- 
 
- 
- 
- 
Field Detail- 
smprotected static final StringManager sm 
 - 
heartbeatprotected 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.
 - 
heartbeatSleeptimeprotected long heartbeatSleeptime Ifheartbeat == truethen how often do we want this heartbeat to run. The default value is 5000 milliseconds.
 - 
heartbeatFutureprotected java.util.concurrent.ScheduledFuture<?> heartbeatFuture Internal heartbeat future
 - 
monitorFutureprotected java.util.concurrent.ScheduledFuture<?> monitorFuture 
 - 
coordinatorprotected final ChannelCoordinator coordinator TheChannelCoordinatorcoordinates the bottom layer components:
 - MembershipService
 - ChannelSender
 - ChannelReceiver
 - 
interceptorsprotected 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
 - 
membershipListenersprotected final java.util.List<MembershipListener> membershipListeners A list of membership listeners that subscribe to membership announcements
 - 
channelListenersprotected final java.util.List<ChannelListener> channelListeners A list of channel listeners that subscribe to incoming messages
 - 
optionCheckprotected boolean optionCheck If set to true, the GroupChannel will check to make sure that
 - 
nameprotected java.lang.String name the name of this channel.
 - 
utilityExecutorprotected java.util.concurrent.ScheduledExecutorService utilityExecutor Executor service.
 - 
ownExecutorprotected boolean ownExecutor 
 
- 
 - 
Method Detail- 
addInterceptorpublic void addInterceptor(ChannelInterceptor interceptor) Adds an interceptor to the stack for message processing
 Interceptors are ordered in the way they are added.
 channel.addInterceptor(A);
 channel.addInterceptor(C);
 channel.addInterceptor(B);
 Will result in an interceptor stack like this:
 A -> C -> B
 The complete stack will look like this:
 Channel -> A -> C -> B -> ChannelCoordinator- Specified by:
- addInterceptorin interface- Channel
- Parameters:
- interceptor- ChannelInterceptorBase
 
 - 
heartbeatpublic 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 interface- Channel
- Specified by:
- heartbeatin interface- ChannelInterceptor
- Specified by:
- heartbeatin interface- Heartbeat
- Overrides:
- heartbeatin class- ChannelInterceptorBase
- See Also:
- Channel.setHeartbeat(boolean)
 
 - 
sendpublic UniqueId send(Member[] destination, java.io.Serializable msg, int options) throws ChannelException Send a message to the destinations specified- Specified by:
- sendin interface- Channel
- Specified by:
- sendin interface- GroupChannelMBean
- Parameters:
- destination- Member[] - destination.length > 0
- msg- Serializable - the message to send
- options- sender options, options can trigger guarantee levels and different interceptors to react to the message see class documentation for the- Channelobject.
- Returns:
- UniqueId - the unique Id that was assigned to this message
- Throws:
- ChannelException- - if an error occurs processing the message
- See Also:
- Channel
 
 - 
sendpublic 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 interface- Channel
- Specified by:
- sendin interface- GroupChannelMBean
- Parameters:
- destination- Member[] - destination.length > 0
- msg- Serializable - the message to send
- options- sender options, options can trigger guarantee levels and different interceptors to react to the message see class documentation for the- Channelobject.
- handler- - callback object for error handling and completion notification, used when a message is sent asynchronously using the- Channel.SEND_OPTIONS_ASYNCHRONOUSflag enabled.
- Returns:
- UniqueId - the unique Id that was assigned to this message
- Throws:
- ChannelException- - if an error occurs processing the message
- See Also:
- Channel
 
 - 
messageReceivedpublic 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 its an extreme case, and you're probably better off doing that logic between the applications itself.- Specified by:
- messageReceivedin interface- ChannelInterceptor
- Overrides:
- messageReceivedin class- ChannelInterceptorBase
- Parameters:
- msg- ChannelMessage
 
 - 
sendNoRpcChannelReplyprotected 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- RpcMessage
- destination- Member - the destination for the reply
 
 - 
memberAddedpublic 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 interface- MembershipListener
- Overrides:
- memberAddedin class- ChannelInterceptorBase
- Parameters:
- member- Member - the new member
 
 - 
memberDisappearedpublic 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 interface- MembershipListener
- Overrides:
- memberDisappearedin class- ChannelInterceptorBase
- Parameters:
- member- Member - the member that left or crashed
- See Also:
- Member.SHUTDOWN_PAYLOAD
 
 - 
setupDefaultStackprotected void setupDefaultStack() throws ChannelExceptionSets up the default implementation interceptor stack if no interceptors have been added- Throws:
- ChannelException- Cluster error
 
 - 
checkOptionFlagsprotected 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
 
 - 
startpublic void start(int svc) throws ChannelExceptionStarts the channel.- Specified by:
- startin interface- Channel
- Specified by:
- startin interface- ChannelInterceptor
- Specified by:
- startin interface- GroupChannelMBean
- Overrides:
- startin class- ChannelInterceptorBase
- Parameters:
- svc- int - what service to start
- Throws:
- ChannelException- Start error
- See Also:
- Channel.start(int)
 
 - 
startHeartbeatprotected void startHeartbeat() 
 - 
stoppublic void stop(int svc) throws ChannelExceptionStops the channel.- Specified by:
- stopin interface- Channel
- Specified by:
- stopin interface- ChannelInterceptor
- Specified by:
- stopin interface- GroupChannelMBean
- Overrides:
- stopin class- ChannelInterceptorBase
- Parameters:
- svc- int
- Throws:
- ChannelException- Stop error
- See Also:
- Channel.stop(int)
 
 - 
getFirstInterceptorpublic ChannelInterceptor getFirstInterceptor() Returns the first interceptor of the stack. Useful for traversal.- Returns:
- ChannelInterceptor
 
 - 
getUtilityExecutorpublic java.util.concurrent.ScheduledExecutorService getUtilityExecutor() Description copied from interface:ChannelReturn executor that can be used for utility tasks.- Specified by:
- getUtilityExecutorin interface- Channel
- Returns:
- the executor
 
 - 
setUtilityExecutorpublic void setUtilityExecutor(java.util.concurrent.ScheduledExecutorService utilityExecutor) Description copied from interface:ChannelSet the executor that can be used for utility tasks.- Specified by:
- setUtilityExecutorin interface- Channel
- Parameters:
- utilityExecutor- the executor
 
 - 
getChannelReceiverpublic ChannelReceiver getChannelReceiver() Returns the channel receiver component- Specified by:
- getChannelReceiverin interface- ManagedChannel
- Returns:
- ChannelReceiver
- See Also:
- ChannelReceiver
 
 - 
getChannelSenderpublic ChannelSender getChannelSender() Returns the channel sender component- Specified by:
- getChannelSenderin interface- ManagedChannel
- Returns:
- ChannelSender
- See Also:
- ChannelSender
 
 - 
getMembershipServicepublic MembershipService getMembershipService() Returns the membership service component- Specified by:
- getMembershipServicein interface- ManagedChannel
- Returns:
- MembershipService
- See Also:
- MembershipService
 
 - 
setChannelReceiverpublic void setChannelReceiver(ChannelReceiver clusterReceiver) Sets the channel receiver component- Specified by:
- setChannelReceiverin interface- ManagedChannel
- Parameters:
- clusterReceiver- ChannelReceiver
- See Also:
- ChannelReceiver
 
 - 
setChannelSenderpublic void setChannelSender(ChannelSender clusterSender) Sets the channel sender component- Specified by:
- setChannelSenderin interface- ManagedChannel
- Parameters:
- clusterSender- ChannelSender
- See Also:
- ChannelSender
 
 - 
setMembershipServicepublic void setMembershipService(MembershipService membershipService) Sets the membership component- Specified by:
- setMembershipServicein interface- ManagedChannel
- Parameters:
- membershipService- MembershipService
- See Also:
- MembershipService
 
 - 
addMembershipListenerpublic void addMembershipListener(MembershipListener membershipListener) Adds a membership listener to the channel.
 Membership listeners are uniquely identified using the equals(Object) method- Specified by:
- addMembershipListenerin interface- Channel
- Specified by:
- addMembershipListenerin interface- GroupChannelMBean
- Parameters:
- membershipListener- MembershipListener
- See Also:
- MembershipListener
 
 - 
removeMembershipListenerpublic void removeMembershipListener(MembershipListener membershipListener) Removes a membership listener from the channel.
 Membership listeners are uniquely identified using the equals(Object) method- Specified by:
- removeMembershipListenerin interface- Channel
- Specified by:
- removeMembershipListenerin interface- GroupChannelMBean
- Parameters:
- membershipListener- MembershipListener
- See Also:
- MembershipListener
 
 - 
addChannelListenerpublic void addChannelListener(ChannelListener channelListener) Adds a channel listener to the channel.
 Channel listeners are uniquely identified using the equals(Object) method- Specified by:
- addChannelListenerin interface- Channel
- Specified by:
- addChannelListenerin interface- GroupChannelMBean
- Parameters:
- channelListener- ChannelListener
- See Also:
- ChannelListener,- Heartbeat
 
 - 
removeChannelListenerpublic void removeChannelListener(ChannelListener channelListener) Removes a channel listener from the channel.
 Channel listeners are uniquely identified using the equals(Object) method- Specified by:
- removeChannelListenerin interface- Channel
- Specified by:
- removeChannelListenerin interface- GroupChannelMBean
- Parameters:
- channelListener- ChannelListener
- See Also:
- ChannelListener
 
 - 
getInterceptorspublic java.util.Iterator<ChannelInterceptor> getInterceptors() Returns an iterator of all the interceptors in this stack- Specified by:
- getInterceptorsin interface- ManagedChannel
- Returns:
- Iterator
- See Also:
- Channel.addInterceptor(ChannelInterceptor)
 
 - 
setOptionCheckpublic 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
 
 - 
setHeartbeatSleeptimepublic void setHeartbeatSleeptime(long heartbeatSleeptime) Configure local heartbeat sleep time
 Only used whengetHeartbeat()==true- Parameters:
- heartbeatSleeptime- long - time in milliseconds to sleep between heartbeats
 
 - 
setHeartbeatpublic 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 interface- Channel
- Parameters:
- heartbeat- boolean
- See Also:
- Channel.heartbeat()
 
 - 
getOptionCheckpublic boolean getOptionCheck() - Specified by:
- getOptionCheckin interface- GroupChannelMBean
- Returns:
- boolean
- See Also:
- setOptionCheck(boolean)
 
 - 
getHeartbeatpublic boolean getHeartbeat() - Specified by:
- getHeartbeatin interface- GroupChannelMBean
- Returns:
- boolean
- See Also:
- setHeartbeat(boolean)
 
 - 
getHeartbeatSleeptimepublic long getHeartbeatSleeptime() Returns the sleep time in milliseconds that the internal heartbeat will sleep in between invocations ofChannel.heartbeat()- Specified by:
- getHeartbeatSleeptimein interface- GroupChannelMBean
- Returns:
- long
 
 - 
getNamepublic java.lang.String getName() Description copied from interface:ChannelReturn the name of this channel.
 - 
setNamepublic void setName(java.lang.String name) Description copied from interface:ChannelSet the name of this channel
 - 
isJmxEnabledpublic boolean isJmxEnabled() Description copied from interface:JmxChannelIf set to true, this channel is registered with jmx.- Specified by:
- isJmxEnabledin interface- JmxChannel
- Returns:
- true if this channel will be registered with jmx.
 
 - 
setJmxEnabledpublic void setJmxEnabled(boolean jmxEnabled) Description copied from interface:JmxChannelIf set to true, this channel is registered with jmx.- Specified by:
- setJmxEnabledin interface- JmxChannel
- Parameters:
- jmxEnabled- set to true if this channel should be registered with jmx.
 
 - 
getJmxDomainpublic java.lang.String getJmxDomain() Description copied from interface:JmxChannelReturn the jmx domain which this channel is registered.- Specified by:
- getJmxDomainin interface- JmxChannel
- Returns:
- jmxDomain
 
 - 
setJmxDomainpublic void setJmxDomain(java.lang.String jmxDomain) Description copied from interface:JmxChannelSet the jmx domain which this channel should be registered.- Specified by:
- setJmxDomainin interface- JmxChannel
- Parameters:
- jmxDomain- The jmx domain which this channel should be registered.
 
 - 
getJmxPrefixpublic java.lang.String getJmxPrefix() Description copied from interface:JmxChannelReturn the jmx prefix which will be used with channel ObjectName.- Specified by:
- getJmxPrefixin interface- JmxChannel
- Returns:
- jmxPrefix
 
 - 
setJmxPrefixpublic void setJmxPrefix(java.lang.String jmxPrefix) Description copied from interface:JmxChannelSet the jmx prefix which will be used with channel ObjectName.- Specified by:
- setJmxPrefixin interface- JmxChannel
- Parameters:
- jmxPrefix- The jmx prefix which will be used with channel ObjectName.
 
 - 
preRegisterpublic javax.management.ObjectName preRegister(javax.management.MBeanServer server, javax.management.ObjectName name) throws java.lang.Exception- Specified by:
- preRegisterin interface- javax.management.MBeanRegistration
- Throws:
- java.lang.Exception
 
 - 
postRegisterpublic void postRegister(java.lang.Boolean registrationDone) - Specified by:
- postRegisterin interface- javax.management.MBeanRegistration
 
 - 
preDeregisterpublic void preDeregister() throws java.lang.Exception- Specified by:
- preDeregisterin interface- javax.management.MBeanRegistration
- Throws:
- java.lang.Exception
 
 - 
postDeregisterpublic void postDeregister() - Specified by:
- postDeregisterin interface- javax.management.MBeanRegistration
 
 
- 
 
-