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
Modifier and TypeClassDescriptionclass
Title: Internal heartbeat runnablestatic class
An iterator to loop through the interceptors in a channel.Nested classes/interfaces inherited from interface org.apache.catalina.tribes.ChannelInterceptor
ChannelInterceptor.InterceptorEvent
-
Field Summary
Modifier and TypeFieldDescriptionprotected final List
<ChannelListener> A list of channel listeners that subscribe to incoming messagesprotected final ChannelCoordinator
TheChannelCoordinator
coordinates the bottom layer components:
- MembershipService
- ChannelSender
- ChannelReceiverprotected boolean
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.protected ScheduledFuture
<?> Internal heartbeat futureprotected long
Ifheartbeat == true
then how often do we want this heartbeat to run.protected ChannelInterceptor
The first interceptor in the interceptor stack.protected final List
<MembershipListener> A list of membership listeners that subscribe to membership announcementsprotected ScheduledFuture
<?> protected String
the name of this channel.protected boolean
If set to true, the GroupChannel will check to make sure thatprotected boolean
protected static final StringManager
protected ScheduledExecutorService
Executor 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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addChannelListener
(ChannelListener channelListener) Add a channel listener, this is a callback object when messages are received.void
addInterceptor
(ChannelInterceptor interceptor) Adds an interceptor to the stack for message processing.void
addMembershipListener
(MembershipListener membershipListener) Add a membership listener, will get notified when a new member joins, leaves or crashes.protected void
Validates 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.boolean
long
Returns 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.boolean
Return executor that can be used for utility tasks.void
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)
boolean
If set to true, this channel is registered with jmx.void
memberAdded
(Member member) memberAdded gets invoked by the interceptor below the channel and the channel will broadcast it to the membership listenersvoid
memberDisappeared
(Member member) memberDisappeared gets invoked by the interceptor below the channel and the channel will broadcast it to the membership listenersvoid
Callback from the interceptor stack.void
void
postRegister
(Boolean registrationDone) void
preRegister
(MBeanServer server, ObjectName name) void
removeChannelListener
(ChannelListener channelListener) Remove a channel listener, listeners are removed based onObject.hashCode()
andObject.equals(Object)
.void
removeMembershipListener
(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 void
sendNoRpcChannelReply
(RpcMessage msg, Member destination) Sends aNoRpcChannelReply
message to a member
This method gets invoked by the channel if an RPC message comes in and no channel listener accepts the message.void
setChannelReceiver
(ChannelReceiver clusterReceiver) Sets the channel receivervoid
setChannelSender
(ChannelSender clusterSender) Sets the channel sendervoid
setHeartbeat
(boolean heartbeat) Enables or disables local heartbeat. ifsetHeartbeat(true)
is invoked then the channel will start an internal thread to invokeChannel.heartbeat()
everygetHeartbeatSleeptime
millisecondsvoid
setHeartbeatSleeptime
(long heartbeatSleeptime) Configure local heartbeat sleep time
Only used whengetHeartbeat()==true
void
setJmxDomain
(String jmxDomain) Set the jmx domain which this channel should be registered.void
setJmxEnabled
(boolean jmxEnabled) If set to true, this channel is registered with jmx.void
setJmxPrefix
(String jmxPrefix) Set the jmx prefix which will be used with channel ObjectName.void
setMembershipService
(MembershipService membershipService) Sets the membership servicevoid
Set the name of this channelvoid
setOptionCheck
(boolean optionCheck) Enables/disables the option check
Setting this to true, will make the GroupChannel perform a conflict check on the interceptors.protected void
Sets up the default implementation interceptor stack if no interceptors have been addedvoid
setUtilityExecutor
(ScheduledExecutorService utilityExecutor) Set the executor that can be used for utility tasks.void
start
(int svc) Starts up the channel.protected void
void
stop
(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 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 == true
then how often do we want this heartbeat to run. The default value is 5000 milliseconds. -
heartbeatFuture
Internal heartbeat future -
monitorFuture
-
coordinator
TheChannelCoordinator
coordinates 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. -
utilityExecutor
Executor service. -
ownExecutor
protected boolean ownExecutor
-
-
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
Description copied from interface:Channel
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);
A -> C -> B
The complete stack will look like this:
Channel -> A -> C -> B -> ChannelCoordinator
- Specified by:
addInterceptor
in 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:
heartbeat
in interfaceChannel
- Specified by:
heartbeat
in interfaceChannelInterceptor
- Specified by:
heartbeat
in interfaceHeartbeat
- Overrides:
heartbeat
in classChannelInterceptorBase
- See Also:
-
send
Description copied from interface:Channel
Send a message to one or more members in the cluster- Specified by:
send
in interfaceChannel
- Specified by:
send
in 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 aByteMessage
to 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:
-
send
public UniqueId send(Member[] destination, Serializable msg, int options, ErrorHandler handler) throws ChannelException Description copied from interface:Channel
Send a message to one or more members in the cluster- Specified by:
send
in interfaceChannel
- Specified by:
send
in 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
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:
messageReceived
in interfaceChannelInterceptor
- Overrides:
messageReceived
in classChannelInterceptorBase
- Parameters:
msg
- ChannelMessage
-
sendNoRpcChannelReply
Sends aNoRpcChannelReply
message 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
memberAdded gets invoked by the interceptor below the channel and the channel will broadcast it to the membership listeners- Specified by:
memberAdded
in interfaceMembershipListener
- Overrides:
memberAdded
in 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:
memberDisappeared
in interfaceMembershipListener
- Overrides:
memberDisappeared
in 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
Description copied from interface:ChannelInterceptor
Starts 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:
start
in interfaceChannel
- Specified by:
start
in interfaceChannelInterceptor
- Specified by:
start
in interfaceGroupChannelMBean
- Overrides:
start
in 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:
-
startHeartbeat
protected void startHeartbeat() -
stop
Description copied from interface:ChannelInterceptor
Shuts 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:
stop
in interfaceChannel
- Specified by:
stop
in interfaceChannelInterceptor
- Specified by:
stop
in interfaceGroupChannelMBean
- Overrides:
stop
in classChannelInterceptorBase
- 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:
-
getFirstInterceptor
Returns the first interceptor of the stack. Useful for traversal.- Returns:
- ChannelInterceptor
-
getUtilityExecutor
Description copied from interface:Channel
Return executor that can be used for utility tasks.- Specified by:
getUtilityExecutor
in interfaceChannel
- Returns:
- the executor
-
setUtilityExecutor
Description copied from interface:Channel
Set the executor that can be used for utility tasks.- Specified by:
setUtilityExecutor
in interfaceChannel
- Parameters:
utilityExecutor
- the executor
-
getChannelReceiver
Description copied from interface:ManagedChannel
returns the channel receiver- Specified by:
getChannelReceiver
in interfaceManagedChannel
- Returns:
- ChannelReceiver
- See Also:
-
getChannelSender
Description copied from interface:ManagedChannel
returns the channel sender- Specified by:
getChannelSender
in interfaceManagedChannel
- Returns:
- ChannelSender
- See Also:
-
getMembershipService
Description copied from interface:ManagedChannel
Returns the membership service- Specified by:
getMembershipService
in interfaceManagedChannel
- Returns:
- MembershipService
- See Also:
-
setChannelReceiver
Description copied from interface:ManagedChannel
Sets the channel receiver- Specified by:
setChannelReceiver
in interfaceManagedChannel
- Parameters:
clusterReceiver
- ChannelReceiver- See Also:
-
setChannelSender
Description copied from interface:ManagedChannel
Sets the channel sender- Specified by:
setChannelSender
in interfaceManagedChannel
- Parameters:
clusterSender
- ChannelSender- See Also:
-
setMembershipService
Description copied from interface:ManagedChannel
Sets the membership service- Specified by:
setMembershipService
in interfaceManagedChannel
- Parameters:
membershipService
- MembershipService- See Also:
-
addMembershipListener
Description copied from interface:Channel
Add 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:
addMembershipListener
in interfaceChannel
- Specified by:
addMembershipListener
in interfaceGroupChannelMBean
- Parameters:
membershipListener
- MembershipListener- See Also:
-
removeMembershipListener
Description copied from interface:Channel
Remove a membership listener, listeners are removed based onObject.hashCode()
andObject.equals(Object)
.- Specified by:
removeMembershipListener
in interfaceChannel
- Specified by:
removeMembershipListener
in interfaceGroupChannelMBean
- Parameters:
membershipListener
- MembershipListener- See Also:
-
addChannelListener
Description copied from interface:Channel
Add 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:
addChannelListener
in interfaceChannel
- Specified by:
addChannelListener
in interfaceGroupChannelMBean
- Parameters:
channelListener
- ChannelListener- See Also:
-
removeChannelListener
Description copied from interface:Channel
Remove a channel listener, listeners are removed based onObject.hashCode()
andObject.equals(Object)
.- Specified by:
removeChannelListener
in interfaceChannel
- Specified by:
removeChannelListener
in interfaceGroupChannelMBean
- Parameters:
channelListener
- ChannelListener- See Also:
-
getInterceptors
Description copied from interface:ManagedChannel
Returns the interceptor stack- Specified by:
getInterceptors
in 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()
everygetHeartbeatSleeptime
milliseconds- Specified by:
setHeartbeat
in interfaceChannel
- Parameters:
heartbeat
- boolean- See Also:
-
getOptionCheck
public boolean getOptionCheck()- Specified by:
getOptionCheck
in interfaceGroupChannelMBean
-
getHeartbeat
public boolean getHeartbeat()- Specified by:
getHeartbeat
in interfaceGroupChannelMBean
-
getHeartbeatSleeptime
public long getHeartbeatSleeptime()- Specified by:
getHeartbeatSleeptime
in interfaceGroupChannelMBean
- Returns:
- the sleep time in milliseconds that the internal heartbeat will sleep in between invocations of
Channel.heartbeat()
-
getName
-
setName
-
isJmxEnabled
public boolean isJmxEnabled()Description copied from interface:JmxChannel
If set to true, this channel is registered with jmx.- Specified by:
isJmxEnabled
in interfaceJmxChannel
- Returns:
- true if this channel will be registered with jmx.
-
setJmxEnabled
public void setJmxEnabled(boolean jmxEnabled) Description copied from interface:JmxChannel
If set to true, this channel is registered with jmx.- Specified by:
setJmxEnabled
in interfaceJmxChannel
- Parameters:
jmxEnabled
- set to true if this channel should be registered with jmx.
-
getJmxDomain
Description copied from interface:JmxChannel
Return the jmx domain which this channel is registered.- Specified by:
getJmxDomain
in interfaceJmxChannel
- Returns:
- jmxDomain
-
setJmxDomain
Description copied from interface:JmxChannel
Set the jmx domain which this channel should be registered.- Specified by:
setJmxDomain
in interfaceJmxChannel
- Parameters:
jmxDomain
- The jmx domain which this channel should be registered.
-
getJmxPrefix
Description copied from interface:JmxChannel
Return the jmx prefix which will be used with channel ObjectName.- Specified by:
getJmxPrefix
in interfaceJmxChannel
- Returns:
- jmxPrefix
-
setJmxPrefix
Description copied from interface:JmxChannel
Set the jmx prefix which will be used with channel ObjectName.- Specified by:
setJmxPrefix
in interfaceJmxChannel
- Parameters:
jmxPrefix
- The jmx prefix which will be used with channel ObjectName.
-
preRegister
- Specified by:
preRegister
in interfaceMBeanRegistration
- Throws:
Exception
-
postRegister
- Specified by:
postRegister
in interfaceMBeanRegistration
-
preDeregister
- Specified by:
preDeregister
in interfaceMBeanRegistration
- Throws:
Exception
-
postDeregister
public void postDeregister()- Specified by:
postDeregister
in interfaceMBeanRegistration
-