if (mailbox == null) {
// First time we've run -- find all the services and ask for
// conversion events to be send to us
// Find the event mailbox service and register with it
ServiceFinder sfem = new ServiceFinder(EventMailbox.class);
EventMailbox em = (EventMailbox) sfem.getObject();
mailbox = em.register(Long.MAX_VALUE);
// Find the lease renewal service, and use it to renew the
// mailbox lease. We intend to run every day, but set the
// renewal time to 3 days if we don't run over a weekend.
ServiceFinder sflrs = new ServiceFinder(LeaseRenewalService.class);
LeaseRenewalService lrs = (LeaseRenewalService) sflrs.getObject();
renewalSet = lrs.createLeaseRenewalSet(TimeConstants.DAYS * 3);
// Find the convert service and ask that it send events to the
// mailbox forever (when we cancel the lease renewal set, this
// lease will get cancelled).
ServiceFinder sf = new ServiceFinder(ConvertService.class);
ConvertService cs = (ConvertService) sf.getObject();
EventRegistration er = cs.trackConversions(Long.MAX_VALUE,
mailbox.getListener(), null);
renewalSet.renewFor(er.getLease(), Long.MAX_VALUE);
}