Interface LookupCache
LookupCache interface defines the methods provided by the object created and
returned by the ServiceDiscoveryManager
when a client-like entity invokes the createLookupCache method. It is within the object returned by that method that discovered
service references, matching criteria defined by the entity, are stored. Through this interface,
the entity may retrieve one or more of the stored service references, register and un-register
with the cache's event mechanism, discard previously discovered service references to make them
eligible for re-discovery, and terminate all of the cache's processing.- Author:
- Sun Microsystems, Inc.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(ServiceDiscoveryListener listener) Registers aServiceDiscoveryListenerobject with the event mechanism of aLookupCache.voidDeletes a service reference from the cache and causes a notification to be sent to all registered listeners indicating that the service has been discarded.booleanReturnstrueif the lookup cache has been initialized.lookup(ServiceItemFilter filter) Finds aServiceItemobject that satisfies the givenfilterparameter.lookup(ServiceItemFilter filter, int maxMatches) Finds an array of instances ofServiceItemthat each satisfy the givenfilterparameter.voidremoveListener(ServiceDiscoveryListener listener) Removes aServiceDiscoveryListenerobject from the set of listeners currently registered with theLookupCache.voidPerforms cleanup duties related to the termination of the processing being performed by a particular instance ofLookupCache.
-
Method Details
-
lookup
Finds aServiceItemobject that satisfies the givenfilterparameter.The service item returned must have been previously discovered to be both registered with one or more of the lookup services in the managed set, and to match criteria defined by the entity.
The semantics of the
filterargument are identical to those of thefilterargument specified for a number of the methods defined in the interface of theServiceDiscoveryManagerutility class. This argument is intended to allow an entity to separate its filtering into two steps: an initial filter applied during the discovery phase, and a finer resolution filter applied upon retrieval from the cache. As with the methods of theServiceDiscoveryManager, ifnullis the value of this argument, then no additional filtering will be performed.- Parameters:
filter- used for matchingServiceItems. A null value means no additional filtering should be applied.- Returns:
- ServiceItem that satisfies the filter, and that was previously discovered to be
registered with one or more lookup services in the managed set. A
nullvalue will be returned if noServiceItemis found that matches the criteria or if the cache is empty.
-
lookup
Finds an array of instances ofServiceItemthat each satisfy the givenfilterparameter.Each service item contained in the returned array must have been previously discovered to be both registered with one or more of the lookup services in the managed set, and to match criteria defined by the entity.
The semantics of the
filterargument are identical to those of thefilterargument specified for a number of the methods defined in the interface of theServiceDiscoveryManagerutility class. This argument is intended to allow an entity to separate its filtering into two steps: an initial filter applied during the discovery phase, and a finer resolution filter applied upon retrieval from the cache. As with the methods of theServiceDiscoveryManager, ifnullis the value of this argument, then no additional filtering will be performed.- Parameters:
filter- used for matchingServiceItems. A null value means no additional filtering should be applied.maxMatches- maximum number of matches to return. If this value is set toInteger.MAX_VALUEthen all elements in the cache that match the criteria will be returned.- Returns:
- ServiceItem[] array whose elements each satisfy the filter, and that were previously
discovered to be registered with one or more lookup services in the managed set. An empty
array will be returned if no
ServiceItemis found that matches the criteria or if the cache is empty. - Throws:
IllegalArgumentException- ifmaxMatchesis a negative number.
-
addListener
Registers aServiceDiscoveryListenerobject with the event mechanism of aLookupCache. The listener object will receive aServiceDiscoveryEventupon the discovery, removal, or modification of one of the cache's services. Once a listener is registered, it will be notified of all service references discovered to date, and will be notified as new services are discovered and existing services are modified or discarded. If the parameter value duplicates (usingequals) another element in the set of listeners, no action is taken. If the parameter value isnull, aNullPointerExceptionis thrown.- Parameters:
listener- theServiceDiscoveryListenerobject to register.- Throws:
NullPointerException- this exception occurs whennullis input to thelistenerparameter.- See Also:
-
removeListener
Removes aServiceDiscoveryListenerobject from the set of listeners currently registered with theLookupCache. Once all listeners are removed from the cache's set of listeners, the cache will send no moreServiceDiscoveryEventnotifications. If the parameter value isnull, or if the parameter value does not exist in the managed set of listeners, no action is taken.- Parameters:
listener- theServiceDiscoveryListenerobject to remove.- See Also:
-
discard
Deletes a service reference from the cache and causes a notification to be sent to all registered listeners indicating that the service has been discarded.- Parameters:
serviceReference- the service reference to discard.
-
terminate
void terminate()Performs cleanup duties related to the termination of the processing being performed by a particular instance ofLookupCache. For that instance, this method cancels all event leases granted by the lookup services that supplied the contents of the cache, and un-exports all remote listener objects registered with those lookup services. Theterminatemethod is typically called when the entity is no longer interested in the contents of theLookupCache. -
isInitialized
boolean isInitialized()Returnstrueif the lookup cache has been initialized.
-