Class GroupChannel
java.lang.Object
org.apache.catalina.tribes.group.ChannelInterceptorBase
org.apache.catalina.tribes.group.GroupChannel
- All Implemented Interfaces:
- 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.
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 ClassesModifier and TypeClassDescriptionclassTitle: Internal heartbeat runnablestatic classAn iterator to loop through the interceptors in a channel.Nested classes/interfaces inherited from interface org.apache.catalina.tribes.ChannelInterceptorChannelInterceptor.InterceptorEvent
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final List<ChannelListener> A list of channel listeners that subscribe to incoming messagesprotected final ChannelCoordinatorTheChannelCoordinatorcoordinates the bottom layer components:
 - MembershipService
 - ChannelSender
 - ChannelReceiverprotected booleanFlag 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 ScheduledFuture<?> Internal heartbeat futureprotected longIfheartbeat == truethen how often do we want this heartbeat to run.protected ChannelInterceptorThe first interceptor in the interceptor stack.protected final List<MembershipListener> A list of membership listeners that subscribe to membership announcementsprotected ScheduledFuture<?> protected Stringthe name of this channel.protected booleanIf set to true, the GroupChannel will check to make sure thatprotected booleanprotected static final StringManagerprotected ScheduledExecutorServiceExecutor service.Fields inherited from class org.apache.catalina.tribes.group.ChannelInterceptorBaseoptionFlagFields 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
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddChannelListener(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 voidValidates the option flags that each interceptor is using and reports an error if two interceptor share the same flag.returns the channel receiverreturns the channel senderReturns the first interceptor of the stack.booleanlongReturns the interceptor stackReturn the jmx domain which this channel is registered.Return the jmx prefix which will be used with channel ObjectName.Returns the membership servicegetName()Return the name of this channel.booleanReturn executor that can be used for utility tasks.voidSends 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)booleanIf 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 listenersvoidCallback from the interceptor stack.voidvoidpostRegister(Boolean registrationDone) voidpreRegister(MBeanServer server, 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).send(Member[] destination, Serializable msg, int options) Send a message to one or more members in the clustersend(Member[] destination, 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(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(String jmxPrefix) Set the jmx prefix which will be used with channel ObjectName.voidsetMembershipService(MembershipService membershipService) Sets the membership servicevoidSet 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 voidSets up the default implementation interceptor stack if no interceptors have been addedvoidsetUtilityExecutor(ScheduledExecutorService utilityExecutor) Set the executor that can be used for utility tasks.voidstart(int svc) Starts up the channel.protected voidvoidstop(int svc) Shuts down 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, setPreviousMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.catalina.tribes.ChannelgetLocalMember, getMember, getMembers, hasMembersMethods inherited from interface org.apache.catalina.tribes.group.GroupChannelMBeangetLocalMember, getMembers, hasMembers
- 
Field Details- 
sm
- 
heartbeatprotected boolean heartbeatFlag 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 heartbeatSleeptimeIfheartbeat == truethen how often do we want this heartbeat to run. The default value is 5000 milliseconds.
- 
heartbeatFutureInternal heartbeat future
- 
monitorFuture
- 
coordinatorTheChannelCoordinatorcoordinates the bottom layer components:
 - MembershipService
 - ChannelSender
 - ChannelReceiver
- 
interceptorsThe first interceptor in the interceptor stack. The interceptors are chained in a linked list, so we only need a reference to the first one
- 
membershipListenersA list of membership listeners that subscribe to membership announcements
- 
channelListenersA list of channel listeners that subscribe to incoming messages
- 
optionCheckprotected boolean optionCheckIf set to true, the GroupChannel will check to make sure that
- 
namethe name of this channel.
- 
utilityExecutorExecutor service.
- 
ownExecutorprotected boolean ownExecutor
 
- 
- 
Constructor Details- 
GroupChannelpublic GroupChannel()Creates a GroupChannel. This constructor will also add the first interceptor in the GroupChannel.
 The first interceptor is always the channel itself.
 
- 
- 
Method Details- 
addInterceptorDescription 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 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:
 
- 
sendDescription 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[] - 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 a- ByteMessageto send a pure byte array
- options- 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:
 
- 
sendpublic UniqueId send(Member[] destination, 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[] - the destinations, null or zero length means all
- msg- ClusterMessage - the message to send
- options- int - sender options, see class documentation
- handler- 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.
 
- 
messageReceivedCallback 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
 
- 
sendNoRpcChannelReplySends 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
 
- 
memberAddedmemberAdded 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
 
- 
memberDisappearedmemberDisappeared 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:
 
- 
setupDefaultStackSets up the default implementation interceptor stack if no interceptors have been added- Throws:
- ChannelException- Cluster error
 
- 
checkOptionFlagsValidates 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
 
- 
startDescription 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 interface- Channel
- Specified by:
- startin interface- ChannelInterceptor
- Specified by:
- startin interface- GroupChannelMBean
- Overrides:
- startin class- ChannelInterceptorBase
- 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:
 
- 
startHeartbeatprotected void startHeartbeat()
- 
stopDescription copied from interface:ChannelInterceptorShuts 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:
- stopin interface- Channel
- Specified by:
- stopin interface- ChannelInterceptor
- Specified by:
- stopin interface- GroupChannelMBean
- Overrides:
- stopin class- ChannelInterceptorBase
- 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:
 
- 
getFirstInterceptorReturns the first interceptor of the stack. Useful for traversal.- Returns:
- ChannelInterceptor
 
- 
getUtilityExecutorDescription copied from interface:ChannelReturn executor that can be used for utility tasks.- Specified by:
- getUtilityExecutorin interface- Channel
- Returns:
- the executor
 
- 
setUtilityExecutorDescription copied from interface:ChannelSet the executor that can be used for utility tasks.- Specified by:
- setUtilityExecutorin interface- Channel
- Parameters:
- utilityExecutor- the executor
 
- 
getChannelReceiverDescription copied from interface:ManagedChannelreturns the channel receiver- Specified by:
- getChannelReceiverin interface- ManagedChannel
- Returns:
- ChannelReceiver
- See Also:
 
- 
getChannelSenderDescription copied from interface:ManagedChannelreturns the channel sender- Specified by:
- getChannelSenderin interface- ManagedChannel
- Returns:
- ChannelSender
- See Also:
 
- 
getMembershipServiceDescription copied from interface:ManagedChannelReturns the membership service- Specified by:
- getMembershipServicein interface- ManagedChannel
- Returns:
- MembershipService
- See Also:
 
- 
setChannelReceiverDescription copied from interface:ManagedChannelSets the channel receiver- Specified by:
- setChannelReceiverin interface- ManagedChannel
- Parameters:
- clusterReceiver- ChannelReceiver
- See Also:
 
- 
setChannelSenderDescription copied from interface:ManagedChannelSets the channel sender- Specified by:
- setChannelSenderin interface- ManagedChannel
- Parameters:
- clusterSender- ChannelSender
- See Also:
 
- 
setMembershipServiceDescription copied from interface:ManagedChannelSets the membership service- Specified by:
- setMembershipServicein interface- ManagedChannel
- Parameters:
- membershipService- MembershipService
- See Also:
 
- 
addMembershipListenerDescription 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 interface- Channel
- Specified by:
- addMembershipListenerin interface- GroupChannelMBean
- Parameters:
- membershipListener- MembershipListener
- See Also:
 
- 
removeMembershipListenerDescription copied from interface:ChannelRemove a membership listener, listeners are removed based onObject.hashCode()andObject.equals(Object).- Specified by:
- removeMembershipListenerin interface- Channel
- Specified by:
- removeMembershipListenerin interface- GroupChannelMBean
- Parameters:
- membershipListener- MembershipListener
- See Also:
 
- 
addChannelListenerDescription 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 interface- Channel
- Specified by:
- addChannelListenerin interface- GroupChannelMBean
- Parameters:
- channelListener- ChannelListener
- See Also:
 
- 
removeChannelListenerDescription copied from interface:ChannelRemove a channel listener, listeners are removed based onObject.hashCode()andObject.equals(Object).- Specified by:
- removeChannelListenerin interface- Channel
- Specified by:
- removeChannelListenerin interface- GroupChannelMBean
- Parameters:
- channelListener- ChannelListener
- See Also:
 
- 
getInterceptorsDescription copied from interface:ManagedChannelReturns the interceptor stack- Specified by:
- getInterceptorsin interface- ManagedChannel
- Returns:
- Iterator
- See Also:
 
- 
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:
 
- 
getOptionCheckpublic boolean getOptionCheck()- Specified by:
- getOptionCheckin interface- GroupChannelMBean
 
- 
getHeartbeatpublic boolean getHeartbeat()- Specified by:
- getHeartbeatin interface- GroupChannelMBean
 
- 
getHeartbeatSleeptimepublic long getHeartbeatSleeptime()- Specified by:
- getHeartbeatSleeptimein interface- GroupChannelMBean
- Returns:
- the sleep time in milliseconds that the internal heartbeat will sleep in between invocations of
             Channel.heartbeat()
 
- 
getName
- 
setName
- 
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.
 
- 
getJmxDomainDescription copied from interface:JmxChannelReturn the jmx domain which this channel is registered.- Specified by:
- getJmxDomainin interface- JmxChannel
- Returns:
- jmxDomain
 
- 
setJmxDomainDescription 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.
 
- 
getJmxPrefixDescription copied from interface:JmxChannelReturn the jmx prefix which will be used with channel ObjectName.- Specified by:
- getJmxPrefixin interface- JmxChannel
- Returns:
- jmxPrefix
 
- 
setJmxPrefixDescription 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.
 
- 
preRegister- Specified by:
- preRegisterin interface- MBeanRegistration
- Throws:
- Exception
 
- 
postRegister- Specified by:
- postRegisterin interface- MBeanRegistration
 
- 
preDeregister- Specified by:
- preDeregisterin interface- MBeanRegistration
- Throws:
- Exception
 
- 
postDeregisterpublic void postDeregister()- Specified by:
- postDeregisterin interface- MBeanRegistration
 
 
-