public class LookupDiscovery extends Object implements DiscoveryManagement, DiscoveryGroupManagement
ServiceRegistrar
,
DiscoveryChangeListener
,
DiscoveryManagement
,
DiscoveryGroupManagement
,
DiscoveryListener
,
DiscoveryEvent
,
DiscoveryPermission
Configuring LookupDiscovery
This implementation of
LookupDiscovery
supports the
following configuration entries; where each configuration entry name
is associated with the component name
net.jini.discovery.LookupDiscovery
. Note that the
configuration entries specified here are specific to this implementation
of LookupDiscovery
. Unless otherwise stated, each entry
is retrieved from the configuration only once per instance of this
utility, where each such retrieval is performed in the constructor.
• |
discoveryConstraints
| |
---|---|---|
  | Type: | MethodConstraints
|
  | Default: | null
|
  | Description: | Constraints to apply to the multicast request, multicast
announcement and unicast discovery protocols. Multicast
request constraints are derived by calling
getConstraints on the
obtained MethodConstraints instance with a
Method object for the
multicastRequest method; multicast announcement and unicast
discovery constraints are similarly obtained by passing
Method objects for the
multicastAnnouncement and
unicastDiscovery methods, respectively. A null
value is interpreted as mapping all methods to empty
constraints.
This class supports the use of the following constraint types to control discovery behavior:
|
• |
finalMulticastRequestInterval
| |
---|---|---|
  | Type: | long
|
  | Default: | 2*60*1000 (2 minutes)
|
  | Description: | With respect to when this utility is started, as well
as when the set of groups to discover is changed, this
entry represents the number of milliseconds to wait
after sending the n-th multicast request where n is
equal to the value of the
multicastRequestMax entry of this component.
|
• |
initialMulticastRequestDelayRange
| |
---|---|---|
  | Type: | long
|
  | Default: | 0 milliseconds
|
  | Description: | With respect to when this utility is started, this entry controls
how long to wait before sending out the first multicast request.
If the value is positive, the first request will be delayed by a random
value between 0 and
initialMulticastRequestDelayRange
milliseconds. Subsequent request intervals are controlled by the
multicastRequestInterval entry. Note that this entry
only has effect when this utility is initialized. The first multicast
request is not delayed if the groups to discover are subsequently
changed.
|
• |
multicastAnnouncementInterval
| |
---|---|---|
  | Type: | long
|
  | Default: | 2*60*1000 (2 minutes)
|
  | Description: | A lookup service will send out multicast packets announcing its existence every N milliseconds; for some value of N. The value of this entry controls how often this utility examines the multicast announcements from previously discovered lookup services for liveness. |
• |
multicastInterfaceRetryInterval
| |
---|---|---|
  | Type: | int
|
  | Default: | 5*60*1000 (5 minutes)
|
  | Description: | With respect to any network interface this utility is configured
to use to send and receive multicast packets (see entry
multicastInterfaces ), if failure is encountered
upon the initial attempt to set the interface or join the
desired multicast group, this utility will retry the failed
interface every
multicastInterfaceRetryInterval milliseconds
until success is encountered.
|
• |
multicastInterfaces
| |
---|---|---|
  | Type: | NetworkInterface[]
|
  | Default: | new
NetworkInterface[]
  {all currently supported interfaces}
|
  | Description: | Each network interface that is represented by an element
in the array corresponding to this configuration item
will be used to send and receive multicast packets when
this utility is participating in the multicast discovery
process. When not set, this utility will use all of the
network interfaces in the system. When this entry is set
to a zero length array, multicast discovery is effectively
disabled. And when set to null ,
the interface to which the operating system defaults will be
used.
|
• |
multicastRequestHost
| |
---|---|---|
  | Type: | String
|
  | Default: |
|
  | Description: | This entry specifies the host name to include in multicast
requests if participating in version 2 of the
multicast request protocol. The name cannot be null .
|
• |
multicastRequestInterval
| |
---|---|---|
  | Type: | long
|
  | Default: | 5000
|
  | Description: | With respect to when this utility is started, as well as
when the set of groups to discover is changed, this entry
represents the number of milliseconds to wait after
sending the n-th multicast request, and before sending
the (n+1)-st request, where n is less than the value of the
multicastRequestMax
entry of this component.
|
• |
multicastRequestMax
| |
---|---|---|
  | Type: | int
|
  | Default: | 7
|
  | Description: | The maximum number multicast requests to send when this utility is started for the first time, and whenever the groups to discover is changed. |
• |
registrarPreparer
| |
---|---|---|
  | Type: | ProxyPreparer
|
  | Default: | new
|
  | Description: | Preparer for the proxies to the lookup services that are
discovered and used by this utility.
This preparer should perform all operations required to use a newly received proxy to a lookup service, which may including verifying trust in the proxy, granting permissions, and setting constraints.
The following methods of the
|
• |
taskManager
| |
---|---|---|
  | Type: | TaskManager
|
  | Default: | new
|
  | Description: | The object that pools and manages the various threads executed by this utility. The default manager creates a maximum of 15 threads, waits 15 seconds before removing idle threads, and uses a load factor of 1.0 when determining whether to create a new thread. This object should not be shared with other components in the application that employs this utility. |
• |
unicastDelayRange
| |
---|---|---|
  | Type: | long
|
  | Default: | 0 milliseconds
|
  | Description: | Controls how long this utility will wait before sending out
unicast discovery requests. If the value is positive, any
unicast discovery request that it initiates will be delayed by a
random value between 0 and
unicastDelayRange milliseconds. A typical use of this
entry would be to achieve a more uniform distribution of unicast
discovery requests to a lookup service, when a large number of
LookupDiscovery instances simultaneously receive multicast
announcements from the lookup service.
|
• |
wakeupManager
| |
---|---|---|
  | Type: | WakeupManager
|
  | Default: | new
|
  | Description: | Object used to schedule unicast discovery requests that are
delayed using the
unicastDelayRange
configuration entry of this utility. This entry is processed only
if unicastDelayRange has a positive value.
|
Logging
This implementation of
LookupDiscovery
uses the Logger
named net.jini.discovery.LookupDiscovery
to log information
at the following logging levels:
Level | Description |
---|---|
SEVERE |
when this utility is configured to use either the default network interface assigned by the system, or a specific list of network interfaces, if one of those interfaces is bad or not configured for multicast, or if a runtime exception occurs while either sending multicast requests, or while configuring one of the interfaces to receive multicast announcements, that fact will be logged at this level |
INFO |
when any exception other than an InterruptedIOException ,
InterruptedException or
UnsupportedConstraintException occurs in a thread or task
while attempting to marshal an outgoing multicast request
|
INFO |
when any exception other than an InterruptedIOException or
SocketTimeoutException occurs in a non-interrupted thread
while attempting to receive an incoming multicast packet
|
INFO |
when any exception other than an InterruptedIOException
occurs while attempting unicast discovery
|
INFO |
when this utility is configured to use either the default network interface assigned by the system, or a specific list of network interfaces, with respect to any such interface, if failure is encountered upon the initial attempt to set the interface or join the desired multicast group, the interface will be periodically retried, and successful recovery will be logged at this level |
INFO |
when any exception occurs while attempting to prepare a proxy |
CONFIG |
when the multicastInterfaces entry is configured to
be null , multicast packets will be sent and received
through the default network interface assigned by the system, and
that fact will be logged at this level
|
CONFIG |
when the multicastInterfaces entry is configured to
be a zero length array, multicast discovery will be disabled, and
and that fact will be logged at this level
|
CONFIG |
when the multicastInterfaces entry contains a specific
list of network interfaces, multicast packets will be sent and
received through only the network interfaces contained in that list,
and those interfaces will be logged at this level
|
CONFIG |
when the multicastInterfaces entry is excluded from
the configuration, multicast packets will be sent and received
through all interfaces in the system, and those interfaces will
be logged at this level
|
FAILED |
when an UnknownHostException occurs while determining
the multicastRequestHost , but the caller does not have
permissions to retrieve the local host name. The original
UnknownHostException with the host name information
is logged
|
HANDLED |
when this utility is configured to use all network interfaces enabled in the system, if one of those interfaces is bad or not configured for multicast, or if a runtime exception occurs while either sending multicast requests, or while configuring one of the interfaces to receive multicast announcements, that fact will be logged at this level |
HANDLED |
when any exception occurs while attempting to unmarshal an incoming multicast announcement |
HANDLED |
when an UnsupportedConstraintException occurs while
marshalling an outgoing multicast request, indicating that the provider
that threw the exception will not be used for encoding that request
|
HANDLED |
when an IOException occurs upon attempting to close the
socket after the thread that listens for multicast responses is asked
to terminate
|
HANDLED |
when an exception is handled during unicast discovery |
FINE |
when this utility is configured to use all network interfaces enabled in the system, with respect to any such interface, if failure is encountered upon the initial attempt to set the interface or join the desired multicast group, the interface will be periodically retried, and successful recovery will be logged at this level |
FINEST |
whenever any thread or task is started |
FINEST |
whenever any thread (except the Notifier thread) or task
completes successfully
|
FINEST |
whenever a discovered, discarded, or changed event is sent |
FINEST |
whenever a proxy is prepared |
Modifier and Type | Field and Description |
---|---|
static String[] |
ALL_GROUPS
Convenience constant used to request that attempts be made to
discover all lookup services that are within range, and which
belong to any group.
|
static String[] |
NO_GROUPS
Convenience constant used to request that discovery by group
membership be halted (or not started, if the group discovery
mechanism is simply being instantiated).
|
Constructor and Description |
---|
LookupDiscovery(String[] groups)
Construct a new lookup discovery object, set to discover the
given set of groups.
|
LookupDiscovery(String[] groups,
Configuration config)
Constructs a new lookup discovery object, set to discover the
given set of groups, and having the given
Configuration . |
Modifier and Type | Method and Description |
---|---|
void |
addDiscoveryListener(DiscoveryListener l)
Register a listener as interested in receiving DiscoveryEvent
notifications.
|
void |
addGroups(String[] newGroups)
Add a set of groups to the set to be discovered.
|
void |
discard(ServiceRegistrar reg)
Discard a registrar from the set of registrars already
discovered.
|
String[] |
getGroups()
Return the set of group names this LookupDiscovery instance is
trying to discover.
|
ServiceRegistrar[] |
getRegistrars()
Returns an array of instances of
ServiceRegistrar , each
corresponding to a proxy to one of the currently discovered lookup
services. |
void |
removeDiscoveryListener(DiscoveryListener l)
Indicate that a listener is no longer interested in receiving
DiscoveryEvent notifications.
|
void |
removeGroups(String[] oldGroups)
Remove a set of groups from the set to be discovered.
|
void |
setGroups(String[] newGroups)
Change the set of groups to be discovered to correspond to the
given set.
|
void |
terminate()
Terminate the discovery process.
|
public static final String[] ALL_GROUPS
DiscoveryGroupManagement
for compatibility with
earlier releases.public static final String[] NO_GROUPS
DiscoveryGroupManagement
for
compatibility with earlier releases.public LookupDiscovery(String[] groups) throws IOException
groups
- the set of group names to discover (null for no
set, empty for no discovery)NullPointerException
- input array contains at least
one null elementIOException
- an exception occurred in starting discoveryNO_GROUPS
,
ALL_GROUPS
,
setGroups(java.lang.String[])
,
DiscoveryPermission
public LookupDiscovery(String[] groups, Configuration config) throws IOException, ConfigurationException
Configuration
.
The set of groups to discover is represented as an array of
strings. This array may be empty, which is taken as the empty
set, and discovery is not performed. The reference passed in
may be null
, which is taken as no set, and in which
case discovery of all reachable lookup services is performed.
Otherwise, the array contains the names of groups to discover.
The caller must have DiscoveryPermission
for each
group (or for all groups, if the array is null
).
groups
- the set of group names to discover (null for no
set, empty for no discovery)config
- an instance of Configuration
, used to
obtain the objects needed to configure the current
instance of this classNullPointerException
- input array contains at least
one null
element or null
is input
for the configurationIOException
- an exception occurred in starting discoveryConfigurationException
- indicates an exception
occurred while retrieving an item from the given
Configuration
NO_GROUPS
,
ALL_GROUPS
,
setGroups(java.lang.String[])
,
DiscoveryPermission
,
Configuration
,
ConfigurationException
public void addDiscoveryListener(DiscoveryListener l)
addDiscoveryListener
in interface DiscoveryManagement
l
- the listener to registerNullPointerException
- this exception occurs when
null
is input to the listener parameter
l
.IllegalStateException
- this exception occurs when
this method is called after the terminate
method has been called.DiscoveryEvent
,
removeDiscoveryListener(net.jini.discovery.DiscoveryListener)
public void removeDiscoveryListener(DiscoveryListener l)
removeDiscoveryListener
in interface DiscoveryManagement
l
- the listener to unregisterIllegalStateException
- this exception occurs when
this method is called after the terminate
method has been called.addDiscoveryListener(net.jini.discovery.DiscoveryListener)
public ServiceRegistrar[] getRegistrars()
ServiceRegistrar
, each
corresponding to a proxy to one of the currently discovered lookup
services. For each invocation of this method, a new array is returned.getRegistrars
in interface DiscoveryManagement
ServiceRegistrar
, each
corresponding to a proxy to one of the currently discovered
lookup servicesIllegalStateException
- this exception occurs when
this method is called after the terminate
method has been called.ServiceRegistrar
,
DiscoveryManagement.removeDiscoveryListener(net.jini.discovery.DiscoveryListener)
public void discard(ServiceRegistrar reg)
If the registrar has been discovered using this LookupDiscovery object, each listener registered with this object will have its discarded method called with the given registrar as parameter.
discard
in interface DiscoveryManagement
reg
- the registrar to discardIllegalStateException
- this exception occurs when
this method is called after the terminate
method has been called.DiscoveryListener.discarded(net.jini.discovery.DiscoveryEvent)
public void terminate()
terminate
in interface DiscoveryManagement
public String[] getGroups()
getGroups
in interface DiscoveryGroupManagement
IllegalStateException
- this exception occurs when
this method is called after the terminate
method has been called.NO_GROUPS
,
ALL_GROUPS
,
setGroups(java.lang.String[])
public void addGroups(String[] newGroups) throws IOException
addGroups
in interface DiscoveryGroupManagement
newGroups
- the groups to addIOException
- the multicast request protocol failed
to startIllegalStateException
- this exception occurs when
this method is called after the terminate
method has been called.UnsupportedOperationException
- there is no set of
groups to add toDiscoveryPermission
public void setGroups(String[] newGroups) throws IOException
setGroups
in interface DiscoveryGroupManagement
newGroups
- the new set of groups to discover (null for
all, empty array for no discovery)IOException
- an exception occurred when starting
multicast discoveryIllegalStateException
- this exception occurs when
this method is called after the terminate
method has been called.LookupDiscovery(java.lang.String[], net.jini.config.Configuration)
,
ALL_GROUPS
,
NO_GROUPS
,
DiscoveryPermission
,
getGroups()
public void removeGroups(String[] oldGroups)
removeGroups
in interface DiscoveryGroupManagement
oldGroups
- groups to removeIllegalStateException
- this exception occurs when
this method is called after the terminate
method has been called.UnsupportedOperationException
- there is no set of
groups from which to removeDiscoveryGroupManagement.addGroups(java.lang.String[])
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.