com.bigdata.service.jini.lookup
Class AbstractCachingServiceClient<S extends Remote>

java.lang.Object
  extended by com.bigdata.service.jini.lookup.AbstractCachingServiceClient<S>
Type Parameters:
S - A class or interface implemented by all services whose proxies will be discovered and cached by this class.
Direct Known Subclasses:
BigdataCachingServiceClient

public abstract class AbstractCachingServiceClient<S extends Remote>
extends Object

Abstract base class for a jini client which uses a LookupCache to reduce round trips to the discovered ServiceRegistrars for a specific class of services.

Version:
$Id$
Author:
Bryan Thompson

Field Summary
protected  long cacheMissTimeout
          Timeout for remote lookup on cache miss (milliseconds).
protected  net.jini.lookup.ServiceItemFilter filter
          The filter provided to the ctor.
protected static org.apache.log4j.Logger log
           
protected  net.jini.lookup.LookupCache lookupCache
          A LookupCache that will be populated with all services that match a filter.
protected  ServiceCache serviceCache
          Provides direct cached lookup of discovered services matching both the template and the optional filter by their ServiceID.
protected  net.jini.core.lookup.ServiceTemplate template
          The template provided to the ctor.
 
Constructor Summary
AbstractCachingServiceClient(net.jini.lookup.ServiceDiscoveryManager serviceDiscoveryManager, net.jini.lookup.ServiceDiscoveryListener serviceDiscoveryListener, Class serviceIface, net.jini.core.lookup.ServiceTemplate template, net.jini.lookup.ServiceItemFilter filter, long cacheMissTimeout)
          Sets up service discovery for the designed class of services.
 
Method Summary
 void destroyDiscoveredServices(ExecutorService executorService, net.jini.lookup.ServiceItemFilter filter)
          Destroy all services in the cache which match the filter.
protected  boolean destroyService(net.jini.core.lookup.ServiceItem serviceItem)
          Sends RemoteDestroyAdmin.destroy() request to the service.
 net.jini.lookup.LookupCache getLookupCache()
          An object that provides cached lookup of discovered services matching both the template and the optional filter.
 S getService()
          Return an arbitrary service from the cache -or- null if there is no such service in the cache and a remote lookup times out.
 S getService(net.jini.lookup.ServiceItemFilter filter)
          Return the proxy for an arbitrary service from the cache -or- null if there is no such service in the cache and a remote lookup times out.
 ServiceCache getServiceCache()
          An object that provides direct cached lookup of discovered services matching both the template and the optional filter by their ServiceID.
protected  net.jini.lookup.ServiceDiscoveryManager getServiceDiscoveryManager()
           
 net.jini.core.lookup.ServiceItem getServiceItem(net.jini.lookup.ServiceItemFilter filter)
          Return an arbitrary ServiceItem from the cache -or- null if there is no such service in the cache and a remote lookup times out.
 net.jini.core.lookup.ServiceItem getServiceItem(UUID serviceUUID)
          Return the ServiceItem associated with the UUID.
 net.jini.core.lookup.ServiceItem[] getServiceItems(int maxCount, net.jini.lookup.ServiceItemFilter filter)
          Return an array ServiceItems for up to maxCount discovered services which satisify the optional filter.
 UUID[] getServiceUUIDs(int maxCount, net.jini.lookup.ServiceItemFilter filter)
          Return an array UUIDs for up to maxCount discovered services which satisify the optional filter.
 void shutdownDiscoveredServices(ExecutorService executorService, net.jini.lookup.ServiceItemFilter filter, boolean immediateShutdown)
          Shutdown all services in the cache which match the filter.
protected  boolean shutdownService(net.jini.core.lookup.ServiceItem serviceItem, boolean immediateShutdown)
          Sends a shutdown request to the service.
 void terminate()
          Terminates asynchronous processing by the LookupCache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final transient org.apache.log4j.Logger log

lookupCache

protected final net.jini.lookup.LookupCache lookupCache
A LookupCache that will be populated with all services that match a filter. This is used to keep track of all services registered with any ServiceRegistrar to which the client is listening.


template

protected final net.jini.core.lookup.ServiceTemplate template
The template provided to the ctor.


filter

protected final net.jini.lookup.ServiceItemFilter filter
The filter provided to the ctor.


cacheMissTimeout

protected final long cacheMissTimeout
Timeout for remote lookup on cache miss (milliseconds).


serviceCache

protected final ServiceCache serviceCache
Provides direct cached lookup of discovered services matching both the template and the optional filter by their ServiceID.

Constructor Detail

AbstractCachingServiceClient

public AbstractCachingServiceClient(net.jini.lookup.ServiceDiscoveryManager serviceDiscoveryManager,
                                    net.jini.lookup.ServiceDiscoveryListener serviceDiscoveryListener,
                                    Class serviceIface,
                                    net.jini.core.lookup.ServiceTemplate template,
                                    net.jini.lookup.ServiceItemFilter filter,
                                    long cacheMissTimeout)
                             throws RemoteException
Sets up service discovery for the designed class of services.

Parameters:
serviceDiscoveryManager - Used to discovery services matching the template and filter.
serviceDiscoveryListener - Service discovery notices are delivered to this class.
serviceIface - The most interesting interface on the service (this is used for log messages).
template - A template used to restrict the services which are discovered and cached by this class (required).
filter - A filter used to further restrict the services which are discovered and cached by this class (optional).
cacheMissTimeout - The timeout in milliseconds that the client will await the discovery of a service if there is a cache miss.
Throws:
RemoteException - if we could not setup the LookupCache
Method Detail

getServiceDiscoveryManager

protected net.jini.lookup.ServiceDiscoveryManager getServiceDiscoveryManager()

getServiceCache

public final ServiceCache getServiceCache()
An object that provides direct cached lookup of discovered services matching both the template and the optional filter by their ServiceID.


getLookupCache

public final net.jini.lookup.LookupCache getLookupCache()
An object that provides cached lookup of discovered services matching both the template and the optional filter.


terminate

public final void terminate()
Terminates asynchronous processing by the LookupCache.


getService

public final S getService()
Return an arbitrary service from the cache -or- null if there is no such service in the cache and a remote lookup times out.


getService

public final S getService(net.jini.lookup.ServiceItemFilter filter)
Return the proxy for an arbitrary service from the cache -or- null if there is no such service in the cache and a remote lookup times out.

Parameters:
filter - An optional filter. If given it will be applied in addition to the optional filter specified to the ctor.

getServiceItem

public final net.jini.core.lookup.ServiceItem getServiceItem(net.jini.lookup.ServiceItemFilter filter)
Return an arbitrary ServiceItem from the cache -or- null if there is no such service in the cache and a remote lookup times out.

Parameters:
filter - An optional filter. If given it will be applied in addition to the optional filter specified to the ctor.

getServiceItem

public final net.jini.core.lookup.ServiceItem getServiceItem(UUID serviceUUID)
Return the ServiceItem associated with the UUID.

Parameters:
serviceUUID - The service UUID.
Returns:
The service item iff it is found in the cache and null otherwise.

getServiceItems

public net.jini.core.lookup.ServiceItem[] getServiceItems(int maxCount,
                                                          net.jini.lookup.ServiceItemFilter filter)
Return an array ServiceItems for up to maxCount discovered services which satisify the optional filter.

Parameters:
maxCount - The maximum #of data services whose UUID will be returned. When zero (0) the UUID for all known data services will be returned.
filter - An optional filter. If given it will be applied in addition to the optional filter specified to the ctor.
Returns:
An array of ServiceItems for matching discovered services.

getServiceUUIDs

public UUID[] getServiceUUIDs(int maxCount,
                              net.jini.lookup.ServiceItemFilter filter)
Return an array UUIDs for up to maxCount discovered services which satisify the optional filter.

Parameters:
maxCount - The maximum #of data services whose UUID will be returned. When zero (0) the UUID for all known data services will be returned.
filter - An optional filter. If given it will be applied in addition to the optional filter specified to the ctor.
Returns:
An array of service UUIDs for matching discovered services.

destroyDiscoveredServices

public void destroyDiscoveredServices(ExecutorService executorService,
                                      net.jini.lookup.ServiceItemFilter filter)
                               throws InterruptedException
Destroy all services in the cache which match the filter. Errors are logged for any service which could not be sent a RemoteDestroyAdmin.destroy() request.

Parameters:
filter - An optional filter. When null all services in the cache will be destroyed.
Throws:
InterruptedException

shutdownDiscoveredServices

public void shutdownDiscoveredServices(ExecutorService executorService,
                                       net.jini.lookup.ServiceItemFilter filter,
                                       boolean immediateShutdown)
                                throws InterruptedException
Shutdown all services in the cache which match the filter. Errors are logged for any service which could not be sent a RemoteDestroyAdmin.shutdown() or RemoteDestroyAdmin.shutdownNow() request.

Parameters:
filter - An optional filter. When null all services in the cache will be shutdown.
immediateShutdown - if shutdownNow() should be used.
Throws:
InterruptedException

destroyService

protected boolean destroyService(net.jini.core.lookup.ServiceItem serviceItem)
                          throws Exception
Sends RemoteDestroyAdmin.destroy() request to the service. Note that the service may process the request asynchronously.

Parameters:
serviceItem - The service item.
Returns:
true if we were able to send that message to the service.
Throws:
Exception - if anything goes wrong.

shutdownService

protected boolean shutdownService(net.jini.core.lookup.ServiceItem serviceItem,
                                  boolean immediateShutdown)
                           throws Exception
Sends a shutdown request to the service. This will invoke either RemoteDestroyAdmin.shutdown() or RemoteDestroyAdmin.shutdownNow() as indicated by the parameter. Note that the service may process the shutdown request asynchronously.

Parameters:
serviceItem - The service item.
immediateShutdown - When true uses shutdownNow().
Returns:
true if we were able to send the request to the service.
Throws:
Exception - if anything goes wrong.


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.