ServerDeliverypublic class ServerDelivery extends Object
Fields Summary |
---|
private Remote | source | private ServerLandlord | lord | private Vector | leases | private long | seqnum |
Constructors Summary |
---|
public ServerDelivery(Remote source, ServerLandlord ll)
this.source = source;
lord = ll;
leases = new Vector();
|
Methods Summary |
---|
public synchronized EventRegistration | addListener(RemoteEventListener l, long duration, java.rmi.MarshalledObject key)
SessionData sd = new SessionData();
sd.listener = l;
sd.key = key;
Lease lease = lord.newLease(sd, duration);
leases.addElement(lease);
return new EventRegistration(ConvertEvent.ID, source, lease, seqnum);
| public synchronized void | deliver(int value)
long seq = seqnum++; // Deliver request number
if (leases.isEmpty())
return;
lord.expireLeases(); // Clean up the leases first
Vector expiredLeases = new Vector();
// Deliver to each client. Save all the expired leases
// and remove those leases after the loop
for (Enumeration e = leases.elements(); e.hasMoreElements();) {
Lease l = (Lease) e.nextElement();
SessionData obj = (SessionData) lord.getSessionData(l);
if (obj == null) {
expiredLeases.addElement(l);
} else {
try {
deliverEvent(obj, seq, value);
} catch (RemoteException rex) {
// Can't really do anything here --
// cancelling the lease is not allowed;
// we'll have to try again next time
} catch (UnknownEventException uee) {
// The client told us it didn't want these events
// anymore, cancel it's registration
expiredLeases.addElement(l);
}
}
}
// Get rid of all the failed clients
for (Enumeration e = expiredLeases.elements(); e.hasMoreElements();) {
Lease l = (Lease) e.nextElement();
leases.remove(l);
}
| private void | deliverEvent(ServerDelivery$SessionData data, long seq, int value)
ConvertEvent event = new ConvertEvent(source, value, seq, data.key);
data.listener.notify(event);
|
|