previous chapter table of contents next chapter

Client Structure

Now that we've looked at how the various pieces interact, we'll take a look at what is going on inside clients and services. Internally a client will look like this:



Prepare for discovery

Discovering a Lookup Service"

Discover a lookup service

Discovering a Lookup Service"

Prepare a template for lookup search

Client Search"

Look up a service

Client Search"

Call the service

A Simple Example"

The "prepare for discovery" step involves setting up a list of service locators that will be looked for. The "discover a lookup service" step is where the unicast or multicast search for lookup services is performed. "Prepare a template for lookup search" involves creating a description of the service so that it can be found. "Look up a service" is when a service locator is queried to see if it has such a service. Once a suitable service has been found, then "call the service" will invoke methods on this service.

The following code has been simplified from the real case by omitting various checks on exceptions and other conditions. It attempts to find a FileClassifier service, and then calls the getMIMEType() method on this service. The full version of the code is given in Chapter 8. I won't give detailed explanations right now ”this is just to show how the preceding schema translates into actual code.

 public class TestUnicastFileClassifier {     public static void main(String argv[]) {     new TestUnicastFileClassifier();   }   public TestUnicastFileClassifier() {     LookupLocator lookup = null;     ServiceRegistrar registrar = null;     FileClassifier classifier = null;         // Prepare for discovery     lookup = new LookupLocator("jini://www.all_about_files.com");       // Discover a lookup service     // This uses the synchronous unicast protocol     registrar = lookup.getRegistrar();       // Prepare a template for lookup search     Class[] classes = new Class[] {FileClassifier.class};     ServiceTemplate template = new ServiceTemplate(null, classes, null);     // Lookup a service     classifier = (FileClassifier) registrar.lookup(template);     // Call the service     MIMEType type;     type = classifier.getMIMEType("file1.txt");     System.out.println("Type is " + type.toString());   } } // TestUnicastFileClassifier 

A Programmer[ap]s Guide to Jini Technology
A Programmer[ap]s Guide to Jini Technology
ISBN: 1893115801
Year: 2000
Pages: 189

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net