public final class LookupDiscoveryManager extends Object implements DiscoveryManagement, DiscoveryGroupManagement, DiscoveryLocatorManagement
LookupLocator
objects, and DiscoveryListener
objects, clients and services can employ this class to provide those
facilities on their behalf.
DiscoveryManagement
,
DiscoveryGroupManagement
,
DiscoveryLocatorManagement
Configuring LookupDiscoveryManager
Currently, there are no configuration entries directly supported by this implementation of
LookupDiscoveryManager
. All configuration
entries affecting the operation of this utility are retrieved by either
the LookupDiscovery
utility, or the LookupLocatorDiscovery
utility. Please refer to the documentation provided with those utilities
when configuring the behavior of LookupDiscoveryManager
.
Logging
With one exception, all logging information produced when using this utility is controlled by the loggers supported by the following utilities:
This implementation of LookupDiscoveryManager
uses the Logger
named net.jini.discovery.LookupDiscoveryManager
to log information
at the following logging levels:
Level | Description |
---|---|
HANDLED |
when this utility asynchronously invokes a DiscoveryListener
implementation and that listener throws and unchecked exception. If the listener throws
in a synchronous path (namely, via addDiscoveryListener(DiscoveryListener) ) then
the exception is not trapped and will instead throw back to the caller.
|
Modifier and Type | Field and Description |
---|---|
static int |
FROM_GROUP
Constant that indicates the discovery mechanism is group discovery
|
static int |
FROM_LOCATOR
Constant that indicates the discovery mechanism is locator discovery
|
ALL_GROUPS, NO_GROUPS
Constructor and Description |
---|
LookupDiscoveryManager(String[] groups,
LookupLocator[] locators,
DiscoveryListener listener)
Constructs an instance of this class that will organize and manage
all discovery-related activities on behalf of the client or service
that instantiates this class.
|
LookupDiscoveryManager(String[] groups,
LookupLocator[] locators,
DiscoveryListener listener,
Configuration config)
Constructs an instance of this class, using the given
Configuration , that will organize and manage all
discovery-related activities on behalf of the client or service
that instantiates this class. |
Modifier and Type | Method and Description |
---|---|
void |
addDiscoveryListener(DiscoveryListener listener)
Adds an instance of
DiscoveryListener to the set of
objects listening for discovery events. |
void |
addGroups(String[] groups)
Adds a set of group names to the managed set of groups.
|
void |
addLocators(LookupLocator[] locators)
Adds a set of locators to the managed set of locators.
|
void |
discard(ServiceRegistrar proxy)
Removes an instance of
ServiceRegistrar from the
managed set of lookup services, making the corresponding lookup
service eligible for re-discovery. |
int |
getFrom(ServiceRegistrar proxy)
Return where the proxy came from.
|
String[] |
getGroups()
Returns an array consisting of the elements of the managed set
of groups; that is, the names of the groups whose members are the
lookup services to discover.
|
LookupLocator[] |
getLocators()
Returns an array consisting of the elements of the managed set
of locators; that is, instances of
LookupLocator in
which each instance corresponds to a specific lookup service 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 listener)
Removes a listener from the set of objects listening for discovery
events.
|
void |
removeGroups(String[] groups)
Deletes a set of group names from the managed set of groups.
|
void |
removeLocators(LookupLocator[] locators)
Deletes a set of locators from the managed set of locators, and discards
any already-discovered lookup service that corresponds to a deleted
locator.
|
void |
setGroups(String[] groups)
Replaces all of the group names in the managed set with names from
a new set.
|
void |
setLocators(LookupLocator[] locators)
Replaces all of the locators in the managed set with locators from
a new set, and discards any already-discovered lookup service that
corresponds to a locator that is removed from the managed set
as a result of an invocation of this method.
|
void |
terminate()
Terminates all threads, ending all discovery processing being
performed by the current instance of this class.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addDiscoveryListener, discard, getRegistrars, removeDiscoveryListener, terminate
addGroups, getGroups, removeGroups, setGroups
addLocators, getLocators, removeLocators, setLocators
public static final int FROM_GROUP
public static final int FROM_LOCATOR
public LookupDiscoveryManager(String[] groups, LookupLocator[] locators, DiscoveryListener listener) throws IOException
If null
(DiscoveryGroupManagement.ALL_GROUPS
)
is input to the groups
parameter, then attempts will be
made via group discovery to discover all lookup services located within
range of the entity that constructs this class. If the empty array
(DiscoveryGroupManagement.NO_GROUPS
) is input to that
parameter, no group discovery will be performed until the set of
groups to discover is populated.
If an empty array or a null
reference is input to the
locators
parameter, no locator discovery will be performed
until the set of locators to discover is populated.
groups
- String
array, none of whose elements may
be null
, consisting of the names of the
groups whose members are lookup services the client
or service wishes to discover.locators
- array of instances of LookupLocator
, none
of whose elements may be null
, and in
which each element corresponds to a specific lookup
service the client or service wishes to discover via
locator discovery.listener
- a reference to DiscoveryListener
object
that will be notified when a targeted lookup service
is discovered or discarded.IOException
- because construction of this class may
initiate the discovery process, which can throw an
IOException
when socket allocation occurs.NullPointerException
- this exception occurs when
either one or more of the elements of the groups
parameter is null
, or one or more elements of
the locators
parameter is null.LookupLocator
,
DiscoveryListener
public LookupDiscoveryManager(String[] groups, LookupLocator[] locators, DiscoveryListener listener, Configuration config) throws IOException, ConfigurationException
Configuration
, that will organize and manage all
discovery-related activities on behalf of the client or service
that instantiates this class.
If null
(DiscoveryGroupManagement.ALL_GROUPS
)
is input to the groups
parameter, then attempts will be
made via group discovery to discover all lookup services located within
range of the entity that constructs this class. If the empty array
(DiscoveryGroupManagement.NO_GROUPS
) is input to that
parameter, no group discovery will be performed until the set of
groups to discover is populated.
If an empty array or a null
reference is input to the
locators
parameter, no locator discovery will be performed
until the set of locators to discover is populated.
groups
- String
array, none of whose elements may
be null
, consisting of the names of the
groups whose members are lookup services the client
or service wishes to discover.locators
- array of instances of LookupLocator
, none
of whose elements may be null
, and in
which each element corresponds to a specific lookup
service the client or service wishes to discover via
locator discovery.listener
- a reference to DiscoveryListener
object
that will be notified when a targeted lookup service
is discovered or discarded.config
- an instance of Configuration
, used to
obtain the objects needed to configure the current
instance of this classIOException
- because construction of this class may
initiate the discovery process, which can throw an
IOException
when socket allocation occurs.ConfigurationException
- indicates an exception
occurred while retrieving an item from the given
Configuration
NullPointerException
- this exception occurs when
either one or more of the elements of the groups
parameter is null
, or one or more elements of
the locators
parameter is null
, or
when null
is input for the configuration.LookupLocator
,
DiscoveryListener
,
Configuration
public LookupLocator[] getLocators()
LookupLocator
in
which each instance corresponds to a specific lookup service to
discover. The returned set will include both the set of
LookupLocator
s corresponding to lookup services
that have already been discovered as well as the set of those
that have not yet been discovered. If the managed set of locators
is empty, this method will return the empty array. This method
returns a new array upon each invocation.getLocators
in interface DiscoveryLocatorManagement
LookupLocator
array consisting of the elements
of the managed set of locatorsDiscoveryLocatorManagement.getLocators()
,
setLocators(net.jini.core.discovery.LookupLocator[])
public void addLocators(LookupLocator[] locators)
LookupLocator.equals
method) elements already in the managed set will be ignored. If the
empty array is input, the managed set of locators will not change.addLocators
in interface DiscoveryLocatorManagement
locators
- LookupLocator
array consisting of the
locators to add to the managed set.UnsupportedOperationException
- this exception
occurs when there is no managed set of locators to augment.
That is, the current managed set of locators is
null
.NullPointerException
- this exception occurs when
either null
is input to the locators
parameter, or one or more of the elements of the
locators
parameter is null
.DiscoveryLocatorManagement.addLocators(net.jini.core.discovery.LookupLocator[])
,
removeLocators(net.jini.core.discovery.LookupLocator[])
public void removeLocators(LookupLocator[] locators)
If the empty array is input, this method takes no action.
removeLocators
in interface DiscoveryLocatorManagement
locators
- LookupLocator
array consisting of the
locators that will be removed from the managed set.UnsupportedOperationException
- this exception
occurs when there is no managed set of locators from which
remove elements.NullPointerException
- this exception occurs when
null
is input to the locators
parameter.DiscoveryLocatorManagement.removeLocators(net.jini.core.discovery.LookupLocator[])
,
addLocators(net.jini.core.discovery.LookupLocator[])
public void setLocators(LookupLocator[] locators)
If the empty array is input, locator discovery will cease until this
method is invoked with an input parameter that is non-null
and non-empty.
setLocators
in interface DiscoveryLocatorManagement
locators
- LookupLocator
array consisting of the
locators that will replace the current locators in the
managed set.NullPointerException
- this exception occurs when
null
is input to the locators
parameter.DiscoveryLocatorManagement.setLocators(net.jini.core.discovery.LookupLocator[])
,
getLocators()
public String[] getGroups()
getGroups
in interface DiscoveryGroupManagement
String
array consisting of the elements of the
managed set of groupsDiscoveryGroupManagement.getGroups()
,
setGroups(java.lang.String[])
public void addGroups(String[] groups) throws IOException
DiscoveryGroupManagement.NO_GROUPS
) is input, the
managed set of groups will not change.
Note that any entity that invokes this method must have
DiscoveryPermission
on each of the groups in the
new set, otherwise a SecurityException
will be
propagated through this method.addGroups
in interface DiscoveryGroupManagement
groups
- String
array consisting of the group names
to add to the managed set.IOException
- because an invocation of this method may
result in the re-initiation of the discovery process, which can
throw an IOException
when socket allocation occurs.UnsupportedOperationException
- this exception
occurs when there is no managed set of groups to augment.
That is, the current managed set of groups is null
.
If the managed set of groups is null
, all groups
are being discovered; thus, requesting that a set of groups be
added to the set of all groups makes no sense.NullPointerException
- this exception occurs when
either null
is input to the groups
parameter, or one or more of the elements of the
groups
parameter is null
. If a
null
is input, then the entity is effectively
requesting that "all groups" be added to the current managed
set of groups; which is not allowed. (Note that if the entity
wishes to change the managed set of groups from a finite set
of names to "all groups", the setGroups
method
should be invoked with null
input.)DiscoveryGroupManagement.addGroups(java.lang.String[])
,
removeGroups(java.lang.String[])
public void removeGroups(String[] groups)
DiscoveryGroupManagement.NO_GROUPS
) is input,
this method takes no action.removeGroups
in interface DiscoveryGroupManagement
groups
- String
array consisting of the group names
that will be removed from the managed set.UnsupportedOperationException
- this exception
occurs when there is no managed set of groups from which to
remove elements.NullPointerException
- this exception occurs when
null
is input to the groups
parameter.DiscoveryGroupManagement.removeGroups(java.lang.String[])
,
addGroups(java.lang.String[])
public void setGroups(String[] groups) throws IOException
If null (DiscoveryGroupManagement.ALL_GROUPS
) is input
to this method, then attempts will be made to discover all (as yet)
undiscovered lookup services that are within range, and which
are members of any group. If the empty array
(DiscoveryGroupManagement.NO_GROUPS
) is input, then
group discovery will cease until this method is invoked with an
input parameter that is non-null
and non-empty.
Note that any entity that invokes this method must have
DiscoveryPermission
on each of the groups in the
new set, otherwise a SecurityException
will be
propagated through this method.
setGroups
in interface DiscoveryGroupManagement
groups
- String
array consisting of the group
names that will replace the current names in the
managed set.IOException
- because an invocation of this method may
result in the re-initiation of the discovery process, which can
throw an IOException
when socket allocation occurs.DiscoveryGroupManagement.setGroups(java.lang.String[])
,
getGroups()
public void addDiscoveryListener(DiscoveryListener listener)
DiscoveryListener
to the set of
objects listening for discovery events. Once the 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.
The listener methods may throw Error or RuntimeException subclasses. They will normally be reported only through the log. If the discovered method throws Throwable T during the initial discovery of existing services then this method will also throw T.
If null
is input, this method takes no action. If the
listener input to this method duplicates (using the equals
method) another element in the current set of listeners, no action
is taken.
addDiscoveryListener
in interface DiscoveryManagement
listener
- an instance of DiscoveryListener
corresponding to the listener to add to the set of
listeners.NullPointerException
- this exception occurs when
null
is input to the listener
parameter.DiscoveryListener
,
DiscoveryManagement.addDiscoveryListener(net.jini.discovery.DiscoveryListener)
,
removeDiscoveryListener(net.jini.discovery.DiscoveryListener)
public void removeDiscoveryListener(DiscoveryListener listener)
removeDiscoveryListener
in interface DiscoveryManagement
listener
- an instance of DiscoveryListener
corresponding to the listener to remove from the set
of listeners.DiscoveryListener
,
DiscoveryManagement.removeDiscoveryListener(net.jini.discovery.DiscoveryListener)
,
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 servicesServiceRegistrar
,
DiscoveryManagement.removeDiscoveryListener(net.jini.discovery.DiscoveryListener)
public void discard(ServiceRegistrar proxy)
ServiceRegistrar
from the
managed set of lookup services, making the corresponding lookup
service eligible for re-discovery. This method takes no action if
the parameter input to this method is null
, or if it
does not match (using equals
) any of the elements in
the managed set.discard
in interface DiscoveryManagement
proxy
- the instance of ServiceRegistrar
to discard
from the managed set of lookup servicesServiceRegistrar
,
DiscoveryManagement.discard(net.jini.core.lookup.ServiceRegistrar)
public void terminate()
After this method has been invoked, no new lookup services will be discovered, and the effect of any new operations performed on the current instance of this class are undefined.
terminate
in interface DiscoveryManagement
DiscoveryManagement.terminate()
public int getFrom(ServiceRegistrar proxy)
An int restricted to the values 0, 1, 2, and 3. Each value represents a bit (or set of bits) that indicates the mechanism (group discovery, locator discovery, or both) through which the registrar referenced by the current instance of this class (proxy) has currently been (or not been) discovered.
That is, if from
proxy
- a ServiceRegistrar objectint
from, indicating whether the proxy
was obtained through group or locator discovery.Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.