A channel represents the group endpoint over which messages can be sent to all (or a subset) of the group members and over which messages multicast to group members can be received. It is on purpose designed to be as simple as possible, similar in semantics to BSD sockets.
Each channel has a name. Channels with the same name form a group, that is, messages sent by a channel will be received by all other channels with the same name.
To use a channel, a client has first to connnect to it. When done, it should disconnect from the channel. There can always only be a single client connected to the same channel. When connected, messages received by the channel will be stored in a queue until Receive is called, which returns the oldest message by removing it from the queue. All messages will be deleted from the queue when the client disconnects.
The main reason for the need to connect to a channel before using it is that this serialization of access to the channel 'resource' prevents clients from removing messages from the channel without other clients seeing them. That is, multiple clients of a channel would not see the same sequence of messages.2.3
A client may send a message to (1) a single other channel, (2) a number of channels, or (3) all of the channels of the same group using the Send (1,2) or Cast (3) methods. To find out the other channels in the group, method GetMembers can be used. It returns the addresses of all members in the group. Since these addresses will typically vary in their form and content, they are only returned in the most general form of Object. Each subclass of Channel has to narrow such an address to the form used by it. Users of JavaGroups must not be concerned about the contents and real class of an address, as this is opaque. They can essentially only receive addresses as result of method calls and subsequently use them as target addresses in sending messages to a single or a set of channels.
Channels use the Half-Sync/Half-Async pattern [SC97] in that they present a synchronous interface to the caller (Receive), but use asynchronous message reception and message queues to block and awake callers. There are two reasons for using a pull-style for receiving messages on a channel: first, it is similar to what programmers are used to do when receiving data from a socket, and second, by not having to use callback into user code at this level, channels cannot get blocked by user-code that takes a long time to complete or that even recursively calls a method of the channel.
If a push-style of message reception is desired, other patterns on top of channel can be used (such as PullPushAdapter (2.2.6) or Dispatcher (2.2.10)).