The JavaSpaces Service
The JavaSpaces service enables distributed components to store and/or exchange objects across a network. Many consider it one of Jini technology's most intriguing and useful innovations. The JavaSpaces service is well employed to meet a wide range of distributed computing needs, including distributed shared memory, communications buffering, workflow processing, asynchronous messaging, message switching, and more.
The JavaSpaces service derives its power from the following three key features:
- The simplicity of its interface
- Its ability to hold and pass objects, rather than just data
- The anonymity is gives to clients that interact across it
The synergistic value of this feature combination is uncommon, and it is what makes the JavaSpaces service so extraordinary.
Most developers find the JavaSpaces service interface simple and easy to use. In fact, you can coordinate highly sophisticated interactions through a JavaSpaces service using only four basic methods: read, write, take, and notify. Clients use the write method to put entries into a "space." They use the read method to examine entries in a space, and the take method to remove entries from a space. When performing a read or take operation, a JavaSpaces service returns entries that match a template that the client provides as part of the read or take method call. Using these methods, distributed components can use the JavaSpaces service as an intermediary through which they conduct asynchronous communications, or simply as a distributed shared memory store.
The fourth commonly used method, notify, further enhances the JavaSpaces interaction paradigm. Clients use it to instruct a JavaSpaces service to inform them whenever an entry that matches a template (that the client provided) is written into the space. This method is often used to facilitate the processing of workflows through a JavaSpaces service: whenever a particular kind of entry is placed into a space, a client that can process that entry is notified. That client takes the entry, works on it, and writes a new entry back into the space. The arrival of the new entry in the space triggers notification to a different client, which in turn takes the entry from the space, and the workflow continues.
The JavaSpaces service also supports the Jini technology transaction model, enabling entries to be read, written, or taken under a transaction. While a transaction is being processed, the work performed under the transaction is visible only to transaction participants. Any entries that have been taken under the transaction will still be visible outside of the transaction (but will be read accessible only) for the transaction's duration. Once the transaction commits, the final results are made visible to all JavaSpaces clients. If a transaction is aborted, the JavaSpaces service rolls back all work performed under the transaction.
The JavaSpaces service is additionally powerful because it enables objects, rather than just data, to be exchanged through it. Leveraging this capability, you can use a JavaSpaces service to help distribute and run executable code across a network. One common pattern for doing this employs generic "workers" that are designed specifically to take executable entries from a space and run them. Using this model yields the added benefit of automatic load balancing: rather than having work pushed to them from a centralized load balancer, workers in this model each regulates its own load independently by taking entries at its own pace when it is ready to process them.
Finally, JavaSpaces clients can exchange objects through a space anonymously. Clients that write entries into a space need not know anything about clients that will later read or take those entries from the space, nor vice versa. This makes it quite easy for you to change the participants in an exchange. It even makes it possible to change the number of participants engaged in a distributed interaction, and is commonly leveraged to facilitate dynamic scaling.
Jini Technology's Security Model
Although the subjects of distributed systems security and Jini technology's treatment of it are beyond the scope of this introductory article, it is essential to recognize the importance of security in distributed systems, and to acknowledge the value that the Jini technology security model provides. Distributed systems must have the capability to secure remote communications, so that their privacy and integrity can be assured, and the capability to control programmatic access to resources or other assets. Programs (not just people) within the systems also must be able to authenticate their identities to one another. The Jini technology security model extends the Java platform security model to enable secure distributed interactions between Jini technology clients and services. It enables you to build authentication, authorization, integrity, and confidentiality into interactions between software components that communicate using remote calls over a network. It also provides support for verifying that downloaded codeso critical to Jini technologycan be trusted.