2.

previous chapter table of contents next chapter
  

Server Structure

A server application will internally look like this:

PSEUDOCODE

WHERE DISCUSSED

Prepare for discovery

Discovering a Lookup Service"

"Discover a lookup service"

Discovering a Lookup Service"

Create information about a service

Entry Objects"

Export a service

Service Registration"

Renew leasing periodically

Chapter 7, "Leasing"

Again, the following code has been simplified by omitting various checks on exceptions and other conditions. It exports an implementation of a file classifier service as a FileClassifierImpl object. 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 FileClassifierServer implements DiscoveryListener {     protected LeaseRenewalManager leaseManager = new LeaseRenewalManager();   public static void main(String argv[]) {     new FileClassifierServer();     // keep server running (almost) forever to     // - allow time for locator discovery and     // - keep re-registering the lease     Thread.currentThread().sleep(Lease.FOREVER);   }     public FileClassifierServer() {     LookupDiscovery discover = null;     // Prepare for discovery - empty here     // Discover a lookup service     // This uses the asynchronous multicast protocol,     // which calls back into the discovered() method     discover = new LookupDiscovery(LookupDiscovery.ALL_GROUPS);     discover.addDiscoveryListener(this);   }   public void discovered(DiscoveryEvent evt) {     ServiceRegistrar registrar = evt.getRegistrars()[0];     // At this point we have discovered a lookup service     // Create information about a service     ServiceItem item = new ServiceItem(null,                                        new FileClassifierImpl(),                                        null);     // Export a service     ServiceRegistration reg = registrar.register(item, Lease.FOREVER);     // Renew leasing     leaseManager.renewUntil(reg.getLease(), Lease.FOREVER, this);   } } // FileClassifierServer 
  


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

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