| Spec Index | A Collection of Jini Technology Helper Utilities and Services Specifications |
| Version 3.0 |
DU - JiniTM Discovery Utilities Specification
DU.1 Introduction
Each discovering entity in a JavaTM virtual machine (JVM)1 on a given host is independently responsible for obtaining references to lookup services. In this specification we first cover a set of discovery management interfaces that define the policies to apply when implementing helper utilities that manage an entity's discovery duties: in particular, the management of multicast (group) discovery and unicast (locator) discovery. After the discovery management interfaces are defined, a set of standard helper utility classes that implement one or more of those interfaces is presented. A utility for performing unicast discovery controlled by constraints is also described. This specification closes with a discussion of a set of lower-level utility classes that can be useful when applying the discovery management policies to build higher-level helper utilities for discovery.
DU.1.1 Dependencies
This specification relies on the following other specifications:
- JavaTM Object Serialization Specification
- JiniTM Discovery and Join Specification
- JiniTM Lookup Service Specification
DU.2 The Discovery Management Interfaces
DU.2.1 Overview
Discovery is one behavior that is common to all entities wishing to interact with a Jini lookup service. Whether an entity is a client, a service, or a service acting as a client, the entity must first discover a lookup service, before the entity can begin interacting with that lookup service.
The interfaces collectively referred to as the discovery management interfaces specify sets of methods that define a mechanism that may be used to manage various aspects of the discovery duties of entities that wish to participate in an application environment for Jini technology (a Jini application environment). These interfaces provide a uniform way to define utility classes that perform the necessary discovery-related management duties on behalf of a client or service. Currently, there are three discovery management interfaces belonging to the package
net.jini.discovery:The
DiscoveryManagementinterface defines semantics for methods related to the discovery event mechanism and discovery process termination. Through this interface, an entity can register or un-register for discovery events, discard a lookup service, or terminate the discovery process.The
DiscoveryGroupManagementinterface defines methods related to the management of the sets of lookup services that are to be discovered using the multicast discovery protocols (see the Jini Discovery and Join Specification). The methods of this interface define how an entity accesses or modifies the set of groups whose members are lookup services that the entity is interested in discovering through group discovery.The
DiscoveryLocatorManagementinterface defines methods related to the management of the set of lookup services that are to be discovered using the unicast discovery protocol (as defined in the Jini Discovery and Join Specification). The methods of this interface define how an entity accesses or modifies the contents of the set ofLookupLocatorobjects corresponding to the specific lookup services the entity has targeted for locator discovery.Although each interface defines semantics for methods involved in the management of the discovery process, the individual roles each interface plays in that process are independent of each other. Because of this independence, there may be scenarios where it is desirable to implement some subset of these interfaces.
For example, a class may wish to implement the functionality defined in
DiscoveryManagement, but may not wish to allow entities to modify the groups and locators associated with the lookup services to be discovered. Such a class may have a "hard-coded" list of the groups and locators that it internally registers with the discovery process. For this case, the class would implement onlyDiscoveryManagement.Alternatively, another class may not wish to allow the entity to register more than one listener with the discovery event mechanism; nor may it wish to allow the entity to terminate discovery. It may simply wish to allow the entity to modify the sets of lookup services that will be discovered. Such a class would implement both
DiscoveryGroupManagementandDiscoveryLocatorManagement, but notDiscoveryManagement.A specific example of a class that implements only a subset of the set of interfaces specified here is the
LookupDiscoveryutility class defined later in this specification. That class implements both theDiscoveryManagementandDiscoveryGroupManagementinterfaces, but not theDiscoveryLocatorManagementinterface.Throughout this discussion of the discovery management interfaces, the phrase implementation class refers to any concrete class that implements one or more of those interfaces. The phrase implementation object should be understood to mean an instance of such an implementation class. Additionally, whenever a description refers to the discovering entity (or simply, the entity), that phrase is intended to be interpreted as the object (the client or service) that has created an implementation object, and which wishes to use the public methods specified by these interfaces and provided by that object.
DU.2.2 Other Types
The types defined in the specification of the discovery management interfaces are in the
net.jini.discoverypackage. The following additional types may also be referenced in this specification. Whenever referenced, these object types will be referenced in unqualified form:net.jini.core.discovery.LookupLocator net.jini.core.lookup.ServiceRegistrar net.jini.discovery.DiscoveryEvent net.jini.discovery.DiscoveryListener net.jini.discovery.DiscoveryChangeListener net.jini.discovery.LookupDiscovery net.jini.discovery.LookupDiscoveryManager java.io.IOException java.security.Permission java.util.EventListener java.util.EventObject java.util.MapDU.2.3 The
DiscoveryManagementInterfaceThe public methods specified by the
DiscoveryManagementinterface are:package net.jini.discovery; public interface DiscoveryManagement { public void addDiscoveryListener (DiscoveryListener listener); public void removeDiscoveryListener (DiscoveryListener listener); public ServiceRegistrar[] getRegistrars(); public void discard(ServiceRegistrar proxy); public void terminate(); }DU.2.3.1 The Semantics
The
DiscoveryManagementinterface defines methods related to the discovery event mechanism and discovery process termination. Through this interface, an entity can register or un-registerDiscoveryListenerobjects to receive discovery events (instances ofDiscoveryEvent), retrieve proxies to the currently discovered lookup services, discard a lookup service so that it is eligible for re-discovery, or terminate the discovery process.Implementation classes of this interface may impose additional semantics on any method. For example, such a class may choose to require that rather than simply terminate discovery processing, the
terminatemethod additionally should cancel all leases held by the implementation object and terminate all lease management being performed on behalf of the entity.For information on any additional semantics imposed on a method of this interface, refer to the specification of the particular implementation class.
The
DiscoveryEvent,DiscoveryListener, andDiscoveryChangeListenerclasses are defined later in this specification.The
addDiscoveryListenermethod adds a listener to the set of objects listening for discovery events. This method takes a single argument as input: an instance ofDiscoveryListenercorresponding to the listener to add to the set.Once a listener is registered, it will be notified of all lookup services discovered to date, and will then be notified as new lookup services are discovered or existing lookup services are discarded.
If the added listener is also an instance of
DiscoveryChangeListener(a subclass ofDiscoveryListener), then in addition to receiving events related to discovered and discarded lookup services, that listener will also be notified of group membership changes that occur in any of the lookup services targeted for at least group discovery.If
nullis input to this method, aNullPointerExceptionis thrown. If thelistenerinput to this method duplicates (using theequalsmethod) another element in the set of listeners, no action is taken.Implementations of the
DiscoveryManagementinterface must guarantee reentrancy with respect toDiscoveryListenerobjects registered through this method. Should the instance ofDiscoveryManagementinvoke a method on a registered listener (a local call), calls from that method to any method of theDiscoveryManagementinstance are guaranteed not to result in a deadlock condition.The
removeDiscoveryListenermethod removes a listener from the set of objects listening for discovery events. This method takes a single argument as input: an instance ofDiscoveryListenercorresponding to the listener to remove from the set.If the listener object input to this method does not exist in the set of listeners maintained by the implementation class, then this method will take no action.
The
getRegistrarsmethod returns an array consisting of instances of theServiceRegistrarinterface. Each element in the returned set is a proxy to one of the currently discovered lookup services. Each time this method is invoked, a new array is returned. If no lookup services have been discovered, an empty array is returned. This method takes no arguments as input.The
discardmethod removes a particular lookup service from the managed set of lookup services, and makes that lookup service eligible to be re-discovered. This method takes a single argument as input: an instance of theServiceRegistrarinterface corresponding to the proxy to the lookup service to discard.If the proxy input to this method is
null, or if it matches (using theequalsmethod) none of the lookup services in the managed set, this method takes no action.Currently, there exist utilities such as the
LookupDiscoveryandLookupDiscoveryManagerhelper utilities that will, on behalf of a discovering entity, automatically discard a lookup service upon determining that the lookup service has become unreachable or uninteresting. Although most entities will typically employ such a utility to help with both its discovery as well as its discard duties, it is important to note that if the entity itself determines that the lookup service is unavailable, it is the responsibility of the entity to invoke thediscardmethod. This scenario usually happens when the entity attempts to interact with a lookup service, but encounters an exceptional condition (for example, a communication failure). When the entity actively discards a lookup service, the discarded lookup service becomes eligible to be re-discovered. Allowing unreachable lookup services to remain in the managed set can result in repeated and unnecessary attempts to interact with lookup services with which the entity can no longer communicate. Thus, the mechanism provided by this method is intended to provide a way to remove such "stale" lookup service references from the managed set.Invoking the
discardmethod defined by theDiscoveryManagementinterface will result in the flushing of the lookup service from the appropriate cache, ultimately causing a discard notification--referred to as a discarded event--to be sent to all listeners registered with the implementation object. When this method completes successfully, the lookup service is guaranteed to have been removed from the managed set, and the lookup service is then said to have been "discarded". No such guarantee is made with respect to when the discarded event is sent to the registered listeners. That is, the event notifying the listeners that the lookup service has been discarded may or may not be sent asynchronously.The
terminatemethod ends all discovery processing being performed on behalf of the entity. This method takes no input arguments.After this method has been invoked, no new lookup services will be discovered, and the effect of any new operations performed on the current implementation object are undefined.
Any additional termination semantics must be defined by the implementation class.
DU.2.4 The
DiscoveryGroupManagementInterfaceThe public methods specified by the
DiscoveryGroupManagementinterface are as follows:package net.jini.discovery; public interface DiscoveryGroupManagement { public static final String[] ALL_GROUPS = null; public static final String[] NO_GROUPS = new String[0]; public String[] getGroups(); public void addGroups(String[] groups) throws IOException; public void setGroups(String[] groups) throws IOException; public void removeGroups(String[] groups); }DU.2.4.1 The Semantics
The
DiscoveryGroupManagementinterface defines methods and constants related to the management of the set containing the names of the groups whose members are the lookup services that are to be discovered using the multicast discovery protocols; that is, lookup services that are discovered by way of group discovery. The methods of this interface define how an entity retrieves or modifies the managed set of groups to discover, where phrases such as "the groups to discover" or "discovering the desired groups" refer to the discovery of the lookup services that are members of those groups.The methods that modify the managed set of groups each take a single input parameter: a
Stringarray, none of whose elements may benull. Each of these methods throws aNullPointerExceptionwhen at least one element of the input array isnull.The empty set is denoted by an empty array, and "no set" is indicated by
null. Invoking any of these methods with an input array that contains duplicate group names is equivalent to performing the invocation with the duplicates removed from the array.The
ALL_GROUPSand theNO_GROUPSconstants are defined for convenience, and represent no set and the empty set respectively.The
getGroupsmethod returns an array consisting of the names of the groups in the managed set; that is, the names of the groups the implementation object is currently configured to discover.If the managed set of groups is empty, this method will return an empty array. If there is no managed set of groups, then null (
ALL_GROUPS) is returned, indicating that any lookup service within range--even those that have no group affiliation--are to be discovered.If an empty array is returned, that array is guaranteed to be referentially equal to the
NO_GROUPSconstant; that is, the array returned from that method and theNO_GROUPSconstant can be tested for equality using the==operator.This method takes no arguments as input and, provided the managed set of groups currently exists, will return a new array upon each invocation.
The
addGroupsmethod adds a set of group names to the managed set. The array input to this method contains the group names to be added to the set.This method throws
IOExceptionbecause an invocation of this method may result in the re-initiation of the discovery process, which can throwIOExceptionwhen socket allocation occurs.This method throws an
UnsupportedOperationExceptionif there is no managed set of groups to augment, and it throws aNullPointerExceptionifnull(ALL_GROUPS) is input. If an empty array (NO_GROUPS) is input, the managed set of groups will not change.The
setGroupsmethod replaces all of the group names in the managed set with names from a new set. The array input to this method contains the group names with which to replace the current names in the managed set.Once a new group name has been placed in the managed set, no event will be sent to the entity's listener for the lookup services belonging to that group that have already been discovered, although attempts to discover all (as yet) undiscovered lookup services belonging to that group will continue to be made.
If
null(ALL_GROUPS) is input tosetGroups, then attempts will be made to discover all (as yet) undiscovered lookup services located within the multicast radius (Section DU.3, "LookupDiscovery Utility") of the implementation object, regardless of group membership.If an empty array (
NO_GROUPS) is input tosetGroups, then group discovery will be halted until the managed set of groups is changed--through a subsequent call to this method or toaddGroups--to a set that is either a non-empty set of group names ornull(ALL_GROUPS).This method throws
IOException. This is because an invocation of this method may result in the re-initiation of the discovery process, a process that can throwIOExceptionwhen socket allocation occurs.The
removeGroupsmethod deletes a set of group names from the managed set of groups. The array input to this method contains the group names to be removed from the managed set.This method throws an
UnsupportedOperationExceptionif there is no managed set of groups from which to remove elements. Ifnull(ALL_GROUPS) is input toremoveGroups, aNullPointerExceptionwill be thrown.If any element of the set of groups to be removed is not contained in the managed set,
removeGroupstakes no action with respect to that element. If an empty array (NO_GROUPS) is input, the managed set of groups will not change.Once a new group name is added to the managed set as a result of an invocation of either
addGroupsorsetGroups, attempts will be made--using the multicast request protocol--to discover all (as yet) undiscovered lookup services that are members of that group. If there are no responses to the multicast requests, the implementation object will stop sending multicast requests, and will simply listen for multicast announcements containing the new groups of interest.Any already discovered lookup service that is a member of one or more of the groups removed from the managed set as a result of an invocation of either
setGroupsorremoveGroupswill be discarded and will no longer be eligible for discovery, but only if that lookup service satisfies both of the following conditions:
- the lookup service is not a member of any group in the new managed set that resulted from the invocation of
setGroupsorremoveGroups, and
- the lookup service is not currently eligible for discovery through other means (such as locator discovery).
DU.2.5 The
DiscoveryLocatorManagementInterfaceThe public methods specified by the
DiscoveryLocatorManagementinterface are as follows:package net.jini.discovery; public interface DiscoveryLocatorManagement { public LookupLocator[] getLocators(); public void addLocators(LookupLocator[] locators); public void setLocators(LookupLocator[] locators); public void removeLocators(LookupLocator[] locators); }DU.2.5.1 The Semantics
The
DiscoveryLocatorManagementinterface defines methods related to the management of the set ofLookupLocatorobjects corresponding to the specific lookup services that are to be discovered using the unicast discovery protocol; that is, lookup services that are discovered by way of locator discovery. The methods of this interface define how an entity retrieves or modifies the managed set of locators to discover. Phrases such as "the locators to discover" and "discovering the desired locators" refer to the discovery of the lookup services that are associated with those locators.The methods that modify the managed set of locators each take a single input parameter: an array of
LookupLocatorobjects, none of whose elements may benull. Each of these methods throws aNullPointerExceptionwhen at least one element of the input array isnull.Invoking any of these methods with an input array that contains duplicate locators (as determined by
LookupLocator.equals) is equivalent to performing the invocation with the duplicates removed from the array.The
getLocatorsmethod returns an array containing the set ofLookupLocatorobjects in the managed set of locators; that is, the locators of the specific lookup services that the implementation object is currently interested in discovering.The returned set includes both the set of locators corresponding to lookup services that have already been discovered and the set of those that have not yet been discovered.
If the managed set is empty, this method returns an empty array. This method takes no arguments as input, and returns a new array upon each invocation.
The
addLocatorsmethod adds a set of locators to the managed set. The array input to this method contains the set ofLookupLocatorobjects to add to the managed set.If
nullis input toaddLocators, aNullPointerExceptionwill be thrown. If an empty array is input, the managed set of locators will not change.The
setLocatorsmethod replaces all of the locators in the managed set withLookupLocatorobjects from a new set. The array input to this method contains the set ofLookupLocatorobjects with which to replace the current locators in the managed set.If
nullis input tosetLocators, aNullPointerExceptionwill be thrown.If an empty array is input to
setLocators, then locator discovery will be halted until the managed set of locators is changed--through a subsequent call to this method or toaddLocators--to a set that is non-null and non-empty.The
removeLocatorsmethod deletes a set of locators from the managed set. The array input to this method contains the set ofLookupLocatorobjects to remove from the managed set.If
nullis input toremoveLocators, aNullPointerExceptionwill be thrown.If any element of the set of locators to remove is not contained in the managed set,
removeLocatorstakes no action with respect to that element. If an empty array is input, the managed set of locators will not change.Any already discovered lookup service, corresponding to a locator that is a member of the set of locators removed from the managed set as a result of an invocation of either
setLocatorsorremoveLocators, will be discarded and will no longer be eligible for discovery, but only if it is not currently eligible for discovery through other means (such as group discovery).DU.2.6 Supporting Interfaces and Classes
Discovery management depends on the interfaces
DiscoveryListenerandDiscoveryChangeListener, and on the concrete classDiscoveryEvent.DU.2.6.1 The
DiscoveryListenerInterfaceThe public methods specified by the
DiscoveryListenerinterface are as follows:package net.jini.discovery; public interface DiscoveryListener extends EventListener { public void discovered(DiscoveryEvent e); public void discarded(DiscoveryEvent e); }When an entity employs an object that implements one or more of the discovery management interfaces to perform and manage the entity's discovery duties, the entity often will want that object--generally referred to as a discovery utility--to notify the entity when a desired lookup service is either discovered or discarded. The
DiscoveryListenerinterface defines a mechanism through which an entity may receive such notifications from a discovery utility. When an entity registers interest in these notifications, an implementation of this interface must be provided to the discovery utility being employed. Through this registered listener, the entity may then receive instances of theDiscoveryEventclass, which encapsulate the required information associated with the desired notifications.The events received by listeners implementing the
DiscoveryListenerinterface can be the result of either group discovery or locator discovery. These events contain the discovered or discarded registrars, as well as the set of member groups corresponding to each registrar (see the specification of theDiscoveryEventclass).The
discoveredmethod is called whenever a new lookup service is discovered or a discarded lookup service is re-discovered.The
discardedmethod is called whenever a previously discovered lookup service is discarded because the lookup service was determined to be either unreachable or no longer interesting to the entity, and the discard process was initiated by either the entity itself (an active discard) or the discovery utility employed by the entity (a passive discard).The
DiscoveryGroupManagementinterface makes the following concurrency guarantee: for any given listener object that implements this interface or any sub-interface, no two methods defined by the interface or sub-interface will be invoked at the same time. This applies to different invocations of the same or different methods, on the same or different listeners registered with a singleDiscoveryManagementinstance. For example, thediscoveredmethod of one listener will not be invoked while the invocation of another listener'sdiscoveredordiscardedmethod is in progress. Similarly, the one listener'sdiscoveredmethod will not be invoked while that same listener'sdiscardmethod is in progress.DU.2.6.2 The
DiscoveryChangeListenerInterfaceThe
DiscoveryChangeListenerinterface specifies only one public method:package net.jini.discovery; public interface DiscoveryChangeListener extends DiscoveryListener { public void changed(DiscoveryEvent e); }In addition to being notified when a desired lookup service is discovered or discarded, some entities may also wish to be notified when a lookup service experiences changes in its group membership. The
DiscoveryChangeListenerinterface defines an extension to theDiscoveryListenerinterface, providing a mechanism through which an entity may receive these additional notifications--referred to as changed events. As with theDiscoveryListenerinterface, when an entity wishes to receive changed events in addition to discovered and discarded events, an implementation of this interface must be provided to the discovery utility being employed. It is through that registered listener that the entity receives the desired notifications encapsulated in instances of theDiscoveryEventclass.When the entity receives a
DiscoveryEventobject through an instance of theDiscoveryChangeListenerinterface, the event contains the discovered, discarded, or changed registrars, as well as the set of member groups corresponding to each registrar. In the case of a changed event, each set of groups referenced in the event contains the new groups in which the corresponding registrar is a member.The
changedmethod is called whenever the discovery utility encounters changes in the set of groups in which a previously discovered lookup service is a member.It is important to note that instances of this interface are eligible to receive changed events for only those lookup services that the entity has requested be discovered by (at least) group discovery. That is, if the entity requests that only locator discovery be used to discover a specific lookup service, the listener will receive no changed events for that lookup service. This is because the semantics of this interface assume that since the entity expressed no interest in discovering the lookup service through its group membership, it must also have no interest in any changes in that lookup service's group membership. Thus, if an entity wishes to receive changed events for one or more lookup services, the entity must request that those lookup services be discovered by either group discovery alone, or by both group and locator discovery.
DU.2.6.3 The
DiscoveryEventClassThe public methods provided by the
DiscoveryEventclass are as follows:package net.jini.discovery; public class DiscoveryEvent extends EventObject { public DiscoveryEvent(Object source, Map groups) {...} public DiscoveryEvent(Object source, ServiceRegistrar[] regs) {...} public Map getGroups() {...} public ServiceRegistrar[] getRegistrars() {...} }The
DiscoveryEventclass provides an encapsulation of event information that discovery utilities can use to notify an entity of the occurrence of an event involving one or moreServiceRegistrarobjects (lookup services) in which the entity has registered interest. Discovery utilities pass an instance of this class to the entity's discovery listener(s) when one of the following events occurs:
- Each lookup service referenced in the event has been discovered for the first time, or re-discovered after having been discarded.
- Each lookup service referenced in the event has been either actively or passively discarded.
- For each lookup service referenced in the event, the set of groups in which the lookup service is a member has changed.
The
DiscoveryEventclass is a subclass ofEventObject, adding the following additional items of abstract state: a set ofServiceRegistrarinstances (registrars) referencing the affected lookup services, and a mapping from each of those registrars to their current set of member groups. Methods are defined through which this additional state may be retrieved upon receipt of an instance of this class.The
equalsmethod for this class returnstrueif and only if two instances of this class refer to the same object. That is,xandyare equal instances of this class if and only ifx==yhas the valuetrue.The constructor for this class has two forms, where both forms expect two input parameters. Each form of the constructor takes, as its first input parameter, a reference to the source of the event; that is, the discovery utility object that created the event instance and sent it to the entity's listener(s) through the invocation of the
discovered,discarded, orchangedmethod on each listener. Note that neither form of the constructor makes a copy of the second parameter. That is, the reference input to the second parameter is shared with the invoking entity.Depending on the constructor employed, the second parameter is one of the following:
- A
Mapinstance in which each element of the map's key set is aServiceRegistrarinstance that references one of the lookup services to be associated with the event being constructed. Each element of the map's value set is aStringarray, containing the names of the groups in which the corresponding lookup service is a member.
- An array of
ServiceRegistrarinstances in which each element references one of the lookup services to be associated with the event being constructed.It is important to note that when this form of the constructor is used to construct a
DiscoveryEvent, although the resulting event contains anon-nullregistrars array, the registrars-to-groups map isnull. Therefore, discovery utilities should no longer use this constructor to instantiate the events they send.The
getGroupsmethod returns the mapping from each registrar referenced by the event to the registrar's current set of member groups. If the event was instantiated using the constructor whose second parameter is an array ofServiceRegistrarinstances, this method will returnnull.The returned map's key set is made up of
ServiceRegistrarinstances corresponding to the lookup services for which the event was constructed and sent. Each element of the returned map's value set is aStringarray, containing the names of the member groups of the corresponding lookup service.On each invocation of this method, the same
Mapobject is returned; that is, a copy is not made.The
getRegistrarsmethod returns an array ofServiceRegistrarinstances, in which each element references one of the lookup services for which the event was constructed and sent.On each invocation of this method, the same array is returned; that is, a copy is not made.
DU.2.7 Serialized Forms
Class serialVersionUIDSerialized Fields DiscoveryEvent5280303374696501479L ServiceRegistrar[] regsMap groupsDU.3
LookupDiscoveryUtilityDU.3.1 Overview
In a Jini application environment the multicast discovery protocols are often collectively referred to as multicast discovery or group discovery. The entities that participate in the multicast discovery protocol are a discovering entity (Jini client or service) and a Jini lookup service, which acts as the entity that is to be discovered. When the discovering entity starts, it uses the multicast request protocol to announce its interest in finding lookup services within range. After a specified amount of time, the entity stops sending multicast requests, and simply listens for multicast announcements from any lookup services within range that may be broadcasting their availability. Through either of these protocols, the discovering entity can obtain references to lookup services belonging to member group in which the entity is interested. For the details of the multicast discovery protocols, refer to the Jini Discovery and Join Specification.
The
LookupDiscoveryhelper utility in the packagenet.jini.discoveryencapsulates the functionality required of an entity that wishes to employ multicast discovery to discover a lookup service located within the entity's multicast radius (roughly, the number of hops beyond which neither the multicast requests from the entity, nor the multicast announcements from the lookup service, will propagate). This utility provides an implementation that makes the process of acquiring lookup service instances, based on no information other than group membership, much simpler for both services and clients.DU.3.2 Other Types
The types defined in the specification of the
LookupDiscoveryutility class are in thenet.jini.discoverypackage. The following additional types may also be referenced in this specification. Whenever referenced, these object types will be referenced in unqualified form:net.jini.core.discovery.LookupLocator net.jini.config.Configuration net.jini.config.ConfigurationException net.jini.discovery.DiscoveryManagement net.jini.discovery.DiscoveryGroupManagement net.jini.discovery.DiscoveryPermission java.io.IOException java.io.Serializable java.security.PermissionDU.3.3 The Interface
The public methods provided by the
LookupDiscoveryclass are as follows:package net.jini.discovery; public class LookupDiscovery implements DiscoveryManagement, DiscoveryGroupManagement { public static final String[] ALL_GROUPS = DiscoveryGroupManagement.ALL_GROUPS; public static final String[] NO_GROUPS = DiscoveryGroupManagement.NO_GROUPS; public LookupDiscovery(String[] groups) throws IOException {...} public LookupDiscovery(String[] groups, ConFiguration config) throws IOException, ConfigurationException {...} }DU.3.4 The Semantics
The only new public method of the
LookupDiscoveryhelper utility class is the constructor. All other public methods implemented by this class are specified in theDiscoveryManagementand theDiscoveryGroupManagementinterfaces.Each instance of the
LookupDiscoveryclass must behave as if it operates independently of all other instances.The
equalsmethod for this class returnstrueif and only if two instances of this class refer to the same object. That is,xandyare equal instances of this class if and only ifx==yhas the valuetrue.For convenience, this class defines the constants
ALL_GROUPSandNO_GROUPS, which represent no set and the empty set respectively. For more information on these constants, refer to the specification of theDiscoveryGroupManagementinterface.The constructor for the
LookupDiscoveryclass has two versions. Each version of the constructor throwsIOExceptionbecause construction of aLookupDiscoveryobject can cause the initiation of the multicast discovery process, a process that can throwIOException.The only difference between the two versions of the constructor is the absence or presence of a parameter of type
Configuration, which is used to classify the constructors as either non-configurable or configurable, respectively.The single input parameter shared by both versions of the constructor is a
Stringarray, none of whose elements may benull. If at least one element of that input array isnull, aNullPointerExceptionis thrown.Constructing this class using an input array that contains duplicate group names is equivalent to constructing the class using an array with the duplicates removed.
If
null(ALL_GROUPS) is input to the constructor, then attempts will be made to discover all lookup services located within the current multicast radius, regardless of group membership.Although discovery events will not be sent by this class until a listener is added through an invocation of the
addListenermethod, discovery processing usually starts as soon as an instance of this class is constructed. However, if an empty array (NO_GROUPS) is passed to the constructor, discovery will not be started until theaddGroupsorsetGroupsmethod is called to change the initial empty set of groups to either a non-empty set, ornull(ALL_GROUPS).As noted, the configurable version of the constructor is characterized by an additional parameter of type
Configuration. Through that parameter, the configurable version of the constructor can be used to customize the behavior of the resultingLookupDiscoveryinstance. Such customizations are implementation dependent. ANullPointerExceptionis thrown ifnullis passed as the value of that parameter. AConfigurationExceptionis thrown to indicate that a problem occurred while attempting to retrieve an item from the givenConfiguration.Creating a
LookupDiscoveryobject using the non-configurable version of the constructor will result in an instance ofLookupDiscoveryhaving only basic, default behavior. Thus, the use of the configurable version of the constructor is strongly encouraged.DU.3.5 Supporting Interfaces and Classes
The
LookupDiscoveryhelper utility class depends on the interfacesDiscoveryManagementandDiscoveryGroupManagement, and on the concrete classDiscoveryPermission.DU.3.5.1 The
DiscoveryManagementInterfacesThe
LookupDiscoveryclass implements both theDiscoveryManagementand theDiscoveryGroupManagementinterfaces, which together define methods related to the coordination and management of all group discovery processing. See Section DU.2, "The Discovery Management Interfaces" for more information on those interfaces.DU.3.5.2 Security and Multicast Discovery: The
DiscoveryPermissionClassWhen an instance of the
LookupDiscoveryclass is constructed, the entity that creates the instance must be granted appropriate discovery permission. For example, if the instance ofLookupDiscoveryis currently configured to discover a non-empty, non-nullset of groups, then the entity that created the instance must have permission to attempt discovery of each of the groups in that set. If the set of groups to discover isnull(ALL_GROUPS), then the entity must have permission to attempt discovery of all possible groups. If appropriate permissions are not granted, the constructor ofLookupDiscovery, as well as the methodsaddGroupsandsetGroups, will throw ajava.lang.SecurityException.Discovery permissions are controlled in security policy files using the permission class
DiscoveryPermission. The public methods provided by theDiscoveryPermissionclass are as follows:package net.jini.discovery; public final class DiscoveryPermission extends Permission implements Serializable { public DiscoveryPermission(String group) {...} public DiscoveryPermission(String group, String actions) {...} }The
DiscoveryPermissionclass is a subclass ofPermission, adding no additional items of abstract state.The
equalsmethod for this class returnstrueif and only if two instances of this class have the same group name.The constructor for this class has two forms: one form expecting one input parameter, the other form expecting two input parameters. Each form of the constructor takes, as its first input parameter, a
Stringrepresenting one or more group names for which to allow discovery.The second parameter of the second form of the constructor is a
Stringvalue that is currently ignored because there are no actions associated with a discovery permission.A number of examples that illustrate the use of this permission are presented. Note that each example represents a line in a policy file.
permission net.jini.discovery.DiscoveryPermission "*";
Grant the entity permission to attempt discovery of all possible groups
permission net.jini.discovery.DiscoveryPermission "";
Grant the entity permission to attempt discovery of only the "public" group
permission net.jini.discovery.DiscoveryPermission "foo";
Grant the entity permission to attempt discovery of the group named "foo"
permission net.jini.discovery.DiscoveryPermission "*.sun.com";
Grant the entity permission to attempt discovery of all groups whose names end with the substring ".sun.com"
Each of the above declarations grants permission to attempt discovery of one name. A name does not necessarily correspond to a single group. That is, the following should be noted:
- The name
"*"grants permission to attempt discovery of all possible groups.
- A name beginning with
"*."grants permission to attempt discovery of all groups that match the remainder of that name; for example, the name"*.example.org"would match a group named"foonly.example.org"and also a group named"sf.ca.example.org".
- The empty name
""denotes the public group.
- All other names are treated as individual groups and must match exactly.
Finally, it is important to note that a restriction of the Java2 platform security model requires that appropriate
DiscoveryPermissionbe granted to the Jini technology infrastructure software codebase itself, in addition to any codebases that may use Jini technology infrastructure software classes.DU.3.6 Serialized Forms
Class serialVersionUIDSerialized Fields DiscoveryPermission-3036978025008149170L none DU.4 The
LookupLocatorDiscoveryUtilityDU.4.1 Overview
The Jini Discovery and Join Specification, states that the "unicast discovery protocol is a simple request-response protocol." In a Jini application environment, the entities that participate in this protocol are a discovering entity (Jini client or service) and a Jini lookup service that acts as the entity to be discovered. The discovering entity sends unicast discovery requests to the lookup service, and the lookup service reacts to those requests by sending unicast discovery responses to the interested discovering entity.
The
LookupLocatorDiscoveryhelper utility (belonging to the packagenet.jini.discovery) encapsulates the functionality required of an entity that wishes to employ the unicast discovery protocol to discover a lookup service. This utility provides an implementation that makes the process of finding specific instances of a lookup service much simpler for both services and clients.Because the
LookupLocatorDiscoveryhelper utility class will participate in only the unicast discovery protocol, and because the unicast discovery protocol imposes no restriction on the physical location of a service or client relative to a lookup service, this utility can be used to discover lookup services running on hosts that are located far from, or near to, the hosts on which the service is running. This lack of a restriction on location brings with it a requirement that the discovering entity supply specific information about the desired lookup services to theLookupLocatorDiscoveryutility; namely, the location of the device(s) hosting each lookup service. This information is supplied through an instance of theLookupLocatorutility, defined in the Jini Discovery and Join Specification, or through an instance ofConstrainableLookupLocator, defined later in this document.It may be of value to note the difference between
LookupLocatorDiscoveryand theLookupDiscoveryhelper utility for group discovery (defined earlier). Although both are non-remote utility classes that entities can use to discover at least one lookup service, theLookupLocatorDiscoveryutility is designed to provide discovery capabilities that satisfy different needs than those satisfied by theLookupDiscoveryutility. These two utilities differ in the following ways:
- Whereas the
LookupLocatorDiscoveryutility is used to discover lookup services by their locators, employing the unicast discovery protocol, theLookupDiscoveryutility uses the multicast discovery protocols to discover lookup services by the groups to which the lookup services belong.
- Whereas the
LookupLocatorDiscoveryutility requires that the discovering entity supply the specific location--or address--of the desired lookup service(s) in the form of aLookupLocatorobject, theLookupDiscoveryutility imposes no such restriction on the discovering entity.
- Whereas the
LookupLocatorDiscoveryutility can be used by a discovering entity to discover lookup services that are both "near" and "far," theLookupDiscoveryutility can be used to discover only those lookup services that are located within the same multicast radius as that of the discovering entity.DU.4.2 Other Types
The types defined in the specification of the
LookupLocatorDiscoveryutility class are in thenet.jini.discoverypackage. The following additional types may also be referenced in this specification. Whenever referenced, these object types will be referenced in unqualified form:net.jini.core.discovery.LookupLocator net.jini.config.Configuration net.jini.config.ConfigurationException net.jini.discovery.DiscoveryManagement net.jini.discovery.DiscoveryLocatorManagementDU.4.3 The Interface
The public methods provided by the
LookupLocatorDiscoveryclass are as follows:package net.jini.discovery; public class LookupLocatorDiscovery implements DiscoveryManagement DiscoveryLocatorManagement { public LookupLocatorDiscovery (LookupLocator[] locators) {...} public LookupLocatorDiscovery (LookupLocator[] locators, ConFiguration config) throws ConfigurationException {...} public LookupLocator[] getDiscoveredLocators() {...} public LookupLocator[] getUndiscoveredLocators() {...} }DU.4.4 The Semantics
Including the constructor, the
LookupLocatorDiscoveryhelper utility class defines three new public methods. All other public methods are inherited from theDiscoveryManagementandDiscoveryLocatorManagementinterfaces.Each instance of the
LookupLocatorDiscoveryclass must behave as if it operates independently of all other instances.The
equalsmethod for this class returnstrueif and only if two instances of this class refer to the same object. That is,xandyare equal instances of this class if and only ifx==yhas the valuetrue.The constructor for the
LookupLocatorDiscoveryclass has two versions. The only difference between the two versions of the constructor is the absence or presence of a parameter of typeConfiguration, which is used to classify the constructors as either non-configurable or configurable, respectively.The single input parameter shared by both versions of the constructor is a set of locators represented as an array of
LookupLocatorobjects, none of whose elements may benull. Each element in the input set corresponds to a specific lookup service the discovering entity wishes to be discovered. Although it is acceptable to inputnullfor the argument itself, if a non-nullarray containing at least onenullelement is input, aNullPointerExceptionis thrown.Invoking either version of the constructor with an input array that contains duplicate locators (as determined by
LookupLocator.equals) is equivalent to performing the invocation with the duplicates removed from the array.Although discovery events will not be sent by this class until a listener is added through an invocation of the
addListenermethod, discovery processing usually starts as soon as an instance of this class is constructed. However, ifnullor an empty array is passed to thelocatorsargument of either version of the constructor, discovery will not be started until theaddLocatorsorsetLocatorsmethod is called to change the managed set of locators to a set of locators that is non-nulland non-empty.As previously noted, the configurable version of the constructor is characterized by an additional parameter of type
Configuration. Through that parameter, the configurable version of the constructor can be used to customize the behavior of the resultingLookupLocatorDiscoveryinstance. Such customizations are implementation dependent. ANullPointerExceptionis thrown ifnullis passed as the value of that parameter. AConfigurationExceptionis thrown to indicate that a problem occurred while attempting to retrieve an item from the givenConfiguration.Creating a
LookupLocatorDiscoveryobject using the non-configurable version of the constructor will result in an instance ofLookupLocatorDiscoveryhaving only basic, default behavior. Thus, the use of the configurable version of the constructor is strongly encouraged.The
getDiscoveredLocatorsmethod returns the set ofLookupLocatorobjects representing the desired lookup services that are currently discovered. If the set is empty, this method will return an empty array. This method takes no arguments as input, and will return a new array upon each invocation.The
getUndiscoveredLocatorsmethod returns the set ofLookupLocatorobjects representing the desired lookup services that have not yet been discovered. If the set is empty, this method will return an empty array. This method takes no arguments as input, and will return a new array upon each invocation.DU.4.5 Supporting Interfaces
The
LookupLocatorDiscoveryhelper utility class depends on the following interfaces:DiscoveryManagementandDiscoveryLocatorManagement.DU.4.5.1 The DiscoveryManagement Interfaces
The
LookupLocatorDiscoveryclass implements theDiscoveryManagementandDiscoveryLocatorManagementinterfaces, which together define methods related to the coordination and management of all locator discovery processing. See Section DU.2, "The Discovery Management Interfaces" for more information on those interfaces.DU.5 The
LookupDiscoveryManagerUtilityDU.5.1 Overview
Although the goals of any well-behaved Jini client or service are application-specific, the goals of such entities with respect to their interaction with Jini lookup services generally begin with employing the Jini discovery protocols (defined in the Jini Discovery and Join Specification) to obtain a reference to at least one lookup service. Because the discovery duties performed by such entities may require the management of significant amounts of state information, those duties can become quite tedious.
The
LookupDiscoveryManageris a helper utility class (belonging to the packagenet.jini.discovery) that organizes and manages all discovery-related activities on behalf of a Jini client or service. Rather than providing its own facility for coordinating and maintaining all of the necessary state information related to group names,LookupLocatorobjects, andDiscoveryListenerobjects, such an entity can employ this class to provide those facilities on its behalf.DU.5.2 Other Types
The types defined in the specification of the
LookupDiscoveryManagerutility class are in thenet.jini.discoverypackage. The following additional types may also be referenced in this specification. Whenever referenced, these object types will be referenced in unqualified form:net.jini.core.discovery.LookupLocator net.jini.config.Configuration net.jini.config.ConfigurationException net.jini.discovery.DiscoveryEvent net.jini.discovery.DiscoveryListener net.jini.discovery.DiscoveryManagement net.jini.discovery.DiscoveryGroupManagement net.jini.discovery.DiscoveryLocatorManagement java.io.IOExceptionDU.5.3 The Interface
The only new public method of the
LookupDiscoveryManagerhelper utility class is the constructor. All other public methods implemented by this class are specified in the discovery management interfaces.package net.jini.discovery; public class LookupDiscoveryManager implements DiscoveryManagement, DiscoveryGroupManagement, DiscoveryLocatorManagement { public LookupDiscoveryManager(String[] groups, LookupLocator[] locators, DiscoveryListener listener) throws IOException {...} public LookupDiscoveryManager(String[] groups, LookupLocator[] locators, DiscoveryListener listener, ConFiguration config) throws IOException, ConfigurationException {...} }DU.5.4 The Semantics
The
equalsmethod for this class returnstrueif and only if two instances of this class refer to the same object. That is,xandyare equal instances of this class if and only ifx==yhas the valuetrue.The constructor for the
LookupDiscoveryManagerhas two versions. Each version of the constructor throwsIOExceptionbecause construction of aLookupDiscoveryManagermay initiate the multicast discovery process, which can throwIOException.The only difference between the two versions of the constructor is the absence or presence of a parameter of type
Configuration, which is used to classify the constructors as either non-configurable or configurable, respectively.The input parameters shared by both versions of the constructor are as follows:
- A
Stringarray, none of whose elements may benull, in which each element is the name of a group whose members are lookup services the entity wishes to be discovered through group discovery
- An array of
LookupLocatorobjects, none of whose elements may benull, in which each element corresponds to a specific lookup service the entity wishes to be discovered through locator discovery
- A reference to an instance of
DiscoveryListenerthat will be notified when a targeted lookup service is discovered, is discarded, or--under certain conditions--has experienced a change in its group membershipThe
LookupDiscoveryManagerwill, on behalf of any entity that constructs an instance of this utility, employ the Jini discovery protocols defined in the Jini Discovery and Join Specification to attempt to find all lookup services that satisfy the criteria set forth by the contents of the first two arguments, and it will maintain and manage any lookup services that it does discover.If either version of the constructor is invoked with a set of group names and a set of locators in which either or both sets contain duplicate elements (where duplicate locators are determined by
LookupLocator.equals), the invocation is equivalent to constructing this class with no duplicates in either set.If
null(DiscoveryGroupManagement.ALL_GROUPS) is input to thegroupsargument, then attempts will be made through group discovery to discover all lookup services located within the multicast radius of the entity, regardless of group membership.Typically, group discovery is initiated as soon as an instance of this class is created. However, if an empty array (
DiscoveryGroupManagement.NO_GROUPS) is passed to the groups argument of the constructor, no lookup service will be discovered through group discovery until theaddGroupsorsetGroupsmethod is called to change the managed set of groups to either a non-empty set, or null (DiscoveryGroupManagement.ALL_GROUPS).If at least one element of the
groupsargument isnull, aNullPointerExceptionis thrown.Typically, locator discovery processing is initiated as soon as an instance of this class is constructed. However, if an empty or
nullarray is input to thelocatorsargument, no attempt will be made to discover specific lookup services through locator discovery until theaddLocatorsorsetLocatorsmethod is called to change the managed set of locators to a set of locators that is non-nulland non-empty.If at least one element of the
locatorsargument isnull, aNullPointerExceptionis thrown.The third argument to either version of the constructor is a reference to a listener object that will be registered to receive discovery event notifications. If a
nullreference is input to this argument, then the entity will receive no discovery events untiladdDiscoveryListeneris invoked with a non-nullinstance ofDiscoveryListener.Once a listener is registered with the
LookupDiscoveryManager, it will be notified of all lookup services discovered through either group or locator discovery, and will be notified whenever those lookup services are discarded. Thus, if an entity wishes to receive discovered and discarded events from theLookupDiscoveryManager, it is the responsibility of the entity to provide an implementation of theDiscoveryListener(or theDiscoveryChangeListener) interface; an implementation that defines the actions to take upon the receipt of those types of events.If a listener registered with the
LookupDiscoveryManageris also an instance ofDiscoveryChangeListener, then in addition to receiving events related to discovered and discarded lookup services, that listener will also be notified of group membership changes that occur in any of the lookup services targeted for at least group discovery. That is, although such listeners are eligible to receive changed events, they will receive no changed events for lookup services for which the entity has requested only locator discovery.Note that if an entity wishes to receive changed events in addition to the discovered and discarded events it receives from the
LookupDiscoveryManager, the entity must provide an implementation ofDiscoveryChangeListenerthat defines the actions to take upon the receipt of any of the three possible discovery event types. That is, if the entity provides only an implementation ofDiscoveryListener, the entity will receive no changed events for any of the discovered lookup services, regardless of the discovery mechanism employed for those lookup services.Once a lookup service is discovered, there is no longer any need to perform discovery processing with respect to that lookup service. This means that if a lookup service becomes unreachable after it has been discovered, the
LookupDiscoveryManagerwill not know when the lookup service becomes reachable again until that lookup service is discarded.Although the
LookupDiscoveryManagerwill monitor the multicast announcements for indications of unavailability, it will discard only those unreachable lookup services for which the entity requested discovery through at least group discovery. That is, if theLookupDiscoveryManagerdetermines that a previously discovered lookup service has become unreachable, but the entity requested that it be discovered by locator discovery alone, then theLookupDiscoveryManagerwill not discard the lookup service.Thus, whenever the entity itself determines that a previously discovered lookup service has become unreachable, it should not rely on the
LookupDiscoveryManagerto discard the lookup service. Instead, the entity should inform theLookupDiscoveryManager--through the invocation of thediscardmethod--that the previously discovered lookup service is no longer available, and that attempts should be made to re-discover that lookup service. Typically, an entity determines that a lookup service is unavailable when the entity attempts to use the lookup service but receives an exception or error (RemoteException, for example) as a result of the attempt.As previously noted, the configurable version of the constructor is characterized by an additional parameter of type
Configuration. Through that parameter, the configurable version of the constructor can be used to customize the behavior of the resultingLookupDiscoveryManagerinstance. Such customizations are implementation dependent. ANullPointerExceptionis thrown ifnullis passed as the value of that parameter. AConfigurationExceptionis thrown to indicate that a problem occurred while attempting to retrieve an item from the givenConfiguration.Creating a
LookupDiscoveryManagerusing the non-configurable version of the constructor will result in aLookupDiscoveryManagerhaving only basic, default behavior. Thus, the use of the configurable version of the constructor is strongly encouraged.DU.5.5 Supporting Interfaces and Classes
The
LookupDiscoveryManagerhelper utility class depends on the interfacesDiscoveryManagement,DiscoveryGroupManagement, andDiscoveryLocatorManagement, and on the concrete classDiscoveryPermission.DU.5.5.1 The
DiscoveryManagementInterfacesThe
LookupDiscoveryManagerclass implements theDiscoveryManagement, theDiscoveryGroupManagement,and theDiscoveryLocatorManagementinterfaces, which together define methods related to the coordination and management of all group and locator discovery processing. See Section DU.2, "The Discovery Management Interfaces" for more information on those interfaces.DU.5.5.2 Security and Multicast Discovery: The
DiscoveryPermissionClassAs is the case for the
LookupDiscoveryclass, when an instance of theLookupDiscoveryManagerclass is constructed, the entity that creates the instance must be granted appropriate discovery permission to perform the group discovery duties that instance attempts to perform on behalf of the entity. If appropriate permissions are not granted, the constructor ofLookupDiscoveryManager, as well as the methodsaddGroupsandsetGroups, will throw ajava.lang.SecurityException.Discovery permissions are controlled in security policy files using the permission class
DiscoveryPermission. The specification of that class, as well as useful examples related to that class, are presented in the specification of theLookupDiscoveryutility (see Section DU.2, "The Discovery Management Interfaces").DU.6 The
ConstrainableLookupLocatorUtilityDU.6.1 Overview
The base
net.jini.core.discovery.LookupLocatorclass, described in Section DJ.6, "LookupLocatorClass", does not provide any means of controlling unicast discovery parameters other than the timeout for reading unicast response data. TheConstrainableLookupLocatorutility is a subclass ofLookupLocatorthat supports additional control of unicast discovery through the use of constraints.DU.6.2 Other Types
The types defined in the specification of the
ConstrainableLookupLocatorutility class are in thenet.jini.discoverypackage. The following additional types are also referenced in this specification. Whenever referenced, these object types will be referred to in unqualified form:net.jini.core.constraint.MethodConstraints net.jini.core.constraint.RemoteMethodControl net.jini.io.UnsupportedConstraintException net.jini.security.Security net.jini.security.TrustVerifier java.io.IOException java.net.MalformedURLExceptionDU.6.3 The Interface
In order to support constraints,
ConstrainableLookupLocatordefines constructors that take the same parameters as those ofLookupLocator, with the addition ofMethodConstraints. All other public members are defined by supertypes: the publicgetRegistrar,getRegistrar(int),getHost, andgetPortmethods, along with the protectedhostandportfields, are defined by theLookupLocatorclass, while the publicgetConstraintsandsetConstraintsmethods are defined by theRemoteMethodControlinterface.public final class ConstrainableLookupLocator extends LookupLocator implements RemoteMethodControl { public ConstrainableLookupLocator (String url, MethodConstraints constraints) throws MalformedURLException {...} public ConstrainableLookupLocator (String host, int port, MethodConstraints constraints) {...} }DU.6.4 The Semantics
The first constructor listed in Section DU.6.3 accepts the following parameters as input:
- A non-
nullStringcontaining a URL, which must be a URL of scheme"jini"as described in the Jini Discovery and Join Specification- A
MethodConstraintsinstance containing the constraints to be applied to unicast discovery, ornull, indicating an empty set of constraintsA
ConstrainableLookupLocatorinstance created with this constructor will attempt unicast discovery to the indicated TCP host and port when one of itsgetRegistrarmethods is called. This constructor invokes the one argument superclass constructor, passing it to the input URL parameter. Any exception thrown by the superclass constructor is rethrown.The second constructor listed in Section DU.6.3 accepts the following parameters as input:
- A non-
nullStringcontaining the name of the host to which to attempt unicast discovery- An
intvalue indicating the number of the port to connect to when attempting unicast discovery- A
MethodConstraintsinstance containing the constraints to be applied to unicast discovery, ornull, indicating an empty set of constraintsThe only difference between this and the previously described constructor is the means by which the target host and port for unicast discovery is specified--rather than a URL string, this constructor accepts explicit host and port values. A
ConstrainableLookupLocatorinstance created with this constructor will attempt unicast discovery to the specified TCP host and port when one of itsgetRegistrarmethods is called. This constructor invokes the two argument superclass constructor, passing to it the input host and port parameters. Any exception thrown by the superclass constructor is rethrown.The
getHost,getPort,equals, andhashCodemethods of this class behave in the same way as those of the baseLookupLocatorclass.The
setConstraintsandgetConstraintsmethods of this class behave as specified by theRemoteMethodControlinterface. Note that the only methods for which constraints are obtained from suppliedMethodConstraintsinstances are thegetRegistrarandgetRegistrar(int)methods of theLookupLocatorclass.The
getRegistrar(int)method of this class behaves as specified by theLookupLocatorclass, except that it also takes into account the constraints (if any) attached for it to theConstrainableLookupLocatorinstance on which the method is invoked. Consequently, this method throwsUnsupportedConstraintException(which is a subclass ofIOException) if the specified constraints cannot be satisfied. The specified timeout value is interpreted as an additional required constraint; if this value conflicts with other constraints specified for thegetRegistrar(int)method, then anUnsupportedConstraintExceptionwill be thrown.The
getRegistrar()method, like thegetRegistrar(int)method, takes into account the constraints (if any) for it. Additionally, as with thegetRegistrar(int)method, it throwsUnsupportedConstraintExceptionif the specified constraints cannot be satisfied. If no timeout constraints are specified, this method assumes a default timeout of 60 seconds. It performs unicast discovery as specified by theLookupLocatorclass, however it does not invoke thegetRegistrar(int)method. Moreover, a non-default timeout can only be specified through the supplied constraints; thenet.jini.discovery.timeoutsystem property is ignored.ConstrainableLookupLocatorimplements this method to use the values of thehostandportfields in determining the host and port to which to connect.DU.6.5 Supporting Interfaces and Classes
The
ConstrainableLookupLocatorclass depends on theLookupLocatorclass, which it subclasses, and theRemoteMethodControlinterface, which it implements. It is also associated with theConstrainableLookupLocatorTrustVerifierclass, described in the following sub-section.DU.6.5.1 The
ConstrainableLookupLocatorTrustVerifierClassThe
ConstrainableLookupLocatorTrustVerifierclass is used for verifying trust inConstrainableLookupLocatorinstances acquired from untrusted sources; it is intended to be specified in a resource to configure the operation of theSecurity.verifyObjectTrustmethod.ConstrainableLookupLocatorTrustVerifierimplements theTrustVerifierinterface and defines a single no-argument constructor:public class ConstrainableLookupLocatorTrustVerifier implements TrustVerifier { public ConstrainableLookupLocatorTrustVerifier() {...} }The constructor creates a new
ConstrainableLookupLocatorTrustVerifierinstance. Note that allConstrainableLookupLocatorTrustVerifierinstances are functionally equivalent, since they do not contain any state.The
isTrustedObjectmethod of theConstrainableLookupLocatorTrustVerifierclass follows the method's general contract, specified by theTrustVerifierinterface: it returnstrueif itsObjectargument is known to be trusted to correctly implement its contract, and returnsfalseotherwise. More specifically, it returnstrueif the given argument is an instance ofConstrainableLookupLocator(which rules out untrusted classes, sinceConstrainableLookupLocatoris afinalclass), and returnsfalseotherwise.DU.6.6 Serialized Form
Class serialVersionUIDSerialized Fields ConstrainableLookupLocator
7061417093114347317L
noneDU.7 Low-Level Discovery Protocol Utilities
The utilities presented in this section of the specification are useful when implementing higher-level utilities or other entities or components that will be involved in the Jini discovery process. These utilities encapsulate functionality that allow one to exercise more control when interacting with the Jini discovery protocols. Anyone wishing to provide their own implementation of the Jini lookup service or their own implementation of the discovery utilities presented previously in this specification, may find the utilities presented in this section useful when creating those alternate implementations.
Note that these utilities only support version 1 of the discovery protocol, as defined in the Jini Discovery and Join Specification.
DU.7.1 The
ConstantsClassDU.7.1.1 Overview
The
Constantsclass provides easy access to defined constants that may be useful when participating in the discovery process.DU.7.1.2 Other Types
The types defined in the specification of the
Constantsclass are in thenet.jini.discoverypackage. The following additional types may also be referenced in this specification. Whenever referenced, these object types will be referenced in unqualified form:java.net.InetAddress java.net.UnknownHostExceptionDU.7.1.3 The Class Definition
The public constants defined by the
Constantsclass are as follows:package net.jini.discovery; public class Constants { public static final short discoveryPort = 4160; public static final InetAddress getRequestAddress() throws UnknownHostException {...} public static final InetAddress getAnnouncementAddress() throws UnknownHostException {...} }DU.7.1.4 The Semantics
The
Constantsclass cannot be instantiated. This class has one public variable and two public accessor methods; each is static and final. The constant value associated with the variable, as well as the values returned by the methods, may be useful in the discovery process.The value of the
discoveryPortconstant serves two purposes:
- The UDP port number over which the multicast request and announcement protocols operate
- The TCP port number over which the unicast discovery protocol operates by default
The
getRequestAddressmethod returns an instance ofInetAddressthat contains the address of the multicast group over which the multicast request protocol takes place.The
getAnnouncementAddressmethod returns an instance ofInetAddressthat contains the address of the multicast group over which the multicast announcement protocol takes place.Note that either
getRequestAddressorgetAnnouncementAddressmay throw anUnknownHostExceptionif called in a circumstance under which multicast address resolution is not permitted.DU.7.2 The
OutgoingMulticastRequestUtilityDU.7.2.1 Overview
The
OutgoingMulticastRequestclass provides facilities for marshalling multicast discovery requests into a form suitable for transmission over a network for the purposes of announcing one's interest in discovering a lookup service. This class is useful when building components that participate in the multicast request protocol as part of a group discovery mechanism. This utility should be viewed from the perspective of an entity that wishes to transmit multicast requests in order to discover a lookup service belonging to a set of groups in which the entity is interested.DU.7.2.2 Other Types
The types defined in the specification of the
OutgoingMulticastRequestutility class are in thenet.jini.discoverypackage. The following additional types may also be referenced in this specification. Whenever referenced, these object types will be referenced in unqualified form:net.jini.core.discovery.ServiceID java.io.IOException java.net.DatagramPacket java.net.InetAddressDU.7.2.3 The Interface
The public methods provided by the
OutgoingMulticastRequestclass are as follows:package net.jini.discovery; public class OutgoingMulticastRequest { public static DatagramPacket[] marshal(int port, String[] groups, ServiceID[] heard) throws IOException {...} }DU.7.2.4 The Semantics
The
OutgoingMulticastRequestclass cannot be instantiated. This class has only one public method, which is static.The
marshalmethod takes as input the following arguments, none of which may benull:
- The port to which respondents should connect in order to start unicast discovery
- A
Stringarray, none of whose elements may benull, in which each element is the name of a group the requesting entity is interested in discovering
- An array of
ServiceIDobjects, none of whose elements may benull, in which each element corresponds to a lookup service the requesting entity has already heard fromSince implementations are not required to check for duplicated elements, the arguments represented as arrays must not contain such elements.
The
marshalmethod returns an array whose elements are instances ofDatagramPacket. The array returned will always contain at least one element, and will contain more if the request is not small enough to fit in a single packet. The array returned by this method is fully initialized; it contains a multicast request as payload and is ready to send over the network.In the event of error, the
marshalmethod may throw anIOExceptionif marshalling fails. In some instances the exception thrown may be a more specific subclass of that exception.DU.7.3 The
IncomingMulticastRequestUtilityDU.7.3.1 Overview
The
IncomingMulticastRequestclass provides facilities that are useful when a requesting entity's announced interest in discovering a lookup service is received. The facilities provided by this class encapsulate the details of the process of unmarshalling such received multicast discovery requests into a form in which the individual parameters of the request may be easily accessed. This class is useful when building components that participate in the multicast request protocol as part of a group discovery mechanism, where an entity that uses such a component wishes to receive multicast requests in order to be discovered through its group membership; for example, an entity such as a lookup service.DU.7.3.2 Other Types
The types defined in the specification of the
IncomingMulticastRequestutility class are in thenet.jini.discoverypackage. The following additional types may also be referenced in this specification. Whenever referenced, these object types will be referenced in unqualified form:net.jini.core.discovery.ServiceID java.io.IOException java.net.DatagramPacket java.net.InetAddressDU.7.3.3 The Interface
The public methods provided by the
IncomingMulticastRequestclass are as follows:package net.jini.discovery; public class IncomingMulticastRequest { public IncomingMulticastRequest(DatagramPacket dgram) throws IOException {...} public InetAddress getAddress() {...} public int getPort() {...} public String[] getGroups() {...} public ServiceID[] getServiceIDs() {...} }DU.7.3.4 The Semantics
Including the constructor, the
IncomingMulticastRequestclass defines five new public methods.The
equalsmethod for this class returns true if and only if two instances of this class have the same address, port, groups, and service ID values.The constructor of the
IncomingMulticastRequestclass takes a single input parameter: an instance ofDatagramPacket. The payload of this parameter is assumed to contain nothing but a marshalled discovery request.If the marshalled request contained in the input parameter is corrupt, an
IOExceptionor aClassNotFoundExceptionwill be thrown. In some such instances, a more specific subclass of either exception may be thrown that will give more detailed information.The
getAddressmethod returns an instance ofInetAddressthat represents the address of the host to contact in order to start unicast discovery.The
getPortmethod returns anintvalue that is the port number to connect to on the remote host in order to start unicast discovery.The
getGroupsmethod returns an array consisting of the names of the groups in which the requesting entity (the originator of this request) is interested. The array returned by this method may be of zero length, none of its elements will benull, and elements in the returned array may or may not be duplicated. Furthermore, the set reflected in the returned array may not be complete, but other incoming packets should contain the rest of the set.The
getServiceIDsmethod returns an array ofServiceIDinstances in which each element of the array corresponds to a lookup service from which the requesting entity has already heard. The array returned by this method may be of zero length, none of its elements will benull, and elements in the returned array may or may not be duplicated. Furthermore, the set returned by this method may not be complete. That is, there may be more lookup services from which the requesting entity has already heard, but the set returned by this method will not exceed the capacity of a packet.DU.7.4 The
OutgoingMulticastAnnouncementUtilityDU.7.4.1 Overview
The
OutgoingMulticastAnnouncementclass encapsulates the details of the process of marshalling multicast discovery announcements into a form suitable for transmission over a network for the purposes of announcing the availability of a lookup service to interested parties. This class is useful when building components that participate in the multicast announcement protocol as part of a group discovery mechanism. This utility should be viewed from the perspective of an entity that wishes to transmit multicast announcements in order to be discovered as a lookup service belonging to a set of groups in which other discovering entities may be interested.DU.7.4.2 Other Types
The types defined in the specification of the
OutgoingMulticastAnnouncementutility class are in thenet.jini.discoverypackage. The following additional types may also be referenced in this specification. Whenever referenced, these object types will be referenced in unqualified form:net.jini.core.discovery.LookupLocator net.jini.core.discovery.ServiceID java.io.IOException java.net.DatagramPacketDU.7.4.3 The Interface
The public methods provided by the
OutgoingMulticastAnnouncementclass are as follows:package net.jini.discovery; public class OutgoingMulticastAnnouncement { public static DatagramPacket[] marshal(ServiceID id, LookupLocator loc, String[]groups) throws IOException {...} }DU.7.4.4 The Semantics
The
OutgoingMulticastAnnouncementclass cannot be instantiated. This class has only one public method, which is static.The
marshalmethod takes as input the following arguments, none of which may benull:
- The instance of
ServiceIDthat corresponds to the lookup service being advertised
- The instance of
LookupLocatorthrough which the lookup service being advertised may be discovered through unicast discovery
- A non-
nullStringarray, none of whose elements may benull, in which each element is the name of a group in which the lookup service being advertised is a memberThe
marshalmethod returns an array whose elements are instances ofDatagramPacket, the contents of which represents a marshalled multicast announcement. The packets created by this method, as represented by the elements of the returned array, are guaranteed to contain all of the groups in which the lookup service being advertised is a member. Note that the set of groups reflected in the returned collection of datagram packets may be distributed among those packets.Each element of the array returned by this method is initialized such that it is ready for transmission to the appropriate multicast address and UDP port.
In the event of error, the
marshalmethod may throw anIOExceptionif marshalling fails. In some instances, the exception thrown may be a more specific subclass of that exception.DU.7.5 The
IncomingMulticastAnnouncementUtilityDU.7.5.1 Overview
The
IncomingMulticastAnnouncementclass encapsulates the details of the process of unmarshalling multicast discovery announcements into a form in which the individual parameters of the announcement may be easily accessed. This class is useful when building components that participate in the multicast announcement protocol as part of a group discovery mechanism. This utility should be viewed from the perspective of an entity that wishes to receive multicast announcements in order to discover a lookup service belonging to a set of groups in which the entity is interested.DU.7.5.2 Other Types
The types defined in the specification of the
IncomingMulticastAnnouncementutility class are in thenet.jini.discoverypackage. The following additional types may also be referenced in this specification. Whenever referenced, these object types will be referenced in unqualified form:net.jini.core.discovery.LookupLocator net.jini.core.discovery.ServiceID java.io.IOException java.net.DatagramPacketDU.7.5.3 The Interface
The public methods provided by the
IncomingMulticastAnnouncementclass are as follows:package net.jini.discovery; public class IncomingMulticastAnnouncement { public IncomingMulticastAnnouncement(DatagramPacket p) throws IOException {...} public ServiceID getServiceID() {...} public LookupLocator getLocator() {...} public String[] getGroups() {...} }DU.7.5.4 The Semantics
Including the constructor, the
IncomingMulticastAnnouncementclass defines four new public methods.The
equalsmethod for this class returns true if and only if two instances of this class have the same service ID values.The constructor of the
IncomingMulticastAnnouncementclass takes a single input parameter: an instance ofDatagramPacket. The constructor attempts to unmarshal the input parameter, storing the results in the various fields of this class.If the contents of the datagram packet cannot be successfully unmarshalled, either an
IOExceptionor aClassNotFoundExceptionis thrown. In some such instances, a more specific subclass of either exception may be thrown that will give more detailed information.The
getServiceIDmethod returns theServiceIDinstance corresponding to the lookup service that sent the announcement.The
getLocatormethod returns theLookupLocatorinstance corresponding to the lookup service that sent the announcement. It is through the object returned by this method that the lookup service may be discovered via unicast discovery.The
getGroupsmethod returns an array consisting of the names of the groups in which the lookup service that sent the announcement is a member. The array returned by this method is nevernull, will contain nonullelements, or may be empty. Additionally, elements in the returned array may or may not be duplicated.DU.7.6 The
OutgoingUnicastRequestUtilityDU.7.6.1 Overview
The
OutgoingUnicastRequestclass encapsulates the details of the process of marshalling unicast discovery requests into a form suitable for transmission over a network to attempt discovery of a specific lookup service. This class is useful when building components that participate in the unicast request protocol as part of either a group or a locator discovery mechanism. This utility should be viewed from the perspective of an entity that wishes to transmit unicast requests in order to discover a specific lookup service in which the entity is interested.DU.7.6.2 Other Types
The types defined in the specification of the
OutgoingUnicastRequestutility class are in thenet.jini.discoverypackage. The following additional types may also be referenced in this specification. Whenever referenced, these object types will be referenced in unqualified form:java.io.IOException java.io.OutputStreamDU.7.6.3 The Interface
The public methods provided by the
OutgoingUnicastRequestclass are as follows:package net.jini.discovery; public class OutgoingUnicastRequest { public static void marshal(OutputStream str) throws IOException {...} }DU.7.6.4 The Semantics
The
OutgoingUnicastRequestclass cannot be instantiated. This class has only one public method, which is static.The
marshalmethod takes only one parameter as input: an instance ofOutputStream, which is the stream to which the unicast request is written. After the unicast request is written to the stream, the stream is flushed.In the event of error, the
marshalmethod may throw anIOExceptionif writing to the stream fails. In some instances, the exception thrown may be a more specific subclass of that exception.DU.7.7 The IncomingUnicastRequest Utility
DU.7.7.1 Overview
The
IncomingUnicastRequestclass encapsulates the details of the process of unmarshalling unicast discovery requests into a form in which the individual parameters of the request may be easily accessed. This class is useful when building components that participate in the unicast request protocol as part of either a group or a locator discovery mechanism. This utility should be viewed from the perspective of an entity--such as a lookup service--that wishes to receive unicast requests in order to be discovered through direct, unicast communication.DU.7.7.2 Other Types
The types defined in the specification of the
IncomingUnicastRequestutility class are in thenet.jini.discoverypackage. The following additional types may also be referenced in this specification. Whenever referenced, these object types will be referenced in unqualified form:java.io.InputStream java.io.IOExceptionDU.7.7.3 The Interface
The public methods provided by the
IncomingUnicastRequestclass are as follows:package net.jini.discovery; public class IncomingUnicastRequest { public IncomingUnicastRequest(InputStream str) throws IOException {...} }DU.7.7.4 The Semantics
The only new public method defined by the
IncomingUnicastRequestclass is the constructor.The constructor of the
IncomingUnicastRequestclass takes a single input parameter: an instance ofInputStream, which is the stream from which the unicast request is read.In the event of error, an
IOExceptionmay be thrown if reading from the stream fails. In some instances, the exception thrown may be a more specific subclass of that exception.DU.7.8 The
OutgoingUnicastResponseUtilityDU.7.8.1 Overview
The
OutgoingUnicastResponseclass encapsulates the details of the process of marshalling a unicast discovery response into a form suitable for transmission over a network to respond to a unicast discovery request. This class is useful when building components that participate in the unicast request protocol as part of either a group or a locator discovery mechanism. This utility should be viewed from the perspective of a entity--such as a lookup service--that wishes to transmit responses to unicast requests in order to be discovered through direct, unicast communication.DU.7.8.2 Other Types
The types defined in the specification of the
OutgoingUnicastResponseutility class are in thenet.jini.discoverypackage. The following additional types may also be referenced in this specification. Whenever referenced, these object types will be referenced in unqualified form:net.jini.core.lookup.ServiceRegistrar java.io.IOException java.io.OutputStreamDU.7.8.3 The Interface
The public methods provided by the
OutgoingUnicastResponseclass are as follows:package net.jini.discovery; public class OutgoingUnicastResponse { public static void marshal(OutputStream s, ServiceRegistrar reg String[] groups) throws IOException {...} }DU.7.8.4 The Semantics
The
OutgoingUnicastResponseclass cannot be instantiated. This class has only one public method, which is static.The
marshalmethod takes as input the following arguments, none of which may benull:
- An instance of
OutputStream, which is the stream to which the unicast response is written.
- An instance of
ServiceRegistrarthat references the proxy to the lookup service that will be marshalled and written to the stream.
- A non-
nullStringarray, none of whose elements may benull, in which each element is the name of a group in which the lookup service referenced by theregparameter is a member. Note that duplicate elements are allowed in this parameter.The
marshalmethod marshals theregparameter and writes the result to the stream. It then writes each element of thegroupsparameter to the stream. After the complete unicast response is written to the stream, the stream is flushed.This method may throw an
IOExceptionif a failure occurs while marshalling or writing to the stream. In some instances, the exception thrown may be a more specific subclass of that exception.DU.7.9 The
IncomingUnicastResponseUtilityDU.7.9.1 Overview
The
IncomingUnicastResponseclass encapsulates the details of the process of unmarshalling a unicast discovery response into a form in which the individual parameters of the request may be easily accessed. This class is useful when building components that participate in the unicast request protocol as part of either a group or a locator discovery mechanism. This utility should be viewed from the perspective of an entity that wishes to receive unicast responses in order to discover lookup services through direct, unicast communication.DU.7.9.2 Other Types
The types defined in the specification of the
IncomingUnicastResponseutility class are in thenet.jini.discoverypackage. The following additional types may also be referenced in this specification. Whenever referenced, these object types will be referenced in unqualified form:net.jini.core.lookup.ServiceRegistrar java.io.InputStream java.io.IOExceptionDU.7.9.3 The Interface
The public methods provided by the
IncomingUnicastResponseclass are as follows:package net.jini.discovery; public class IncomingUnicastResponse { public IncomingUnicastResponse(InputStream s) throws IOException, ClassNotFoundException {...} public ServiceRegistrar getRegistrar() {...} public String[] getGroups() {...} }DU.7.9.4 The Semantics
Including the constructor, the
IncomingUnicastResponseclass defines three new methods.The
equalsmethod for this class returnstrueif and only if two instances of this class reference the same lookup service proxy (registrar).The constructor of the
IncomingUnicastResponseclass takes a single input parameter: an instance ofInputStream, which is the stream from which the contents of the unicast response is read.An
IOExceptionmay be thrown if reading from the stream fails. AClassNotFoundExceptionmay be thrown if failure occurs while unmarshalling the proxy to the lookup service contained in the unicast response. In some such instances, a more specific subclass of either exception may be thrown that will give more detailed information.The
getRegistrarmethod returns an instance ofServiceRegistrarthat references the proxy to the lookup service sent in the unicast response.The
getGroupsmethod returns an array consisting of the names of the groups in which the lookup service referenced in the response is a member. The array returned by this method is nevernull, will contain nonullelements, or may be empty. Additionally, elements in the returned array may or may not be duplicated.DU.8 History
1 The terms "Java virtual machine" and "JVM" mean a virtual machine for the Java platform.
Version Change v1.0 Initial release of this specification. v2.0 New constructors added to accommodate configuration, along with supporting text.
Added section specifying theConstrainableLookupLocator.
Miscellaneous corrections.v3.0 Clarify ConstrainableLookupLocatorURL parsing, remove reference toLookupLocatortoString
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
| Spec Index | A Collection of Jini Technology Helper Utilities and Services Specifications |