com.bigdata.service.jini.lookup
Class ServiceCache

java.lang.Object
  extended by com.bigdata.service.jini.lookup.ServiceCache
All Implemented Interfaces:
net.jini.lookup.ServiceDiscoveryListener

public class ServiceCache
extends Object
implements net.jini.lookup.ServiceDiscoveryListener

A mapping from ServiceID to ServiceItem that is maintained by a suitable ServiceDiscoveryManager manager. In order to use this class, you must register it as the ServiceDiscoveryListener with the ServiceDiscoveryManager.

Note: instances of this class this will track all services discovered by a given ServiceDiscoveryManager, not just those that the client actually uses. This is not a problem since the notification events will be generated anyway and we will be storing at most 1000s of services in this map.

Version:
$Id$
Author:
Bryan Thompson

Field Summary
protected static org.apache.log4j.Logger log
           
 
Constructor Summary
ServiceCache(net.jini.lookup.ServiceDiscoveryListener listener)
           
 
Method Summary
 int getServiceCount()
          Return the #of known services.
 net.jini.core.lookup.ServiceItem getServiceItemByID(net.jini.core.lookup.ServiceID serviceID)
          Resolve the ServiceID for a service to the cached ServiceItem for that service.
 net.jini.core.lookup.ServiceItem[] getServiceItems(int maxCount, net.jini.lookup.ServiceItemFilter filter)
          Return an array of cached service items.
 void serviceAdded(net.jini.lookup.ServiceDiscoveryEvent e)
          Adds the ServiceItem to the internal map to support #getServiceByID()
 void serviceChanged(net.jini.lookup.ServiceDiscoveryEvent e)
          updates the map and delegates to the listener.
 void serviceRemoved(net.jini.lookup.ServiceDiscoveryEvent e)
          This removes the service from the cache.
 
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
Constructor Detail

ServiceCache

public ServiceCache(net.jini.lookup.ServiceDiscoveryListener listener)
Parameters:
listener - An optional delegate listener that will also see the ServiceDiscoveryEvents observed by this class.
Method Detail

serviceAdded

public void serviceAdded(net.jini.lookup.ServiceDiscoveryEvent e)
Adds the ServiceItem to the internal map to support #getServiceByID()

Note: This event is generated by the LookupCache. There is an event for each service as it joins any registrar in the set of registrars this class is listening. The set of distinct joined services is accessible via the LookupCache.

Specified by:
serviceAdded in interface net.jini.lookup.ServiceDiscoveryListener

serviceChanged

public void serviceChanged(net.jini.lookup.ServiceDiscoveryEvent e)
updates the map and delegates to the listener.

Specified by:
serviceChanged in interface net.jini.lookup.ServiceDiscoveryListener

serviceRemoved

public void serviceRemoved(net.jini.lookup.ServiceDiscoveryEvent e)
This removes the service from the cache. However, if the service is an IService and it will still respond to its interface then we DO NOT remove the service from the cache. This makes the cache more robust in the face of transient de-registrations of a service. The most common explanation for those transients is that the host with the service is swapping and has failed to keep up its pings to the jini registrar(s).

Specified by:
serviceRemoved in interface net.jini.lookup.ServiceDiscoveryListener

getServiceItemByID

public net.jini.core.lookup.ServiceItem getServiceItemByID(net.jini.core.lookup.ServiceID serviceID)
Resolve the ServiceID for a service to the cached ServiceItem for that service.

Parameters:
serviceID - The ServiceID for the service.
Returns:
The cache ServiceItem for that service.

getServiceCount

public int getServiceCount()
Return the #of known services.

Returns:
The #of services in the cache.

getServiceItems

public net.jini.core.lookup.ServiceItem[] getServiceItems(int maxCount,
                                                          net.jini.lookup.ServiceItemFilter filter)
Return an array of cached service items.

Parameters:
maxCount - The maximum #of service items to be returned. When zero (0) all known service items will be returned.
filter - An optional filter.
Returns:
An array of ServiceItems.


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