System.setSecurityManager(new RMISecurityManager());
LeaseRenewalManager lrm = new LeaseRenewalManager();
// Find the JavaSpaces service
ServiceFinder sf = new ServiceFinder(JavaSpace.class);
JavaSpace js = (JavaSpace) sf.getObject();
Conversion request = new Conversion(5, true);
Conversion result = (Conversion) js.read(request, null, JavaSpace.NO_WAIT);
if (result == null) {
// There was no cached result. Make a new request and retrieve
// that answer
request.done = new Boolean(false);
Lease l = js.write(request, null, Lease.FOREVER);
lrm.renewUntil(l, Lease.FOREVER, null);
request.done = new Boolean(true);
result = (Conversion) js.read(request, null, Long.MAX_VALUE);
lrm.cancel(l);
lrm.remove(l);
}
// else just use the cached value
System.out.println(result.result);
System.exit(0);