FileDocCategorySizeDatePackage
ServerLandlord.javaAPI DocExample5021Thu Mar 16 11:52:48 GMT 2000None

ServerLandlord

public class ServerLandlord extends UnicastRemoteObject implements Landlord

Fields Summary
protected Hashtable
resources
protected long
MAXLEASETIME
protected LeasePolicy
policy
Constructors Summary
public ServerLandlord()


        
        policy = new LeaseDurationPolicy(MAXLEASETIME, MAXLEASETIME, this, new Expirer(this), null);
    
Methods Summary
public voidcancel(java.lang.Object cookie)

        synchronized (this) {
            ServerResource sr = (ServerResource)resources.get(cookie);
            if (sr == null)
                throw new UnknownLeaseException();

            resources.remove(cookie);
	    if (resources.size() == 0)
		notifyAll();
        }

    
public voidcancelAll(java.lang.Object[] cookie)

        Map map = null;
        for (int i = 0; i < cookie.length; i++) {
            try {
                cancel(cookie[i]);
            } catch (LeaseException ex) {
                if (map == null)
                    map = new HashMap();
                map.put(cookie[i], ex);
            }
        }
	if (map != null)
	    throw new LeaseMapException("Can't cancel all leases", map);
    
public java.lang.ObjectgetSessionData(Lease lease)

        Object sessiondata = null;
        synchronized (this) {
            for (Enumeration e = resources.elements();e.hasMoreElements();) {
                ServerResource sr = (ServerResource) e.nextElement();
                if (lease.equals(sr.lease)) {
                    sessiondata = sr.sessionData;
                    break;
                }
            }
        }
        return sessiondata;
    
public LeasenewLease(java.lang.Object sessionData, long duration)

        ServerResource sr = new ServerResource(sessionData);

        try {
            sr.lease = policy.leaseFor(sr, duration);
            synchronized(this) {
                resources.put(sr.getCookie(), sr);
            }
            return sr.lease;
        } catch (LeaseDeniedException e) {};
        return null;
    
public longrenew(java.lang.Object cookie, long duration)

        synchronized (this) {
            ServerResource sr = (ServerResource)resources.get(cookie);
            if (sr == null)
                throw new UnknownLeaseException();

            return policy.renew(sr, duration);
        }
    
public Landlord.RenewResultsrenewAll(java.lang.Object[] cookie, long[] duration)

        long[] granted = new long[cookie.length];
        Vector denied = new Vector();

        for (int i = 0; i < cookie.length; i++) {
            try {
                granted[i] = renew(cookie[i], duration[i]);
            } catch (LeaseException lex) {
                granted[i] = -1;
                denied.add(lex);
            }
        }
        return new Landlord.RenewResults(granted,
                denied.isEmpty() ? null : (Exception[]) denied.toArray());
    
public synchronized voidwaitForEmpty()

	while (resources.size() != 0) {
	    try {
		wait();
	    } catch (InterruptedException ie) {}
	}