5.4. A Basic Channel

To implement a channel, we use an ordered collection of Message entries (similar to the distributed data structure we used in Chapter 3 to implement a distributed array)—one for each message in the channel. Each Message entry contains its position number in the channel. For instance, the fourth message to be added to the channel has a position of four (assuming that the message sequence starts from one). Each channel also has a Tail entry that marks the end of the channel. For example, if there are four messages in the channel, the tail entry contains the value four to represent the end position.

Using the channel is straightforward. To send a message into the channel, a “channel writer” appends a new Message entry to the ...

Get JavaSpaces™ Principles, Patterns, and Practice now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.