📄 channel.java
字号:
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.catalina.tribes;
import java.io.Serializable;
/**
* Channel interface<br>
* A channel is a representation of a group of nodes all participating in some sort of
* communication with each other.<br>
* 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:<br>
* 1. send messages<br>
* 2. receive message (by registering a <code>ChannelListener</code><br>
* 3. get all members of the group <code>getMembers()</code><br>
* 4. receive notifications of members added and members disappeared by
* registerering a <code>MembershipListener</code><br>
* <br>
* The channel has 5 major components:<br>
* 1. Data receiver, with a built in thread pool to receive messages from other peers<br>
* 2. Data sender, an implementation for sending data using NIO or java.io<br>
* 3. Membership listener,listens for membership broadcasts<br>
* 4. Membership broadcaster, broadcasts membership pings.<br>
* 5. Channel interceptors, the ability to manipulate messages as they are sent or arrive<br><br>
* The channel layout is:
* <pre><code>
* 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]
* </code></pre>
*
* For example usage @see org.apache.catalina.tribes.group.GroupChannel
* @author Filip Hanik
* @version $Revision: 467222 $, $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
*/
public interface Channel {
/**
* Start and stop sequences can be controlled by these constants
* This allows you to start separate components of the channel <br>
* DEFAULT - starts or stops all components in the channel
* @see #start(int)
* @see #stop(int)
*/
public static final int DEFAULT = 15;
/**
* Start and stop sequences can be controlled by these constants
* This allows you to start separate components of the channel <br>
* SND_RX_SEQ - starts or stops the data receiver. Start means opening a server socket
* in case of a TCP implementation
* @see #start(int)
* @see #stop(int)
*/
public static final int SND_RX_SEQ = 1;
/**
* Start and stop sequences can be controlled by these constants
* This allows you to start separate components of the channel <br>
* SND_TX_SEQ - starts or stops the data sender. This should not open any sockets,
* as sockets are opened on demand when a message is being sent
* @see #start(int)
* @see #stop(int)
*/
public static final int SND_TX_SEQ = 2;
/**
* Start and stop sequences can be controlled by these constants
* This allows you to start separate components of the channel <br>
* MBR_RX_SEQ - starts or stops the membership listener. In a multicast implementation
* this will open a datagram socket and join a group and listen for membership messages
* members joining
* @see #start(int)
* @see #stop(int)
*/
public static final int MBR_RX_SEQ = 4;
/**
* Start and stop sequences can be controlled by these constants
* This allows you to start separate components of the channel <br>
* MBR_TX_SEQ - starts or stops the membership broadcaster. In a multicast implementation
* this will open a datagram socket and join a group and broadcast the local member information
* @see #start(int)
* @see #stop(int)
*/
public static final int MBR_TX_SEQ = 8;
/**
* Send options, when a message is sent, it can have an option flag
* to trigger certain behavior. Most flags are used to trigger channel interceptors
* as the message passes through the channel stack. <br>
* However, there are five default flags that every channel implementation must implement<br>
* SEND_OPTIONS_BYTE_MESSAGE - The message is a pure byte message and no marshalling or unmarshalling will
* be performed.<br>
*
* @see #send(Member[], Serializable , int)
* @see #send(Member[], Serializable, int, ErrorHandler)
*/
public static final int SEND_OPTIONS_BYTE_MESSAGE = 0x0001;
/**
* Send options, when a message is sent, it can have an option flag
* to trigger certain behavior. Most flags are used to trigger channel interceptors
* as the message passes through the channel stack. <br>
* However, there are five default flags that every channel implementation must implement<br>
* SEND_OPTIONS_USE_ACK - Message is sent and an ACK is received when the message has been received by the recipient<br>
* If no ack is received, the message is not considered successful<br>
* @see #send(Member[], Serializable , int)
* @see #send(Member[], Serializable, int, ErrorHandler)
*/
public static final int SEND_OPTIONS_USE_ACK = 0x0002;
/**
* Send options, when a message is sent, it can have an option flag
* to trigger certain behavior. Most flags are used to trigger channel interceptors
* as the message passes through the channel stack. <br>
* However, there are five default flags that every channel implementation must implement<br>
* SEND_OPTIONS_SYNCHRONIZED_ACK - Message is sent and an ACK is received when the message has been received and
* processed by the recipient<br>
* If no ack is received, the message is not considered successful<br>
* @see #send(Member[], Serializable , int)
* @see #send(Member[], Serializable, int, ErrorHandler)
*/
public static final int SEND_OPTIONS_SYNCHRONIZED_ACK = 0x0004;
/**
* Send options, when a message is sent, it can have an option flag
* to trigger certain behavior. Most flags are used to trigger channel interceptors
* as the message passes through the channel stack. <br>
* However, there are five default flags that every channel implementation must implement<br>
* SEND_OPTIONS_ASYNCHRONOUS - Message is sent and an ACK is received when the message has been received and
* processed by the recipient<br>
* If no ack is received, the message is not considered successful<br>
* @see #send(Member[], Serializable , int)
* @see #send(Member[], Serializable, int, ErrorHandler)
*/
public static final int SEND_OPTIONS_ASYNCHRONOUS = 0x0008;
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -