All Packages Class Hierarchy This Package Previous Next Index
Class JavaGroups.ChannelNew
java.lang.Object
|
+----JavaGroups.ChannelNew
- public abstract class ChannelNew
- extends Object
- implements Transportable
A channel represents one member of a specific group in a Java VM. Only a single object
at a time is allowed to connect to a channel, but there can be more than one channel in
an application (for different or the same groups).
Messages can be multicast to all objects connected to all channels with the same name
using the Send method and messages can be received using the
Receive method.
A channel instance is created using a ChannelFactory. Each implementation of a channel
must provide a subclass of Channel
and an implementation of ChannelFactory
.
Various degrees of sophistication in message exchange can be achieved using building
blocks on top of channels, e.g. light-weight groups, synchronous message invocation, or
remote method calls. Channels are on the same abstraction level as sockets, and should really
be simple to use. Higher-level abstractions are all built on top of channels.
-
ChannelNew()
-
-
BlockOk()
- Called to acknowledge a Block (callback in
MembershipListener
).
-
Connect(String)
- Private constructor.
-
Disconnect()
- Disconnects a client from a channel.
-
GetAddress()
-
Returns the channel's address.
-
GetOpt(int)
-
Gets an option.
-
GetView()
- Gets the current view.
-
Receive(long)
-
-
Receive(long)
- Receives a message, a view change or a block event.
-
Send(Message)
- Sends a message to a destination.
-
SetOpt(int, Object)
-
Sets an option.
ChannelNew
public ChannelNew()
Connect
public abstract void Connect(String group_address)
- Private constructor. Channels should be created through ChannelFactories.
private ChannelNew() {}
/** Connects a client to a channel. The client is now able to receive messages, views and block
events (depending on the options set) and to send messages. If the channel is already
connected, this is a null operation. All channels with the same name form a group.
- Parameters:
- group_address - The name of the group to be joined.
Disconnect
public abstract void Disconnect()
- Disconnects a client from a channel. This is a null operation if not connected.
Send
public abstract void Send(Message msg) throws NotConnected
- Sends a message to a destination. The message contains
- a destination address (Object). If it is null, the message is sent to all members of
the group.
- a source address. Can be left empty. Will be filled in by the protocol stack.
- a byte buffer. The message contents.
- several additional fields. They can be used by application programs (or patterns). E.g.
a message ID, a
oneway
field which determines whether a response is expected etc.
- Parameters:
- msg - The message to be sent. Destination and buffer should be set. A null destination
(default) means send to all members of the group.
- Throws: NotConnected
- The channel is not connected. Messages can only be sent in the
connected state.
Receive
public abstract Object Receive(long timeout) throws NotConnected, TimeoutException
- Receives a message, a view change or a block event. By using
SetOpt
,
the type of objects to be received can be determined (e.g. not views and blocks, just messages).
The channel must be connected to receive messages. The possible types returned can be:
Message
. Normal message
View
. A view change.
BlockEvent
. A block event indicating an impending view change.
The instanceof
operator can be used to discriminate between different types returned.
- Parameters:
- timeout - Value in milliseconds. Value <= 0 means wait forever
- Returns:
- A Message, View or BlockEvent object, depending on what is on top of the internal queue.
- Throws: TimeoutException
- Thrown when a timeout has occurred.
- Throws: NotConnected
- The channel is not connected. Messages can only be received
in the connected state.
GetView
public abstract View GetView()
- Gets the current view. This does not retrieve a new view, use
Receive
to do so. The view may only be available after a successful Connect
. The result of
calling this method on an unconnected channel is implementation defined (may return null).
- Returns:
- The current view.
GetAddress
public abstract Object GetAddress()
- Returns the channel's address. The result of calling this method on an unconnected channel
is implementation defined (may return null).
- Returns:
- The channel's address. Generated by the underlying transport, and opaque.
Addresses can be used as destination in the
Send
operation.
SetOpt
public abstract void SetOpt(int option,
Object value)
- Sets an option. The following options are currently recognized:
BLOCK
(0). Turn the reception of BLOCK events on/off (value is Boolean).
Default is off. If set to on, receiving VIEW events will be set to on, too.
VIEW
(1). Turn the reception of VIEW events on/off (value is Boolean).
Default is off.
LOCAL
(2). Receive its own broadcast messages to the group (value is Boolean).
Default is on.
This method can be called on an unconnected channel.
GetOpt
public abstract Object GetOpt(int option)
- Gets an option. This method can be called on an unconnected channel.
- Parameters:
- option - The option to be returned.
- Returns:
- The object associated with an option.
BlockOk
public abstract void BlockOk()
- Called to acknowledge a Block (callback in
MembershipListener
).
After sending BlockOk, no messages should be sent until a new view has been received.
All Packages Class Hierarchy This Package Previous Next Index