The Artima Developer Community
Sponsored Link

Make Room for JavaSpaces, Part V
Make Your Compute Server Robust and Scalable
by Susan Hupfer
First Published in JavaWorld, June 2000

<<  Page 5 of 8  >>

Advertisement

Gaining Access to Multiple Spaces

Both master and worker processes use Jini to find the set of JavaSpace services that are currently available. The processes will each make a call that looks like this:



ServiceMatches spaces = SpaceAccessor.getSpaces();

SpaceAccessor is a utility class that Eric Freeman and I created (which we've used in previous columns) that lets you gain access to spaces. We've added a new static getSpaces method to SpaceAccessor to find all currently available spaces. Without going into all the details of the getSpaces method, here is a peek at how it locates and returns JavaSpace services:



public static ServiceMatches getSpaces() {
    . . .
    Locator locator = new com.sun.jini.outrigger.DiscoveryLocator();
    ServiceRegistrar lookupService = (ServiceRegistrar)locator.locate();
    Class[] types = { JavaSpace.class };
    ServiceTemplate template = new ServiceTemplate(null, types, null);
    ServiceMatches matches = lookupService.lookup(template, 50);
    return matches;
}

If you're unfamiliar with the mechanics and terminology of Jini lookup and discovery, you may want to make a detour to the Jini resources listed in Resources to get acquainted with them. In short, the preceding code first makes use of the DiscoveryLocator class's locate method to locate a Jini lookup service. Then it creates a ServiceTemplate, specifying that the template should match services of type JavaSpace. Next, the method passes the service template to the lookup service, which searches all of its registered services for matches and returns up to 50 of them (as was specified in the second argument to the lookup call). Finally, the getSpaces method returns the matches in the form of ServiceMatches, an object that will contain an array of matching ServiceItem objects, as well as a count of them. From each ServiceItem, you can retrieve the actual JavaSpace service and its service ID.

<<  Page 5 of 8  >>


Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2017 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us