|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jgroups.Channel
org.jgroups.JChannel
JChannel is a pure Java implementation of Channel When a JChannel object is instantiated it automatically sets up the protocol stack
Field Summary |
Fields inherited from class org.jgroups.Channel |
AUTO_GETSTATE, AUTO_RECONNECT, BLOCK, channel_listener, GET_STATE_EVENTS, LOCAL, SUSPECT, up_handler, VIEW |
Constructor Summary | |
|
JChannel()
initializes the JChannel with its default settings and default protocol stack |
protected |
JChannel(boolean dummy)
initializes the JChannel with its default settings and default protocol stack |
|
JChannel(java.lang.Object properties)
creates a new JChannel with the protocol stack as defined in the properties parameter. |
Method Summary | |
void |
blockOk()
Called to acknowledge a block() (callback in MembershipListener or
BlockEvent received from call to receive() ). |
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 |
void |
connect(java.lang.String channel_name)
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 |
void |
disconnect()
Disconnects the channel if it is connected. |
void |
down(Event evt)
Sends a message through the protocol stack if the stack is available |
boolean |
getAllStates(java.util.Vector targets,
long timeout)
Retrieves the current group state. |
java.lang.String |
getChannelName()
returns the name of the channel if the channel is not connected or if it is closed it will return null |
Address |
getLocalAddress()
returns the local address of the channel returns null if the channel is closed |
int |
getNumMessages()
Returns the number of messages that are waiting. |
java.lang.Object |
getOpt(int option)
returns the value of an option. |
java.lang.String |
getProperties()
returns the protocol stack configuration in string format. |
ProtocolStack |
getProtocolStack()
Returns the protocol stack. |
boolean |
getState(Address target,
long timeout)
Retrieves the current group state. |
View |
getView()
returns the current view. if the channel is not connected or if it is closed it will return null |
boolean |
isConnected()
returns true if the Connect operation has been called successfully |
boolean |
isOpen()
returns true if the Open operation has been called successfully |
void |
open()
Opens the channel. this does the following actions 1. |
java.lang.Object |
peek(long timeout)
Just peeks at the next message, view or block. |
java.lang.String |
printProtocolSpec(boolean include_properties)
Returns a pretty-printed form of all the protocols. |
java.lang.Object |
receive(long timeout)
Blocking receive method. |
void |
returnState(byte[] state)
Called by the application is response to receiving a getState() object when
calling receive() .When the application receives a getState() message on the receive() method, it should call returnState() to reply with the state of the application |
void |
send(Address dst,
Address src,
java.io.Serializable obj)
creates a new message with the destination address, and the source address and the object as the message value |
void |
send(Message msg)
implementation of the Transport interface. Sends a message through the protocol stack |
void |
setOpt(int option,
java.lang.Object value)
sets a channel option the options can be either |
java.lang.String |
toString(boolean details)
|
void |
up(Event evt)
Callback method Called by the ProtocolStack when a message is received. |
Methods inherited from class org.jgroups.Channel |
option2String, setChannelListener, setUpHandler |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected JChannel(boolean dummy) throws ChannelException
public JChannel() throws ChannelException
public JChannel(java.lang.Object properties) throws ChannelException
properties
- the protocol stack setup, if null, the default protocol stack will be usedMethod Detail |
public ProtocolStack getProtocolStack()
public java.lang.String getProperties()
public java.lang.String printProtocolSpec(boolean include_properties)
public void connect(java.lang.String channel_name) throws ChannelException, ChannelClosedException
connect
in class Channel
channel_name
- A String
denoting the group name. Cannot be null.
ChannelException
- The protocol stack cannot be started
ChannelClosedException
- The channel is closed and therefore cannot be used any longer.
A new channel has to be created first.Channel.disconnect()
public void disconnect()
disconnect
in class Channel
Channel.connect(String)
public void close()
close
in class Channel
public void open() throws ChannelException
open
in class Channel
ChannelException
public boolean isOpen()
isOpen
in class Channel
public boolean isConnected()
isConnected
in class Channel
public int getNumMessages()
Channel
Channel.receive(long)
. Note that this number could change after
calling this method and before calling receive() (e.g. the latter
method might be called by a different thread).
getNumMessages
in class Channel
public void send(Message msg) throws ChannelNotConnectedException, ChannelClosedException
send
in interface Transport
send
in class Channel
msg
- the message to be sent through the protocol stack,
the destination of the message is specified inside the message itself
ChannelNotConnectedException
ChannelClosedException
public void send(Address dst, Address src, java.io.Serializable obj) throws ChannelNotConnectedException, ChannelClosedException
send
in class Channel
dst
- - the destination address of the message, null for all memberssrc
- - the source address of the messageobj
- - the value of the message
ChannelNotConnectedException
ChannelClosedException
send(org.jgroups.Message)
public java.lang.Object receive(long timeout) throws ChannelNotConnectedException, ChannelClosedException, TimeoutException
receive
in interface Transport
receive
in class Channel
timeout
- the number of milliseconds to wait if the receive queue is empty. 0 means wait forever
TimeoutException
- if a timeout occured prior to a new message was received
ChannelNotConnectedException
ChannelClosedException
peek(long)
public java.lang.Object peek(long timeout) throws ChannelNotConnectedException, ChannelClosedException, TimeoutException
peek
in class Channel
timeout
- Value in milliseconds. Value <= 0 means wait forever
ChannelClosedException
- The channel is closed and therefore cannot be used any longer.
A new channel has to be created first.
ChannelNotConnectedException
- The channel must be connected to receive messages.
TimeoutException
- Thrown when a timeout has occurred.Channel.receive(long)
public View getView()
getView
in class Channel
public Address getLocalAddress()
getLocalAddress
in class Channel
Send
operation.public java.lang.String getChannelName()
getChannelName
in class Channel
public void setOpt(int option, java.lang.Object value)
Channel.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
setOpt
in class Channel
option
- the parameter option Channel.VIEW, Channel.SUSPECT, etcvalue
- the value to set for this optionpublic java.lang.Object getOpt(int option)
getOpt
in class Channel
option
- the option you want to see the value for
setOpt(int, java.lang.Object)
public void blockOk()
MembershipListener
or
BlockEvent
received from call to receive()
).
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.
blockOk
in class Channel
public boolean getState(Address target, long timeout) throws ChannelNotConnectedException, ChannelClosedException
timeout
milliseconds have elapsed. The argument of GET_STATE_OK should be a single object.
getState
in class Channel
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
ChannelNotConnectedException
- The channel must be connected to receive messages.
ChannelClosedException
- The channel is closed and therefore cannot be used
any longer. A new channel has to be created first.public boolean getAllStates(java.util.Vector targets, long timeout) throws ChannelNotConnectedException, ChannelClosedException
timeout
milliseconds have elapsed. The argument of GET_STATE_OK should be a vector of objects.
getAllStates
in class Channel
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
ChannelClosedException
- The channel is closed and therefore cannot be used
any longer. A new channel has to be created first.
ChannelNotConnectedException
- The channel must be connected to
receive messages.public void returnState(byte[] state)
getState()
object when
calling receive()
.
returnState
in class Channel
state
- The state of the application as a byte buffer
(to send over the network).public void up(Event evt)
Receive
s will dequeue it.
evt
- the event carrying the message from the protocol stackpublic void down(Event evt)
down
in class Channel
evt
- the message to send down, encapsulated in an eventpublic java.lang.String toString(boolean details)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |