ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

First Contact: Is There Life in JavaSpace?
Pages: 1, 2, 3

Activating JavaSpaces

JavaSpaces is a JINI service that supports distributed persistence and the design of distributed algorithms. It uses RMI and object serialization from the Java programming language to provide these services.

The process to access the JavaSpaces service is like accessing any other JINI service. You perform the Lookup process with an LUS that has the JavaSpaces service registered. The net.jini.space package provides the service interface and related classes for the Sun/Jini supplied implementation. There are basically four operations that can be performed in space:

  • read -- reads an Entry object from JavaSpaces
  • write -- writes an Entry object to JavaSpaces
  • take -- deletes or removes an Entry object from JavaSpaces
  • notify -- request to be notification when JavaSpaces changes (an entry is written or removed from JavaSpaces)

The net.jini.core.entry.Entry interface is used to identify entries that are capable of being used in JavaSpaces. You will implement this interface or extend the AbstractEntry class to create objects for use.

JavaSpaces requires the use of a transaction service like the Jini supplied mahalo service. This enables support for transactional properties such as isolation through a two-phase commit protocol. There are two types of JavaSpaces instances that can be defined, transient and persistent. Transient space does not provide persistence across system restarts, while persistent space does.

The following script starts the mahalo transaction service.

java -jar -Djava.security.policy=%JINI_HOME%\example\lookup\policy.all -Dcom.sun.jini.mahalo.managerName=TransactionManager %JINI_HOME%\lib\mahalo.jar http://%IP_ADDRESS%:8080/mahalo-dl.jar %JINI_HOME%\example\txn\policy.all %JINI_HOME%\tmp\txn_log public\

Reading and taking entries from JavaSpaces requires a template to be constructed that matches the entry requested.

In our example Elliot and Ian were exchanging information by writing entries to and from an instance of JavaSpaces. The JavaOffice Space service provided a proxy to the JavaSpaces service that was running in London at Ian's office. When Elliot accessed the service, a reference to the JOS JavaSpaces instance was also made available. The space channel that was constructed allowed Ian and Elliot to view and exchange information using the JavaSpace API.

The following script starts the outrigger persistent service.

java -jar -Djava.security.policy=%JINI_HOME%\policy.all -Dcom.sun.jini.outrigger.spaceName=JavaSpaces %JINI_HOME%\lib\outrigger.jar http://%IP_ADDRESS%:8080/outrigger-dl.jar %JINI_HOME%\policy.all %JINI_HOME%\tmp\js_log public

Our Jini environment now contains.

  • An HTTP server running with a defined codebase for downloading files.
  • An RMI daemon running to activate services
  • An LUS (reggie) running to register and lookup services
  • The transaction service mahalo
  • The persistent service outrigger

One thing to note is that once your environment is in place, subsequent start-ups only require the first two services. An HTTP server for downloading code and the RMI daemon for activating services. Since reggie, mahalo, and outrigger are all activating services they will be started by RMI automatically when requested.

The Scout

The following class Scout can be used to display the services available in your JINI environment. It displays the services that match a specific template. You should be able to customize this class for finding specific services and displaying them on a console or visual editor.

View class here.

View Scout display of active services here.

JWorkPlace as an Example JavaOffice Space

JWorkPlace is a project I am promoting that presents a foundation for learning, sharing, and collaborating using Jini and JavaSpaces technologies. Like the fictional JavaOffice Space, JWorkPlace essentially will define the concept of a virtual development center, allowing development members to enter and leave the space, while providing multiple levels of community participation.

The current space can be segmented into components.

JWorkPlace Development and Resource Center
JWorkPlace Development and Resource Center

As we continue with this series we will build the necessary components for collaboration using JINI and JavaSpaces. Now that we have made "first contact" the opportunities that exist are only limited by our imagination. Stay tuned.

Robert Flenner is an active author, software developer, and independent contractor who is actively involved with emerging B2B technologies.

Return to ONJava.com.