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 Summary
Nested Classes Modifier and Type Class Description class
GroupChannel.HeartbeatRunnable
Title: Internal heartbeat runnablestatic class
GroupChannel.InterceptorIterator
Title: Interceptor Iterator-
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>
channelListeners
A list of channel listeners that subscribe to incoming messagesprotected ChannelCoordinator
coordinator
TheChannelCoordinator
coordinates the bottom layer components:
- MembershipService
- ChannelSender
- ChannelReceiverprotected 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.protected java.util.concurrent.ScheduledFuture<?>
heartbeatFuture
Internal heartbeat futureprotected long
heartbeatSleeptime
Ifheartbeat == true
then how often do we want this heartbeat to run.protected ChannelInterceptor
interceptors
The first interceptor in the interceptor stack.protected java.util.List<MembershipListener>
membershipListeners
A list of membership listeners that subscribe to membership announcementsprotected java.util.concurrent.ScheduledFuture<?>
monitorFuture
protected java.lang.String
name
the name of this channel.protected boolean
optionCheck
If set to true, the GroupChannel will check to make sure thatprotected boolean
ownExecutor
protected static StringManager
sm
protected java.util.concurrent.ScheduledExecutorService
utilityExecutor
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
Constructors Constructor Description GroupChannel()
Creates a GroupChannel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChannelListener(ChannelListener channelListener)
Adds a channel listener to the channel.
Channel listeners are uniquely identified using the equals(Object) methodvoid
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
void
addMembershipListener(MembershipListener membershipListener)
Adds a membership listener to the channel.
Membership listeners are uniquely identified using the equals(Object) methodprotected void
checkOptionFlags()
Validates the option flags that each interceptor is using and reports an error if two interceptor share the same flag.ChannelReceiver
getChannelReceiver()
Returns the channel receiver componentChannelSender
getChannelSender()
Returns the channel sender componentChannelInterceptor
getFirstInterceptor()
Returns the first interceptor of the stack.boolean
getHeartbeat()
long
getHeartbeatSleeptime()
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.String
getJmxDomain()
Return the jmx domain which this channel is registered.java.lang.String
getJmxPrefix()
Return the jmx prefix which will be used with channel ObjectName.MembershipService
getMembershipService()
Returns the membership service componentjava.lang.String
getName()
Return the name of this channel.boolean
getOptionCheck()
java.util.concurrent.ScheduledExecutorService
getUtilityExecutor()
Return executor that can be used for utility tasks.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)
boolean
isJmxEnabled()
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
messageReceived(ChannelMessage msg)
Callback from the interceptor stack.void
postDeregister()
void
postRegister(java.lang.Boolean registrationDone)
void
preDeregister()
javax.management.ObjectName
preRegister(javax.management.MBeanServer server, javax.management.ObjectName name)
void
removeChannelListener(ChannelListener channelListener)
Removes a channel listener from the channel.
Channel listeners are uniquely identified using the equals(Object) methodvoid
removeMembershipListener(MembershipListener membershipListener)
Removes a membership listener from the channel.
Membership listeners are uniquely identified using the equals(Object) methodUniqueId
send(Member[] destination, java.io.Serializable msg, int options)
Send a message to the destinations specifiedUniqueId
send(Member[] destination, java.io.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 receiver componentvoid
setChannelSender(ChannelSender clusterSender)
Sets the channel sender componentvoid
setHeartbeat(boolean heartbeat)
Enables or disables local heartbeat.void
setHeartbeatSleeptime(long heartbeatSleeptime)
Configure local heartbeat sleep time
Only used whengetHeartbeat()==true
void
setJmxDomain(java.lang.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(java.lang.String jmxPrefix)
Set the jmx prefix which will be used with channel ObjectName.void
setMembershipService(MembershipService membershipService)
Sets the membership componentvoid
setName(java.lang.String name)
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
setupDefaultStack()
Sets up the default implementation interceptor stack if no interceptors have been addedvoid
setUtilityExecutor(java.util.concurrent.ScheduledExecutorService utilityExecutor)
Set the executor that can be used for utility tasks.void
start(int svc)
Starts the channel.protected void
startHeartbeat()
void
stop(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, 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 == true
then 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
TheChannelCoordinator
coordinates 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)
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:
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:
Channel.setHeartbeat(boolean)
-
send
public UniqueId send(Member[] destination, java.io.Serializable msg, int options) throws ChannelException
Send a message to the destinations specified- Specified by:
send
in interfaceChannel
- Specified by:
send
in 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 theChannel
object.- Returns:
- UniqueId - the unique Id that was assigned to this message
- Throws:
ChannelException
- - if an error occurs processing the message- See Also:
Channel
-
send
public UniqueId send(Member[] destination, java.io.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[] - 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 theChannel
object.handler
- - callback object for error handling and completion notification, used when a message is sent asynchronously using theChannel.SEND_OPTIONS_ASYNCHRONOUS
flag enabled.- Returns:
- UniqueId - the unique Id that was assigned to this message
- Throws:
ChannelException
- - if an error occurs processing the message- See Also:
Channel
-
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 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
protected 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. 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:
memberAdded
in interfaceMembershipListener
- Overrides:
memberAdded
in 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:
memberDisappeared
in interfaceMembershipListener
- Overrides:
memberDisappeared
in classChannelInterceptorBase
- Parameters:
member
- Member - the member that left or crashed- See Also:
Member.SHUTDOWN_PAYLOAD
-
setupDefaultStack
protected void setupDefaultStack() throws ChannelException
Sets up the default implementation interceptor stack if no interceptors have been added- Throws:
ChannelException
- Cluster error
-
checkOptionFlags
protected void checkOptionFlags() throws ChannelException
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
public void start(int svc) throws ChannelException
Starts the channel.- Specified by:
start
in interfaceChannel
- Specified by:
start
in interfaceChannelInterceptor
- Specified by:
start
in interfaceGroupChannelMBean
- Overrides:
start
in classChannelInterceptorBase
- Parameters:
svc
- int - what service to start- Throws:
ChannelException
- Start error- See Also:
Channel.start(int)
-
startHeartbeat
protected void startHeartbeat()
-
stop
public void stop(int svc) throws ChannelException
Stops the channel.- Specified by:
stop
in interfaceChannel
- Specified by:
stop
in interfaceChannelInterceptor
- Specified by:
stop
in interfaceGroupChannelMBean
- Overrides:
stop
in classChannelInterceptorBase
- Parameters:
svc
- int- Throws:
ChannelException
- Stop error- See Also:
Channel.stop(int)
-
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:Channel
Return executor that can be used for utility tasks.- Specified by:
getUtilityExecutor
in interfaceChannel
- Returns:
- the executor
-
setUtilityExecutor
public void setUtilityExecutor(java.util.concurrent.ScheduledExecutorService utilityExecutor)
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
public ChannelReceiver getChannelReceiver()
Returns the channel receiver component- Specified by:
getChannelReceiver
in interfaceManagedChannel
- Returns:
- ChannelReceiver
- See Also:
ChannelReceiver
-
getChannelSender
public ChannelSender getChannelSender()
Returns the channel sender component- Specified by:
getChannelSender
in interfaceManagedChannel
- Returns:
- ChannelSender
- See Also:
ChannelSender
-
getMembershipService
public MembershipService getMembershipService()
Returns the membership service component- Specified by:
getMembershipService
in interfaceManagedChannel
- Returns:
- MembershipService
- See Also:
MembershipService
-
setChannelReceiver
public void setChannelReceiver(ChannelReceiver clusterReceiver)
Sets the channel receiver component- Specified by:
setChannelReceiver
in interfaceManagedChannel
- Parameters:
clusterReceiver
- ChannelReceiver- See Also:
ChannelReceiver
-
setChannelSender
public void setChannelSender(ChannelSender clusterSender)
Sets the channel sender component- Specified by:
setChannelSender
in interfaceManagedChannel
- Parameters:
clusterSender
- ChannelSender- See Also:
ChannelSender
-
setMembershipService
public void setMembershipService(MembershipService membershipService)
Sets the membership component- Specified by:
setMembershipService
in interfaceManagedChannel
- Parameters:
membershipService
- MembershipService- See Also:
MembershipService
-
addMembershipListener
public void addMembershipListener(MembershipListener membershipListener)
Adds a membership listener to the channel.
Membership listeners are uniquely identified using the equals(Object) method- Specified by:
addMembershipListener
in interfaceChannel
- Specified by:
addMembershipListener
in interfaceGroupChannelMBean
- Parameters:
membershipListener
- MembershipListener- See Also:
MembershipListener
-
removeMembershipListener
public void removeMembershipListener(MembershipListener membershipListener)
Removes a membership listener from the channel.
Membership listeners are uniquely identified using the equals(Object) method- Specified by:
removeMembershipListener
in interfaceChannel
- Specified by:
removeMembershipListener
in interfaceGroupChannelMBean
- Parameters:
membershipListener
- MembershipListener- See Also:
MembershipListener
-
addChannelListener
public void addChannelListener(ChannelListener channelListener)
Adds a channel listener to the channel.
Channel listeners are uniquely identified using the equals(Object) method- Specified by:
addChannelListener
in interfaceChannel
- Specified by:
addChannelListener
in interfaceGroupChannelMBean
- Parameters:
channelListener
- ChannelListener- See Also:
ChannelListener
,Heartbeat
-
removeChannelListener
public void removeChannelListener(ChannelListener channelListener)
Removes a channel listener from the channel.
Channel listeners are uniquely identified using the equals(Object) method- Specified by:
removeChannelListener
in interfaceChannel
- Specified by:
removeChannelListener
in interfaceGroupChannelMBean
- Parameters:
channelListener
- ChannelListener- See Also:
ChannelListener
-
getInterceptors
public java.util.Iterator<ChannelInterceptor> getInterceptors()
Returns an iterator of all the interceptors in this stack- Specified by:
getInterceptors
in 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()
everygetHeartbeatSleeptime
milliseconds- Specified by:
setHeartbeat
in interfaceChannel
- Parameters:
heartbeat
- boolean- See Also:
Channel.heartbeat()
-
getOptionCheck
public boolean getOptionCheck()
- Specified by:
getOptionCheck
in interfaceGroupChannelMBean
- Returns:
- boolean
- See Also:
setOptionCheck(boolean)
-
getHeartbeat
public boolean getHeartbeat()
- Specified by:
getHeartbeat
in interfaceGroupChannelMBean
- Returns:
- boolean
- See Also:
setHeartbeat(boolean)
-
getHeartbeatSleeptime
public long getHeartbeatSleeptime()
Returns the sleep time in milliseconds that the internal heartbeat will sleep in between invocations ofChannel.heartbeat()
- Specified by:
getHeartbeatSleeptime
in interfaceGroupChannelMBean
- Returns:
- long
-
getName
public java.lang.String getName()
Description copied from interface:Channel
Return the name of this channel.
-
setName
public void setName(java.lang.String name)
Description copied from interface:Channel
Set the name of this channel
-
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
public java.lang.String getJmxDomain()
Description copied from interface:JmxChannel
Return the jmx domain which this channel is registered.- Specified by:
getJmxDomain
in interfaceJmxChannel
- Returns:
- jmxDomain
-
setJmxDomain
public void setJmxDomain(java.lang.String jmxDomain)
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
public java.lang.String 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
public void setJmxPrefix(java.lang.String jmxPrefix)
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
public javax.management.ObjectName preRegister(javax.management.MBeanServer server, javax.management.ObjectName name) throws java.lang.Exception
- Specified by:
preRegister
in interfacejavax.management.MBeanRegistration
- Throws:
java.lang.Exception
-
postRegister
public void postRegister(java.lang.Boolean registrationDone)
- Specified by:
postRegister
in interfacejavax.management.MBeanRegistration
-
preDeregister
public void preDeregister() throws java.lang.Exception
- Specified by:
preDeregister
in interfacejavax.management.MBeanRegistration
- Throws:
java.lang.Exception
-
postDeregister
public void postDeregister()
- Specified by:
postDeregister
in interfacejavax.management.MBeanRegistration
-
-