com.kedwards.swt.landlord
Class BasicLandlord

com.kedwards.swt.landlord.BasicLandlord

public class BasicLandlord

BasicLandlord.java

This class provides a simple landlord implementation designed to work with Sun's framework.

See http://www.kedwards.com/jini

No warranty expressed or implied; use at your own risk; for educational purposes only.

Author:
Keith Edwards

Constructor Summary
BasicLandlord()
          Create a landlord with a default duration policy and no manager.
BasicLandlord(com.sun.jini.lease.landlord.LeaseManager manager)
          Create a landlord with a default duration policy and the specified manager.
BasicLandlord(com.sun.jini.lease.landlord.LeasePolicy policy)
          Create a landlord with the specified policy.
BasicLandlord(java.lang.String name)
          Create a landlord with a default duration policy and no manager.
 
Method Summary
 void cancel(java.lang.Object cookie)
          Cancel the lease represented by 'cookie'
 java.util.Map cancelAll(java.lang.Object[] cookies)
          Cancel a set of leases
 com.sun.jini.lease.landlord.LeaseDurationPolicy createPolicy(long maximumTime, long defaultTime)
          A little utility factory method to create new lease policies.
 boolean ensureCurrent(com.sun.jini.lease.landlord.LeasedResource resource)
          Ensure that a currently-managed resource is current.
 java.lang.String getName()
          Get the name used to identify this landlord.
 com.sun.jini.lease.landlord.LeasedResource getResource(java.lang.Object cookie)
          Returns the resource for the provided cookie, or null.
 com.sun.jini.lease.landlord.LeasedResource[] getResources()
          Return all of the resources currently under management by this landlord.
 net.jini.core.lease.Lease manageResource(com.sun.jini.lease.landlord.LeasedResource resource, com.sun.jini.lease.landlord.LeasePolicy policy, long requestedDuration)
          Pass in a new resource to be managed.
 net.jini.core.lease.Lease manageResource(com.sun.jini.lease.landlord.LeasedResource resource, long requestedDuration)
          Pass in a new resource to be managed.
 long renew(java.lang.Object cookie, long extension)
          Renew the lease specified by 'cookie'
 com.sun.jini.lease.landlord.Landlord.RenewResults renewAll(java.lang.Object[] cookies, long[] extensions)
          Renew a set of leases.
 void setName(java.lang.String name)
          Set the name used to identify this landlord.
 void terminate()
          Shut down the landlord, killing the reaper thread and terminating all the leased resources.
 

Constructor Detail

BasicLandlord

public BasicLandlord()
              throws java.rmi.RemoteException
Create a landlord with a default duration policy and no manager.

BasicLandlord

public BasicLandlord(java.lang.String name)
              throws java.rmi.RemoteException
Create a landlord with a default duration policy and no manager.

BasicLandlord

public BasicLandlord(com.sun.jini.lease.landlord.LeaseManager manager)
              throws java.rmi.RemoteException
Create a landlord with a default duration policy and the specified manager.

BasicLandlord

public BasicLandlord(com.sun.jini.lease.landlord.LeasePolicy policy)
              throws java.rmi.RemoteException
Create a landlord with the specified policy. If the policy was created with a manager, that manager will be used for notifications.
Method Detail

createPolicy

public com.sun.jini.lease.landlord.LeaseDurationPolicy createPolicy(long maximumTime,
                                                                    long defaultTime)
A little utility factory method to create new lease policies. This guy returns LeaseDurationPolicies based on the params. (It's a little easier than creating them by hand and passing in all the various args.)
Parameters:
maximum - The maximum time, in milliseconds, of the leases that will be granted by this policy.
default - The default time, in milliseconds, of the leases that will be granted by this policy.

getName

public java.lang.String getName()
Get the name used to identify this landlord.

setName

public void setName(java.lang.String name)
Set the name used to identify this landlord.

manageResource

public net.jini.core.lease.Lease manageResource(com.sun.jini.lease.landlord.LeasedResource resource,
                                                long requestedDuration)
                                         throws net.jini.core.lease.LeaseDeniedException
Pass in a new resource to be managed. This call will process the requested duration into a real expiration time, generate and return a lease for the resource, and add the resource to the set of managed resources. Note that this variant of the call uses the default polilcy for the lease.

manageResource

public net.jini.core.lease.Lease manageResource(com.sun.jini.lease.landlord.LeasedResource resource,
                                                com.sun.jini.lease.landlord.LeasePolicy policy,
                                                long requestedDuration)
                                         throws net.jini.core.lease.LeaseDeniedException
Pass in a new resource to be managed. This call will process the requested duration into a real expiration time, generate and return a lease for the resource, and add the resource to the set of managed resources. Note that this variant of the call uses the passed policy, if it's not null, or the default policy if it is.

getResources

public com.sun.jini.lease.landlord.LeasedResource[] getResources()
Return all of the resources currently under management by this landlord.

getResource

public com.sun.jini.lease.landlord.LeasedResource getResource(java.lang.Object cookie)
Returns the resource for the provided cookie, or null.

cancel

public void cancel(java.lang.Object cookie)
            throws net.jini.core.lease.UnknownLeaseException
Cancel the lease represented by 'cookie'

renew

public long renew(java.lang.Object cookie,
                  long extension)
           throws net.jini.core.lease.UnknownLeaseException,
                  net.jini.core.lease.LeaseDeniedException
Renew the lease specified by 'cookie'

cancelAll

public java.util.Map cancelAll(java.lang.Object[] cookies)
Cancel a set of leases

renewAll

public com.sun.jini.lease.landlord.Landlord.RenewResults renewAll(java.lang.Object[] cookies,
                                                                  long[] extensions)
Renew a set of leases.

ensureCurrent

public boolean ensureCurrent(com.sun.jini.lease.landlord.LeasedResource resource)
Ensure that a currently-managed resource is current.

terminate

public void terminate()
Shut down the landlord, killing the reaper thread and terminating all the leased resources.