You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by pe...@apache.org on 2010/04/23 07:14:11 UTC

svn commit: r937157 [2/2] - in /incubator/river/jtsk/trunk/src: com/sun/jini/discovery/ com/sun/jini/discovery/internal/ com/sun/jini/jeri/internal/runtime/ com/sun/jini/lease/ com/sun/jini/lookup/entry/ com/sun/jini/mahalo/ net/jini/core/discovery/ ne...

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=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java Fri Apr 23 05:14:10 2010
@@ -29,6 +29,7 @@ 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;
 
 /** 
@@ -89,7 +90,9 @@ import net.jini.core.lookup.ServiceRegis
  * @see net.jini.discovery.DiscoveryLocatorManagement
  * 
  */
+@SuppressWarnings("deprecation")
 public class LookupDiscoveryManager implements DiscoveryManagement,
+                                               DiscoveryManagement2,
                                                DiscoveryGroupManagement,
                                                DiscoveryLocatorManagement
 {
@@ -156,7 +159,7 @@ public class LookupDiscoveryManager impl
      */
     private final class ProxyReg  {
         /** The discovered registrar to be managed */
-	public ServiceRegistrar proxy;
+	public PortableServiceRegistrar proxy;
         /** The groups to which the discovered registrar belongs */
         public String[] memberGroups;
         /** Special-purpose flag used in the discard process. This flag is
@@ -228,12 +231,20 @@ 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,
+                        String[] memberGroups,
+                        int from)
+        {
             if(proxy == null) {
 	        throw new IllegalArgumentException("proxy cannot be null");
             }//endif
@@ -1257,10 +1268,39 @@ public class LookupDiscoveryManager impl
      *
      * @see net.jini.core.lookup.ServiceRegistrar
      * @see net.jini.discovery.DiscoveryManagement#removeDiscoveryListener
+     * @deprecated replaced by {@link #getPRegistrars()}
      */
+    @Deprecated
     public ServiceRegistrar[] getRegistrars() {
-	ArrayList proxySet = new ArrayList(1);;
+	PortableServiceRegistrar[] psr = getPRegistrars();
+        int l = psr.length;
+        ServiceRegistrar[] sr = new ServiceRegistrar[l];
+        for ( int i = 0; i < l; i++){
+            if (psr[i] instanceof ServiceRegistrar){
+                sr[i] = (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;
 	synchronized(discoveredSet) {
+            proxySet = new ArrayList<PortableServiceRegistrar>(discoveredSet.size());
 	    int k = 0;
 	    Iterator iter = discoveredSet.iterator();
 	    while(iter.hasNext()) {
@@ -1269,7 +1309,7 @@ public class LookupDiscoveryManager impl
 		    proxySet.add(reg.proxy);
 	    }
 	}
-	ServiceRegistrar[] ret = new ServiceRegistrar[proxySet.size()];
+	PortableServiceRegistrar[] ret = new PortableServiceRegistrar[proxySet.size()];
 	proxySet.toArray(ret);
 	return ret;
     }
@@ -1287,8 +1327,28 @@ public class LookupDiscoveryManager impl
      *
      * @see net.jini.core.lookup.ServiceRegistrar
      * @see net.jini.discovery.DiscoveryManagement#discard
+     * @deprecated 
      */
+    @Deprecated
     public void discard(ServiceRegistrar proxy) {
+        discard(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) {
         if(proxy == null) return;
 	ProxyReg reg = findReg(proxy);
 	if(reg != null) {
@@ -1321,15 +1381,31 @@ 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(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) {
 	ProxyReg reg = findReg(proxy);
-	if(reg != null)
-	    return reg.getFrom();
+	if(reg != null) return reg.getFrom();
 	return 0;
     }
 
-    private ProxyReg findReg(ServiceRegistrar proxy) {
+    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();
+        }
 	synchronized(discoveredSet) {
 	    Iterator iter = discoveredSet.iterator();
 	    while(iter.hasNext()) {

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=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java Fri Apr 23 05:14:10 2010
@@ -48,7 +48,9 @@ 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;
 
@@ -305,7 +307,7 @@ import net.jini.security.ProxyPreparer;
  *
  * @see net.jini.core.discovery.LookupLocator
  */
-public class LookupLocatorDiscovery implements DiscoveryManagement,
+public class LookupLocatorDiscovery implements DiscoveryManagement, DiscoveryManagement2,
                                                DiscoveryLocatorManagement
 {
     /* Name of this component; used in config entry retrieval and the logger.*/
@@ -319,7 +321,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.getRegistrar method, used for looking up client
+    /** LookupLocator.getPRegistrar method, used for looking up client
      *  constraints of contained lookup locators.
      */
     private static final Method getRegistrarMethod;
@@ -388,7 +390,7 @@ public class LookupLocatorDiscovery impl
      *  to discover via unicast discovery.
      */
     private class LocatorReg {
-        public ServiceRegistrar proxy = null;
+        public PortableServiceRegistrar proxy = null;
         public final LookupLocator l;
         public String[] memberGroups = null;
 	private boolean discarded = false;
@@ -534,8 +536,8 @@ public class LookupLocatorDiscovery impl
 	    }.getResponse(locator.getHost(), locator.getPort(), ic);
 	    	    
 	    /* Proxy preparation */
-	    proxy = (ServiceRegistrar)registrarPreparer.prepareProxy
-							(resp.getRegistrar());
+	    proxy = (PortableServiceRegistrar)registrarPreparer.prepareProxy
+							(resp.getPRegistrar());
 	    logger.log(Level.FINEST, "LookupLocatorDiscovery - prepared "
 		       +"lookup service proxy: {0}", proxy);
 	    memberGroups = resp.getGroups();
@@ -889,12 +891,129 @@ public class LookupLocatorDiscovery impl
             if((discoveredLocators == null) || (discoveredLocators.isEmpty())){
                 return new ServiceRegistrar[0];
             }
-            return buildServiceRegistrar();
+            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;
         }//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>ServiceRegistrar</code> from the
+     * Removes an instance of <code>PortableServiceRegistrar</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
@@ -911,12 +1030,16 @@ public class LookupLocatorDiscovery impl
      * @see net.jini.core.lookup.ServiceRegistrar
      * @see net.jini.discovery.DiscoveryManagement#discard
      */
-    public void discard(ServiceRegistrar proxy) {
+    public void discard(PortableServiceRegistrar 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 */
@@ -1265,7 +1388,7 @@ public class LookupLocatorDiscovery impl
      *  Upon finding such an element, the corresponding LookupLocator is
      *  returned; otherwise, null is returned. 
      */
-    private LookupLocator findRegFromProxy(ServiceRegistrar proxy) {
+    private LookupLocator findRegFromProxy(PortableServiceRegistrar proxy) {
 	Iterator iter = discoveredLocators.iterator();
 	while(iter.hasNext()) {
 	    LocatorReg reg = (LocatorReg)iter.next();
@@ -1329,23 +1452,6 @@ 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
@@ -1506,8 +1612,9 @@ 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(ServiceRegistrar reg, String[] curGroups) {
-        HashMap groupsMap = new HashMap(1);
+    private Map mapRegToGroups(PortableServiceRegistrar reg, String[] curGroups) {
+        HashMap<PortableServiceRegistrar,String[]> groupsMap = 
+                new HashMap<PortableServiceRegistrar,String[]>(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=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/LookupUnmarshalException.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/LookupUnmarshalException.java Fri Apr 23 05:14:10 2010
@@ -28,6 +28,7 @@ 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;
@@ -326,11 +327,13 @@ 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()];
@@ -339,7 +342,7 @@ public class LookupUnmarshalException ex
     
     /**
      * Accessor method that returns an array consisting of instances of 
-     * <code>PortableServiceRegistrar</code>, where each element of the array
+     * <code>StreamServiceRegistrar</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.
@@ -347,9 +350,20 @@ public class LookupUnmarshalException ex
      * @return array of instances of <code>PortableServiceRegistrar</code>, where
      *         each element corresponds to a successfully unmarshalled object.
      */
-    public PortableServiceRegistrar[] getPRegistrars() {
+    public StreamServiceRegistrar[] getStreamRegistrars() {
         // Defensive copy.
-        return Arrays.copyOf(registrars, registrars.length);
+        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);
+        
     }//end getRegistrars
 
     /**

Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/OutgoingUnicastResponse.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/OutgoingUnicastResponse.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/OutgoingUnicastResponse.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/OutgoingUnicastResponse.java Fri Apr 23 05:14:10 2010
@@ -21,7 +21,10 @@ import java.io.ObjectOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.rmi.MarshalledObject;
+import net.jini.core.lookup.PortableServiceRegistrar;
 import net.jini.core.lookup.ServiceRegistrar;
+import net.jini.io.MarshalledInstance;
+import net.jini.io.MiToMoOutputStream;
 
 /**
  * Encapsulate the details of marshaling a unicast response.
@@ -39,6 +42,22 @@ public class OutgoingUnicastResponse {
     /**
      * Marshal a unicast response to the given output stream.  The
      * stream is flushed afterwards.
+     * 
+     * Older Versions of Apache River prior to 2.2.0 participating in a djinn,
+     * will not have the ability to wrap a PortableServiceRegistrar, so it
+     * can participate as a ServiceRegistrar instance. 
+     * However it is intended that the Registrar's
+     * proxy's implementation will be able to be unmarshalled
+     * with a suitable codebase that also implements ServiceRegistrar for
+     * recipients IncomingUnicastRequest's
+     * 
+     * At some future point in time, a djinn will have a minimum Apache River
+     * version requirement for participation, at that stage old application
+     * code will rely upon the PortableServiceRegistrarWrapper and ServiceRegistrar
+     * will no longer be implemented directly by the proxy class.
+     * 
+     * At the same point in time the serialized form of the PortableServiceRegistrar
+     * will be that of MarshalledInstance, not MarshalledObject as it currently is.
      *
      * @param str the stream to marshal to
      * @param reg the registrar object to marshal
@@ -47,16 +66,17 @@ public class OutgoingUnicastResponse {
      * @exception IOException a problem occurred during marshaling
      */
     public static void marshal(OutputStream str,
-			       ServiceRegistrar reg,
+			       PortableServiceRegistrar reg,
 			       String[] groups)
 	throws IOException
     {
-	ObjectOutputStream ostr = new ObjectOutputStream(str);
-	ostr.writeObject(new MarshalledObject(reg));
+	ObjectOutputStream ostr = new MiToMoOutputStream(str);
+	ostr.writeObject(new MarshalledInstance(reg));
 	ostr.writeInt(groups.length);
 	for (int i = 0; i < groups.length; i++) {
 	    ostr.writeUTF(groups[i]);
 	}
 	ostr.flush();
     }
+    
 }

Added: incubator/river/jtsk/trunk/src/net/jini/discovery/ServiceRegistrarFacade.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/ServiceRegistrarFacade.java?rev=937157&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/ServiceRegistrarFacade.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/ServiceRegistrarFacade.java Fri Apr 23 05:14:10 2010
@@ -0,0 +1,121 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package net.jini.discovery;
+
+import java.rmi.MarshalledObject;
+import java.rmi.RemoteException;
+import net.jini.core.discovery.LookupLocator;
+import net.jini.core.event.EventRegistration;
+import net.jini.core.event.RemoteEventListener;
+import net.jini.core.lookup.PortableServiceRegistrar;
+import net.jini.core.lookup.ServiceID;
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceMatches;
+import net.jini.core.lookup.ServiceRegistrar;
+import net.jini.core.lookup.ServiceRegistration;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.core.lookup.StreamServiceRegistrar;
+import net.jini.io.Convert;
+import net.jini.io.MarshalledInstance;
+
+/**
+ *
+ * @author Peter Firmstone.
+ * @since 2.2.0
+ */
+public class ServiceRegistrarFacade implements ServiceRegistrar, Facade<PortableServiceRegistrar>{
+    
+    private final PortableServiceRegistrar sr; //Never allow a facade referent.
+    private final boolean isStreamingServiceRegistrar;
+    
+    public ServiceRegistrarFacade(PortableServiceRegistrar psr){
+        while (psr instanceof Facade){ //always ensure we have uncovered any facades.
+            @SuppressWarnings("unchecked")
+                Facade<PortableServiceRegistrar> f = (Facade<PortableServiceRegistrar>) psr;
+                psr = f.reveal();
+        }
+        sr = psr;       
+        if (psr instanceof StreamServiceRegistrar){
+            isStreamingServiceRegistrar = true;
+        } else {
+            isStreamingServiceRegistrar = false;
+        }
+    }
+
+    public EventRegistration notify(ServiceTemplate tmpl, int transitions, 
+            RemoteEventListener listener, MarshalledObject handback, 
+            long leaseDuration) throws RemoteException {
+        if ( isStreamingServiceRegistrar ) {
+            Convert convert = Convert.getInstance();
+            @SuppressWarnings("unchecked")
+            MarshalledInstance hback = convert.toMarshalledInstance(handback);
+            StreamServiceRegistrar ssr = (StreamServiceRegistrar) sr;
+            return ssr.notify(hback, tmpl, transitions, listener, leaseDuration);
+        }
+        throw new UnsupportedOperationException("PortableServiceRegistrar " +
+                "doesn't implement this method");
+    }
+
+    public Class[] getEntryClasses(ServiceTemplate tmpl) throws RemoteException {
+        return sr.getEntryClasses(tmpl);
+    }
+
+    public Object[] getFieldValues(ServiceTemplate tmpl, int setIndex, String field) throws NoSuchFieldException, RemoteException {
+        return sr.getFieldValues(tmpl, setIndex, field);
+    }
+
+    public String[] getGroups() throws RemoteException {
+        return sr.getGroups();
+    }
+
+    public LookupLocator getLocator() throws RemoteException {
+        return sr.getLocator();
+    }
+
+    public ServiceID getServiceID() {
+        return sr.getServiceID();
+    }
+
+    public Class[] getServiceTypes(ServiceTemplate tmpl, String prefix) throws RemoteException {
+        return sr.getServiceTypes(tmpl, prefix);
+    }
+
+    public Object lookup(ServiceTemplate tmpl) throws RemoteException {
+        return sr.lookup(tmpl);
+    }
+
+    public ServiceMatches lookup(ServiceTemplate tmpl, int maxMatches) throws RemoteException {
+        return sr.lookup(tmpl, maxMatches);
+    }
+
+    public ServiceRegistration register(ServiceItem item, long leaseDuration) throws RemoteException {
+        return sr.register(item, leaseDuration);
+    }
+    
+    @Override
+    public boolean equals(Object obj){
+        if (obj == this) return true;
+        while (obj instanceof Facade){
+            Facade f = (Facade) obj;
+            obj = f.reveal();
+        }
+        if (obj instanceof PortableServiceRegistrar){
+            PortableServiceRegistrar psr = (PortableServiceRegistrar) obj;
+            if (sr.equals(psr)) return true;
+        }
+        return false;
+    }
+    
+    @Override
+    public int hashCode(){
+        return sr.hashCode();
+    }
+
+    public PortableServiceRegistrar reveal() {
+        return sr;
+    }
+
+}

Propchange: incubator/river/jtsk/trunk/src/net/jini/discovery/ServiceRegistrarFacade.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/river/jtsk/trunk/src/net/jini/discovery/StreamServiceRegistrarFacade.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/StreamServiceRegistrarFacade.java?rev=937157&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/StreamServiceRegistrarFacade.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/StreamServiceRegistrarFacade.java Fri Apr 23 05:14:10 2010
@@ -0,0 +1,132 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package net.jini.discovery;
+
+import java.io.ObjectInput;
+import java.rmi.RemoteException;
+import net.jini.core.discovery.LookupLocator;
+import net.jini.core.event.EventRegistration;
+import net.jini.core.event.RemoteEventListener;
+import net.jini.core.lookup.PortableServiceRegistrar;
+import net.jini.core.lookup.ServiceID;
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceMatches;
+import net.jini.core.lookup.ServiceRegistration;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.core.lookup.StreamServiceRegistrar;
+import net.jini.io.Convert;
+import net.jini.io.MarshalledInstance;
+
+/**
+ *
+ * @author Peter Firmstone
+ * @since 2.2.0
+ */
+public class StreamServiceRegistrarFacade implements StreamServiceRegistrar, 
+        Facade<PortableServiceRegistrar> {
+    private final PortableServiceRegistrar psr;
+    
+    public StreamServiceRegistrarFacade(PortableServiceRegistrar registrar) {
+        while (registrar instanceof Facade){ //always ensure we have uncovered any facades.
+            @SuppressWarnings("unchecked")
+                Facade<PortableServiceRegistrar> f = (Facade<PortableServiceRegistrar>) registrar;
+                registrar = f.reveal();
+        }
+        psr = registrar;
+    }
+
+    public EventRegistration notify(MarshalledInstance handback,
+            ServiceTemplate tmpl, int transitions, RemoteEventListener listener,
+            long leaseDuration) throws RemoteException {
+        try {
+            if ( psr instanceof net.jini.core.lookup.ServiceRegistrar) {
+                net.jini.core.lookup.ServiceRegistrar sr = 
+                        (net.jini.core.lookup.ServiceRegistrar) psr;
+                Convert convert = Convert.getInstance();
+                @SuppressWarnings("unchecked")
+                java.rmi.MarshalledObject hback = 
+                        convert.toRmiMarshalledObject(handback);
+                return sr.notify(tmpl, transitions, listener, hback, leaseDuration);
+            }
+            throw new UnsupportedOperationException("Unsupported Method");
+        } catch (Exception e ) {
+            throw new UnsupportedOperationException("Unsupported Method");
+        }
+    }
+
+    public ObjectInput lookup(ServiceTemplate tmpl, boolean marshalled)
+            throws RemoteException {
+        if ( psr instanceof StreamServiceRegistrar ){
+            StreamServiceRegistrar ssr = (StreamServiceRegistrar) psr;
+            return ssr.lookup(tmpl, marshalled);
+        }
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public Class[] getEntryClasses(ServiceTemplate tmpl) throws RemoteException {
+        return psr.getEntryClasses(tmpl);
+    }
+
+    public Object[] getFieldValues(ServiceTemplate tmpl, int setIndex, String field) 
+            throws NoSuchFieldException, RemoteException {
+        return psr.getFieldValues(tmpl, setIndex, field);
+    }
+
+    public String[] getGroups() throws RemoteException {
+        return psr.getGroups();
+    }
+
+    public LookupLocator getLocator() throws RemoteException {
+        return psr.getLocator();
+    }
+
+    public ServiceID getServiceID() {
+        return psr.getServiceID();
+    }
+
+    public Class[] getServiceTypes(ServiceTemplate tmpl, String prefix) 
+            throws RemoteException {
+        return psr.getServiceTypes(tmpl, prefix);
+    }
+
+    public Object lookup(ServiceTemplate tmpl) throws RemoteException {
+        return psr.lookup(tmpl);
+    }
+
+    public ServiceMatches lookup(ServiceTemplate tmpl, int maxMatches) 
+            throws RemoteException {
+        return psr.lookup(tmpl, maxMatches);
+    }
+
+    public ServiceRegistration register(ServiceItem item, long leaseDuration) 
+            throws RemoteException {
+        return psr.register(item, leaseDuration);
+    }
+    
+    @Override
+    public boolean equals(Object obj){
+        if (obj == this) return true;
+        while (obj instanceof Facade){
+            Facade f = (Facade) obj;
+            obj = f.reveal();
+        }
+        if (obj instanceof PortableServiceRegistrar){
+            PortableServiceRegistrar p = (PortableServiceRegistrar) obj;
+            if (psr.equals(p)) return true;
+        }
+        return false;
+    }
+    
+    @Override
+    public int hashCode(){
+        return psr.hashCode();
+    }
+
+    public PortableServiceRegistrar reveal() {
+        return psr;
+    }
+
+}

Propchange: incubator/river/jtsk/trunk/src/net/jini/discovery/StreamServiceRegistrarFacade.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/river/jtsk/trunk/src/net/jini/lease/RenewalFailureEvent.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/lease/RenewalFailureEvent.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/lease/RenewalFailureEvent.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/lease/RenewalFailureEvent.java Fri Apr 23 05:14:10 2010
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.rmi.MarshalledObject;
 import net.jini.core.lease.Lease;
 import net.jini.core.event.RemoteEvent;
+import net.jini.io.MarshalledInstance;
 
 /**
  * Event generated by a lease renewal set when it can't renew a lease it
@@ -50,7 +51,9 @@ public abstract class RenewalFailureEven
      *	      event
      * @param seqNum the sequence number of this event
      * @param handback the client handback
+     * @deprecated 
      */
+    @Deprecated
     public RenewalFailureEvent(LeaseRenewalSet  source, 
 			       long             seqNum,
 			       MarshalledObject handback)
@@ -58,6 +61,22 @@ public abstract class RenewalFailureEven
 	super(source, LeaseRenewalSet.RENEWAL_FAILURE_EVENT_ID, seqNum, 
 	      handback);
     }
+    
+    /**
+     * Simple constructor. Note event id is fixed to
+     * <code>LeaseRenewalSet.RENEWAL_FAILURE_EVENT_ID</code>.
+     *
+     * @param source the <code>LeaseRenewalSet</code> that generated the
+     *	      event
+     * @param seqNum the sequence number of this event
+     * @param handback the client handback
+     */
+    public RenewalFailureEvent(MarshalledInstance handback,
+                               LeaseRenewalSet  source, 
+			       long             seqNum)
+    {
+	super(handback, source, LeaseRenewalSet.RENEWAL_FAILURE_EVENT_ID, seqNum);
+    }
 
     /**
      * Returns the lease that could not be renewed. This method may

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=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/lookup/JoinManager.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/lookup/JoinManager.java Fri Apr 23 05:14:10 2010
@@ -53,6 +53,13 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import net.jini.core.lookup.PortableServiceRegistrar;
+import net.jini.discovery.DiscManFacade;
+import net.jini.discovery.DiscoveryListenerManagement;
+import net.jini.discovery.DiscoveryManagement2;
+import net.jini.discovery.DiscMan2Facade;
+import net.jini.discovery.Facade;
+import net.jini.discovery.ServiceRegistrarFacade;
 
 /**
  * A goal of any well-behaved service is to advertise the facilities and
@@ -437,7 +444,30 @@ import java.util.logging.Logger;
  * @see java.util.logging.Logger
  */
 public class JoinManager {
-
+    
+    private static void discard(DiscoveryListenerManagement dlm, 
+            PortableServiceRegistrar proxy, Logger logger){
+        try {
+            if (dlm instanceof DiscoveryManagement2) {
+                ((DiscoveryManagement2)dlm).discard(proxy);
+            } else {
+                DiscMan2Facade dm2f = new DiscMan2Facade(dlm);
+                dm2f.discard(proxy);
+            }
+        } catch(IllegalStateException e1) {
+           logger.log(Level.FINEST,
+                      "JoinManager - cannot discard lookup, "
+                      +"discovery manager already terminated",
+                      e1);
+        } catch(UnsupportedOperationException ex){
+            logger.log(Level.FINEST,
+                      "JoinManager - cannot discard lookup, "
+                      +"DiscoveryManager not supported on this" +
+                      " platform, use DiscoveryManager2 instead.",
+                      ex);
+        }
+    }
+     
     /** Implementation Note:
      *
      *  This class executes a number of tasks asynchronously. Each task is
@@ -1145,7 +1175,7 @@ public class JoinManager {
          *  this class, and with which this join manager's service will be
          *  registered.
          */
-	public ServiceRegistrar proxy;
+	public PortableServiceRegistrar proxy;
         /** The <i>prepared</i> registration proxy returned by this class'
          *  associated lookup service when this join manager registers its
          *  associated service.
@@ -1173,12 +1203,12 @@ public class JoinManager {
 	 *               which the sub-tasks referenced in this class will be
 	 *               executed in order
          */
-	public ProxyReg(ServiceRegistrar proxy) {
+	public ProxyReg(PortableServiceRegistrar proxy) {
 	    if(proxy == null)  throw new IllegalArgumentException
                                                       ("proxy can't be null");
 	    this.proxy = proxy;
-	}//end constructor	    
-
+	}//end constructor
+        
         /** Convenience method that adds new sub-tasks to this class' 
          *  task queue.
          *
@@ -1326,17 +1356,12 @@ public class JoinManager {
 		    LogUtil.logThrow(logger, Level.INFO, ProxyReg.class, "fail",
 			"JoinManager - failure for lookup service proxy: {0}",
 			new Object[] { proxy }, e);
-		    try {
-			discMgr.discard(proxy);
-		    } catch(IllegalStateException e1) {
-		       logger.log(Level.FINEST,
-				  "JoinManager - cannot discard lookup, "
-				  +"discovery manager already terminated",
-				  e1);
-		    }
+		    discard(discMgr, proxy, logger);
 		}//endif
 	    }//end sync(this)
 	}//end ProxyReg.fail
+        
+
 
 	/** Returns true if the both objects' associated proxies are equal. */
 	public boolean equals(Object obj) {
@@ -1359,15 +1384,15 @@ public class JoinManager {
 	/* Invoked when new or previously discarded lookup is discovered. */
 	public void discovered(DiscoveryEvent e) {
 	    synchronized(joinSet) {
-		ServiceRegistrar[] proxys
-				       = (ServiceRegistrar[])e.getRegistrars();
+		PortableServiceRegistrar[] proxys
+				       = (PortableServiceRegistrar[])e.getPRegistrars();
 		for(int i=0;i<proxys.length;i++) {
 		    /* Prepare the proxy to the discovered lookup service
 					 * before interacting with it.
 					 */
 		    try {
 			proxys[i]
-			  = (ServiceRegistrar)registrarPreparer.prepareProxy
+			  = (PortableServiceRegistrar)registrarPreparer.prepareProxy
 								   (proxys[i]);
 			logger.log(Level.FINEST, "JoinManager - discovered "
 				   +"lookup service proxy prepared: {0}",
@@ -1377,7 +1402,7 @@ public class JoinManager {
 			    DiscMgrListener.class, "discovered", "failure "
 			    + "preparing discovered ServiceRegistrar proxy: "
 			    + "{0}", new Object[] { proxys[i] }, e1);
-			discMgr.discard(proxys[i]);
+			discard( discMgr, proxys[i], logger);
 			continue;
 		    }
 		    /* If the serviceItem is a lookup service, don't need to
@@ -1476,11 +1501,11 @@ public class JoinManager {
      *  references a proxy to one of the lookup services with which this
      *  join manager's service is registered.
      */
-    private final ArrayList joinSet = new ArrayList(1);
+    private final ArrayList<ProxyReg> joinSet = new ArrayList<ProxyReg>(1);
     /** Contains the discovery manager that discovers the lookup services
      *  with which this join manager will register its associated service.
      */
-    private DiscoveryManagement discMgr = null;
+    private DiscoveryListenerManagement discMgr = null;
     /** Contains the discovery listener registered by this join manager with
      *  the discovery manager so that this join manager is notified whenever
      *  one of the desired lookup services is discovered or discarded.
@@ -1612,7 +1637,9 @@ public class JoinManager {
      * @see net.jini.discovery.DiscoveryManagement
      * @see net.jini.discovery.LookupDiscoveryManager
      * @see net.jini.lease.LeaseRenewalManager
+     * @deprecated {@link replaced by #JoinManager(Object, Entry[], ServiceIDListener, LeaseRenewalManager, DiscoveryListenerManagement)}
      */
+    @Deprecated
      public JoinManager(Object serviceProxy,
                         Entry[] attrSets,
 			ServiceIDListener callback,
@@ -1625,6 +1652,19 @@ public class JoinManager {
                              EmptyConfiguration.INSTANCE);
         } catch(ConfigurationException e) { /* swallow this exception */ }
     }//end constructor
+     
+     public JoinManager(Object serviceProxy,
+                        Entry[] attrSets,
+			ServiceIDListener callback,
+			LeaseRenewalManager leaseMgr,
+                        DiscoveryListenerManagement discoveryMgr)    throws IOException
+    {
+        discMgr = discoveryMgr;
+        try {
+           createJoinManager(null, serviceProxy, attrSets, callback, leaseMgr,
+                             EmptyConfiguration.INSTANCE);
+        } catch(ConfigurationException e) { /* swallow this exception */ }
+    }//end constructor
 
     /** 
      * Constructs an instance of this class, configured using the items
@@ -1729,6 +1769,7 @@ public class JoinManager {
      * @see net.jini.config.Configuration
      * @see net.jini.config.ConfigurationException
      */
+     @Deprecated
      public JoinManager(Object serviceProxy,
                         Entry[] attrSets,
 			ServiceIDListener callback,
@@ -1742,6 +1783,19 @@ public class JoinManager {
                           callback, leaseMgr, config);
     }//end constructor
 
+     public JoinManager(Object serviceProxy,
+                        Entry[] attrSets,
+			ServiceIDListener callback,
+                        LeaseRenewalManager leaseMgr,
+			DiscoveryListenerManagement discoveryMgr,
+                        Configuration config)
+                                    throws IOException, ConfigurationException
+    {
+        discMgr = discoveryMgr;
+        createJoinManager(null, serviceProxy, attrSets,
+                          callback, leaseMgr, config);
+    }//end constructor
+     
     /** 
      * Constructs an instance of this class that will register the
      * service with all discovered lookup services, using the supplied 
@@ -1791,6 +1845,7 @@ public class JoinManager {
      * @see net.jini.discovery.LookupDiscoveryManager
      * @see net.jini.lease.LeaseRenewalManager
      */
+     @Deprecated
      public JoinManager(Object serviceProxy,
                         Entry[] attrSets,
 			ServiceID serviceID,
@@ -1805,6 +1860,21 @@ public class JoinManager {
         } catch(ConfigurationException e) { /* swallow this exception */ }
     }//end constructor
 
+     public JoinManager(Object serviceProxy,
+                        Entry[] attrSets,
+			ServiceID serviceID,
+                        LeaseRenewalManager leaseMgr,
+			DiscoveryListenerManagement discoveryMgr)
+                        throws IOException
+    {
+        discMgr = discoveryMgr;
+        try {
+           createJoinManager(serviceID, serviceProxy, attrSets,
+                             (ServiceIDListener)null, leaseMgr,
+                             EmptyConfiguration.INSTANCE);
+        } catch(ConfigurationException e) { /* swallow this exception */ }
+    }//end constructor
+     
     /** 
      * Constructs an instance of this class, configured using the items
      * retrieved through the given <code>Configuration</code>, that will
@@ -1869,6 +1939,7 @@ public class JoinManager {
      * @see net.jini.config.Configuration
      * @see net.jini.config.ConfigurationException
      */
+     @Deprecated
      public JoinManager(Object serviceProxy,
                         Entry[] attrSets,
 			ServiceID serviceID,
@@ -1881,6 +1952,19 @@ public class JoinManager {
         createJoinManager(serviceID, serviceProxy, attrSets,
                           (ServiceIDListener)null, leaseMgr, config);
     }//end constructor
+     
+     public JoinManager(Object serviceProxy,
+                        Entry[] attrSets,
+			ServiceID serviceID,
+                        LeaseRenewalManager leaseMgr,
+			DiscoveryListenerManagement discoveryMgr,
+                        Configuration config)
+                                    throws IOException, ConfigurationException
+    {
+        discMgr = discoveryMgr;
+        createJoinManager(serviceID, serviceProxy, attrSets,
+                          (ServiceIDListener)null, leaseMgr, config);
+    }//end constructor
 
     /** 
      * Returns the instance of <code>DiscoveryManagement</code> that was
@@ -1899,16 +1983,54 @@ public class JoinManager {
      * 
      * @see net.jini.discovery.DiscoveryManagement
      * @see net.jini.discovery.LookupDiscoveryManager
+     * @deprecated replaced by {@link #discoveryManager()}
      */
+    @Deprecated
     public DiscoveryManagement getDiscoveryManager(){
         synchronized(this) {
             if(bTerminated) {
                 throw new IllegalStateException("join manager was terminated");
             }//endif
         }//end sync
-	return discMgr; 
+        // Don't need to worry about revealing facades, they do that in their
+        // constructor.
+        if (discMgr instanceof DiscoveryManagement){
+            return (DiscoveryManagement) discMgr;
+        }
+	return new DiscManFacade(discMgr);
+        
     }//end getDiscoveryManager
-
+    
+    /** 
+     * Returns the instance of <code>DiscoveryListenerManagement</code> that was
+     * either passed into the constructor, or that was created as a result
+     * of <code>null</code> being input to that parameter.
+     * <p>
+     * The object returned by this method encapsulates the mechanism by which
+     * either the <code>JoinManager</code> or the entity itself can set
+     * discovery listeners and discard previously discovered lookup services
+     * when they are found to be unavailable.
+     *
+     * @return the instance of the <code>DiscoveryListenerManagement</code> interface
+     *         that was either passed into the constructor, or that was
+     *         created as a result of <code>null</code> being input to that
+     *         parameter.
+     * 
+     * @see net.jini.discovery.DiscoveryListenerManagement
+     * @see net.jini.discovery.DiscoveryManagement2
+     * @see net.jini.discovery.LookupDiscoveryManager
+     */
+    public DiscoveryListenerManagement discoveryManager(){
+        synchronized(this) {
+            if(bTerminated) {
+                throw new IllegalStateException("join manager was terminated");
+            }//endif
+        }//end sync
+        // Don't need to worry about revealing facades, they do that in their
+        // constructor.
+	return discMgr;
+    }//end getDiscoveryManager
+    
     /** 
      * Returns the instance of the <code>LeaseRenewalManager</code> class
      * that was either passed into the constructor, or that was created
@@ -1938,6 +2060,7 @@ public class JoinManager {
 	return leaseRenewalMgr;
     }//end getLeaseRenewalManager
 
+
     /** 
      * Returns an array of <code>ServiceRegistrar</code> objects, each
      * corresponding to a lookup service with which the service is currently
@@ -1951,7 +2074,7 @@ public class JoinManager {
      * 
      * @see net.jini.core.lookup.ServiceRegistrar
      */
-    public ServiceRegistrar[] getJoinSet() {
+    public PortableServiceRegistrar[] getPJoinSet() {
         synchronized(this) {
             if(bTerminated) {
                 throw new IllegalStateException("join manager was terminated");
@@ -1966,11 +2089,38 @@ public class JoinManager {
                     retList.add(proxyReg.proxy);
                 }//endif
 	    }//end loop
+            return ( (PortableServiceRegistrar[])(retList.toArray
+                                 (new PortableServiceRegistrar[retList.size()]) ) );
+	}//end sync(joinSet)
+    }//end getPJoinSet
+    
+    @Deprecated
+    public ServiceRegistrar[] getJoinSet() {
+        synchronized(this) {
+            if(bTerminated) {
+                throw new IllegalStateException("join manager was terminated");
+            }//endif
+        }//end sync
+	synchronized(joinSet) {
+            ArrayList<ServiceRegistrar> retList = 
+                    new ArrayList<ServiceRegistrar>(joinSet.size());
+	    int k = 0;
+	    for (Iterator iter = joinSet.iterator(); iter.hasNext(); ) {
+                ProxyReg proxyReg = (ProxyReg)iter.next();
+                if(proxyReg.srvcRegistration != null) {//test registration flag
+                    PortableServiceRegistrar psr = proxyReg.proxy;
+                    if (psr instanceof ServiceRegistrar){
+                        retList.add((ServiceRegistrar)psr);
+                    }else{
+                        retList.add(new ServiceRegistrarFacade(psr));
+                    }
+                }//endif
+	    }//end loop
             return ( (ServiceRegistrar[])(retList.toArray
                                  (new ServiceRegistrar[retList.size()]) ) );
 	}//end sync(joinSet)
     }//end getJoinSet
-
+    
     /** 
      * Returns an array containing the set of attributes currently associated
      * with the service. If the service is not currently associated with an
@@ -2560,10 +2710,12 @@ public class JoinManager {
 	if(discMgr == null) {
 	    bCreateDiscMgr = true;
             try {
-                discMgr = (DiscoveryManagement)config.getEntry
+                // Changed to the new Interface which all DiscoveryManagers
+                // must implement.
+                discMgr = (DiscoveryManagement2)config.getEntry
                                                  (COMPONENT_NAME,
                                                   "discoveryManager",
-                                                  DiscoveryManagement.class);
+                                                  DiscoveryManagement2.class);
             } catch(NoSuchEntryException e) { /* use default */
                 discMgr = new LookupDiscoveryManager
                                      (new String[] {""}, null, null, config);
@@ -2577,7 +2729,11 @@ public class JoinManager {
      *  such an element, returns that element; otherwise returns
      *  <code>null</code>.
      */
-    private ProxyReg findReg(ServiceRegistrar proxy) {
+    private ProxyReg findReg(PortableServiceRegistrar proxy) {
+        while ( proxy instanceof Facade){
+            Facade f = (Facade)proxy;
+            proxy = (PortableServiceRegistrar) f.reveal();
+        }
 	for (Iterator iter = joinSet.iterator(); iter.hasNext(); ) {
 	    ProxyReg reg =(ProxyReg)iter.next();
 	    if(reg.proxy.equals(proxy))  return reg;

Modified: incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceDiscoveryManager.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceDiscoveryManager.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceDiscoveryManager.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceDiscoveryManager.java Fri Apr 23 05:14:10 2010
@@ -21,7 +21,6 @@ import com.sun.jini.logging.Levels;
 import com.sun.jini.lookup.entry.LookupAttributes;
 import com.sun.jini.proxy.BasicProxyTrustVerifier;
 import com.sun.jini.thread.TaskManager;
-import com.sun.jini.thread.TaskManager.Task;
 
 import net.jini.config.Configuration;
 import net.jini.config.ConfigurationException;
@@ -53,15 +52,12 @@ import net.jini.core.lookup.ServiceID;
 import net.jini.core.lookup.ServiceEvent;
 import net.jini.core.lookup.ServiceItem;
 import net.jini.core.lookup.ServiceMatches;
-import net.jini.core.lookup.ServiceRegistrar;
 import net.jini.core.lookup.ServiceTemplate;
 
 import java.io.IOException;
 
 import java.rmi.RemoteException;
 import java.rmi.server.ExportException;
-import java.rmi.server.RemoteObject;
-import java.rmi.server.UnicastRemoteObject;
 
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -72,6 +68,12 @@ import java.util.logging.Logger;
 import java.util.Map;
 import java.util.Random;
 import java.util.Set;
+import net.jini.core.lookup.PortableServiceRegistrar;
+import net.jini.core.lookup.StreamServiceRegistrar;
+import net.jini.discovery.DiscMan2Facade;
+import net.jini.discovery.DiscManFacade;
+import net.jini.discovery.DiscoveryManagement2;
+import net.jini.discovery.Facade;
 
 /**
  * The <code>ServiceDiscoveryManager</code> class is a helper utility class
@@ -600,7 +602,7 @@ import java.util.Set;
  * @see net.jini.lookup.LookupCache
  * @see net.jini.lookup.ServiceDiscoveryListener
  * @see net.jini.lookup.ServiceDiscoveryEvent
- * @see net.jini.core.lookup.ServiceRegistrar
+ * @see net.jini.core.lookup.PortableServiceRegistrar
  */
 public class ServiceDiscoveryManager {
 
@@ -742,7 +744,8 @@ public class ServiceDiscoveryManager {
      */
     private final static class ServiceItemReg  {
 	/* Stores ServiceRegistrars that has the ServiceItem registered. */
-	private final ArrayList proxys = new ArrayList(1);
+	private final ArrayList<PortableServiceRegistrar> proxys = 
+                new ArrayList<PortableServiceRegistrar>(1);
 	/* Flag that indicates that the ServiceItem has been discarded. */
 	private boolean bDiscarded = false;
         /* The discovered service, prior to filtering. */
@@ -752,21 +755,21 @@ public class ServiceDiscoveryManager {
         /* Creates an instance of this class, and associates it with the given
          * lookup service proxy.
          */
-	public ServiceItemReg(ServiceRegistrar proxy, ServiceItem item) {
+	public ServiceItemReg(PortableServiceRegistrar proxy, ServiceItem item) {
 	    addProxy(proxy);
 	    this.item = item;
-	}
+	}  
 	/* Adds the given proxy to the 'id-to-itemReg' map. This method is
          * called from this class' constructor, LookupTask, NotifyEventTask,
          * and ProxyRegDropTask.
          */
-	public void addProxy(ServiceRegistrar proxy) {
+	public void addProxy(PortableServiceRegistrar proxy) {
 	    if(!proxys.contains(proxy))  proxys.add(proxy);
 	}
 	/* Removes the given proxy from the 'id-to-itemReg' map. This method
          * is called from NotifyEventTask and ProxyRegDropTask.
          */
-	public void removeProxy(ServiceRegistrar proxy) {
+	public void removeProxy(PortableServiceRegistrar proxy) {
 	    int index = proxys.indexOf(proxy);
 	    if(index != -1)  proxys.remove(index);
 	}
@@ -788,10 +791,14 @@ public class ServiceDiscoveryManager {
 
     /** A wrapper class for a ServiceRegistrar. */
     private final static class ProxyReg  {
-	public ServiceRegistrar proxy;
-	public ProxyReg(ServiceRegistrar proxy) {
+	public PortableServiceRegistrar proxy;
+	public ProxyReg(PortableServiceRegistrar proxy) {
 	    if(proxy == null)  throw new IllegalArgumentException
                                                      ("proxy cannot be null");
+            // Unwrap any facades.
+            while ( proxy instanceof Facade){
+                proxy = (PortableServiceRegistrar) ((Facade)proxy).reveal();
+            }
 	    this.proxy = proxy;
 	}//end constructor	    
 
@@ -809,8 +816,8 @@ public class ServiceDiscoveryManager {
     
     /** The Listener class for the LeaseRenewalManager. */
     private final class LeaseListenerImpl implements LeaseListener {
-	private ServiceRegistrar proxy;
-	public LeaseListenerImpl(ServiceRegistrar proxy) {
+	private PortableServiceRegistrar proxy;
+	public LeaseListenerImpl(PortableServiceRegistrar proxy) {
 	    this.proxy = proxy;
 	}
 	/* When lease renewal fails, we discard the proxy  */
@@ -932,7 +939,7 @@ public class ServiceDiscoveryManager {
 	    }
             public void run() {
                 logger.finest("ServiceDiscoveryManager - LookupTask started");
-		ServiceRegistrar proxy = reg.proxy;
+		PortableServiceRegistrar proxy = reg.proxy;
 		ServiceMatches matches;
                 /* For the given lookup, get all services matching the tmpl */
 		try {
@@ -1149,21 +1156,21 @@ public class ServiceDiscoveryManager {
                  * the associated ServiceItem is an old, previously discovered
                  * item, or a newly discovered item.
                  */
-                if(transition == ServiceRegistrar.TRANSITION_MATCH_NOMATCH) {
+                if(transition == PortableServiceRegistrar.TRANSITION_MATCH_NOMATCH) {
                     logger.finer("ServiceDiscoveryManager.NotifyEventTask - "
                                  +"transition=TRANSITION_MATCH_NOMATCH");
                     handleMatchNoMatch(reg.proxy, sid, item);
                 } else {//(transition == NOMATCH_MATCH or MATCH_MATCH)
                     if (logger.isLoggable(Level.FINER)) {
                         if(transition == 
-                                   ServiceRegistrar.TRANSITION_MATCH_MATCH)
+                                   PortableServiceRegistrar.TRANSITION_MATCH_MATCH)
                         {
                             logger.finer("ServiceDiscoveryManager."
                                          +"NotifyEventTask - "
                                          +"transition="
                                          +"TRANSITION_MATCH_MATCH");
                         } else if(transition == 
-                                   ServiceRegistrar.TRANSITION_NOMATCH_MATCH)
+                                   PortableServiceRegistrar.TRANSITION_NOMATCH_MATCH)
                         { 
                             logger.finer("ServiceDiscoveryManager."
                                          +"NotifyEventTask - "
@@ -1173,7 +1180,7 @@ public class ServiceDiscoveryManager {
                     }//endif
 
                     (new NewOldServiceTask(reg, item,
-                       (transition == ServiceRegistrar.TRANSITION_MATCH_MATCH),
+                       (transition == PortableServiceRegistrar.TRANSITION_MATCH_MATCH),
                                                thisTaskSeqN)).run();
                 }//endif(transition)
                 logger.finest("ServiceDiscoveryManager - NotifyEventTask "
@@ -2053,7 +2060,7 @@ public class ServiceDiscoveryManager {
          *  This method applies the filter only after the above comparisons
          *  and determinations have been completed.
          */ 
-	private void itemMatchMatchChange(ServiceRegistrar proxy,
+	private void itemMatchMatchChange(PortableServiceRegistrar proxy,
                                           ServiceItem newItem,
                                           ServiceItemReg itemReg,
                                           boolean matchMatchEvent )
@@ -2326,7 +2333,7 @@ public class ServiceDiscoveryManager {
          *  <code>serviceIdMap</code> is left unchanged.
 	 */
   	private ServiceItem filterMaybeDiscard(ServiceItem item,
-                                               ServiceRegistrar proxy,
+                                               PortableServiceRegistrar proxy,
 				               boolean sendEvent) 
         {
             if( (item == null) || (item.service == null) ) return null;
@@ -2403,7 +2410,7 @@ public class ServiceDiscoveryManager {
          *  given <code>ServiceItem</code>, then this method simply returns.
 	 */
   	private void discardRetryLater(ServiceItem item, 
-                                       ServiceRegistrar proxy,
+                                       PortableServiceRegistrar proxy,
                                        boolean sendEvent) {
             ServiceItemReg itemReg = null;
             synchronized(serviceIdMap) {
@@ -2436,7 +2443,7 @@ public class ServiceDiscoveryManager {
          *  and wakes up the <code>ServiceDiscardTimerTask</code> if the given
          *  <code>item</code> is discarded; otherwise, sends a removed event.
 	 */
-  	private void handleMatchNoMatch(ServiceRegistrar proxy,
+  	private void handleMatchNoMatch(PortableServiceRegistrar proxy,
                                         ServiceID srvcID,
                                         ServiceItem item)
         {
@@ -2482,7 +2489,7 @@ public class ServiceDiscoveryManager {
     /* Logger used by this utility. */
     private static final Logger logger = Logger.getLogger(COMPONENT_NAME);
     /* The discovery manager to use (passed in, or create one). */
-    private DiscoveryManagement discMgr;
+    private DiscoveryManagement2 discMgr;
     /* Indicates whether the discovery manager was created internally or not */
     private boolean discMgrInternal = false;
     /* The listener added to discMgr that receives DiscoveryEvents */
@@ -2490,13 +2497,13 @@ public class ServiceDiscoveryManager {
     /* The LeaseRenewalManager to use (passed in, or create one). */
     private LeaseRenewalManager leaseRenewalMgr;
     /* Contains all of the discovered lookup services (ServiceRegistrar). */
-    private final ArrayList proxyRegSet = new ArrayList(1);
+    private final ArrayList<ProxyReg> proxyRegSet = new ArrayList<ProxyReg>(1);
     /* Contains all of the DiscoveryListener's employed in lookup discovery. */
-    private final ArrayList listeners = new ArrayList(1);
+    private final ArrayList<DiscoveryListener> listeners = new ArrayList<DiscoveryListener>(1);
     /* Random number generator for use in lookup. */
     private final Random random = new Random();
     /* Contains all of the instances of LookupCache that are requested. */
-    private final ArrayList caches = new ArrayList(1);
+    private final ArrayList<LookupCache> caches = new ArrayList<LookupCache>(1);
 
     /* Flag to indicate if the ServiceDiscoveryManager has been terminated. */
     private boolean bTerminated = false;
@@ -2518,14 +2525,14 @@ public class ServiceDiscoveryManager {
     private class DiscMgrListener implements DiscoveryListener {
 	/* New or previously discarded proxy has been discovered. */
 	public void discovered(DiscoveryEvent e) {
-	    ServiceRegistrar[] proxys = (ServiceRegistrar[])e.getRegistrars();
+	    PortableServiceRegistrar[] proxys = (PortableServiceRegistrar[])e.getPRegistrars();
 	    ArrayList newProxys = new ArrayList(1);
 	    ArrayList notifies  = null;
 	    for(int i=0; i<proxys.length; i++) {
                 /* Prepare each lookup service proxy before using it. */
                 try {
                     proxys[i]
-                          = (ServiceRegistrar)registrarPreparer.prepareProxy
+                          = (PortableServiceRegistrar)registrarPreparer.prepareProxy
                                                                    (proxys[i]);
                     logger.log(Level.FINEST, "ServiceDiscoveryManager - "
                               +"discovered lookup service proxy prepared: {0}",
@@ -2558,7 +2565,7 @@ public class ServiceDiscoveryManager {
 
 	/* Previously discovered proxy has been discarded. */
 	public void discarded(DiscoveryEvent e) {
-	    ServiceRegistrar[] proxys = (ServiceRegistrar[])e.getRegistrars();
+	   PortableServiceRegistrar[] proxys = e.getPRegistrars();
 	    ArrayList notifies;
 	    ArrayList drops = new ArrayList(1);
 	    synchronized(proxyRegSet) {
@@ -2568,7 +2575,10 @@ public class ServiceDiscoveryManager {
 			proxyRegSet.remove(proxyRegSet.indexOf(reg));
 			drops.add(reg);
 		    } else {
-			throw new RuntimeException("discard error");
+			//throw new RuntimeException("discard error");
+                        if (logger.isLoggable(Level.WARNING)){
+                            logger.log(Level.WARNING, COMPONENT_NAME, "River-337");
+                        }
                     }//endif
 		}//end loop
 	    }//end sync(proxyRegSet)
@@ -2770,7 +2780,9 @@ public class ServiceDiscoveryManager {
      * @see net.jini.discovery.DiscoveryManagement
      * @see net.jini.core.event.RemoteEventListener
      * @see net.jini.core.lookup.ServiceRegistrar
+     * @deprecated 
      */
+    @Deprecated
     public ServiceDiscoveryManager(DiscoveryManagement discoveryMgr,
                                    LeaseRenewalManager leaseMgr)
                                                             throws IOException
@@ -2779,6 +2791,15 @@ public class ServiceDiscoveryManager {
             init(discoveryMgr, leaseMgr, EmptyConfiguration.INSTANCE);
         } catch(ConfigurationException e) { /* swallow this exception */ }
     }//end constructor
+    
+    public ServiceDiscoveryManager(LeaseRenewalManager leaseMgr,
+                                   DiscoveryManagement2 discoveryMgr)
+                                                            throws IOException
+    {
+        try {
+            init(discoveryMgr, leaseMgr, EmptyConfiguration.INSTANCE);
+        } catch(ConfigurationException e) { /* swallow this exception */ }
+    }//end constructor
 
     /**
      * Constructs an instance of this class, which is configured using the
@@ -2841,7 +2862,9 @@ public class ServiceDiscoveryManager {
      * @see net.jini.core.lookup.ServiceRegistrar
      * @see net.jini.config.Configuration
      * @see net.jini.config.ConfigurationException
+     * @deprecated 
      */
+    @Deprecated
     public ServiceDiscoveryManager(DiscoveryManagement discoveryMgr,
                                    LeaseRenewalManager leaseMgr,
                                    Configuration config)
@@ -2851,39 +2874,51 @@ public class ServiceDiscoveryManager {
         init(discoveryMgr, leaseMgr, config);
     }//end constructor
 
+    public ServiceDiscoveryManager(LeaseRenewalManager leaseMgr,
+                                   Configuration config,
+                                   DiscoveryManagement2 discoveryMgr)
+                                                throws IOException,
+                                                       ConfigurationException
+    {
+        init(discoveryMgr, leaseMgr, config);
+    }//end constructor
+    
     /** Sends discarded event to each listener waiting for discarded lookups.*/
-    private void listenerDropped(ArrayList drops, ArrayList notifies) {
-	ServiceRegistrar[] proxys = new ServiceRegistrar[drops.size()];
+    private void listenerDropped(ArrayList<PortableServiceRegistrar> drops,
+            ArrayList<DiscoveryListener> notifies) {
+	PortableServiceRegistrar[] proxys = new PortableServiceRegistrar[drops.size()];
 	drops.toArray(proxys);
 	listenerDropped(proxys, notifies);
     }//end listenerDropped
 
     /** Sends discarded event to each listener waiting for discarded lookups.*/
-    private void listenerDropped(ServiceRegistrar[] proxys,ArrayList notifies){
+    private void listenerDropped(PortableServiceRegistrar[] proxys,
+            ArrayList<DiscoveryListener> notifies){
 	Iterator iter = notifies.iterator();
 	while (iter.hasNext()) {
 	    DiscoveryEvent evt = new DiscoveryEvent
                                         ( this,
-                                          (ServiceRegistrar[])proxys.clone() );
+                                          (PortableServiceRegistrar[])proxys.clone() );
 	    ((DiscoveryListener)iter.next()).discarded(evt);
 	}//end loop
     }//end listenerDropped
 
     /** Sends discovered event to each listener listening for new lookups. */
-    private void listenerDiscovered(ServiceRegistrar proxy,ArrayList notifies){
+    private void listenerDiscovered(PortableServiceRegistrar proxy,
+            ArrayList<DiscoveryListener> notifies){
 	Iterator iter = notifies.iterator();
 	while (iter.hasNext()) {
 	    DiscoveryEvent evt = new DiscoveryEvent
                                         ( this,
-                                          new ServiceRegistrar[]{proxy} );
+                                          new PortableServiceRegistrar[]{proxy} );
 	    ((DiscoveryListener)iter.next()).discovered(evt);
 	}//end loop
     }//end listenerDiscovered
    
     /** Returns array of ServiceRegistrar created from the proxyRegSet */
-    private ServiceRegistrar[] buildServiceRegistrar() {
+    private PortableServiceRegistrar[] buildServiceRegistrar() {
 	int k = 0;
-	ServiceRegistrar[] proxys = new ServiceRegistrar[proxyRegSet.size()];
+	PortableServiceRegistrar[] proxys = new PortableServiceRegistrar[proxyRegSet.size()];
 	Iterator iter = proxyRegSet.iterator();
 	while(iter.hasNext()) {
 	    ProxyReg reg = (ProxyReg)iter.next();
@@ -2970,7 +3005,7 @@ public class ServiceDiscoveryManager {
      */
     public ServiceItem lookup(ServiceTemplate tmpl, ServiceItemFilter filter) {
 	checkTerminated();
-	ServiceRegistrar[] proxys;
+	PortableServiceRegistrar[] proxys;
 	synchronized(proxyRegSet) {
 	    proxys =  buildServiceRegistrar();
 	}
@@ -2978,7 +3013,7 @@ public class ServiceDiscoveryManager {
 	if(len == 0 ) return null;
 	int rand = Math.abs(random.nextInt()) % len;
 	for(int i=0; i<len; i++) {
-	    ServiceRegistrar proxy = proxys[(i + rand) % len];
+	    PortableServiceRegistrar proxy = proxys[(i + rand) % len];
 	    ServiceItem sItem = null;
 	    try {
                 int maxMatches = ( (filter != null) ? Integer.MAX_VALUE : 1 );
@@ -3198,10 +3233,16 @@ public class ServiceDiscoveryManager {
      *  @return DiscoveryManagement implementation
      *  @see net.jini.discovery.DiscoveryManagement
      */
+    @Deprecated
     public DiscoveryManagement getDiscoveryManager() {
 	checkTerminated();
-	return discMgr;
+	return new DiscManFacade(discMgr);
     }//end getDiscoveryManager
+    
+    public DiscoveryManagement2 discoveryManager() {
+        checkTerminated();
+        return discMgr;
+    }
 
     /** 
      * The <code>getLeaseRenewalManager</code> method will return an
@@ -3364,9 +3405,9 @@ public class ServiceDiscoveryManager {
 	if (maxMatches < 1)
 	    throw new IllegalArgumentException("maxMatches must be > 0");
         /* retrieve the lookup service(s) to query for matching service(s) */
-	ServiceRegistrar[] proxys;
+	PortableServiceRegistrar[] proxys;
 	synchronized(proxyRegSet) {
-	    proxys =  buildServiceRegistrar();
+	    proxys = buildServiceRegistrar();
 	}
 	int len = proxys.length;
 	ArrayList sItemSet = new ArrayList(len);
@@ -3375,7 +3416,7 @@ public class ServiceDiscoveryManager {
 	    int rand = (Math.abs(random.nextInt())) % len;
 	    for(int i=0; i<len; i++) {
                 int max = maxMatches;
-		ServiceRegistrar proxy = proxys[(i + rand) % len];
+		PortableServiceRegistrar proxy = proxys[(i + rand) % len];
 		try {
                     /* If a filter is to be applied (filter != null), then
                      * the value of the maxMatches parameter will not 
@@ -3650,7 +3691,10 @@ public class ServiceDiscoveryManager {
     }//end createLookupCache
 
     /** Returns element from proxyRegSet that corresponds to the given proxy.*/
-    private ProxyReg findReg(ServiceRegistrar proxy) {
+    private ProxyReg findReg(PortableServiceRegistrar proxy) {
+        if (proxy instanceof Facade){
+            proxy = (PortableServiceRegistrar) ((Facade)proxy).reveal();
+        }
 	Iterator iter = proxyRegSet.iterator();
 	while(iter.hasNext()) {
 	    ProxyReg reg =(ProxyReg)iter.next();
@@ -3682,7 +3726,7 @@ public class ServiceDiscoveryManager {
      *  For more information, refer to Bug 4490358 and 4858211.
      */
     private void fail(Throwable e,
-                      ServiceRegistrar proxy,
+                      PortableServiceRegistrar proxy,
                       String sourceClass,
                       String sourceMethod,
                       String msg,
@@ -3714,7 +3758,7 @@ public class ServiceDiscoveryManager {
     }//end fail
 
     /** Discards a ServiceRegistrar through the discovery manager.*/
-    private void discard(ServiceRegistrar proxy) {
+    private void discard(PortableServiceRegistrar proxy) {
 	discMgr.discard(proxy);
     }//end discard
 
@@ -3740,17 +3784,27 @@ public class ServiceDiscoveryManager {
      *  attempt, this method discards the lookup service and returns
      *  <code>null</code>.
      */
-    private EventReg registerListener(ServiceRegistrar proxy,
+    private EventReg registerListener(PortableServiceRegistrar proxy,
 			              ServiceTemplate tmpl,
 			              RemoteEventListener listenerProxy,
 			              long duration)  throws RemoteException
     {
         /* Register with the event mechanism of the given lookup service */
         EventRegistration e = null;
-        int transition = (   ServiceRegistrar.TRANSITION_NOMATCH_MATCH
-                           | ServiceRegistrar.TRANSITION_MATCH_NOMATCH
-                           | ServiceRegistrar.TRANSITION_MATCH_MATCH   );
-        e = proxy.notify(tmpl, transition, listenerProxy, null, duration);
+        int transition = (   PortableServiceRegistrar.TRANSITION_NOMATCH_MATCH
+                           | PortableServiceRegistrar.TRANSITION_MATCH_NOMATCH
+                           | PortableServiceRegistrar.TRANSITION_MATCH_MATCH   );
+        if (proxy instanceof StreamServiceRegistrar){
+            e = ((StreamServiceRegistrar)proxy).notify(null, tmpl, transition, listenerProxy, duration);
+        }
+        try {
+            // This should be the only occurrance of ServiceRegistrar in this class.
+            if (proxy instanceof net.jini.core.lookup.ServiceRegistrar){
+                e = ((net.jini.core.lookup.ServiceRegistrar)proxy).notify(tmpl, transition, listenerProxy, null, duration);
+            }
+        } catch (NoClassDefFoundError er) {
+             // This is expected for Java CDC, ServiceRegistrar is not supported.
+        }
         /* Proxy preparation -
          * 
          * Prepare the proxy to the lease on the event registration just
@@ -3825,11 +3879,19 @@ public class ServiceDiscoveryManager {
 	}//end loop
 	return false;
     }//end isArrayContainsServiceItems
+    
+    private void init(DiscoveryManagement discoveryMgr,
+                      LeaseRenewalManager leaseMgr,
+                      Configuration config)
+                                    throws IOException, ConfigurationException
+    {
+        init(new DiscMan2Facade(discoveryMgr), leaseMgr, config);
+    }
 
     /* Convenience method that encapsulates the retrieval of the configurable
      * items from the given <code>Configuration</code> object.
      */
-    private void init(DiscoveryManagement discoveryMgr,
+    private void init(DiscoveryManagement2 discoveryMgr,
                       LeaseRenewalManager leaseMgr,
                       Configuration config)
                                     throws IOException, ConfigurationException
@@ -3872,10 +3934,11 @@ public class ServiceDiscoveryManager {
 	if(discMgr == null) {
 	    discMgrInternal = true;
             try {
-                discMgr = (DiscoveryManagement)thisConfig.getEntry
+                // All Discovery Managers Must implement DiscoveryManagement2
+                discMgr = (DiscoveryManagement2)thisConfig.getEntry
                                                    (COMPONENT_NAME,
                                                     "discoveryManager",
-                                                    DiscoveryManagement.class);
+                                                    DiscoveryManagement2.class);
             } catch(NoSuchEntryException e) { /* use default */
                 discMgr = new LookupDiscoveryManager
                                    (new String[] {""}, null, null, thisConfig);

Modified: incubator/river/jtsk/trunk/src/net/jini/security/ProxyPreparer.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/security/ProxyPreparer.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/security/ProxyPreparer.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/security/ProxyPreparer.java Fri Apr 23 05:14:10 2010
@@ -19,9 +19,6 @@
 package net.jini.security;
 
 import java.rmi.RemoteException;
-import net.jini.config.Configuration;
-import net.jini.core.constraint.RemoteMethodControl;
-import net.jini.security.Security;
 
 /**
  * Performs operations on a newly unmarshalled remote proxy to prepare it for