abstract class AbstractLookupDiscoveryManager extends Object implements DiscoveryManagement, DiscoveryGroupManagement, DiscoveryLocatorManagement
Modifier and Type | Class and Description |
---|---|
private class |
AbstractLookupDiscoveryManager.GroupDiscoveryListener
Class that defines the listener that is registered with the
LookupDiscovery that performs group discovery
on behalf of this LookupDiscoveryManager . |
(package private) class |
AbstractLookupDiscoveryManager.LocatorDiscoveryListener
Class that defines the listener that is registered with the
LookupLocatorDiscovery that performs locator discovery
on behalf of this LookupDiscoveryManager . |
(package private) class |
AbstractLookupDiscoveryManager.ProxyReg
Wrapper class in which each instance corresponds to a lookup service
that has been discovered via either group discovery, locator discovery,
or both.
|
Modifier and Type | Field and Description |
---|---|
private static int |
CHANGED |
private static String |
COMPONENT_NAME |
private static int |
DISCARDED |
private static int |
DISCOVERED
Constants used to indicate the type of event to send
|
private List<AbstractLookupDiscoveryManager.ProxyReg> |
discoveredSet
Contains instances of the
ProxyReg wrapper class. |
private java.util.concurrent.locks.Lock |
discoveredSetAddLock |
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
|
private DiscoveryListener |
groupListener
The listener that receives discovered, discarded, and changed events
from the
LookupDiscovery utility that manages group
discovery on behalf of this LookupDiscoveryManager . |
private Set<DiscoveryListener> |
listeners
Contains the instances of
DiscoveryListener that clients
register with the LookupDiscoveryManager . |
private LookupLocatorDiscovery |
locatorDisc
The
LookupLocatorDiscovery utility used to manage the
locator discovery mechanism. |
private DiscoveryListener |
locatorListener
The listener that receives discovered and discarded events from the
LookupLocatorDiscovery utility that manages locator
discovery on behalf of this LookupDiscoveryManager . |
private static Logger |
logger |
private LookupDiscovery |
lookupDisc
The
LookupDiscovery utility used to manage the group
discovery mechanism. |
ALL_GROUPS, NO_GROUPS
Constructor and Description |
---|
AbstractLookupDiscoveryManager(DiscoveryListener listener,
LookupDiscovery lookup,
LookupLocatorDiscovery locator)
Constructs an instance of 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.
|
(package private) void |
beginDiscovery()
Initiates the discovery process for
the given set of groups and the given set of locators.
|
private Map<ServiceRegistrar,String[]> |
deepCopy(Map<ServiceRegistrar,String[]> groupsMap)
Creates and returns a deep copy of the input parameter.
|
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. |
private AbstractLookupDiscoveryManager.ProxyReg |
findReg(ServiceRegistrar proxy) |
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. |
private static boolean |
groupSetsEqual(String[] groupSet0,
String[] groupSet1)
Determines if two sets of registrar member groups have identical
contents.
|
private void |
notifyListener(DiscoveryListener l,
Map<ServiceRegistrar,String[]> groupsMap,
int eventType)
Notify a specific listener for a discovery event.
|
private void |
notifyListener(Map<ServiceRegistrar,String[]> groupsMap,
int eventType)
Notify all listeners for a discovery event.
|
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.
|
private boolean |
stillInterested(String[] regGroups,
String[] desiredGroups)
Determines if at least one member group of a given registrar is
contained in the given set of desired groups.
|
void |
terminate()
Terminates all threads, ending all discovery processing being
performed by the current instance of this class.
|
private static final String COMPONENT_NAME
private static final Logger logger
public static final int FROM_GROUP
public static final int FROM_LOCATOR
private static final int DISCOVERED
private static final int DISCARDED
private static final int CHANGED
private final List<AbstractLookupDiscoveryManager.ProxyReg> discoveredSet
ProxyReg
wrapper class. This
set acts as what is referred to as the "managed set of registrars"
or simply, the "managed set". When a registrar is discovered, that
registrar and its associated "discovered state" is wrapped in an
instance of ProxyReg
, which is then placed in this set,
which is managed by this LookupDiscoveryManager
. As
registrars are discovered and discarded, and as the discovered state
of those registrars is modified, the contents of this set are modified
appropriately.
Note that this set is shared across threads; therefore, when
accessing or modifying the contents of this set, the appropriate
synchronization must be applied.
A list is used instead of a Set, because hashCode and equals are
remote calls. However we need to avoid duplicates and since this
requires list traversal using remote method calls during add,
we need a lock to prevent concurrent additions. Removal while an
add operation is in progress would be acceptable, since the worst
case scenario is the iterator snapshot would contain the removed
ProxyReg.private final java.util.concurrent.locks.Lock discoveredSetAddLock
private final Set<DiscoveryListener> listeners
DiscoveryListener
that clients
register with the LookupDiscoveryManager
. The elements
of this set receive discovered events, discarded events and, when
appropriate, changed events.private final LookupDiscovery lookupDisc
LookupDiscovery
utility used to manage the group
discovery mechanism. Note that this object cannot be accessed outside
of this LookupDiscoveryManager
.private final DiscoveryListener groupListener
LookupDiscovery
utility that manages group
discovery on behalf of this LookupDiscoveryManager
.private final LookupLocatorDiscovery locatorDisc
LookupLocatorDiscovery
utility used to manage the
locator discovery mechanism. Note that this object cannot be accessed
outside of this LookupDiscoveryManager
.private final DiscoveryListener locatorListener
LookupLocatorDiscovery
utility that manages locator
discovery on behalf of this LookupDiscoveryManager
.AbstractLookupDiscoveryManager(DiscoveryListener listener, LookupDiscovery lookup, LookupLocatorDiscovery locator)
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.private AbstractLookupDiscoveryManager.ProxyReg findReg(ServiceRegistrar proxy)
private void notifyListener(Map<ServiceRegistrar,String[]> groupsMap, int eventType)
groupsMap
- mapping from the elements of the registrars of this
event to the member groups in which each registrar is
a member.eventType
- The type of event.private void notifyListener(DiscoveryListener l, Map<ServiceRegistrar,String[]> groupsMap, int eventType)
l
- The listener to notify.groupsMap
- mapping from the elements of the registrars of this
event to the member groups in which each registrar is
a member.eventType
- The type of the event.private static boolean groupSetsEqual(String[] groupSet0, String[] groupSet1)
groupSet0
- String
array containing the group
names from the first set used in the comparisongroupSet1
- String
array containing the group
names from the second set used in the comparisontrue
if the contents of each set is identical;
false
otherwiseprivate boolean stillInterested(String[] regGroups, String[] desiredGroups)
regGroups
- String
array containing the member
groups of a given registrar (will never be null)desiredGroups
- String
array containing the groups
to discover (can be null - ALL_GROUPS)true
if at least one element of regGroups is
contained in desiredGroups; false
otherwiseprivate Map<ServiceRegistrar,String[]> deepCopy(Map<ServiceRegistrar,String[]> groupsMap)
groupsMap
- mapping from a set of registrars to the member groups
of each registrarvoid beginDiscovery()
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.