JavaSpaces is a powerful Jini service that provides a high-level tool for creating .. In a tutorial style, we cover the mechanics of creating a space-based. Selection from JavaSpaces™ Principles, Patterns, and Practice [Book] access to videos, live online training, learning paths, books, tutorials, and more. If you want more detail, I recommend Jan Newmarch’s Jini Tutorial. A JavaSpace is a Jini service that stores Java objects in memory. This makes it very useful.

Author: Tudal Gardashura
Country: Chile
Language: English (Spanish)
Genre: Environment
Published (Last): 3 April 2006
Pages: 325
PDF File Size: 15.71 Mb
ePub File Size: 10.34 Mb
ISBN: 613-7-32072-661-5
Downloads: 31216
Price: Free* [*Free Regsitration Required]
Uploader: Narg

Jini is a distributed computing technology developed by Sun Microsystems. It is now being continued under the auspices of the Apache River project. This page provides some background information about Jini, a description of one of the most common patterns used in Tuhorial systems, and a simple introductory example.

The network is reliable Latency is zero Bandwidth is infinite The network is secure Topology doesn’t change There is one administrator Transport cost is zero The network is homogeneous Deutsch noted “All prove to javaspacse false in the long run and all cause big trouble and painful learning experiences.

Jini directly addresses each of the fallacies Deutsch described. Jini supports the development and deployment of highly available, highly reliable distributed systems despite the unreliability of the underlying machines, operating systems, and networks. To do so, Jini relies on four core capabilities: Location Independence Components that use services do not need to be configured with explicit knowledge of the location of the service.

Service implementations can be moved without impacting clients. Multiple different implementations can run simultaneously. Automatic Performance Tuning Load balancing and other performance enhancements can be made dynamically by bringing up additional instances of services or moving instances to better hardware.

Clients are not impacted by, or even aware of, these operations. Jini comes with several standard infrastructure components out of the box. To achieve the non-functional requirements NFRs of performance, resiliency, and scalability, multiple instances of these components run simultaneously on different machines.

The standard Jini services are: Lookup Service The lookup service, named reggieis the first among equals of Jini services. All services in a Jini architecture register with the lookup service to make themselves available to other services. All initial access to other services is via the lookup service, after which clients bind directly. Class Server The class server, a simple HTTP daemon, eliminates the coupling between clients and service implementations.

Clients deal with interfaces. If a particular implementation class is required, it is downloaded transparently. Transaction Manager Distributed transactions support is provided by the transaction manager service called mahalo.

JavaSpace Services with a requirement to share information with other services do so through a JavaSpace. The reference implementation of the JavaSpace is named outrigger. The Jini reference implementation includes other services that are not required for this introductory example. A JavaSpace is a Jini service that stores Java objects in memory. This makes it very useful for supporting collaboration among other services, in addition to its uses as a simple shared memory.

This returns a copy and leaves a copy in the JavaSpace.

This returns a copy and removes the object from the JavaSpace. All of these methods take a transaction context as an optional parameter. The JavaSpaces05 specification adds support for batch operations. Those four methods suffice to provide the core features most often required in distributed systems: One feature of Jini worth separate mention is the concept of leasing. All resources in a Jini system are leased, including proxy records in the lookup service, transactions, and, of course, memory in a JavaSpace.


When a lease expires, the resource is recovered and made available to other components. This prevents resource accretion, a common problem in distributed systems. Leases can be renewed explicitly, or implicitly through a lease renewal manager. In the interests of simplicity, the example below uses leases that last “forever. All objects that can be stored in a JavaSpace must implement the Entry interface.

Entry is a simple tag interface that does not add any methods but does extend Serializable. Like JavaBeans, all Entry implementations must provide a public constructor that takes no arguments. Unlike JavaBeans, all of the data members javaspacse an Entry must be public.

This design decision is explained by Ken Arnold in an interview with Bill Venners: So if you examine the contract description for an entry’s get and set methods, you would see it describes a javspaces.

Therefore, we asked ourselves, why should we have get and set methods whose behavior is exactly like this other language construct called a field? Why not just make it a field? If we make it a field, it will have the correct behavior.

Nobody can accidentally screw up their get and set methods. Making it a field eliminates a source of error. Now this sometimes makes people uncomfortable because they’ve been told not to have public fields; that public fields are bad. And often, people interpret those things religiously.

But we’re not a very religious bunch. And the reason for the private data rule doesn’t apply in this particular case. It is a rare exception to the rule. I also tell people not to put public fields in their objects, but exceptions exist. This is an exception to the rule, because it is simpler and safer to just say it is a field.

We sat back and asked: Why is the rule thus? In this case it doesn’t. In production Jini systems, the public data members are a non-issue because of common techniques like the envelope-letter idiom.

The Entry implementation acts as an envelope or wrapper around the “real” payload, which may be any serializable Java object. The only public data members exposed are those required for the template-based matching of the JavaSpaces API.

After simple object caching, the Master-Worker pattern is the most common use of JavaSpaces. This pattern is quite simple: The master-worker pattern is used in a wide variety of problem domains where either a problem is highly parallelizable or there are a set of tasks that can be performed by any of a set of workers.

Patrick May

One particularly nice feature of this pattern is that there is no need for complex scheduling algorithms. The workers take tasks at whatever rate they are able to process them, automatically load balancing the work across available resources. A variant of the master-worker pattern takes advantage of the fact that a JavaSpace holds full Java objects, not just data.


This makes it possible to pass behaviors as well as state between the master and workers. This, in turn, allows the creation of generic workers that can process any task. In this version of the pattern, tasks either expose an execute method or include a strategy to configure the generic worker.

The purpose of this example is to be a walking skeleton of a Jini system. The Jini lookup service The Jini transaction manager A JavaSpace The master, a JavaSpace client that writes tasks and reads results The worker, a JavaSpace client that takes tasks and writes results Functionally, the example is uninteresting — the workers just sleep for random periods of time.

The SleepTask and SleepResult classes are simple Entry implementations, not using the envelope-letter idiom. The SleepMaster class writes a specified number of SleepTask objects to a JavaSpace and then loops until it has retrieved the same number of SleepResult objects. Before SleepMaster can write to a JavaSpace, it needs a reference to one. For simplicity, this example uses my Jini Lookup Utilities to connect to available lookup services and find JavaSpace proxies.

The SleepMaster creates a random ID to uniquely identify the tasks it has created. The tasks themselves are numbered sequentially. This design allows multiple masters to run simultaneously. Shorn of its exception handling, the code to write to the space looks like this: In a production system, the lease specified in the final parameter would not typically be permanent. The code to take results from the space is: In this case I want to retrieve any result associated with the current master, so I only specify the masterID.

JavaSpaces™ Principles, Patterns, and Practice [Book]

JavaSpaces ignores the fields left null. In a production environment, the timeout period specified in the last parameter would be much shorter. The SleepWorker class loops, performing a blocking take for SleepTask objects.

When a task is found, the worker removes it from the space, sleeps for the specified duration, and writes a corresponding SleepResult back to the space. The take and write tutirial are performed in a transaction to ensure that all tasks are processed and a result is returned. SleepWorker uses the same utilities to find transaction manager proxies as well.

The code to take tasks from the space looks very similar to javaspacs SleepMaster for retrieving results: One aspect that is not obvious is that, like all Jini resources, transactions are leased. If a transaction is not committed or javasaces before the lease expires, it is rolled back. Writing the result back mirrors the initial task write, again with the addition of a transactional context: You will need the Jini 2.

Building javaspacss example is straightforward. Deploying the Jini infrastructure is considerably less straightforward than building the example. In fact, deployment configuration is the most difficult and error prone aspect of Jini, the first time you do it. This example includes scripts to start the core Jini components.