|
Apache Tomcat 7.0.28 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Channel
Channel interface
A channel is a representation of a group of nodes all participating in some sort of
communication with each other.
The channel is the main API class for Tribes, this is essentially the only class
that an application needs to be aware of. Through the channel the application can:
1. send messages
2. receive message (by registering a ChannelListener
3. get all members of the group getMembers()
4. receive notifications of members added and members disappeared by
registering a MembershipListener
The channel has 5 major components:
1. Data receiver, with a built in thread pool to receive messages from other peers
2. Data sender, an implementation for sending data using NIO or java.io
3. Membership listener,listens for membership broadcasts
4. Membership broadcaster, broadcasts membership pings.
5. Channel interceptors, the ability to manipulate messages as they are sent or arrive
The channel layout is:
ChannelListener_1..ChannelListener_N MembershipListener_1..MembershipListener_N [Application Layer]
\ \ / /
\ \ / /
\ \ / /
\ \ / /
\ \ / /
\ \ / /
---------------------------------------
|
|
Channel
|
ChannelInterceptor_1
| [Channel stack]
ChannelInterceptor_N
|
Coordinator (implements MessageListener,MembershipListener,ChannelInterceptor)
--------------------
/ | \
/ | \
/ | \
/ | \
/ | \
MembershipService ChannelSender ChannelReceiver [IO layer]
For example usage @see org.apache.catalina.tribes.group.GroupChannel
Field Summary | |
---|---|
static int |
DEFAULT
Start and stop sequences can be controlled by these constants This allows you to start separate components of the channel DEFAULT - starts or stops all components in the channel |
static int |
MBR_RX_SEQ
Start and stop sequences can be controlled by these constants This allows you to start separate components of the channel MBR_RX_SEQ - starts or stops the membership listener. |
static int |
MBR_TX_SEQ
Start and stop sequences can be controlled by these constants This allows you to start separate components of the channel MBR_TX_SEQ - starts or stops the membership broadcaster. |
static int |
SEND_OPTIONS_ASYNCHRONOUS
Send options, when a message is sent, it can have an option flag to trigger certain behavior. |
static int |
SEND_OPTIONS_BYTE_MESSAGE
Send options, when a message is sent, it can have an option flag to trigger certain behavior. |
static int |
SEND_OPTIONS_DEFAULT
Send options, when a message is sent, it can have an option flag to trigger certain behavior. |
static int |
SEND_OPTIONS_MULTICAST
Send options. |
static int |
SEND_OPTIONS_SECURE
Send options, when a message is sent, it can have an option flag to trigger certain behavior. |
static int |
SEND_OPTIONS_SYNCHRONIZED_ACK
Send options, when a message is sent, it can have an option flag to trigger certain behavior. |
static int |
SEND_OPTIONS_UDP
Send options. |
static int |
SEND_OPTIONS_USE_ACK
Send options, when a message is sent, it can have an option flag to trigger certain behavior. |
static int |
SND_RX_SEQ
Start and stop sequences can be controlled by these constants This allows you to start separate components of the channel SND_RX_SEQ - starts or stops the data receiver. |
static int |
SND_TX_SEQ
Start and stop sequences can be controlled by these constants This allows you to start separate components of the channel SND_TX_SEQ - starts or stops the data sender. |
Method Summary | |
---|---|
void |
addChannelListener(ChannelListener listener)
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 |
void |
addInterceptor(ChannelInterceptor interceptor)
Adds an interceptor to the channel message chain. |
void |
addMembershipListener(MembershipListener listener)
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 |
Member |
getLocalMember(boolean incAlive)
Return the member that represents this node. |
Member |
getMember(Member mbr)
Returns the member from the membership service with complete and recent data. |
Member[] |
getMembers()
Get all current group members |
boolean |
hasMembers()
Returns true if there are any members in the group, this call is the same as getMembers().length>0 |
void |
heartbeat()
Sends a heart beat through the interceptor stacks Use this method to alert interceptors and other components to clean up garbage, timed out messages etc. |
void |
removeChannelListener(ChannelListener listener)
remove a channel listener, listeners are removed based on Object.hashCode and Object.equals |
void |
removeMembershipListener(MembershipListener listener)
remove a membership listener, listeners are removed based on Object.hashCode and Object.equals |
UniqueId |
send(Member[] destination,
Serializable msg,
int options)
Send a message to one or more members in the cluster |
UniqueId |
send(Member[] destination,
Serializable msg,
int options,
ErrorHandler handler)
Send a message to one or more members in the cluster |
void |
setHeartbeat(boolean enable)
Enables or disables internal heartbeat. |
void |
start(int svc)
Starts up the channel. |
void |
stop(int svc)
Shuts down the channel. |
Field Detail |
---|
static final int DEFAULT
start(int)
,
stop(int)
,
Constant Field Valuesstatic final int SND_RX_SEQ
start(int)
,
stop(int)
,
Constant Field Valuesstatic final int SND_TX_SEQ
start(int)
,
stop(int)
,
Constant Field Valuesstatic final int MBR_RX_SEQ
start(int)
,
stop(int)
,
Constant Field Valuesstatic final int MBR_TX_SEQ
start(int)
,
stop(int)
,
Constant Field Valuesstatic final int SEND_OPTIONS_BYTE_MESSAGE
send(Member[], Serializable , int)
,
send(Member[], Serializable, int, ErrorHandler)
,
Constant Field Valuesstatic final int SEND_OPTIONS_USE_ACK
send(Member[], Serializable , int)
,
send(Member[], Serializable, int, ErrorHandler)
,
Constant Field Valuesstatic final int SEND_OPTIONS_SYNCHRONIZED_ACK
send(Member[], Serializable , int)
,
send(Member[], Serializable, int, ErrorHandler)
,
Constant Field Valuesstatic final int SEND_OPTIONS_ASYNCHRONOUS
send(Member[], Serializable , int)
,
send(Member[], Serializable, int, ErrorHandler)
,
Constant Field Valuesstatic final int SEND_OPTIONS_SECURE
send(Member[], Serializable , int)
,
send(Member[], Serializable, int, ErrorHandler)
,
Constant Field Valuesstatic final int SEND_OPTIONS_UDP
send(Member[], Serializable , int)
,
send(Member[], Serializable, int, ErrorHandler)
,
Constant Field Valuesstatic final int SEND_OPTIONS_MULTICAST
send(Member[], Serializable , int)
,
send(Member[], Serializable, int, ErrorHandler)
,
Constant Field Valuesstatic final int SEND_OPTIONS_DEFAULT
int SEND_OPTIONS_DEFAULT = SEND_OPTIONS_USE_ACK;
SEND_OPTIONS_USE_ACK
,
send(Member[], Serializable , int)
,
send(Member[], Serializable, int, ErrorHandler)
,
Constant Field ValuesMethod Detail |
---|
void addInterceptor(ChannelInterceptor interceptor)
interceptor
- ChannelInterceptorvoid start(int svc) throws ChannelException
svc
- int value of ChannelException
- if a startup error occurs or the service is already started or an error occurs.void stop(int svc) throws ChannelException
svc
- int value of ChannelException
- if a startup error occurs or the service is already stopped or an error occurs.UniqueId send(Member[] destination, Serializable msg, int options) throws ChannelException
destination
- Member[] - the destinations, can not 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 ByteMessage
to
send a pure byte arrayoptions
- int - sender options, see class documentation for each interceptor that is configured in order to trigger interceptors
ChannelException
ByteMessage
,
SEND_OPTIONS_USE_ACK
,
SEND_OPTIONS_ASYNCHRONOUS
,
SEND_OPTIONS_SYNCHRONIZED_ACK
UniqueId send(Member[] destination, Serializable msg, int options, ErrorHandler handler) throws ChannelException
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
ChannelException
- - if a serialization error happens.void heartbeat()
setHeartbeat(boolean)
void setHeartbeat(boolean enable)
enable
- boolean - default value is implementation specificheartbeat()
void addMembershipListener(MembershipListener listener)
heartbeat()
method will be invoked when the heartbeat runs on the channel
listener
- MembershipListenerMembershipListener
void addChannelListener(ChannelListener listener)
heartbeat()
method will be invoked when the heartbeat runs on the channel
listener
- ChannelListenerChannelListener
,
Heartbeat
void removeMembershipListener(MembershipListener listener)
listener
- MembershipListenerMembershipListener
void removeChannelListener(ChannelListener listener)
listener
- ChannelListenerChannelListener
boolean hasMembers()
getMembers().length>0
Member[] getMembers()
Member getLocalMember(boolean incAlive)
incAlive
- - optimization, true if you want it to calculate alive time
since the membership service started.
Member getMember(Member mbr)
mbr
- Member
|
Apache Tomcat 7.0.28 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |