ENTERPRISE JAVAHow to Use Jini Distributed Leasing

How to Use Jini Distributed Leasing

Kathy Kozel

Listing 3. Simple client that just obtains a lease.

import java.rmi.*;

// Client version 1, simply gets a lease but doesn't do anything to
// renew it! Dog is trained... but client never takes it back home 
// again.

public class DogClient1 {

      private Confirmation confirm;
      private Trainable myDog = new Dog();
      private Kennel kennel;

     // launch client application
     public static void main (String args[]) {
           DogClient1 client = new DogClient1();

     // gets a reference to a remote Kennel and attempts to book a room for a Trainable

     public void startUp() {

       try {
            // Use RMI lookup to get a reference to a Kennel
            // (for a "real" Jini service, we'd be using Jini lookup 
           // instead)

            kennel = (Kennel)
            System.out.println("got the kennel from registry");
            confirm = kennel.bookRoom(myDog, 500000);
            System.out.println("We got a lease for " +

           } catch(Exception e) {
      } // close go

  } // close client