FileDocCategorySizeDatePackage
ServerDelivery.javaAPI DocExample4323Thu Mar 16 11:52:18 GMT 2000None

ServerDelivery

public 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 EventRegistrationaddListener(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 voiddeliver(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 voiddeliverEvent(ServerDelivery$SessionData data, long seq, int value)

        ConvertEvent event = new ConvertEvent(source, value, seq, data.key);
        data.listener.notify(event);