ENTERPRISE JAVAHow to Use Jini Distributed Leasing
- By Kathy Kozel
- May 13, 2000
ENTERPRISE JAVA
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();
client.startUp();
}
// 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)
Naming.lookup("rmi://127.0.0.1:1099/Kennel");
System.out.println("got the kennel from registry");
confirm = kennel.bookRoom(myDog, 500000);
System.out.println("We got a lease for " +
confirm.getLease().getExpiration());
} catch(Exception e) {
e.printStackTrace();
}
} // close go
} // close client