You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by jc...@apache.org on 2010/09/06 19:40:23 UTC
svn commit: r993107 - in /incubator/river/jtsk/trunk:
qa/src/com/sun/jini/qa/harness/ qa/src/com/sun/jini/test/share/reggie/
src/com/sun/jini/mercury/ src/com/sun/jini/reggie/ src/net/jini/discovery/
src/net/jini/lookup/
Author: jcosters
Date: Mon Sep 6 17:40:22 2010
New Revision: 993107
URL: http://svn.apache.org/viewvc?rev=993107&view=rev
Log:
backout some more recent changes ...
Modified:
incubator/river/jtsk/trunk/qa/src/com/sun/jini/qa/harness/RunningServiceAdmin.java
incubator/river/jtsk/trunk/qa/src/com/sun/jini/test/share/reggie/RegistrarImpl.java
incubator/river/jtsk/trunk/src/com/sun/jini/mercury/MailboxImpl.java
incubator/river/jtsk/trunk/src/com/sun/jini/reggie/RegistrarImpl.java
incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java
incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java
incubator/river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java
incubator/river/jtsk/trunk/src/net/jini/discovery/LookupUnmarshalException.java
incubator/river/jtsk/trunk/src/net/jini/lookup/JoinManager.java
Modified: incubator/river/jtsk/trunk/qa/src/com/sun/jini/qa/harness/RunningServiceAdmin.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/qa/src/com/sun/jini/qa/harness/RunningServiceAdmin.java?rev=993107&r1=993106&r2=993107&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/qa/src/com/sun/jini/qa/harness/RunningServiceAdmin.java (original)
+++ incubator/river/jtsk/trunk/qa/src/com/sun/jini/qa/harness/RunningServiceAdmin.java Mon Sep 6 17:40:22 2010
@@ -27,8 +27,6 @@ import java.util.logging.Level;
import java.util.NoSuchElementException;
// net.jini
-import java.util.logging.Logger;
-import net.jini.config.ConfigurationException;
import net.jini.core.lookup.ServiceRegistrar;
import net.jini.core.lookup.ServiceTemplate;
import net.jini.discovery.LookupDiscoveryManager;
@@ -139,10 +137,7 @@ public class RunningServiceAdmin extends
manager = new LookupDiscoveryManager(getGroups(),
getLocators(),
listener);
- } catch (ConfigurationException e) {
- throw new TestException("failed to create a LookupDiscoveryManager",
- e);
- } catch (IOException e) {
+ } catch (IOException e) {
throw new TestException("failed to create a LookupDiscoveryManager",
e);
}
Modified: incubator/river/jtsk/trunk/qa/src/com/sun/jini/test/share/reggie/RegistrarImpl.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/qa/src/com/sun/jini/test/share/reggie/RegistrarImpl.java?rev=993107&r1=993106&r2=993107&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/qa/src/com/sun/jini/test/share/reggie/RegistrarImpl.java (original)
+++ incubator/river/jtsk/trunk/qa/src/com/sun/jini/test/share/reggie/RegistrarImpl.java Mon Sep 6 17:40:22 2010
@@ -75,7 +75,6 @@ import net.jini.discovery.*;
import com.sun.jini.reliableLog.ReliableLog;
import com.sun.jini.reliableLog.LogException;
import com.sun.jini.reliableLog.LogHandler;
-import net.jini.config.ConfigurationException;
/**
* The server side of an implementation of the lookup service. Multiple
@@ -3937,15 +3936,10 @@ public class RegistrarImpl implements Re
}
}
log.snapshot();
- discoer = null;
- try {
discoer = new LookupDiscoveryManager(lookupGroups, lookupLocators,
null);
- } catch (ConfigurationException e) {
- throw new IOException("LookupDiscoveryManager constructor threw exeption", e);
- }
joiner = new JoinManager(proxy, lookupAttrs, myServiceID,
- (DiscoveryListenerManagement) discoer, null);
+ discoer, null);
/* start up all the daemon threads */
serviceExpirer.start();
eventExpirer.start();
Modified: incubator/river/jtsk/trunk/src/com/sun/jini/mercury/MailboxImpl.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/mercury/MailboxImpl.java?rev=993107&r1=993106&r2=993107&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/com/sun/jini/mercury/MailboxImpl.java (original)
+++ incubator/river/jtsk/trunk/src/com/sun/jini/mercury/MailboxImpl.java Mon Sep 6 17:40:22 2010
@@ -898,9 +898,9 @@ class MailboxImpl implements MailboxBack
// Get shorthand reference to the discovery manager
try {
lookupDiscMgr =
- (DiscoveryListenerManagement)Config.getNonNullEntry(config,
+ (DiscoveryManagement)Config.getNonNullEntry(config,
MERCURY, "discoveryManager",
- DiscoveryListenerManagement.class);
+ DiscoveryManagement.class);
if(lookupDiscMgr instanceof DiscoveryGroupManagement) {
// Verify proper initial state ---> NO_GROUPS
String[] groups =
Modified: incubator/river/jtsk/trunk/src/com/sun/jini/reggie/RegistrarImpl.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/reggie/RegistrarImpl.java?rev=993107&r1=993106&r2=993107&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/com/sun/jini/reggie/RegistrarImpl.java (original)
+++ incubator/river/jtsk/trunk/src/com/sun/jini/reggie/RegistrarImpl.java Mon Sep 6 17:40:22 2010
@@ -284,7 +284,7 @@ class RegistrarImpl implements Registrar
private long minEventExpiration = Long.MAX_VALUE;
/** Manager for discovering other lookup services */
- private DiscoveryListenerManagement discoer;
+ private DiscoveryManagement discoer;
/** Manager for joining other lookup services */
private JoinManager joiner;
/** Task manager for sending events and discovery responses */
@@ -4515,8 +4515,8 @@ class RegistrarImpl implements Registrar
new BasicMethodConstraints(InvocationConstraints.EMPTY);
}
try {
- discoer = (DiscoveryListenerManagement) config.getEntry(
- COMPONENT, "discoveryManager", DiscoveryListenerManagement.class);
+ discoer = (DiscoveryManagement) config.getEntry(
+ COMPONENT, "discoveryManager", DiscoveryManagement.class);
} catch (NoSuchEntryException e) {
discoer = new LookupDiscoveryManager(
DiscoveryGroupManagement.NO_GROUPS, null, null, config);
Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java?rev=993107&r1=993106&r2=993107&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java Mon Sep 6 17:40:22 2010
@@ -17,8 +17,6 @@
*/
package net.jini.discovery;
-import net.jini.lookup.StreamServiceRegistrarFacade;
-import net.jini.lookup.ServiceRegistrarFacade;
import com.sun.jini.config.Config;
import com.sun.jini.discovery.Discovery;
import com.sun.jini.discovery.DiscoveryConstraints;
@@ -74,10 +72,8 @@ import net.jini.constraint.BasicMethodCo
import net.jini.core.constraint.InvocationConstraints;
import net.jini.core.constraint.MethodConstraints;
import net.jini.core.discovery.LookupLocator;
-import net.jini.core.lookup.PortableServiceRegistrar;
import net.jini.core.lookup.ServiceID;
import net.jini.core.lookup.ServiceRegistrar;
-import net.jini.core.lookup.StreamServiceRegistrar;
import net.jini.io.UnsupportedConstraintException;
import net.jini.security.BasicProxyPreparer;
import net.jini.security.ProxyPreparer;
@@ -697,9 +693,7 @@ import net.jini.security.SecurityContext
* @see DiscoveryEvent
* @see DiscoveryPermission
*/
-public class LookupDiscovery implements DiscoveryManagement,
- RegistrarManagement,
- DiscoveryListenerManagement,
+public class LookupDiscovery implements DiscoveryManagement,
DiscoveryGroupManagement
{
/* Name of this component; used in config entry retrieval and the logger.*/
@@ -741,7 +735,7 @@ public class LookupDiscovery implements
/** The groups to discover. Empty set -- NO_GROUPS, null -- ALL_GROUPS */
private Set groups = null;
/** Map from ServiceID to UnicastResponse. */
- private Map<ServiceID,UnicastResponse> registrars = new HashMap<ServiceID,UnicastResponse>(11);
+ private Map registrars = new HashMap(11);
/**
* Set that takes one of the following:
* <p><ul>
@@ -953,7 +947,7 @@ public class LookupDiscovery implements
new String[]{"discovered",
"discarded",
"changed"}[task.eventType];
- PortableServiceRegistrar[] regs = e.getPRegistrars();
+ ServiceRegistrar[] regs = e.getRegistrars();
logger.finest(eType+" event -- "+regs.length
+" lookup(s)");
Map groupsMap = e.getGroups();
@@ -1486,13 +1480,13 @@ public class LookupDiscovery implements
}
public int hashCode() {
- return response.getPRegistrar().hashCode();
+ return response.getRegistrar().hashCode();
}
public boolean equals(Object obj) {
return obj instanceof CheckReachabilityMarker &&
- response.getPRegistrar().equals(
- ((CheckReachabilityMarker) obj).response.getPRegistrar());
+ response.getRegistrar().equals(
+ ((CheckReachabilityMarker) obj).response.getRegistrar());
}
}
@@ -1979,7 +1973,7 @@ public class LookupDiscovery implements
Iterator iter = registrars.values().iterator();
while (iter.hasNext()) {
UnicastResponse resp = (UnicastResponse)iter.next();
- groupsMap.put(resp.getPRegistrar(),resp.getGroups());
+ groupsMap.put(resp.getRegistrar(),resp.getGroups());
}
ArrayList list = new ArrayList(1);
list.add(l);
@@ -2035,91 +2029,13 @@ public class LookupDiscovery implements
Iterator iter = registrars.values().iterator();
ServiceRegistrar[] regs = new ServiceRegistrar[registrars.size()];
for (int i=0;iter.hasNext();i++) {
- PortableServiceRegistrar psr = ((UnicastResponse)iter.next()).getPRegistrar();
- if ( psr instanceof ServiceRegistrar){
- regs[i] = (ServiceRegistrar) psr;
- } else {
- regs[i] = new ServiceRegistrarFacade(psr);
- }
+ regs[i] = ((UnicastResponse)iter.next()).getRegistrar();
}
return regs;
}
}//end getRegistrars
/**
- * Returns an array of instances of <code>PortableServiceRegistrar</code>, each
- * corresponding to a proxy to one of the currently discovered lookup
- * services. For each invocation of this method, a new array is returned.
- *
- * @return array of instances of <code>ServiceRegistrar</code>, each
- * corresponding to a proxy to one of the currently discovered
- * lookup services
- *
- * @throws java.lang.IllegalStateException this exception occurs when
- * this method is called after the <code>terminate</code>
- * method has been called.
- *
- * @see net.jini.core.lookup.ServiceRegistrar
- * @see net.jini.discovery.DiscoveryManagement#removeDiscoveryListener
- */
- public PortableServiceRegistrar[] getPRegistrars() {
- synchronized (registrars) {
- if (terminated) {
- throw new IllegalStateException("discovery terminated");
- }
- if (registrars.isEmpty()) {
- return new PortableServiceRegistrar[0];
- }
- Iterator iter = registrars.values().iterator();
- PortableServiceRegistrar[] regs = new PortableServiceRegistrar[registrars.size()];
- for (int i=0;iter.hasNext();i++) {
- regs[i] = ((UnicastResponse)iter.next()).getPRegistrar();
- }
- return regs;
- }
- }//end getPRegistrars
-
-
-
- /**
- * Returns an array of instances of <code>StreamServiceRegistrar</code>, each
- * corresponding to a proxy to one of the currently discovered lookup
- * services. For each invocation of this method, a new array is returned.
- *
- * @return array of instances of <code>ServiceRegistrar</code>, each
- * corresponding to a proxy to one of the currently discovered
- * lookup services
- *
- * @throws java.lang.IllegalStateException this exception occurs when
- * this method is called after the <code>terminate</code>
- * method has been called.
- *
- * @see net.jini.core.lookup.ServiceRegistrar
- * @see net.jini.discovery.DiscoveryManagement#removeDiscoveryListener
- */
- public StreamServiceRegistrar[] getStreamRegistrars() {
- synchronized (registrars) {
- if (terminated) {
- throw new IllegalStateException("discovery terminated");
- }
- if (registrars.isEmpty()) {
- return new StreamServiceRegistrar[0];
- }
- Iterator iter = registrars.values().iterator();
- StreamServiceRegistrar[] regs = new StreamServiceRegistrar[registrars.size()];
- for (int i=0;iter.hasNext();i++) {
- PortableServiceRegistrar psr = ((UnicastResponse)iter.next()).getPRegistrar();
- if ( psr instanceof StreamServiceRegistrar){
- regs[i] = (StreamServiceRegistrar) psr;
- } else {
- regs[i] = new StreamServiceRegistrarFacade(psr);
- }
- }
- return regs;
- }
-
- }//end getRegistrars
- /**
* Discard a registrar from the set of registrars already
* discovered. This does not prevent that registrar from being
* rediscovered; it is intended to be used to clear unreachable
@@ -2135,9 +2051,9 @@ public class LookupDiscovery implements
* this method is called after the <code>terminate</code>
* method has been called.
*
- * @see DiscoveryListener2#discarded
+ * @see DiscoveryListener#discarded
*/
- public void discard(PortableServiceRegistrar reg) {
+ public void discard(ServiceRegistrar reg) {
synchronized (registrars) {
if (terminated) {
throw new IllegalStateException("discovery terminated");
@@ -2146,10 +2062,6 @@ public class LookupDiscovery implements
sendDiscarded(reg,null);
}//end sync
}//end discard
-
- public void discard(ServiceRegistrar proxy) {
- discard((PortableServiceRegistrar) proxy);
- }
/** Terminate the discovery process. */
public void terminate() {
@@ -2540,7 +2452,7 @@ public class LookupDiscovery implements
UnicastResponse resp2)
{
return resp1 != null && resp2 != null &&
- resp2.getPRegistrar().equals(resp1.getPRegistrar());
+ resp2.getRegistrar().equals(resp1.getRegistrar());
}//end registrarsEqual
/**
@@ -2680,9 +2592,9 @@ public class LookupDiscovery implements
* that object is not accessed by any other thread.
*/
try {
- final PortableServiceRegistrar srcReg = resp.getPRegistrar();
- PortableServiceRegistrar prepReg
- = (PortableServiceRegistrar)AccessController.doPrivileged
+ final ServiceRegistrar srcReg = resp.getRegistrar();
+ ServiceRegistrar prepReg
+ = (ServiceRegistrar)AccessController.doPrivileged
( securityContext.wrap( new PrivilegedExceptionAction() {
public Object run() throws RemoteException {
Object proxy = registrarPreparer.prepareProxy
@@ -2715,7 +2627,7 @@ public class LookupDiscovery implements
if(groupsOverlap(resp.getGroups()) &&
!registrarsEqual(resp,
(UnicastResponse) registrars.put
- (resp.getPRegistrar().getServiceID(), resp)))
+ (resp.getRegistrar().getServiceID(), resp)))
{
/* Time stamp the service ID and store its current sequence
* number. The first time stamp associated
@@ -2736,11 +2648,11 @@ public class LookupDiscovery implements
* cause the lookup to be discovered before the first
* announcement arrives.
*/
- regInfo.put(resp.getPRegistrar().getServiceID(),
+ regInfo.put(resp.getRegistrar().getServiceID(),
new AnnouncementInfo(System.currentTimeMillis(), -1));
if(!listeners.isEmpty()) {
addNotify((ArrayList)listeners.clone(),
- mapRegToGroups(resp.getPRegistrar(),
+ mapRegToGroups(resp.getRegistrar(),
resp.getGroups()),
DISCOVERED);
}//endif
@@ -2758,8 +2670,8 @@ public class LookupDiscovery implements
for(Iterator iter=registrars.values().iterator();iter.hasNext(); ){
UnicastResponse ent = (UnicastResponse)iter.next();
if(!groupsOverlap(ent.getGroups())) { // not interested anymore
- groupsMap.put(ent.getPRegistrar(),ent.getGroups());
- regInfo.remove(ent.getPRegistrar().getServiceID());
+ groupsMap.put(ent.getRegistrar(),ent.getGroups());
+ regInfo.remove(ent.getRegistrar().getServiceID());
iter.remove(); // remove (srvcID,response) mapping
}//endif
}//end loop
@@ -2897,7 +2809,7 @@ public class LookupDiscovery implements
* possible change)
*/
private void maybeSendEvent(UnicastResponse response, String[] newGroups) {
- PortableServiceRegistrar reg = response.getPRegistrar();
+ ServiceRegistrar reg = response.getRegistrar();
boolean getActual = true;
if(newGroups == null) { // newGroups null means get actual groups now
newGroups = getActualGroups(reg);
@@ -2958,7 +2870,7 @@ public class LookupDiscovery implements
* member groups of the <code>reg</code> parameter
* (just after a possible change)
*/
- private void notifyOnGroupChange(PortableServiceRegistrar reg,
+ private void notifyOnGroupChange(ServiceRegistrar reg,
String[] oldGroups,
String[] newGroups)
{
@@ -2983,7 +2895,7 @@ public class LookupDiscovery implements
* member groups of the registrar referenced by the
* <code>reg</code> parameter
*/
- private void sendDiscarded(PortableServiceRegistrar reg, String[] curGroups) {
+ private void sendDiscarded(ServiceRegistrar reg, String[] curGroups) {
ServiceID srvcID = reg.getServiceID();
if(curGroups == null) { // discard request is from external source
UnicastResponse resp = (UnicastResponse)registrars.get(srvcID);
@@ -3011,7 +2923,7 @@ public class LookupDiscovery implements
* member groups of the registrar referenced by the
* <code>reg</code> parameter
*/
- private void sendChanged(PortableServiceRegistrar reg, String[] curGroups) {
+ private void sendChanged(ServiceRegistrar reg, String[] curGroups) {
/* replace old groups with new; prevents repeated changed events */
UnicastResponse resp =
(UnicastResponse)registrars.get(reg.getServiceID());
@@ -3019,7 +2931,7 @@ public class LookupDiscovery implements
new UnicastResponse(resp.getHost(),
resp.getPort(),
curGroups,
- resp.getPRegistrar()));
+ resp.getRegistrar()));
if( !listeners.isEmpty() ) {
addNotify((ArrayList)listeners.clone(),
mapRegToGroups(reg,curGroups), CHANGED);
@@ -3061,7 +2973,7 @@ public class LookupDiscovery implements
* @return <code>String</code> array containing the current member groups
* of the registrar referenced by the <code>reg</code> parameter
*/
- private String[] getActualGroups(final PortableServiceRegistrar reg) {
+ private String[] getActualGroups(final ServiceRegistrar reg) {
/* The retrieval of the member groups of the given ServiceRegistrar
* is performed inside a doPrivileged block that restores the access
* control context that was in place when this utility was created.
@@ -3108,7 +3020,7 @@ public class LookupDiscovery implements
* @return <code>Map</code> instance containing a single mapping from
* a given registrar to its current member groups
*/
- private Map mapRegToGroups(PortableServiceRegistrar reg, String[] curGroups) {
+ private Map mapRegToGroups(ServiceRegistrar reg, String[] curGroups) {
HashMap groupsMap = new HashMap(1);
groupsMap.put(reg,curGroups);
return groupsMap;
Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java?rev=993107&r1=993106&r2=993107&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java Mon Sep 6 17:40:22 2010
@@ -18,22 +18,18 @@
package net.jini.discovery;
-import org.apache.river.api.util.Facade;
-import net.jini.lookup.ServiceRegistrarFacade;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.Set;
import net.jini.config.Configuration;
import net.jini.config.ConfigurationException;
import net.jini.config.EmptyConfiguration;
import net.jini.core.discovery.LookupLocator;
-import net.jini.core.lookup.PortableServiceRegistrar;
+import net.jini.core.lookup.ServiceRegistrar;
/**
* This class is a helper utility class that organizes and manages all
@@ -93,10 +89,7 @@ import net.jini.core.lookup.PortableServ
* @see net.jini.discovery.DiscoveryLocatorManagement
*
*/
-@SuppressWarnings("deprecation")
public class LookupDiscoveryManager implements DiscoveryManagement,
- RegistrarManagement,
- DiscoveryListenerManagement,
DiscoveryGroupManagement,
DiscoveryLocatorManagement
{
@@ -124,25 +117,23 @@ public class LookupDiscoveryManager impl
* accessing or modifying the contents of this set, the appropriate
* synchronization must be applied.
*/
- private final ArrayList<ProxyReg> discoveredSet =
- new ArrayList<ProxyReg>(300);
+ private final ArrayList discoveredSet = new ArrayList(1);
/** Contains the instances of <code>DiscoveryListener</code> that clients
* register with the <code>LookupDiscoveryManager</code>. The elements
* of this set receive discovered events, discarded events and, when
* appropriate, changed events.
*/
- private final ArrayList<DiscoveryListener> listeners =
- new ArrayList<DiscoveryListener>(300);
+ private final ArrayList listeners = new ArrayList(1);
/** The <code>LookupDiscovery</code> utility used to manage the group
* discovery mechanism. Note that this object cannot be accessed outside
* of this <code>LookupDiscoveryManager</code>.
*/
- private final LookupDiscovery lookupDisc;
+ private LookupDiscovery lookupDisc;
/** The listener that receives discovered, discarded, and changed events
* from the <code>LookupDiscovery</code> utility that manages group
* discovery on behalf of this <code>LookupDiscoveryManager</code>.
*/
- private final DiscoveryListener groupListener = new GroupDiscoveryListener();
+ private DiscoveryListener groupListener = new GroupDiscoveryListener();
/** The <code>LookupLocatorDiscovery</code> utility used to manage the
* locator discovery mechanism. Note that this object cannot be accessed
* outside of this <code>LookupDiscoveryManager</code>.
@@ -154,7 +145,6 @@ public class LookupDiscoveryManager impl
*/
private DiscoveryListener locatorListener = new LocatorDiscoveryListener();
-
/** Wrapper class in which each instance corresponds to a lookup service
* that has been discovered via either group discovery, locator discovery,
* or both.
@@ -166,9 +156,9 @@ public class LookupDiscoveryManager impl
*/
private final class ProxyReg {
/** The discovered registrar to be managed */
- private final PortableServiceRegistrar proxy;
+ public ServiceRegistrar proxy;
/** The groups to which the discovered registrar belongs */
- private volatile List<String> memberGroups;
+ public String[] memberGroups;
/** Special-purpose flag used in the discard process. This flag is
* only relevant to <code>LocatorDiscoveryListener.discarded</code>.
* This flag is set to <code>true</code> only when the method
@@ -209,7 +199,7 @@ public class LookupDiscoveryManager impl
* value of <code>true</code> in this flag is equivalent to a
* communication discard.
*/
- public volatile boolean commDiscard = false;
+ public boolean commDiscard = false;
/** Integer restricted to the values 0, 1, 2, and 3. Each value
* represents a bit (or set of bits) that, when set, indicates the
* mechanism (group discovery, locator discovery, or both) through
@@ -221,14 +211,14 @@ public class LookupDiscoveryManager impl
* = 2 (bit 1 set) ==> discovered by only locator discovery
* = 3 (bits 1&2 set) ==> discovered by both group and locator
*/
- private volatile int from;
+ private int from;
/** Indicates whether the registrar referenced by this class is
* currently in the process of being discarded. This flag is used to
* prevent access, or inadvertent modifications to, the discovered
* state of registrars that are in the process of being discarded,
* but which have not yet been removed from the managed set.
*/
- private volatile boolean bDiscarded = false;
+ private boolean bDiscarded = false;
/** Constructs an instance of this wrapper class.
*
* @param proxy reference to a registrar that has been newly
@@ -238,17 +228,9 @@ public class LookupDiscoveryManager impl
* @param from indicates the mechanism by which the registrar
* was discovered (group or locator discovery).
* The only values which are valid for this
- * parameter are FROM_GROUP or FROM_LOCATOR.
+ * parameter are FROM_GROUP or FROM_LOCATOR.
*/
-
-// public ProxyReg(ServiceRegistrar proxy,
-// String[] memberGroups,
-// int from)
-// {
-// this((PortableServiceRegistrar) proxy, memberGroups, from);
-// }
-
- public ProxyReg(PortableServiceRegistrar proxy,
+ public ProxyReg(ServiceRegistrar proxy,
String[] memberGroups,
int from)
{
@@ -261,19 +243,18 @@ public class LookupDiscoveryManager impl
+"FROM_GROUP or FROM_LOCATOR");
}//endif
this.proxy = proxy;
- this.memberGroups = new ArrayList<String>(memberGroups.length);
- this.memberGroups.addAll(Arrays.asList(memberGroups));
+ this.memberGroups = memberGroups;
this.from = from;
}//end constructor
public boolean equals(Object obj) {
if (obj instanceof ProxyReg){
- return getProxy().equals(((ProxyReg) obj).getProxy());
+ return proxy.equals(((ProxyReg)obj).proxy);
} else return false;
}//end equals
public int hashCode() {
- return getProxy().hashCode();
+ return proxy.hashCode();
}//end hashCode
/** Sets the appropriate bit in the 'from' variable to indicate the
@@ -319,7 +300,7 @@ public class LookupDiscoveryManager impl
* @return <code>int</code> representing either group discovery (1),
* or locator discovery (2), or both (3).
*/
- public int getFrom() {
+ public synchronized int getFrom() {
return this.from;
}//end getFrom
@@ -373,24 +354,25 @@ public class LookupDiscoveryManager impl
* which ultimately will result in the registrar being discarded
* from the <code>LookupLocatorDiscovery</code>.
*/
- public void discard() {
- bDiscarded = true;
- //end sync
+ public void discard() {
+ synchronized(this) {
+ bDiscarded = true;
+ }//end sync
/* Give group discovery priority to avoid race condition. When
* appropriate, locator discard will eventually occur as a result
* of the first group discard.
*/
if((from & FROM_GROUP) != 0) {
- lookupDisc.discard(getProxy());
+ lookupDisc.discard(proxy);
} else if((from & FROM_LOCATOR) != 0) {
- locatorDisc.discard(getProxy());
+ locatorDisc.discard(proxy);
}//endif
}//end discard
/** Accessor method that returns the value of the <code>boolean</code>
* variable <code>bDiscarded</code>.
*/
- public boolean isDiscarded() {
+ public synchronized boolean isDiscarded() {
return bDiscarded;
}
@@ -398,27 +380,19 @@ public class LookupDiscoveryManager impl
* containing the names of the groups to which the registrar
* referenced in this class belongs.
*/
- public String[] getMemberGroups() {
- String [] mg;
- List<String> thismg = memberGroups; // copy the reference
- mg = thismg.toArray(new String[thismg.size()]);
- return mg;
+ public synchronized String[] getMemberGroups() {
+ return memberGroups;
}//end getMemberGroups
/** Modifier method that changes the set of member groups - stored in
* this class and associated with the registrar referenced in this
* class - to the given set of member groups.
*/
- public void setMemberGroups(String[] newMemberGroups) {
- List<String> nmg = new ArrayList<String>(newMemberGroups.length);
- nmg.addAll(Arrays.asList(newMemberGroups));
- memberGroups = nmg; // change reference to new List of Member Groups
+ public synchronized void setMemberGroups(String[] newMemberGroups) {
+ memberGroups = newMemberGroups;
}//end setMemberGroups
-
- public PortableServiceRegistrar getProxy() {
- return proxy;
- }
}//end class ProxyReg
+
/** Class that defines the listener that is registered with the
* <code>LookupLocatorDiscovery</code> that performs locator discovery
* on behalf of this <code>LookupDiscoveryManager</code>.
@@ -442,7 +416,7 @@ public class LookupDiscoveryManager impl
* and send no event at all.
*/
public void discovered(DiscoveryEvent e) {
- PortableServiceRegistrar[] proxys = e.getPRegistrars();
+ ServiceRegistrar[] proxys = (ServiceRegistrar[])e.getRegistrars();
Map groupsMap = e.getGroups();
HashMap discoveredGroupsMap = new HashMap(proxys.length);
for(int i=0; i<proxys.length; i++) {
@@ -544,7 +518,7 @@ public class LookupDiscoveryManager impl
* </pre>
*/
public void discarded(DiscoveryEvent e) {
- PortableServiceRegistrar[] proxys = e.getPRegistrars();
+ ServiceRegistrar[] proxys = (ServiceRegistrar[])e.getRegistrars();
Map groupsMap = e.getGroups();
HashMap discardedGroupsMap = new HashMap(proxys.length);
for(int i=0; i<proxys.length; i++) {
@@ -552,10 +526,10 @@ public class LookupDiscoveryManager impl
ProxyReg reg = findReg(proxys[i]);
if(reg != null) {
String[] newGroups = (String[])groupsMap.get
- (reg.getProxy());
+ (reg.proxy);
if( removeDiscoveredSet(reg,FROM_LOCATOR) ) {
/* Locator discovery only, always send discarded */
- discardedGroupsMap.put(reg.getProxy(),newGroups);
+ discardedGroupsMap.put(reg.proxy,newGroups);
} else {//group and loc discovery
if( reg.commDiscard ) {//unreachable, send later
reg.discard();//discard from LookupDiscovery
@@ -629,7 +603,7 @@ public class LookupDiscoveryManager impl
* may simply update state and send no event at all.
*/
public void discovered(DiscoveryEvent e) {
- PortableServiceRegistrar[] proxys = e.getPRegistrars();
+ ServiceRegistrar[] proxys = (ServiceRegistrar[])e.getRegistrars();
Map groupsMap = e.getGroups();
HashMap discoveredGroupsMap = new HashMap(proxys.length);
HashMap changedGroupsMap = new HashMap(proxys.length);
@@ -646,12 +620,12 @@ public class LookupDiscoveryManager impl
} else {//previously discovered by group, by loc or by both
String[] oldGroups = reg.getMemberGroups();
String[] newGroups = (String[])groupsMap.get
- (reg.getProxy());
+ (reg.proxy);
if( groupSetsEqual(oldGroups,newGroups) ) {//by loc
reg.addFrom(FROM_GROUP);//send no event
} else {//by group or by both, send changed event
reg.setMemberGroups(newGroups);//update groups
- changedGroupsMap.put(reg.getProxy(),newGroups);
+ changedGroupsMap.put(reg.proxy,newGroups);
}//endif
}//endif
}//end sync(discoveredSet)
@@ -784,7 +758,7 @@ public class LookupDiscoveryManager impl
* </pre>
*/
public void discarded(DiscoveryEvent e) {
- PortableServiceRegistrar[] proxys = e.getPRegistrars();
+ ServiceRegistrar[] proxys = (ServiceRegistrar[])e.getRegistrars();
Map groupsMap = e.getGroups();
HashMap discardedGroupsMap = new HashMap(proxys.length);
HashMap changedGroupsMap = new HashMap(proxys.length);
@@ -793,17 +767,17 @@ public class LookupDiscoveryManager impl
ProxyReg reg = findReg(proxys[i]);
if(reg != null) {
String[] newGroups = (String[])groupsMap.get
- (reg.getProxy());
+ (reg.proxy);
if( removeDiscoveredSet(reg,FROM_GROUP) ) {
/* group discovery only, always send discarded */
- discardedGroupsMap.put(reg.getProxy(),newGroups);
+ discardedGroupsMap.put(reg.proxy,newGroups);
} else {//discovered by group and locator
String[] desiredGroups = lookupDisc.getGroups();
if( !stillInterested(newGroups,desiredGroups) ) {
String[] oldGroups = reg.getMemberGroups();
if( !groupSetsEqual(oldGroups,newGroups) ) {
reg.setMemberGroups(newGroups);
- changedGroupsMap.put(reg.getProxy(),newGroups);
+ changedGroupsMap.put(reg.proxy,newGroups);
}//endif(!groupSetsEqual ==> groups changed)
} else {//stillInterested ==> communication discard
reg.discard();//from LookupLocatorDiscovery
@@ -827,7 +801,7 @@ public class LookupDiscoveryManager impl
*/
public void changed(DiscoveryEvent e) {
/* update the groups of each changed registrar */
- PortableServiceRegistrar[] proxys = e.getPRegistrars();
+ ServiceRegistrar[] proxys = (ServiceRegistrar[])e.getRegistrars();
Map groupsMap = e.getGroups();
HashMap changedGroupsMap = new HashMap(proxys.length);
for(int i=0; i<proxys.length; i++) {
@@ -835,9 +809,9 @@ public class LookupDiscoveryManager impl
ProxyReg reg = findReg(proxys[i]);
if(reg != null) {//previously discovered
String[] newGroups = (String[])groupsMap.get
- (reg.getProxy());
+ (reg.proxy);
reg.setMemberGroups(newGroups);
- changedGroupsMap.put(reg.getProxy(),newGroups);
+ changedGroupsMap.put(reg.proxy,newGroups);
}//endif
}//end sync(discoveredSet)
}//end loop
@@ -846,7 +820,6 @@ public class LookupDiscoveryManager impl
}//end changed
}//end class GroupDiscoveryListener
-
/**
* Constructs an instance of this class that will organize and manage
* all discovery-related activities on behalf of the client or service
@@ -881,9 +854,6 @@ public class LookupDiscoveryManager impl
* initiate the discovery process, which can throw an
* <code>IOException</code> when socket allocation occurs.
*
- * @throws net.jini.config.ConfigurationException Since River 2.2.0 this
- * breaks source code compatiblity, the contract but not
- * binary compatibility.
* @throws java.lang.NullPointerException this exception occurs when
* either one or more of the elements of the <code>groups</code>
* parameter is <code>null</code>, or one or more elements of
@@ -895,18 +865,14 @@ public class LookupDiscoveryManager impl
public LookupDiscoveryManager(String[] groups,
LookupLocator[] locators,
DiscoveryListener listener)
- throws IOException, ConfigurationException
+ throws IOException
{
- /* By allowing the ConfigurationException we can set some private
- * references to final. This breaks the contract, but not binary
- * compatibility. Developers will need to change their source code
- * when they recompile.
- */
- //try {
- this(groups, locators, listener,
+ try {
+ beginDiscovery(groups, locators, listener,
EmptyConfiguration.INSTANCE);
- //} catch(ConfigurationException e) { /* swallow this exception */ }
+ } catch(ConfigurationException e) { /* swallow this exception */ }
}//end constructor
+
/**
* Constructs an instance of this class, using the given
* <code>Configuration</code>, that will organize and manage all
@@ -964,23 +930,9 @@ public class LookupDiscoveryManager impl
LookupLocator[] locators,
DiscoveryListener listener,
Configuration config)
- throws IOException, ConfigurationException, NullPointerException
+ throws IOException, ConfigurationException
{
- /*
- * Using the given <code>Configuration</code>, initializes the current
- * instance of this utility, and initiates the discovery process for
- * the given set of groups and the given set of locators. Whenever a
- * lookup service is discovered, discarded, or changed, the appropriate
- * notification will be sent to the given listener.
- */
- /* Initiate the discovery process */
- if(listener != null) listeners.add(listener);
- /* Configure for group discovery */
- lookupDisc = new LookupDiscovery(groups, config);
- lookupDisc.addDiscoveryListener(groupListener);
- /* Configure for locator discovery */
- locatorDisc = new LookupLocatorDiscovery(locators, config);
- locatorDisc.addDiscoveryListener(locatorListener);
+ beginDiscovery(groups, locators, listener, config);
}//end constructor
/**
@@ -1269,7 +1221,7 @@ public class LookupDiscoveryManager impl
if(discoveredSet.isEmpty()) return;
for(int i=0; i< discoveredSet.size(); i++) {
ProxyReg reg = (ProxyReg)discoveredSet.get(i);
- groupsMap.put(reg.getProxy(),reg.getMemberGroups());
+ groupsMap.put(reg.proxy,reg.getMemberGroups());
}
}
notifyListener(listener, groupsMap, DISCOVERED);
@@ -1305,48 +1257,19 @@ public class LookupDiscoveryManager impl
*
* @see net.jini.core.lookup.ServiceRegistrar
* @see net.jini.discovery.DiscoveryManagement#removeDiscoveryListener
- * @deprecated replaced by {@link #getPRegistrars()}
*/
- @Deprecated
- public net.jini.core.lookup.ServiceRegistrar[] getRegistrars() {
- PortableServiceRegistrar[] psr = getPRegistrars();
- int l = psr.length;
- net.jini.core.lookup.ServiceRegistrar[] sr = new net.jini.core.lookup.ServiceRegistrar[l];
- for ( int i = 0; i < l; i++){
- if (psr[i] instanceof net.jini.core.lookup.ServiceRegistrar){
- sr[i] = (net.jini.core.lookup.ServiceRegistrar) psr[i];
- }else{
- sr[i] = new ServiceRegistrarFacade(psr[i]);
- }
- }
- return sr;
- }
-
- /**
- * Returns an array of instances of <code>ServiceRegistrar</code>, each
- * corresponding to a proxy to one of the currently discovered lookup
- * services. For each invocation of this method, a new array is returned.
- *
- * @return array of instances of <code>ServiceRegistrar</code>, each
- * corresponding to a proxy to one of the currently discovered
- * lookup services
- *
- * @see net.jini.core.lookup.ServiceRegistrar
- * @see net.jini.discovery.DiscoveryManagement#removeDiscoveryListener
- */
- public PortableServiceRegistrar[] getPRegistrars() {
- ArrayList<PortableServiceRegistrar> proxySet;
+ public ServiceRegistrar[] getRegistrars() {
+ ArrayList proxySet = new ArrayList(1);;
synchronized(discoveredSet) {
- proxySet = new ArrayList<PortableServiceRegistrar>(discoveredSet.size());
int k = 0;
Iterator iter = discoveredSet.iterator();
while(iter.hasNext()) {
ProxyReg reg = (ProxyReg)iter.next();
if(!reg.isDiscarded())
- proxySet.add(reg.getProxy());
+ proxySet.add(reg.proxy);
}
}
- PortableServiceRegistrar[] ret = new PortableServiceRegistrar[proxySet.size()];
+ ServiceRegistrar[] ret = new ServiceRegistrar[proxySet.size()];
proxySet.toArray(ret);
return ret;
}
@@ -1364,28 +1287,8 @@ public class LookupDiscoveryManager impl
*
* @see net.jini.core.lookup.ServiceRegistrar
* @see net.jini.discovery.DiscoveryManagement#discard
- * @deprecated
*/
- @Deprecated
- public void discard(net.jini.core.lookup.ServiceRegistrar proxy) {
- discard((PortableServiceRegistrar) proxy);
- }//end discard
-
- /**
- * Removes an instance of <code>ServiceRegistrar</code> 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 <code>null</code>, or if it
- * does not match (using <code>equals</code>) any of the elements in
- * the managed set.
- *
- * @param proxy the instance of <code>ServiceRegistrar</code> to discard
- * from the managed set of lookup services
- *
- * @see net.jini.core.lookup.ServiceRegistrar
- * @see net.jini.discovery.DiscoveryManagement#discard
- */
- public void discard(PortableServiceRegistrar proxy) {
+ public void discard(ServiceRegistrar proxy) {
if(proxy == null) return;
ProxyReg reg = findReg(proxy);
if(reg != null) {
@@ -1418,36 +1321,20 @@ public class LookupDiscoveryManager impl
* @param proxy a ServiceRegistrar object
* @return an <code>int</code> indicating whether the proxy
* was obtained through group or locator discovery.
- * @deprecated replaced by {@link #getFrom(PortableServiceRegistrar)}
*/
- @Deprecated
- public int getFrom(net.jini.core.lookup.ServiceRegistrar proxy) {
- return getFrom(proxy);
- }
-
- /** Return where the proxy come from.
- * @param proxy a ServiceRegistrar object
- * @return an <code>int</code> indicating whether the proxy
- * was obtained through group or locator discovery.
- * Returns 0 if proxy not found.
- */
- public int getFrom(PortableServiceRegistrar proxy) {
+ public int getFrom(ServiceRegistrar proxy) {
ProxyReg reg = findReg(proxy);
- if(reg != null) return reg.getFrom();
+ if(reg != null)
+ return reg.getFrom();
return 0;
}
- private ProxyReg findReg(PortableServiceRegistrar proxy) {
- while (proxy instanceof Facade){ //always ensure we have uncovered any facades.
- @SuppressWarnings("unchecked")
- Facade<PortableServiceRegistrar> f = (Facade<PortableServiceRegistrar>) proxy;
- proxy = f.reveal();
- }
+ private ProxyReg findReg(ServiceRegistrar proxy) {
synchronized(discoveredSet) {
Iterator iter = discoveredSet.iterator();
while(iter.hasNext()) {
ProxyReg reg =(ProxyReg)iter.next();
- if(reg.getProxy().equals(proxy))
+ if(reg.proxy.equals(proxy))
return reg;
}
}
@@ -1565,4 +1452,46 @@ public class LookupDiscoveryManager impl
return newMap;
}//end deepCopy
+ /**
+ * Using the given <code>Configuration</code>, initializes the current
+ * instance of this utility, and initiates the discovery process for
+ * the given set of groups and the given set of locators. Whenever a
+ * lookup service is discovered, discarded, or changed, the appropriate
+ * notification will be sent to the given listener.
+ *
+ * @param groups the set of group names to discover
+ *
+ * @param locators the set of locators to discover
+ *
+ * @param listener the listener that will be notified when a targeted
+ * lookup service is discovered, discarded, or changed.
+ *
+ * @param config an instance of <code>Configuration</code>, used to
+ * obtain the objects needed to configure this utility
+ *
+ * @throws java.lang.NullPointerException either input array contains at
+ * least one <code>null</code> element
+ *
+ * @throws java.io.IOException an exception occurred initiating discovery
+ *
+ * @throws net.jini.config.ConfigurationException indicates an exception
+ * occurred while retrieving an item from the given
+ * <code>Configuration</code>
+ */
+ private void beginDiscovery(String[] groups,
+ LookupLocator[] locators,
+ DiscoveryListener listener,
+ Configuration config)
+ throws IOException, ConfigurationException
+ {
+ /* Initiate the discovery process */
+ if(listener != null) listeners.add(listener);
+ /* Configure for group discovery */
+ lookupDisc = new LookupDiscovery(groups, config);
+ lookupDisc.addDiscoveryListener(groupListener);
+ /* Configure for locator discovery */
+ locatorDisc = new LookupLocatorDiscovery(locators, config);
+ locatorDisc.addDiscoveryListener(locatorListener);
+ }//end beginDiscovery
+
}//end class LookupDiscoveryManager
Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java?rev=993107&r1=993106&r2=993107&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java Mon Sep 6 17:40:22 2010
@@ -17,9 +17,6 @@
*/
package net.jini.discovery;
-import org.apache.river.api.util.Facade;
-import net.jini.lookup.StreamServiceRegistrarFacade;
-import net.jini.lookup.ServiceRegistrarFacade;
import com.sun.jini.config.Config;
import com.sun.jini.discovery.Discovery;
import com.sun.jini.discovery.DiscoveryConstraints;
@@ -51,9 +48,7 @@ import net.jini.core.constraint.Invocati
import net.jini.core.constraint.MethodConstraints;
import net.jini.core.constraint.RemoteMethodControl;
import net.jini.core.discovery.LookupLocator;
-import net.jini.core.lookup.PortableServiceRegistrar;
import net.jini.core.lookup.ServiceRegistrar;
-import net.jini.core.lookup.StreamServiceRegistrar;
import net.jini.security.BasicProxyPreparer;
import net.jini.security.ProxyPreparer;
@@ -310,9 +305,7 @@ import net.jini.security.ProxyPreparer;
*
* @see net.jini.core.discovery.LookupLocator
*/
-public class LookupLocatorDiscovery implements DiscoveryManagement,
- RegistrarManagement,
- DiscoveryListenerManagement,
+public class LookupLocatorDiscovery implements DiscoveryManagement,
DiscoveryLocatorManagement
{
/* Name of this component; used in config entry retrieval and the logger.*/
@@ -326,7 +319,7 @@ public class LookupLocatorDiscovery impl
private static final int MAX_N_TASKS = 15;
/** Default timeout to set on sockets used for unicast discovery. */
private static final int DEFAULT_SOCKET_TIMEOUT = 1*60*1000;
- /** LookupLocator.getPRegistrar method, used for looking up client
+ /** LookupLocator.getRegistrar method, used for looking up client
* constraints of contained lookup locators.
*/
private static final Method getRegistrarMethod;
@@ -395,7 +388,7 @@ public class LookupLocatorDiscovery impl
* to discover via unicast discovery.
*/
private class LocatorReg {
- public PortableServiceRegistrar proxy = null;
+ public ServiceRegistrar proxy = null;
public final LookupLocator l;
public String[] memberGroups = null;
private boolean discarded = false;
@@ -541,8 +534,8 @@ public class LookupLocatorDiscovery impl
}.getResponse(locator.getHost(), locator.getPort(), ic);
/* Proxy preparation */
- proxy = (PortableServiceRegistrar)registrarPreparer.prepareProxy
- (resp.getPRegistrar());
+ proxy = (ServiceRegistrar)registrarPreparer.prepareProxy
+ (resp.getRegistrar());
logger.log(Level.FINEST, "LookupLocatorDiscovery - prepared "
+"lookup service proxy: {0}", proxy);
memberGroups = resp.getGroups();
@@ -896,129 +889,12 @@ public class LookupLocatorDiscovery impl
if((discoveredLocators == null) || (discoveredLocators.isEmpty())){
return new ServiceRegistrar[0];
}
- int k = 0;
- ServiceRegistrar[] proxys =
- new ServiceRegistrar[discoveredLocators.size()];
- Iterator iter = discoveredLocators.iterator();
- while(iter.hasNext()) {
- LocatorReg reg = (LocatorReg)iter.next();
- PortableServiceRegistrar psr = reg.proxy;
- if ( psr instanceof ServiceRegistrar){
- proxys[k++] = (ServiceRegistrar) psr;
- } else {
- proxys[k++] = new ServiceRegistrarFacade(psr);
- }
- }//end loop
- return proxys;
+ return buildServiceRegistrar();
}//end sync(this)
}//end getRegistrars
-
- /**
- * Returns an array of instances of <code>StreamServiceRegistrar</code>, each
- * corresponding to a proxy to one of the currently discovered lookup
- * services. For each invocation of this method, a new array is returned.
- *
- * @return array of instances of <code>StreamServiceRegistrar</code>, each
- * corresponding to a proxy to one of the currently discovered
- * lookup services
- *
- * @throws java.lang.IllegalStateException this exception occurs when
- * this method is called after the <code>terminate</code>
- * method has been called.
- *
- * @see net.jini.core.lookup.StreamServiceRegistrar
- */
- public StreamServiceRegistrar[] getStreamRegistrars() {
- synchronized(this) {
- if (terminated) {
- throw new IllegalStateException("discovery terminated");
- }
- if((discoveredLocators == null) || (discoveredLocators.isEmpty())){
- return new StreamServiceRegistrar[0];
- }
- int k = 0;
- StreamServiceRegistrar[] proxys =
- new StreamServiceRegistrar[discoveredLocators.size()];
- Iterator iter = discoveredLocators.iterator();
- while(iter.hasNext()) {
- LocatorReg reg = (LocatorReg)iter.next();
- PortableServiceRegistrar psr = reg.proxy;
- if ( psr instanceof StreamServiceRegistrar){
- proxys[k++] = (StreamServiceRegistrar) psr;
- } else {
- proxys[k++] = new StreamServiceRegistrarFacade(psr);
- }
- }//end loop
- return proxys;
- }//end sync(this)
- }//end getStreamRegistrars
-
- /**
- * Returns an array of instances of <code>PortableServiceRegistrar</code>, each
- * corresponding to a proxy to one of the currently discovered lookup
- * services. For each invocation of this method, a new array is returned.
- *
- * @return array of instances of <code>ServiceRegistrar</code>, each
- * corresponding to a proxy to one of the currently discovered
- * lookup services
- *
- * @throws java.lang.IllegalStateException this exception occurs when
- * this method is called after the <code>terminate</code>
- * method has been called.
- *
- * @see net.jini.core.lookup.ServiceRegistrar
- * @see net.jini.discovery.DiscoveryManagement#removeDiscoveryListener
- */
- public PortableServiceRegistrar[] getPRegistrars() {
- synchronized(this) {
- if (terminated) {
- throw new IllegalStateException("discovery terminated");
- }
- if((discoveredLocators == null) || (discoveredLocators.isEmpty())){
- return new PortableServiceRegistrar[0];
- }
- /* From each element of the set of LocatorReg objects that correspond
- * to lookup services that have been discovered, this method extracts
- * the PortableServiceRegistrar reference and returns all of the references
- * in an array of PortableServiceRegistrar.
- */
- int k = 0;
- PortableServiceRegistrar[] proxys =
- new PortableServiceRegistrar[discoveredLocators.size()];
- Iterator iter = discoveredLocators.iterator();
- while(iter.hasNext()) {
- LocatorReg reg = (LocatorReg)iter.next();
- proxys[k++] = reg.proxy;
- }//end loop
- return proxys;
- }//end sync(this)
- }//end getPRegistrars
-
- /** From each element of the set of LocatorReg objects that correspond
- * to lookup services that have been discovered, this method extracts
- * the ServiceRegistrar reference and returns all of the references
- * in an array of ServiceRegistrar.
- */
- private PortableServiceRegistrar[] buildServiceRegistrar() {
- int k = 0;
- PortableServiceRegistrar[] proxys =
- new PortableServiceRegistrar[discoveredLocators.size()];
- Iterator iter = discoveredLocators.iterator();
- while(iter.hasNext()) {
- LocatorReg reg = (LocatorReg)iter.next();
- proxys[k++] = reg.proxy;
- }//end loop
- return proxys;
- }//end buildServiceRegistrar
-
-
- // Just to maintain binary compatibility (Method Signature cannot change)
- public void discard(ServiceRegistrar proxy){
- discard((PortableServiceRegistrar) proxy);
- }
/**
- * Removes an instance of <code>PortableServiceRegistrar</code> from the
+ * Removes an instance of <code>ServiceRegistrar</code> 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 <code>null</code>, or if it
@@ -1035,16 +911,12 @@ public class LookupLocatorDiscovery impl
* @see net.jini.core.lookup.ServiceRegistrar
* @see net.jini.discovery.DiscoveryManagement#discard
*/
- public void discard(PortableServiceRegistrar proxy) {
+ public void discard(ServiceRegistrar proxy) {
synchronized(this) {
if (terminated) {
throw new IllegalStateException("discovery terminated");
}
if(proxy == null) return;
- while ( proxy instanceof Facade ){
- Facade f = (Facade) proxy;
- proxy = (PortableServiceRegistrar) f.reveal();
- }
LookupLocator lct = findRegFromProxy(proxy);
if(lct == null) return;
/* Remove locator from the set of already-discovered locators */
@@ -1393,7 +1265,7 @@ public class LookupLocatorDiscovery impl
* Upon finding such an element, the corresponding LookupLocator is
* returned; otherwise, null is returned.
*/
- private LookupLocator findRegFromProxy(PortableServiceRegistrar proxy) {
+ private LookupLocator findRegFromProxy(ServiceRegistrar proxy) {
Iterator iter = discoveredLocators.iterator();
while(iter.hasNext()) {
LocatorReg reg = (LocatorReg)iter.next();
@@ -1457,6 +1329,23 @@ public class LookupLocatorDiscovery impl
}//end sync(this)
}//end regTryGetProxy
+ /** From each element of the set of LocatorReg objects that correspond
+ * to lookup services that have been discovered, this method extracts
+ * the ServiceRegistrar reference and returns all of the references
+ * in an array of ServiceRegistrar.
+ */
+ private ServiceRegistrar[] buildServiceRegistrar() {
+ int k = 0;
+ ServiceRegistrar[] proxys =
+ new ServiceRegistrar[discoveredLocators.size()];
+ Iterator iter = discoveredLocators.iterator();
+ while(iter.hasNext()) {
+ LocatorReg reg = (LocatorReg)iter.next();
+ proxys[k++] = reg.proxy;
+ }//end loop
+ return proxys;
+ }//end buildServiceRegistrar
+
/**
* Adds the given LocatorReg object to the set containing the objects
* corresponding to the locators of desired lookup services that have
@@ -1617,9 +1506,8 @@ public class LookupLocatorDiscovery impl
* @return <code>Map</code> instance containing a single mapping from
* a given registrar to its current member groups
*/
- private Map mapRegToGroups(PortableServiceRegistrar reg, String[] curGroups) {
- HashMap<PortableServiceRegistrar,String[]> groupsMap =
- new HashMap<PortableServiceRegistrar,String[]>(1);
+ private Map mapRegToGroups(ServiceRegistrar reg, String[] curGroups) {
+ HashMap groupsMap = new HashMap(1);
groupsMap.put(reg,curGroups);
return groupsMap;
}//end mapRegToGroups
Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/LookupUnmarshalException.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/LookupUnmarshalException.java?rev=993107&r1=993106&r2=993107&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/LookupUnmarshalException.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/LookupUnmarshalException.java Mon Sep 6 17:40:22 2010
@@ -30,7 +30,6 @@ import java.io.ObjectOutputStream;
import java.rmi.MarshalledObject;
import java.util.ArrayList;
import java.util.Arrays;
-import net.jini.core.lookup.StreamServiceRegistrar;
import net.jini.io.Convert;
import net.jini.io.MarshalledInstance;
import net.jini.io.MiToMoOutputStream;
@@ -329,13 +328,11 @@ public class LookupUnmarshalException ex
* each element corresponds to a successfully unmarshalled object.
*/
public ServiceRegistrar[] getRegistrars() {
+ ArrayList<ServiceRegistrar> sr = new ArrayList<ServiceRegistrar>();
int l = registrars.length;
- ArrayList<ServiceRegistrar> sr = new ArrayList<ServiceRegistrar>(l);
for ( int i = 0; i < l; i++){
if (registrars[i] instanceof ServiceRegistrar) {
sr.add((ServiceRegistrar) registrars[i]);
- } else {
- sr.add(new ServiceRegistrarFacade(registrars[i]));
}
}
ServiceRegistrar[] sra = new ServiceRegistrar[sr.size()];
@@ -344,7 +341,7 @@ public class LookupUnmarshalException ex
/**
* Accessor method that returns an array consisting of instances of
- * <code>StreamServiceRegistrar</code>, where each element of the array
+ * <code>PortableServiceRegistrar</code>, where each element of the array
* corresponds to a successfully unmarshalled object. Note that the
* same array is returned on each invocation of this method; that is,
* a copy is not made.
@@ -352,20 +349,9 @@ public class LookupUnmarshalException ex
* @return array of instances of <code>PortableServiceRegistrar</code>, where
* each element corresponds to a successfully unmarshalled object.
*/
- public StreamServiceRegistrar[] getStreamRegistrars() {
+ public PortableServiceRegistrar[] getPRegistrars() {
// Defensive copy.
- int l = registrars.length;
- ArrayList<StreamServiceRegistrar> sr = new ArrayList<StreamServiceRegistrar>(l);
- for ( int i = 0; i < l; i++){
- if (registrars[i] instanceof StreamServiceRegistrar) {
- sr.add((StreamServiceRegistrar) registrars[i]);
- } else {
- sr.add(new StreamServiceRegistrarFacade(registrars[i]));
- }
- }
- StreamServiceRegistrar[] sra = new StreamServiceRegistrar[sr.size()];
- return sr.toArray(sra);
-
+ return Arrays.copyOf(registrars, registrars.length);
}//end getRegistrars
/**
@@ -409,7 +395,7 @@ public class LookupUnmarshalException ex
}
public MarshalledInstance[] getMarshalledInstRegistrars(){
- // Defensive copy. TODO: Java 6 only method revise
+ // Defensive copy.
return Arrays.copyOf(marshalledRegistrars, marshalledRegistrars.length);
}
@@ -499,38 +485,32 @@ public class LookupUnmarshalException ex
private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException
{
- if (s instanceof MoToMiInputStream){
- s.defaultReadObject();
- /* Verify marshalledRegistrars and exceptions fields */
- if(marshalledRegistrars == null) {
- throw new InvalidObjectException
- ("LookupUnmarshalException.readObject "
- +"failure - marshalledRegistrars field is null");
- }//endif
- if(exceptions == null) {
- throw new InvalidObjectException
- ("LookupUnmarshalException.readObject "
- +"failure - exceptions field is null");
- }//endif
- if(marshalledRegistrars.length == 0) {
- throw new InvalidObjectException
- ("LookupUnmarshalException.readObject "
- +"failure - marshalledRegistrars.length == 0");
- }//endif
- if(exceptions.length != marshalledRegistrars.length) {
- throw new InvalidObjectException
- ("LookupUnmarshalException.readObject failure - "
- +"exceptions.length ("+exceptions.length
- +") is not equal to marshalledRegistrars.length "
- +"("+marshalledRegistrars.length+")");
- }//endif
- return;
- }
ObjectInputStream fois = new MoToMiInputStream(s); // convert to java.rmi.MarshalledObject
- LookupUnmarshalException lue = (LookupUnmarshalException) fois.readObject();
- this.exceptions = lue.exceptions;
- this.registrars = lue.registrars;
- this.marshalledRegistrars = lue.marshalledRegistrars;
+ fois.defaultReadObject();
+ /* Verify marshalledRegistrars and exceptions fields */
+ if(marshalledRegistrars == null) {
+ throw new InvalidObjectException
+ ("LookupUnmarshalException.readObject "
+ +"failure - marshalledRegistrars field is null");
+ }//endif
+ if(exceptions == null) {
+ throw new InvalidObjectException
+ ("LookupUnmarshalException.readObject "
+ +"failure - exceptions field is null");
+ }//endif
+ if(marshalledRegistrars.length == 0) {
+ throw new InvalidObjectException
+ ("LookupUnmarshalException.readObject "
+ +"failure - marshalledRegistrars.length == 0");
+ }//endif
+ if(exceptions.length != marshalledRegistrars.length) {
+ throw new InvalidObjectException
+ ("LookupUnmarshalException.readObject failure - "
+ +"exceptions.length ("+exceptions.length
+ +") is not equal to marshalledRegistrars.length "
+ +"("+marshalledRegistrars.length+")");
+ }//endif
+
}//end readObject
/**
@@ -541,12 +521,8 @@ public class LookupUnmarshalException ex
* @throws java.io.IOException
*/
private void writeObject(java.io.ObjectOutputStream stream) throws IOException{
- if (stream instanceof MiToMoOutputStream){
- stream.defaultWriteObject();
- return;
- }
ObjectOutputStream newOutStream = new MiToMoOutputStream(stream); // Convert from java.rmi.MarshalledObject
- newOutStream.writeObject(this);
+ newOutStream.defaultWriteObject();
}
}//end class LookupUnmarshalException
Modified: incubator/river/jtsk/trunk/src/net/jini/lookup/JoinManager.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/lookup/JoinManager.java?rev=993107&r1=993106&r2=993107&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/lookup/JoinManager.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/lookup/JoinManager.java Mon Sep 6 17:40:22 2010
@@ -442,18 +442,13 @@ import org.apache.river.api.util.Facade;
*/
public class JoinManager {
- @SuppressWarnings("deprecation")
private static void discard(DiscoveryListenerManagement dlm,
PortableServiceRegistrar proxy, Logger logger){
try {
if (dlm instanceof RegistrarManagement){
RegistrarManagement rm = (RegistrarManagement) dlm;
rm.discard(proxy);
- } else if ( dlm instanceof DiscoveryManagement
- && proxy instanceof ServiceRegistrar) {
- DiscoveryManagement dm = (DiscoveryManagement) dlm;
- dm.discard((ServiceRegistrar) proxy);
- } else {
+ } else {
throw new UnsupportedOperationException("Not instance of " +
"RegistrarManagement");
}