Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.jgroups.Channel
org.jgroups.JChannel
public class JChannel
extends Channel
Field Summary | |
static String |
|
protected org.jgroups.JChannel.CloserThread |
|
protected Log | |
protected boolean |
|
Fields inherited from class org.jgroups.Channel | |
AUTO_GETSTATE , AUTO_RECONNECT , BLOCK , GET_STATE_EVENTS , LOCAL , SUSPECT , VIEW , channel_listener , up_handler |
Constructor Summary | |
| |
| |
| |
| |
| |
| |
|
Method Summary | |
void |
|
void |
|
void |
|
void |
|
void | |
boolean |
|
String |
|
Address |
|
int | |
Object |
|
String |
|
ProtocolStack |
|
boolean | |
View |
|
boolean |
|
boolean |
|
void |
|
Object |
|
String |
|
Object |
|
void |
|
void | |
void | |
void |
|
String |
|
void |
Methods inherited from class org.jgroups.Channel | |
blockOk , close , connect , disconnect , down , getAllStates , getChannelName , getLocalAddress , getNumMessages , getOpt , getState , getView , isConnected , isOpen , open , option2String , peek , receive , returnState , send , send , setChannelListener , setOpt , setUpHandler |
public static final String DEFAULT_PROTOCOL_STACK
The default protocol stack used by the default constructor.
protected org.jgroups.JChannel.CloserThread closer
Thread responsible for closing a channel and potentially reconnecting to it (e.g. when shunned)
protected Log log
protected boolean state_received
Indicates whether the state was retrieved correctly (even a null state if we are the first member)
public JChannel() throws ChannelException
Constructs aJChannel
instance with the protocol stack specified by theDEFAULT_PROTOCOL_STACK
member.
- Throws:
ChannelException
- if problems occur during the initialization of the protocol stack.
public JChannel(Element properties) throws ChannelException
Constructs aJChannel
instance with the protocol stack configuration contained by the specified XML element.
- Parameters:
properties
- a XML element containing a JGroups XML protocol stack configuration.
- Throws:
ChannelException
- if problems occur during the configuration or initialization of the protocol stack.
public JChannel(File properties) throws ChannelException
Constructs aJChannel
instance with the protocol stack configuration contained by the specified file.
- Parameters:
properties
- a file containing a JGroups XML protocol stack configuration.
- Throws:
ChannelException
- if problems occur during the configuration or initialization of the protocol stack.
public JChannel(Object properties) throws ChannelException
Deprecated. Use the constructors with specific parameter types instead.
creates a new JChannel with the protocol stack as defined in the properties parameter. an example of this parameter is
"UDP:PING:FD:STABLE:NAKACK:UNICAST:FRAG:FLUSH:GMS:VIEW_ENFORCER:STATE_TRANSFER:QUEUE"
Another example is http://www.filip.net/jgroups/jgroups-protocol.xml
- Parameters:
properties
- the protocol stack setup, if null, the default protocol stack will be used
public JChannel(String properties) throws ChannelException
Constructs aJChannel
instance with the protocol stack configuration based upon the specified properties parameter.
- Parameters:
properties
- an old style property string, a string representing a system resource containing a JGroups XML configuration, a string representing a URL pointing to a JGroups XML XML configuration, or a string representing a file name that contains a JGroups XML configuration.
- Throws:
ChannelException
- if problems occur during the configuration and initialization of the protocol stack.
public JChannel(URL properties) throws ChannelException
Constructs aJChannel
instance with the protocol stack configuration indicated by the specified URL.
- Parameters:
properties
- a URL pointing to a JGroups XML protocol stack configuration.
- Throws:
ChannelException
- if problems occur during the configuration or initialization of the protocol stack.
protected JChannel(ProtocolStackConfigurator configurator) throws ChannelException
Constructs aJChannel
instance with the protocol stack configuration contained by the protocol stack configurator parameter. All of the public constructors of this class eventually delegate to this method.
- Parameters:
configurator
- a protocol stack configurator containing a JGroups protocol stack configuration.
- Throws:
ChannelException
- if problems occur during the initialization of the protocol stack.
public void blockOk()
Called to acknowledge a block() (callback inMembershipListener
orBlockEvent
received from call toreceive()
). After sending blockOk(), no messages should be sent until a new view has been received. Calling this method on a closed channel has no effect.
- Overrides:
- blockOk in interface Channel
public void close()
Destroys the channel.
After this method has been called, the channel us unusable.
This operation will disconnect the channel and close the channel receive queue immediately
- Overrides:
- close in interface Channel
public void connect(String channel_name) throws ChannelException, ChannelClosedException
Connects the channel to a group.
If the channel is already connected, an error message will be printed to the error log
If the channel is closed a ChannelClosed exception will be thrown
This method starts the protocol stack by calling ProtocolStack.start
then it sends an Event.CONNECT event down the stack and waits to receive a CONNECT_OK event
Once the CONNECT_OK event arrives from the protocol stack, any channel listeners are notified
and the channel is considered connected
- Overrides:
- connect in interface Channel
- Parameters:
channel_name
- AString
denoting the group name. Cannot be null.
- Throws:
ChannelException
- The protocol stack cannot be startedChannelClosedException
- The channel is closed and therefore cannot be used any longer. A new channel has to be created first.
public void disconnect()
Disconnects the channel if it is connected. If the channel is closed, this operation is ignored
Otherwise the following actions happen in the listed order
- The JChannel sends a DISCONNECT event down the protocol stack
- Blocks until the channel to receives a DISCONNECT_OK event
- Sends a STOP_QUEING event down the stack
- Stops the protocol stack by calling ProtocolStack.stop()
- Notifies the listener, if the listener is available
- Overrides:
- disconnect in interface Channel
public void down(Event evt)
Sends a message through the protocol stack if the stack is available
- Overrides:
- down in interface Channel
- Parameters:
evt
- the message to send down, encapsulated in an event
public boolean getAllStates(Vector targets, long timeout) throws ChannelNotConnectedException, ChannelClosedException
Retrieves the current group state. Sends GET_STATE event down to STATE_TRANSFER layer. Blocks until STATE_TRANSFER sends up a GET_STATE_OK event or untiltimeout
milliseconds have elapsed. The argument of GET_STATE_OK should be a vector of objects.
- Overrides:
- getAllStates in interface Channel
- Parameters:
targets
- - the target members to receive the state from ( an Address list )timeout
- - the number of milliseconds to wait for the operation to complete successfully
- Returns:
- true of the state was received, false if the operation timed out
public String getChannelName()
returns the name of the channel if the channel is not connected or if it is closed it will return null
- Overrides:
- getChannelName in interface Channel
public Address getLocalAddress()
returns the local address of the channel returns null if the channel is closed
- Overrides:
- getLocalAddress in interface Channel
public Object getOpt(int option)
returns the value of an option.
- Overrides:
- getOpt in interface Channel
- Parameters:
option
- the option you want to see the value for
- Returns:
- the object value, in most cases java.lang.Boolean
- See Also:
setOpt(int,Object)
public String getProperties()
returns the protocol stack configuration in string format. an example of this property is
"UDP:PING:FD:STABLE:NAKACK:UNICAST:FRAG:FLUSH:GMS:VIEW_ENFORCER:STATE_TRANSFER:QUEUE"
public ProtocolStack getProtocolStack()
Returns the protocol stack. Currently used by Debugger. Specific to JChannel, therefore not visible in Channel
public boolean getState(Address target, long timeout) throws ChannelNotConnectedException, ChannelClosedException
Retrieves the current group state. Sends GET_STATE event down to STATE_TRANSFER layer. Blocks until STATE_TRANSFER sends up a GET_STATE_OK event or untiltimeout
milliseconds have elapsed. The argument of GET_STATE_OK should be a single object.
- Overrides:
- getState in interface Channel
- Parameters:
target
- - the target member to receive the state from. if null, state is retrieved from coordinatortimeout
- - the number of milliseconds to wait for the operation to complete successfully
- Returns:
- true of the state was received, false if the operation timed out
public View getView()
returns the current view.
if the channel is not connected or if it is closed it will return null
- Overrides:
- getView in interface Channel
- Returns:
- returns the current group view, or null if the channel is closed or disconnected
public boolean isConnected()
returns true if the Connect operation has been called successfully
- Overrides:
- isConnected in interface Channel
public boolean isOpen()
returns true if the Open operation has been called successfully
- Overrides:
- isOpen in interface Channel
public void open() throws ChannelException
Opens the channel.
this does the following actions
1. Resets the receiver queue by calling Queue.reset
2. Sets up the protocol stack by calling ProtocolStack.setup
3. Sets the closed flag to false.
- Overrides:
- open in interface Channel
public Object peek(long timeout) throws ChannelNotConnectedException, ChannelClosedException, TimeoutException
Just peeks at the next message, view or block. Does not install new view if view is received
Does the same thing as JChannel.receive but doesn't remove the object from the receiver queue
- Overrides:
- peek in interface Channel
public String printProtocolSpec(boolean include_properties)
Returns a pretty-printed form of all the protocols. If include_properties is set, the properties for each protocol will also be printed.
public Object receive(long timeout) throws ChannelNotConnectedException, ChannelClosedException, TimeoutException
Blocking receive method. This method returns the object that was first received by this JChannel and that has not been received before. After the object is received, it is removed from the receive queue.
If you only want to inspect the object received without removing it from the queue call JChannel.peek
If no messages are in the receive queue, this method blocks until a message is added or the operation times out
By specifying a timeout of 0, the operation blocks forever, or until a message has been received.
- Overrides:
- receive in interface Channel
- Parameters:
timeout
- the number of milliseconds to wait if the receive queue is empty. 0 means wait forever
- Throws:
TimeoutException
- if a timeout occured prior to a new message was receivedChannelNotConnectedException
-ChannelClosedException
-
- See Also:
peek(long)
public void returnState(byte[] state)
Called by the application is response to receiving agetState()
object when callingreceive()
.
When the application receives a getState() message on the receive() method, it should call returnState() to reply with the state of the application
- Overrides:
- returnState in interface Channel
- Parameters:
state
- The state of the application as a byte buffer (to send over the network).
public void send(Address dst, Address src, Serializable obj) throws ChannelNotConnectedException, ChannelClosedException
creates a new message with the destination address, and the source address and the object as the message value
- Overrides:
- send in interface Channel
- Parameters:
dst
- - the destination address of the message, null for all memberssrc
- - the source address of the messageobj
- - the value of the message
- See Also:
JChannel.send
public void send(Message msg) throws ChannelNotConnectedException, ChannelClosedException
implementation of the Transport interface.
Sends a message through the protocol stack
- Overrides:
- send in interface Channel
- Parameters:
msg
- the message to be sent through the protocol stack, the destination of the message is specified inside the message itself
public void setOpt(int option, Object value)
sets a channel option the options can be eitherChannel.BLOCK Channel.VIEW Channel.SUSPECT Channel.LOCAL Channel.GET_STATE_EVENTS Channel.AUTO_RECONNECT Channel.AUTO_GETSTATEThere are certain dependencies between the options that you can set, I will try to describe them here
Option: Channel.VIEW option
Value: java.lang.Boolean
Result: set to true the JChannel will receive VIEW change events
Option: Channel.SUSPECT
Value: java.lang.Boolean
Result: set to true the JChannel will receive SUSPECT events
Option: Channel.BLOCK
Value: java.lang.Boolean
Result: set to true will set setOpt(VIEW, true) and the JChannel will receive BLOCKS and VIEW events
Option: GET_STATE_EVENTS
Value: java.lang.Boolean
Result: set to true the JChannel will receive state events
Option: LOCAL
Value: java.lang.Boolean
Result: set to true the JChannel will receive messages that it self sent out.
Option: AUTO_RECONNECT
Value: java.lang.Boolean
Result: set to true and the JChannel will try to reconnect when it is being closed
Option: AUTO_GETSTATE
Value: java.lang.Boolean
Result: set to true, the AUTO_RECONNECT will be set to true and the JChannel will try to get the state after a close and reconnect happens
- Overrides:
- setOpt in interface Channel
- Parameters:
option
- the parameter option Channel.VIEW, Channel.SUSPECT, etcvalue
- the value to set for this option
public String toString(boolean details)
public void up(Event evt)
Callback method
Called by the ProtocolStack when a message is received. It will be added to the message queue from which subsequentReceive
s will dequeue it.
- Parameters:
evt
- the event carrying the message from the protocol stack