5.1. Basic Message Passing
It is easy to perform message passing in space-based programming by passing an entry from one process to another. To do so, we first need a message to pass. Let's begin by defining a Message entry with two fields: one that identifies the receiver, and another that holds the content of the message:
public class Message implements Entry { public String receiver; public String content; public Message() { } }
To send a message, a process creates a Message entry and writes it into a space:
Message msg = new Message(); msg.receiver = "duke@sun.com"; msg.content = "Hello"; space.write(msg, null, Lease.FOREVER);
You'll note that we've used the string “duke@sun.com” as a way to identify the receiver, but any agreed-upon ...
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.