Internally a client will look as shown in Table 1-1.
Pseudocode | Where Discussed |
---|---|
prepare for discovery | Chapter 4, "Discovering a Lookup Service" |
discover a lookup service | Chapter 4, "Discovering a Lookup Service" |
prepare a template for lookup search | Chapter 5, "Entry Objects" and "Client Search" |
lookup a service | Chapter 7, "Client Search" |
call the service |
The following code is a simplified version of a real case, with various checks on exceptions and other conditions omitted. It attempts to find a FileClassifier service, and then calls the method getMIMEType() on this service. The full version of the code is given in a later chapter. I don't provide detailed code explanations right now, as this example is just intended to show how the preceding schema translates into actual code.
package nonworking; 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