JavaSpaces is a service specification from Sun Microsystems that provides a simple yet powerful infrastructure for building distributed applications. The JavaSpaces specification defines a reliable distributed repository for objects, along with support for distributed transactions, events and leasing. In the JavaSpaces programming model, applications are viewed as a group of processes, cooperating via the flow of objects into and out of spaces.
The JavaSpaces API provides software developers with a simple and effective tool for solving coordination problems in distributed systems, especially in domains like parallel processing and distributed persistence. The developer designs the solution as a flow of objects instead of a traditional request/reply message-based scenario.
Inspired by David Gelernter's Tuple-Spaces
JavaSpaces is based on the concept of Tuple-Spaces, first described in 1982 in the Linda programming language and system, originally propounded by Dr. David Gelernter at Yale University. The public-domain Linda system is a coordination language that expresses parallel processing algorithms without reference to any specific computer or network architecture. The Linda system also provides inter-process coordination via virtual shared memories, or tuple-spaces, that can be accessed associatively.
The tuple-space model is especially useful for concurrent algorithms. Although JavaSpaces technology is strongly influenced by the Linda system, it differs from it in several ways. For example, Java contains richer typing, object orientation, subtype matching, and transactional support spanning multiple spaces, leasing, and events.
The JavaSpaces API
The JavaSpaces API consists of 4 main method types:
- write() – writes an entry to a space.
- read() – reads an entry from a space.
- take() – reads an entry and deletes it from a space.
- notify() – registers interest in entries arriving at a space.
In addition, the API enables JavaSpaces' clients (applications) to provide optimization hints to space implementation (the snapshot method).
This minimal API set reduces the learning curve, making it easier to adopt JavaSpaces. The API is also natural to Jini developers, since it is built on top of Jini specifications (entries, leases, service, etc.). Jini itself is built on Java and RMI, so there is no need to understand complex distributed Java technologies, like EJB or CORBA.
JavaSpaces enables full use of transactions, leveraging the default semantics of the Jini Distributed Transactions model. Developers can build transactional, secure distributed applications using JavaSpaces as a coordination mechanism. Since Jini transactions can span more than one Jini Service, and a JavaSpace instance is a Jini Service, a transaction may span more than one space.
The JavaSpaces read and take operations can block for a user-defined period of time, in case no matching Entry is found in the space. This allows application instances to wait for data to be written by other instances. Defining a limited block time prevents the application from being blocked indefinitely in case the data does not arrive or the space is in deadlock.
JavaSpaces also makes extensive use of Jini leases, as it mandates leasing of entries in the space (they expire at a certain time unless renewed by a client). This eliminates out-of-date entries and removes the need for manual cleanup administration work.
JavaSpaces notifications are a great tool for developers who wish to build event-driven, distributed applications. The notifications make use of Jini Remote Events, thus enabling a large number of event-handling design patterns, like the famous Jini MailBox Service.
- About Entries — An Entry is a typed set of objects, each of which may be tested for exact match with a template.
- About Jini — Jini is an open architecture that allows the implementation of network services - One such service is JavaSpaces.
- About Space Operations — A description of Entries, templates, the four primary kinds of operations – write, read, take, and notify, and the UpdateModifiers.UPDATE_OR_WRITE modifier.
- Batch Operations — An extension of the JavaSpaces API, enabling operations with multiple objects in one call.
- Compute Server - Master-Worker Pattern — Demonstrates how the master-worker is used to implement a parallel computing engine that calculates whether or not a given number is prime.
- Continuous Query — How to continuously query the space with advanced matching, including boolean operators and inequalities.
- Custom Query Pattern — The purpose of the custom query pattern is to extend the existing query capabilities by enabling users to write code and execute it as part of the query path.
- ExternalEntry — A wrapper that allows any Java class to be written to the space, even if it does not comply with JavaSpaces requirements.
- IGSEntry — Each instance of this class contains a reference to the Entry value plus any other necessary information about the Entry; including its class name, field types, and field values.
- Externalizable Support — Using Externalizable to boost remote space performance with JavaSpaces operations.
- FIFO Support — How to get objects in the same order in which they were written to the space.
- Hello World Example — The Hello World example provides a short and simple illustration of how to use the space API.
- Inheritance Support — GigaSpaces provides implicit access to the inheritence capabilities in the JavaSpaces specification.
- JavaSpaces Iterator — Used to read objects matching multiple templates in one call.
- JavaSpaces Notifications — Registering to receive notifications when objects are added or modified in the space – unicast, multicast and tokenized notifications.
- JavaSpaces Multicast Notifications — IP supports multicasting, where a source device can send to a group of devices. With Multicast, traffic is sent to a single address, but is processed by multiple hosts.
- JavaSpaces Tokenized Notifications — The NotifyDelegator is a convenient and efficient mechanism for registering notifications. These notifications are delivered as remote events for matching Entries.
- JavaSpaces POJO — GigaSpaces JavaSpaces API Plain Old Java Object support - the POJO.
- JavaSpaces Transaction Support — How to use distributed transactions (with Jini Transaction Manager), or local transactions.
- Jini Transaction Manager — The Jini Distributed Transactions provide a two-phase commit protocol.
- Local Transaction Manager — The transactional operation enables distributed transactions - i.e. performing a series of operations on several distributed transactional resources in a single logical transaction.
- XA Transaction Manager — The XA specification and its Java version (JTA) introduce a standard way to control and manage distributed transactions among different participants.
- JavaSpaces UID Support — How to access space objects using their unique identifiers (UID).
- Managing Resources Lease — The LeaseRenewalManager provides systematic renewal and overall management of a set of leases associated with one or more remote entities on behalf of a local entity.
- Moving From Outrigger to GigaSpaces — How to migrate from Outrigger with no re-compilation or re-deployment of code to clients.
- Partial Update — Updating only some of the fields of an object in the space.
- POJO Class and Field Level Annotations — POJO class and field level decorations using annotations and XML configuration files.
- POJO Class and Field Level Annotations - 5.1 — POJO class and field level decorations using annotations and XML configuration files.
- Querying the Space — An extension to the JavaSpaces API which allows object matching by SQL syntax or regular expression.
- Space Administration API — Allows applications to start and stop a space; get status, statistics, and cluster mode; and shutdown a container.
- Space Locking and Blocking — Using optimistic and pessimistic locking to preserve the integrity of changes in multi-user scenarios.
- Exclusive Read Lock — To allow a user to block other users from reading an object, a read using exclusive read lock mode with a transaction should be performed.
- Optimistic Locking — With optimistic locking, you write your program under the assumption that an update operation has a chance of failing, if your updated object has been changed by someone else since you read it.
- Pessimistic Locking — In the pessimistic locking approach, your program must explicitly obtain a lock using transaction on one or more objects before making any changes.
- Typical JavaSpaces Workflow — How an application allocates a space and then uses the space to share information with another application.