org.apache.catalina.tribes.group

Class GroupChannel

public class GroupChannel extends ChannelInterceptorBase implements ManagedChannel

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.

Version: $Revision: 568742 $, $Date: 2007-08-22 22:19:54 +0200 (Wed, 22 Aug 2007) $

Author: Filip Hanik

Nested Class Summary
static classGroupChannel.HeartbeatThread

Title: Internal heartbeat thread

Description: if Channel.getHeartbeat()==true then a thread of this class is created

static classGroupChannel.InterceptorIterator

Title: Interceptor Iterator

Description: An iterator to loop through the interceptors in a channel

Field Summary
protected ArrayListchannelListeners
A list of channel listeners that subscribe to incoming messages
protected ChannelCoordinatorcoordinator
The ChannelCoordinator coordinates the bottom layer components:
- MembershipService
- ChannelSender
- ChannelReceiver
protected GroupChannel.HeartbeatThreadhbthread
Internal heartbeat thread
protected booleanheartbeat
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 longheartbeatSleeptime
If heartbeat == true then how often do we want this heartbeat to run. default is one minute
protected ChannelInterceptorinterceptors
The first interceptor in the inteceptor stack.
protected ArrayListmembershipListeners
A list of membership listeners that subscribe to membership announcements
protected booleanoptionCheck
If set to true, the GroupChannel will check to make sure that
Constructor Summary
GroupChannel()
Creates a GroupChannel.
Method Summary
voidaddChannelListener(ChannelListener channelListener)
Adds a channel listener to the channel.
Channel listeners are uniquely identified using the equals(Object) method
voidaddInterceptor(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 a interceptor stack like this:
A -> C -> B
The complete stack will look like this:
Channel -> A -> C -> B -> ChannelCoordinator
voidaddMembershipListener(MembershipListener membershipListener)
Adds a membership listener to the channel.
Membership listeners are uniquely identified using the equals(Object) method
protected 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 component
ChannelSendergetChannelSender()
Returns the channel sender component
ChannelInterceptorgetFirstInterceptor()
Returns the first interceptor of the stack.
booleangetHeartbeat()
longgetHeartbeatSleeptime()
Returns the sleep time in milliseconds that the internal heartbeat will sleep in between invokations of Channel.heartbeat()
IteratorgetInterceptors()
Returns an iterator of all the interceptors in this stack
MembershipServicegetMembershipService()
Returns the membership service component
booleangetOptionCheck()
voidheartbeat()
Sends a heartbeat through the interceptor stack.
Invoke this method from the application on a periodic basis if you have turned off internal heartbeats channel.setHeartbeat(false)
voidmemberAdded(Member member)
memberAdded gets invoked by the interceptor below the channel and the channel will broadcast it to the membership listeners
voidmemberDisappeared(Member member)
memberDisappeared gets invoked by the interceptor below the channel and the channel will broadcast it to the membership listeners
voidmessageReceived(ChannelMessage msg)
Callback from the interceptor stack.
voidremoveChannelListener(ChannelListener channelListener)
Removes a channel listener from the channel.
Channel listeners are uniquely identified using the equals(Object) method
voidremoveMembershipListener(MembershipListener membershipListener)
Removes a membership listener from the channel.
Membership listeners are uniquely identified using the equals(Object) method
UniqueIdsend(Member[] destination, Serializable msg, int options)
Send a message to the destinations specified
UniqueIdsend(Member[] destination, Serializable msg, int options, ErrorHandler handler)
protected voidsendNoRpcChannelReply(RpcMessage msg, Member destination)
Sends a NoRpcChannelReply message 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 component
voidsetChannelSender(ChannelSender clusterSender)
Sets the channel sender component
voidsetHeartbeat(boolean heartbeat)
Enables or disables local heartbeat. if setHeartbeat(true) is invoked then the channel will start an internal thread to invoke Channel.heartbeat() every getHeartbeatSleeptime milliseconds
voidsetHeartbeatSleeptime(long heartbeatSleeptime)
Configure local heartbeat sleep time
Only used when getHeartbeat()==true
voidsetMembershipService(MembershipService membershipService)
Sets the membership component
voidsetOptionCheck(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 added
voidstart(int svc)
Starts the channel
voidstop(int svc)
Stops the channel

Field Detail

channelListeners

protected ArrayList channelListeners
A list of channel listeners that subscribe to incoming messages

coordinator

protected ChannelCoordinator coordinator
The ChannelCoordinator coordinates the bottom layer components:
- MembershipService
- ChannelSender
- ChannelReceiver

hbthread

protected GroupChannel.HeartbeatThread hbthread
Internal heartbeat thread

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
If heartbeat == true then how often do we want this heartbeat to run. default is one minute

interceptors

protected ChannelInterceptor interceptors
The first interceptor in the inteceptor stack. The interceptors are chained in a linked list, so we only need a reference to the first one

membershipListeners

protected ArrayList membershipListeners
A list of membership listeners that subscribe to membership announcements

optionCheck

protected boolean optionCheck
If set to true, the GroupChannel will check to make sure that

Constructor Detail

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 Detail

addChannelListener

public void addChannelListener(ChannelListener channelListener)
Adds a channel listener to the channel.
Channel listeners are uniquely identified using the equals(Object) method

Parameters: channelListener ChannelListener

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 a interceptor stack like this:
A -> C -> B
The complete stack will look like this:
Channel -> A -> C -> B -> ChannelCoordinator

Parameters: interceptor ChannelInterceptorBase

addMembershipListener

public void addMembershipListener(MembershipListener membershipListener)
Adds a membership listener to the channel.
Membership listeners are uniquely identified using the equals(Object) method

Parameters: membershipListener MembershipListener

checkOptionFlags

protected void checkOptionFlags()
Validates the option flags that each interceptor is using and reports an error if two interceptor share the same flag.

Throws: ChannelException

getChannelReceiver

public ChannelReceiver getChannelReceiver()
Returns the channel receiver component

Returns: ChannelReceiver

getChannelSender

public ChannelSender getChannelSender()
Returns the channel sender component

Returns: ChannelSender

getFirstInterceptor

public ChannelInterceptor getFirstInterceptor()
Returns the first interceptor of the stack. Useful for traversal.

Returns: ChannelInterceptor

getHeartbeat

public boolean getHeartbeat()

Returns: boolean

See Also: GroupChannel

getHeartbeatSleeptime

public long getHeartbeatSleeptime()
Returns the sleep time in milliseconds that the internal heartbeat will sleep in between invokations of Channel.heartbeat()

Returns: long

getInterceptors

public Iterator getInterceptors()
Returns an iterator of all the interceptors in this stack

Returns: Iterator

getMembershipService

public MembershipService getMembershipService()
Returns the membership service component

Returns: MembershipService

getOptionCheck

public boolean getOptionCheck()

Returns: boolean

See Also: GroupChannel

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 heartbeats channel.setHeartbeat(false)

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

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

Parameters: member Member - the member that left or crashed

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.

Parameters: msg ChannelMessage

removeChannelListener

public void removeChannelListener(ChannelListener channelListener)
Removes a channel listener from the channel.
Channel listeners are uniquely identified using the equals(Object) method

Parameters: channelListener ChannelListener

removeMembershipListener

public void removeMembershipListener(MembershipListener membershipListener)
Removes a membership listener from the channel.
Membership listeners are uniquely identified using the equals(Object) method

Parameters: membershipListener MembershipListener

send

public UniqueId send(Member[] destination, Serializable msg, int options)
Send a message to the destinations specified

Parameters: destination Member[] - destination.length > 1 msg Serializable - the message to send options int - sender options, options can trigger guarantee levels and different interceptors to react to the message see class documentation for the Channel 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, Serializable msg, int options, ErrorHandler handler)

Parameters: destination Member[] - destination.length > 1 msg Serializable - the message to send options int - sender options, options can trigger guarantee levels and different interceptors to react to the message see class documentation for the Channel object.
handler - callback object for error handling and completion notification, used when a message is sent asynchronously using the Channel.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

sendNoRpcChannelReply

protected void sendNoRpcChannelReply(RpcMessage msg, Member destination)
Sends a NoRpcChannelReply message 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 RpcMessage destination Member - the destination for the reply

setChannelReceiver

public void setChannelReceiver(ChannelReceiver clusterReceiver)
Sets the channel receiver component

Parameters: clusterReceiver ChannelReceiver

setChannelSender

public void setChannelSender(ChannelSender clusterSender)
Sets the channel sender component

Parameters: clusterSender ChannelSender

setHeartbeat

public void setHeartbeat(boolean heartbeat)
Enables or disables local heartbeat. if setHeartbeat(true) is invoked then the channel will start an internal thread to invoke Channel.heartbeat() every getHeartbeatSleeptime milliseconds

Parameters: heartbeat boolean

setHeartbeatSleeptime

public void setHeartbeatSleeptime(long heartbeatSleeptime)
Configure local heartbeat sleep time
Only used when getHeartbeat()==true

Parameters: heartbeatSleeptime long - time in milliseconds to sleep between heartbeats

setMembershipService

public void setMembershipService(MembershipService membershipService)
Sets the membership component

Parameters: membershipService MembershipService

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

setupDefaultStack

protected void setupDefaultStack()
Sets up the default implementation interceptor stack if no interceptors have been added

Throws: ChannelException

start

public void start(int svc)
Starts the channel

Parameters: svc int - what service to start

Throws: ChannelException

See Also: Channel

stop

public void stop(int svc)
Stops the channel

Parameters: svc int

Throws: ChannelException

See Also: Channel

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.