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:
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 Summary
Nested ClassesModifier and TypeClassDescriptionstatic classIfChannel.getHeartbeat()==truethen a thread of this class is created.static classAn iterator to loop through the interceptors in a channel.Nested classes/interfaces inherited from interface org.apache.catalina.tribes.ChannelInterceptor
ChannelInterceptor.InterceptorEvent -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<ChannelListener>A list of channel listeners that subscribe to incoming messagesprotected final ChannelCoordinatorTheChannelCoordinatorcoordinates the bottom layer components:
- MembershipService
- ChannelSender
- ChannelReceiverprotected GroupChannel.HeartbeatThreadInternal heartbeat threadprotected 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 longIfheartbeat == truethen how often do we want this heartbeat to run. default is one minuteprotected ChannelInterceptorThe first interceptor in the interceptor stack.protected final List<MembershipListener>A list of membership listeners that subscribe to membership announcementsprotected Stringthe name of this channel.protected booleanIf set to true, the GroupChannel will check to make sure thatprotected static final StringManagerFields inherited from class org.apache.catalina.tribes.group.ChannelInterceptorBase
optionFlagFields 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 -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChannelListener(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 voidValidates the option flags that each interceptor is using and reports an error if two interceptor share the same flag.Returns the channel receiver componentReturns the channel sender componentReturns the first interceptor of the stack.booleanlongReturns the sleep time in milliseconds that the internal heartbeat will sleep in between invocations ofChannel.heartbeat()Returns an iterator of all the interceptors in this stackReturn the jmx domain which this channel is registered.Return the jmx prefix which will be used with channel ObjectName.Returns the membership service componentgetName()Return the name of this channel.booleanvoidSends 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) 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) methodsend(Member[] destination, Serializable msg, int options) Send a message to the destinations specifiedsend(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 a 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(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 componentvoidSet 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 addedvoidstart(int svc) Starts the channel.voidstop(int svc) Stops 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, setPreviousMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.catalina.tribes.Channel
getLocalMember, getMember, getMembers, hasMembersMethods inherited from interface org.apache.catalina.tribes.group.GroupChannelMBean
getLocalMember, getMembers, hasMembers
-
Field Details
-
sm
-
heartbeat
protected 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. -
heartbeatSleeptime
protected long heartbeatSleeptimeIfheartbeat == truethen how often do we want this heartbeat to run. default is one minute -
hbthread
Internal heartbeat thread -
coordinator
TheChannelCoordinatorcoordinates the bottom layer components:
- MembershipService
- ChannelSender
- ChannelReceiver -
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
A list of membership listeners that subscribe to membership announcements -
channelListeners
A list of channel listeners that subscribe to incoming messages -
optionCheck
protected boolean optionCheckIf set to true, the GroupChannel will check to make sure that -
name
the name of this channel.
-
-
Constructor Details
-
GroupChannel
public 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
-
addInterceptor
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 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:
-
send
Send a message to the destinations specified- Specified by:
sendin interfaceChannel- Specified by:
sendin interfaceGroupChannelMBean- Parameters:
destination- Member[] - destination.length > 0msg- Serializable - the message to sendoptions- sender options, options can trigger guarantee levels and different interceptors to react to the message see class documentation for theChannelobject.- Returns:
- UniqueId - the unique Id that was assigned to this message
- Throws:
ChannelException- - if an error occurs processing the message- See Also:
-
send
public 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 interfaceChannel- Specified by:
sendin interfaceGroupChannelMBean- Parameters:
destination- Member[] - destination.length > 0msg- Serializable - the message to sendoptions- sender options, options can trigger guarantee levels and different interceptors to react to the message see class documentation for theChannelobject.handler- - callback object for error handling and completion notification, used when a message is sent asynchronously using theChannel.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:
-
messageReceived
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 interfaceChannelInterceptor- Overrides:
messageReceivedin classChannelInterceptorBase- Parameters:
msg- ChannelMessage
-
sendNoRpcChannelReply
Sends aNoRpcChannelReplymessage to a member
This method gets invoked by the channel if a RPC message comes in and no channel listener accepts the message. This avoids timeout- Parameters:
msg- RpcMessagedestination- Member - the destination for the reply
-
memberAdded
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
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:
-
setupDefaultStack
Sets up the default implementation interceptor stack if no interceptors have been added- Throws:
ChannelException- Cluster error
-
checkOptionFlags
Validates 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
Starts the channel.- Specified by:
startin interfaceChannel- Specified by:
startin interfaceChannelInterceptor- Specified by:
startin interfaceGroupChannelMBean- Overrides:
startin classChannelInterceptorBase- Parameters:
svc- int - what service to start- Throws:
ChannelException- Start error- See Also:
-
stop
Stops the channel.- Specified by:
stopin interfaceChannel- Specified by:
stopin interfaceChannelInterceptor- Specified by:
stopin interfaceGroupChannelMBean- Overrides:
stopin classChannelInterceptorBase- Parameters:
svc- int- Throws:
ChannelException- Stop error- See Also:
-
getFirstInterceptor
Returns the first interceptor of the stack. Useful for traversal.- Returns:
- ChannelInterceptor
-
getChannelReceiver
Returns the channel receiver component- Specified by:
getChannelReceiverin interfaceManagedChannel- Returns:
- ChannelReceiver
- See Also:
-
getChannelSender
Returns the channel sender component- Specified by:
getChannelSenderin interfaceManagedChannel- Returns:
- ChannelSender
- See Also:
-
getMembershipService
Returns the membership service component- Specified by:
getMembershipServicein interfaceManagedChannel- Returns:
- MembershipService
- See Also:
-
setChannelReceiver
Sets the channel receiver component- Specified by:
setChannelReceiverin interfaceManagedChannel- Parameters:
clusterReceiver- ChannelReceiver- See Also:
-
setChannelSender
Sets the channel sender component- Specified by:
setChannelSenderin interfaceManagedChannel- Parameters:
clusterSender- ChannelSender- See Also:
-
setMembershipService
Sets the membership component- Specified by:
setMembershipServicein interfaceManagedChannel- Parameters:
membershipService- MembershipService- See Also:
-
addMembershipListener
Adds a membership listener to the channel.
Membership listeners are uniquely identified using the equals(Object) method- Specified by:
addMembershipListenerin interfaceChannel- Specified by:
addMembershipListenerin interfaceGroupChannelMBean- Parameters:
membershipListener- MembershipListener- See Also:
-
removeMembershipListener
Removes a membership listener from the channel.
Membership listeners are uniquely identified using the equals(Object) method- Specified by:
removeMembershipListenerin interfaceChannel- Specified by:
removeMembershipListenerin interfaceGroupChannelMBean- Parameters:
membershipListener- MembershipListener- See Also:
-
addChannelListener
Adds a channel listener to the channel.
Channel listeners are uniquely identified using the equals(Object) method- Specified by:
addChannelListenerin interfaceChannel- Specified by:
addChannelListenerin interfaceGroupChannelMBean- Parameters:
channelListener- ChannelListener- See Also:
-
removeChannelListener
Removes a channel listener from the channel.
Channel listeners are uniquely identified using the equals(Object) method- Specified by:
removeChannelListenerin interfaceChannel- Specified by:
removeChannelListenerin interfaceGroupChannelMBean- Parameters:
channelListener- ChannelListener- See Also:
-
getInterceptors
Returns an iterator of all the interceptors in this stack- Specified by:
getInterceptorsin interfaceManagedChannel- Returns:
- Iterator
- See Also:
-
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:
-
getOptionCheck
public boolean getOptionCheck()- Specified by:
getOptionCheckin interfaceGroupChannelMBean- Returns:
- boolean
- See Also:
-
getHeartbeat
public boolean getHeartbeat()- Specified by:
getHeartbeatin interfaceGroupChannelMBean- Returns:
- boolean
- See Also:
-
getHeartbeatSleeptime
public long getHeartbeatSleeptime()Returns the sleep time in milliseconds that the internal heartbeat will sleep in between invocations ofChannel.heartbeat()- Specified by:
getHeartbeatSleeptimein interfaceGroupChannelMBean- Returns:
- long
-
getName
Description copied from interface:ChannelReturn the name of this channel. -
setName
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
Description copied from interface:JmxChannelReturn the jmx domain which this channel is registered.- Specified by:
getJmxDomainin interfaceJmxChannel- Returns:
- jmxDomain
-
setJmxDomain
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
Description copied from interface:JmxChannelReturn the jmx prefix which will be used with channel ObjectName.- Specified by:
getJmxPrefixin interfaceJmxChannel- Returns:
- jmxPrefix
-
setJmxPrefix
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
- Specified by:
preRegisterin interfaceMBeanRegistration- Throws:
Exception
-
postRegister
- Specified by:
postRegisterin interfaceMBeanRegistration
-
preDeregister
- Specified by:
preDeregisterin interfaceMBeanRegistration- Throws:
Exception
-
postDeregister
public void postDeregister()- Specified by:
postDeregisterin interfaceMBeanRegistration
-