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 [1/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...

Author: peter_firmstone
Date: Fri Apr 23 05:14:10 2010
New Revision: 937157

URL: http://svn.apache.org/viewvc?rev=937157&view=rev
Log:
A significant number of changes to commence integrating the new StreamServiceRegistrar and DiscoveryManager2 implementations into Jini's API.

This is very experimental please comment, suggest improvements etc, where new classes should go etc.

Also please check for backward compatibility issues.

Added:
    incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamServiceRegistrar.java
      - copied, changed from r935433, incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamingServiceRegistrar.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/DiscMan2Facade.java   (with props)
    incubator/river/jtsk/trunk/src/net/jini/discovery/DiscManFacade.java   (with props)
    incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryListenerManagement.java   (with props)
    incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryManagement2.java   (with props)
    incubator/river/jtsk/trunk/src/net/jini/discovery/Facade.java   (with props)
    incubator/river/jtsk/trunk/src/net/jini/discovery/ServiceRegistrarFacade.java   (with props)
    incubator/river/jtsk/trunk/src/net/jini/discovery/StreamServiceRegistrarFacade.java   (with props)
Removed:
    incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamingServiceRegistrar.java
Modified:
    incubator/river/jtsk/trunk/src/com/sun/jini/discovery/DiscoveryV1.java
    incubator/river/jtsk/trunk/src/com/sun/jini/discovery/UnicastResponse.java
    incubator/river/jtsk/trunk/src/com/sun/jini/discovery/internal/MultiIPDiscovery.java
    incubator/river/jtsk/trunk/src/com/sun/jini/discovery/internal/Plaintext.java
    incubator/river/jtsk/trunk/src/com/sun/jini/jeri/internal/runtime/Util.java
    incubator/river/jtsk/trunk/src/com/sun/jini/lease/BasicRenewalFailureEvent.java
    incubator/river/jtsk/trunk/src/com/sun/jini/lookup/entry/LookupAttributes.java
    incubator/river/jtsk/trunk/src/com/sun/jini/mahalo/JoinStateManager.java
    incubator/river/jtsk/trunk/src/com/sun/jini/mahalo/TxnManagerTransaction.java
    incubator/river/jtsk/trunk/src/net/jini/core/discovery/LookupLocator.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/ConstrainableLookupLocator.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryEvent.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryManagement.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/IncomingUnicastResponse.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/discovery/OutgoingUnicastResponse.java
    incubator/river/jtsk/trunk/src/net/jini/lease/RenewalFailureEvent.java
    incubator/river/jtsk/trunk/src/net/jini/lookup/JoinManager.java
    incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceDiscoveryManager.java
    incubator/river/jtsk/trunk/src/net/jini/security/ProxyPreparer.java

Modified: incubator/river/jtsk/trunk/src/com/sun/jini/discovery/DiscoveryV1.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/discovery/DiscoveryV1.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/com/sun/jini/discovery/DiscoveryV1.java (original)
+++ incubator/river/jtsk/trunk/src/com/sun/jini/discovery/DiscoveryV1.java Fri Apr 23 05:14:10 2010
@@ -21,17 +21,13 @@ package com.sun.jini.discovery;
 import com.sun.jini.discovery.internal.Plaintext;
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutput;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.io.UTFDataFormatException;
 import java.net.DatagramPacket;
 import java.net.Socket;
 import java.nio.ByteBuffer;
-import java.rmi.MarshalledObject;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedList;
@@ -43,6 +39,8 @@ import net.jini.core.lookup.ServiceID;
 import net.jini.core.lookup.ServiceRegistrar;
 import net.jini.discovery.Constants;
 import net.jini.io.MarshalledInstance;
+import net.jini.io.MiToMoOutputStream;
+import net.jini.io.MoToMiInputStream;
 import net.jini.io.UnsupportedConstraintException;
 
 /**
@@ -389,11 +387,10 @@ class DiscoveryV1 extends Discovery {
 	    String host = socket.getInetAddress().getHostAddress();
 	    int port = socket.getPort();
 
-	    // read LUS proxy
-	    ObjectInputStream oin = new ObjectInputStream(
+	    // read LUS proxy - Converted from java.rmi.MarshalledObject form.
+	    ObjectInputStream oin = new MoToMiInputStream(
 		new BufferedInputStream(socket.getInputStream()));
-	    MarshalledInstance mi = 
-		new MarshalledInstance((MarshalledObject) oin.readObject());
+	    MarshalledInstance mi = (MarshalledInstance) oin.readObject();
 	    ServiceRegistrar reg = 
 		(ServiceRegistrar) mi.get(defaultLoader, false, null, context);
 
@@ -435,11 +432,11 @@ class DiscoveryV1 extends Discovery {
 	// note: unicast request (the protocol version) already consumed
 
 	// write LUS proxy
-	ObjectOutputStream oout = new ObjectOutputStream(
+	ObjectOutputStream oout = new MiToMoOutputStream(
 	    new BufferedOutputStream(socket.getOutputStream()));
 	oout.writeObject(
 	    new MarshalledInstance(
-		response.getRegistrar(), context).convertToMarshalledObject());
+		response.getPRegistrar(), context));
 
 	// write LUS member groups
 	String[] groups = response.getGroups();

Modified: incubator/river/jtsk/trunk/src/com/sun/jini/discovery/UnicastResponse.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/discovery/UnicastResponse.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/com/sun/jini/discovery/UnicastResponse.java (original)
+++ incubator/river/jtsk/trunk/src/com/sun/jini/discovery/UnicastResponse.java Fri Apr 23 05:14:10 2010
@@ -19,7 +19,9 @@
 package com.sun.jini.discovery;
 
 import java.util.Arrays;
+import net.jini.core.lookup.PortableServiceRegistrar;
 import net.jini.core.lookup.ServiceRegistrar;
+import net.jini.discovery.ServiceRegistrarFacade;
 
 /**
  * Class representing the values obtained as the result of unicast discovery.
@@ -36,12 +38,16 @@ public class UnicastResponse {
     /** The lookup service member groups. */
     protected String[] groups;
     /** The lookup service proxy. */
-    protected ServiceRegistrar registrar;
-
+    protected PortableServiceRegistrar registrar;
+    
     /**
      * Creates new <code>UnicastResponse</code> instance containing the given
      * values.  The <code>groups</code> array is copied; a <code>null</code>
      * value is considered equivalent to an empty array.
+     * 
+     * This constructor has been changed in 2.2.0 to break binary compatibility
+     * with 2.2.1 however it is still compile time compatible.  I figured
+     * that client code will utilise this class, but be unlikely to construct it.
      *
      * @param host the lookup service host
      * @param port the lookup service listen port
@@ -55,9 +61,9 @@ public class UnicastResponse {
     public UnicastResponse(String host,
 			   int port,
 			   String[] groups,
-			   ServiceRegistrar registrar)
+			   PortableServiceRegistrar registrar)
     {
-	groups = (groups != null) ? (String[]) groups.clone() : new String[0];
+	groups = (groups != null) ? groups.clone() : new String[0];
 	if (host == null ||
 	    registrar == null ||
 	    Arrays.asList(groups).contains(null))
@@ -102,13 +108,28 @@ public class UnicastResponse {
 
     /**
      * Returns the lookup service proxy.
-     *
+     * 
      * @return the lookup service proxy
+     * @since 2.2.0
      */
-    public ServiceRegistrar getRegistrar() {
+    public PortableServiceRegistrar getPRegistrar() {
 	return registrar;
     }
-
+    
+    /**
+     * Returns the lookup service proxy.
+     * 
+     * @return the lookup service proxy
+     * @deprecated replaced by {@link #getPRegistrar()}
+     */
+    @Deprecated
+    public ServiceRegistrar getRegistrar() {
+        if(registrar instanceof ServiceRegistrar ){
+            return (ServiceRegistrar)registrar;
+        }
+        return new ServiceRegistrarFacade(registrar);
+    }
+    
     /**
      * Returns a string representation of this response.
      *

Modified: incubator/river/jtsk/trunk/src/com/sun/jini/discovery/internal/MultiIPDiscovery.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/discovery/internal/MultiIPDiscovery.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/com/sun/jini/discovery/internal/MultiIPDiscovery.java (original)
+++ incubator/river/jtsk/trunk/src/com/sun/jini/discovery/internal/MultiIPDiscovery.java Fri Apr 23 05:14:10 2010
@@ -29,7 +29,6 @@ import java.net.SocketException;
 import java.net.SocketTimeoutException;
 import java.net.UnknownHostException;
 import net.jini.core.constraint.InvocationConstraints;
-import net.jini.core.lookup.ServiceRegistrar;
 
 /**
  * Utility class used by implementations which want to perform unicast

Modified: incubator/river/jtsk/trunk/src/com/sun/jini/discovery/internal/Plaintext.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/discovery/internal/Plaintext.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/com/sun/jini/discovery/internal/Plaintext.java (original)
+++ incubator/river/jtsk/trunk/src/com/sun/jini/discovery/internal/Plaintext.java Fri Apr 23 05:14:10 2010
@@ -424,7 +424,7 @@ public class Plaintext {
 
 	    // write LUS proxy
 	    new ObjectOutputStream(out).writeObject(
-		new MarshalledInstance(response.getRegistrar(), context));
+		new MarshalledInstance(response.getPRegistrar(), context));
 	} catch (RuntimeException e) {
 	    throw new DiscoveryProtocolException(null, e);
 	}

Modified: incubator/river/jtsk/trunk/src/com/sun/jini/jeri/internal/runtime/Util.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/jeri/internal/runtime/Util.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/com/sun/jini/jeri/internal/runtime/Util.java (original)
+++ incubator/river/jtsk/trunk/src/com/sun/jini/jeri/internal/runtime/Util.java Fri Apr 23 05:14:10 2010
@@ -31,10 +31,8 @@ import java.lang.ref.SoftReference;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.net.URL;
-import java.rmi.MarshalledObject;
 import java.rmi.Remote;
 import java.rmi.RemoteException;
-import java.rmi.activation.ActivationID;
 import java.security.DigestOutputStream;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
@@ -46,6 +44,7 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.WeakHashMap;
 import java.net.InetAddress;
+// We need a JERI equivalent that extends RemoteException
 import java.rmi.server.ServerNotActiveException;
 import javax.security.auth.Subject;
 import net.jini.export.ServerContext;
@@ -70,9 +69,10 @@ public class Util {
     private static Map proxyRemoteMethodCache = new WeakHashMap();
 
     /** parameter types for activatable constructor or activate method */
-    private static Class[] paramTypes = {
-	ActivationID.class, MarshalledObject.class
-    };
+//   Doesn't appear to be utilised?    
+//    private static Class[] paramTypes = {
+//	ActivationID.class, MarshalledObject.class
+//    };
 
     /** name of the resource containing prohibited proxy interfaces */
     private static final String prohibitedProxyInterfacesResource =

Modified: incubator/river/jtsk/trunk/src/com/sun/jini/lease/BasicRenewalFailureEvent.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/lease/BasicRenewalFailureEvent.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/com/sun/jini/lease/BasicRenewalFailureEvent.java (original)
+++ incubator/river/jtsk/trunk/src/com/sun/jini/lease/BasicRenewalFailureEvent.java Fri Apr 23 05:14:10 2010
@@ -82,7 +82,9 @@ public class BasicRenewalFailureEvent ex
      *        last chain of renewal failures, in marshalled form.  May be
      *        <code>null</code> in which case <code>getThrowable</code> will
      *        return <code>null</code>.
+     * @deprecated 
      */
+    @Deprecated
     public BasicRenewalFailureEvent(LeaseRenewalSet source, 
 				    long seqNum,
 				    MarshalledObject handback,
@@ -93,6 +95,31 @@ public class BasicRenewalFailureEvent ex
 	this.marshalledThrowable = marshalledThrowable;
 	this.marshalledLease = marshalledLease;
     }
+    
+    /**
+     * 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
+     * @param marshalledLease the lease which could not be renewed, in
+     *        marshalled form
+     * @param marshalledThrowable the first exception that was thrown in the
+     *        last chain of renewal failures, in marshalled form.  May be
+     *        <code>null</code> in which case <code>getThrowable</code> will
+     *        return <code>null</code>.
+     */
+    public BasicRenewalFailureEvent(MarshalledInstance handback,
+                                    LeaseRenewalSet source, 
+				    long seqNum,
+				    MarshalledInstance marshalledLease,
+				    MarshalledInstance marshalledThrowable) 
+    {
+	super(handback, source, seqNum);
+	this.marshalledThrowable = marshalledThrowable;
+	this.marshalledLease = marshalledLease;
+    }
 
     /**
      * Returns the lease that could not be renewed.  When the event is

Modified: incubator/river/jtsk/trunk/src/com/sun/jini/lookup/entry/LookupAttributes.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/lookup/entry/LookupAttributes.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/com/sun/jini/lookup/entry/LookupAttributes.java (original)
+++ incubator/river/jtsk/trunk/src/com/sun/jini/lookup/entry/LookupAttributes.java Fri Apr 23 05:14:10 2010
@@ -22,10 +22,10 @@ import net.jini.core.entry.Entry;
 import net.jini.lookup.entry.ServiceControlled;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
-import java.rmi.MarshalledObject;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Comparator;
+import net.jini.io.MarshalledInstance;
 
 /**
  * Some simple utilities for manipulating lookup service attributes.
@@ -345,7 +345,7 @@ public class LookupAttributes {
 	    c == Short.class)
 	    return o1.equals(o2);
 	try {
-	    return new MarshalledObject(o1).equals(new MarshalledObject(o2));
+	    return new MarshalledInstance(o1).equals(new MarshalledInstance(o2));
 	} catch (IOException ex) {
 	    throw new IllegalArgumentException("unexpected IOException");
 	}

Modified: incubator/river/jtsk/trunk/src/com/sun/jini/mahalo/JoinStateManager.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/mahalo/JoinStateManager.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/com/sun/jini/mahalo/JoinStateManager.java (original)
+++ incubator/river/jtsk/trunk/src/com/sun/jini/mahalo/JoinStateManager.java Fri Apr 23 05:14:10 2010
@@ -50,6 +50,7 @@ import com.sun.jini.config.Config;
 import com.sun.jini.logging.Levels;
 import com.sun.jini.reliableLog.LogHandler;
 import com.sun.jini.reliableLog.ReliableLog;
+import net.jini.io.MiToMoOutputStream;
 
 /**
  * <code>JoinStateManager</code> provides a utility that manages
@@ -725,7 +726,7 @@ class JoinStateManager extends LogHandle
         // this makes sure that the attribute's code base is preserved
         // and when we unpack to discard attributes who's codebase
         // has been lost without throwing away those we can still deal with.
-         
+        // ObjectOutput newOut = new MiToMoOutputStream(out);
         out.writeInt(attributes.length);
         for (int i=0; i<attributes.length; i++) {
             out.writeObject(new MarshalledObject(attributes[i]));

Modified: incubator/river/jtsk/trunk/src/com/sun/jini/mahalo/TxnManagerTransaction.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/mahalo/TxnManagerTransaction.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/com/sun/jini/mahalo/TxnManagerTransaction.java (original)
+++ incubator/river/jtsk/trunk/src/com/sun/jini/mahalo/TxnManagerTransaction.java Fri Apr 23 05:14:10 2010
@@ -18,7 +18,6 @@
 package com.sun.jini.mahalo;
 
 import net.jini.id.Uuid;
-import net.jini.core.lease.Lease;
 import net.jini.core.transaction.*;
 import net.jini.core.transaction.server.*;
 import net.jini.security.ProxyPreparer;
@@ -32,18 +31,13 @@ import com.sun.jini.logging.Levels;
 import com.sun.jini.thread.TaskManager;
 import com.sun.jini.thread.WakeupManager;
 
-import java.rmi.MarshalledObject;
 import java.rmi.RemoteException;
 import java.util.Enumeration;
 
-import java.util.Collections;
 import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import java.util.Map;
 import java.util.Vector;
 
 /**

Modified: incubator/river/jtsk/trunk/src/net/jini/core/discovery/LookupLocator.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/core/discovery/LookupLocator.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/core/discovery/LookupLocator.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/core/discovery/LookupLocator.java Fri Apr 23 05:14:10 2010
@@ -29,11 +29,16 @@ import java.net.SocketException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.UnknownHostException;
-import java.rmi.MarshalledObject;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import javax.net.SocketFactory;
+import net.jini.core.lookup.PortableServiceRegistrar;
 import net.jini.core.lookup.ServiceRegistrar;
+import net.jini.core.lookup.StreamServiceRegistrar;
+import net.jini.discovery.ServiceRegistrarFacade;
+import net.jini.discovery.StreamServiceRegistrarFacade;
+import net.jini.io.MarshalledInstance;
+import net.jini.io.MoToMiInputStream;
 
 /**
  * A utility class that performs unicast discovery, using version 1 of the
@@ -307,6 +312,7 @@ public class LookupLocator implements Se
 	return port;
     }
 
+
     /**
      * Perform unicast discovery and return the ServiceRegistrar
      * object for the given lookup service.  Unicast discovery is
@@ -323,13 +329,38 @@ public class LookupLocator implements Se
      * @throws IOException an error occurred during discovery
      * @throws ClassNotFoundException if a class required to unmarshal the
      * <code>ServiceRegistrar</code> proxy cannot be found
+     * @deprecated replaced by {@link #reveal()}
      */
+    @Deprecated
     public ServiceRegistrar getRegistrar()
 	throws IOException, ClassNotFoundException
     {
 	return getRegistrar(defaultTimeout);
     }
-
+    
+    /**
+     * Perform unicast discovery and return the PortableServiceRegistrar
+     * object for the given lookup service.  Unicast discovery is
+     * performed anew each time this method is called.
+     * <code>LookupLocator</code> implements this method to simply invoke
+     * {@link #getRegistrar(int)} with a timeout value, which is determined
+     * by the value of the <code>net.jini.discovery.timeout</code> system
+     * property.  If the property is set, is not negative, and can be parsed as
+     * an <code>Integer</code>, the value of the property is used as the timeout
+     * value. Otherwise, a default value of <code>60</code> seconds is assumed.
+     *
+     * @return the PortableServiceRegistrar for the lookup service denoted by
+     * this LookupLocator object
+     * @throws IOException an error occurred during discovery
+     * @throws ClassNotFoundException if a class required to unmarshal the
+     * <code>ServiceRegistrar</code> proxy cannot be found
+     */
+    public StreamServiceRegistrar getStreamRegistrar()
+	throws IOException, ClassNotFoundException
+    {
+	return getStreamRegistrar(defaultTimeout);
+    }
+    
     /**
      * Perform unicast discovery and return the ServiceRegistrar
      * object for the given lookup service, with the given discovery timeout.
@@ -351,8 +382,82 @@ public class LookupLocator implements Se
      * @throws ClassNotFoundException if a class required to unmarshal the
      * <code>ServiceRegistrar</code> proxy cannot be found
      * @throws IllegalArgumentException if <code>timeout</code> is negative
+     * @deprecated replaced by {@link #reveal(int)}
      */
+    @Deprecated
     public ServiceRegistrar getRegistrar(int timeout)
+            throws IOException, ClassNotFoundException
+    {
+        PortableServiceRegistrar psr = getPortableRegistrar(timeout);
+	if ( psr instanceof ServiceRegistrar) {
+            return (ServiceRegistrar) psr;
+        }
+        return new ServiceRegistrarFacade(psr);
+    }
+    
+    /**
+     * Perform unicast discovery and return the StreamServiceRegistrar
+     * object for the given lookup service, with the given discovery timeout.
+     * Unicast discovery is performed anew each time this method is called.
+     * <code>LookupLocator</code> implements this method to use the values
+     * of the <code>host</code> and <code>port</code> field in determining
+     * the host and port to connect to.
+     * 
+     * The Java CDC platform can only recieve implementations of
+     * PortableServiceRegistrar or StreamServiceRegistrar, however this
+     * method will return a ServiceRegistrar, wrapped as
+     * a StreamServiceRegistrar, the notify method will be converted on
+     * platforms that support java.rmi.MarshalledObject and will throw
+     * an UnsupportedMethodException on those that don't.
+     *
+     * <p>
+     * If a connection can be established to start unicast discovery
+     * but the remote end fails to respond within the given time
+     * limit, an exception is thrown.
+     *
+     * @param timeout the maximum time to wait for a response, in
+     * milliseconds.  A value of <code>0</code> specifies an infinite timeout.
+     * @return the StreamServiceRegistrar for the lookup service denoted by
+     * this LookupLocator object
+     * @throws IOException an error occurred during discovery
+     * @throws ClassNotFoundException if a class required to unmarshal the
+     * <code>ServiceRegistrar</code> proxy cannot be found
+     * @throws IllegalArgumentException if <code>timeout</code> is negative
+     */
+    public StreamServiceRegistrar getStreamRegistrar(int timeout)
+            throws IOException, ClassNotFoundException
+    {
+        PortableServiceRegistrar psr = getPortableRegistrar(timeout);
+        if ( psr instanceof StreamServiceRegistrar){
+            return (StreamServiceRegistrar) psr;
+        }
+        return new StreamServiceRegistrarFacade(psr);
+    }
+
+    /**
+     * Perform unicast discovery and return the PortableServiceRegistrar
+     * object for the given lookup service, with the given discovery timeout.
+     * Unicast discovery is performed anew each time this method is called.
+     * <code>LookupLocator</code> implements this method to use the values
+     * of the <code>host</code> and <code>port</code> field in determining
+     * the host and port to connect to.
+     *
+     * <p>
+     * If a connection can be established to start unicast discovery
+     * but the remote end fails to respond within the given time
+     * limit, an exception is thrown.
+     *
+     * @param timeout the maximum time to wait for a response, in
+     * milliseconds.  A value of <code>0</code> specifies an infinite timeout.
+     * @param true if a ServiceRegistrar instance is to be returned.
+     * @return the ServiceRegistrar for the lookup service denoted by
+     * this LookupLocator object
+     * @throws IOException an error occurred during discovery
+     * @throws ClassNotFoundException if a class required to unmarshal the
+     * <code>PortableServiceRegistrar</code> proxy cannot be found
+     * @throws IllegalArgumentException if <code>timeout</code> is negative
+     */
+    private PortableServiceRegistrar getPortableRegistrar(int timeout)
 	throws IOException, ClassNotFoundException
     {
 	InetAddress[] addrs = null;
@@ -367,7 +472,9 @@ public class LookupLocator implements Se
             } else {
                 sock = sf.createSocket(host, port);
             }
-	    return getRegistrarFromSocket(sock, timeout);
+            PortableServiceRegistrar psr = 
+                    getRegistrarFromSocket(sock, timeout);
+	    return psr;
 	}
 	IOException ioEx = null;
 	SecurityException secEx = null;
@@ -380,7 +487,9 @@ public class LookupLocator implements Se
                 } else {
                     sock = sf.createSocket(addrs[i], port);
                 }
-		return getRegistrarFromSocket(sock, timeout);
+                PortableServiceRegistrar psr = 
+                        getRegistrarFromSocket(sock, timeout);
+                return psr;		
 	    } catch (ClassNotFoundException ex) {
 		cnfEx = ex;
 	    } catch (IOException ex) {
@@ -402,7 +511,7 @@ public class LookupLocator implements Se
     }
 
     // Convenience method to do unicast discovery on a socket
-    private static ServiceRegistrar getRegistrarFromSocket(Socket sock,
+    private static PortableServiceRegistrar getRegistrarFromSocket(Socket sock,
 							   int timeout)
 	throws IOException, ClassNotFoundException
     {
@@ -422,10 +531,12 @@ public class LookupLocator implements Se
 		new DataOutputStream(sock.getOutputStream());
 	    dstr.writeInt(protoVersion);
 	    dstr.flush();
+            // Convert any MarshalledObject into MarshalledInstance.
 	    ObjectInputStream istr =
-		new ObjectInputStream(sock.getInputStream());
-	    ServiceRegistrar registrar =
-		(ServiceRegistrar)((MarshalledObject)istr.readObject()).get();
+		new MoToMiInputStream(sock.getInputStream());
+            // Reminder, should we check codebase integrity or make it an option?
+	    PortableServiceRegistrar registrar =
+		(PortableServiceRegistrar)((MarshalledInstance)istr.readObject()).get(false);
 	    for (int grpCount = istr.readInt(); --grpCount >= 0; ) {
 		istr.readUTF(); // ensure proper format, then discard
 	    }

Copied: incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamServiceRegistrar.java (from r935433, incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamingServiceRegistrar.java)
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamServiceRegistrar.java?p2=incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamServiceRegistrar.java&p1=incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamingServiceRegistrar.java&r1=935433&r2=937157&rev=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamingServiceRegistrar.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamServiceRegistrar.java Fri Apr 23 05:14:10 2010
@@ -26,20 +26,20 @@ import net.jini.io.MarshalledInstance;
 /**
  * Defines the interface to the lookup service.  The interface is not a
  * remote interface; each implementation of the lookup service exports
- * proxy objects that implement the StreamingServiceRegistrar interface local to
+ * proxy objects that implement the StreamServiceRegistrar interface local to
  * the client, using an implementation-specific protocol to communicate
  * with the actual remote server.  All of the proxy methods obey normal
  * RMI remote interface semantics except where explicitly noted.  Two
  * proxy objects are equal if they are proxies for the same lookup service.
- * Every method invocation (on both StreamingServiceRegistrar and ServiceRegistration)
+ * Every method invocation (on both StreamServiceRegistrar and ServiceRegistration)
  * is atomic with respect to other invocations.
  * 
- * The StreamingServiceRegistrar is intended to perform the same function
+ * The StreamServiceRegistrar is intended to perform the same function
  * as the ServiceRegistrar, but with the ability to return results as a 
  * stream, so memory consumption can be minimised at the client.
  * 
  * All clients utilising ServiceRegistrar, should switch to the 
- * StreamingServiceRegistrar.
+ * StreamServiceRegistrar.
  * 
  * @see ServiceRegistrar
  * @see PortableServiceRegistrar
@@ -47,7 +47,7 @@ import net.jini.io.MarshalledInstance;
  * @author Peter Firmstone
  * @since 2.2.0
  */
-public interface StreamingServiceRegistrar extends PortableServiceRegistrar{
+public interface StreamServiceRegistrar extends PortableServiceRegistrar{
     
      /**
      * Registers for event notification.  The registration is leased; the
@@ -96,7 +96,7 @@ public interface StreamingServiceRegistr
      * are minimised and common packages can share code.  This is intended to
      * be used with the new codebase services (TODO once implemented).
      * 
-     * The ObjectInput should be an InputStream, in order to minimise the
+     * ObjectInput should be an InputStream, in order to minimise
      * memory consumption requirements at the client.
      *
      * @param tmpl template to match

Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/ConstrainableLookupLocator.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/ConstrainableLookupLocator.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/ConstrainableLookupLocator.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/ConstrainableLookupLocator.java Fri Apr 23 05:14:10 2010
@@ -33,15 +33,17 @@ 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;
 
 /**
  * <code>LookupLocator</code> subclass which supports constraint operations
  * through the {@link RemoteMethodControl} interface.  The constraints of a
  * <code>ConstrainableLookupLocator</code> instance control how it performs
- * unicast discovery, and apply only to its {@link LookupLocator#getRegistrar()
- * getRegistrar()} and {@link LookupLocator#getRegistrar(int)
- * getRegistrar(int)} methods.  The constraints may also be used by other
+ * unicast discovery, and apply only to its {@link LookupLocator#getPRegistrar()
+ * getPRegistrar()} and {@link LookupLocator#getPRegistrar(int)
+ * getPRegistrar(int)} methods.  The constraints may also be used by other
  * utilities, such as {@link LookupLocatorDiscovery}, to determine how unicast
  * discovery should be performed on behalf of a given
  * <code>ConstrainableLookupLocator</code> instance.  Untrusted
@@ -88,7 +90,7 @@ import net.jini.core.lookup.ServiceRegis
  * used) perform unicast discovery to the host <code>target_host</code> on port
  * 4160 using discovery protocol version 2, with a socket read timeout of
  * 120000 milliseconds unless one was explicitly specified using the {@link
- * #getRegistrar(int)} method.
+ * #getPRegistrar(int)} method.
  */
 public final class ConstrainableLookupLocator
     extends LookupLocator implements RemoteMethodControl
@@ -97,7 +99,9 @@ public final class ConstrainableLookupLo
 
     private static final int DEFAULT_TIMEOUT = 60 * 1000;
     private static final Method getRegistrarMethod;
+    private static final Method getStreamRegistrarMethod;
     private static final Method getRegistrarTimeoutMethod;
+    private static final Method getStreamRegistrarTimeoutMethod;
     static {
 	try {
 	    // REMIND: lookup methods on ConstrainableLookupLocator instead?
@@ -105,6 +109,10 @@ public final class ConstrainableLookupLo
 		"getRegistrar", new Class[0]);
 	    getRegistrarTimeoutMethod = LookupLocator.class.getMethod(
 		"getRegistrar", new Class[]{ int.class });
+          	    getStreamRegistrarMethod = LookupLocator.class.getMethod(
+		"getStreamRegistrar", new Class[0]);
+	    getStreamRegistrarTimeoutMethod = LookupLocator.class.getMethod(
+		"getStreamRegistrar", new Class[]{ int.class });  
 	} catch (NoSuchMethodException e) {
 	    throw new AssertionError(e);
 	}
@@ -127,7 +135,7 @@ public final class ConstrainableLookupLo
      * The <code>url</code> must be a valid URL of scheme <code>"jini"</code> as
      * described in <code>LookupLocator(String)</code>.  A <code>null
      * constraints</code> value is interpreted as mapping both
-     * <code>getRegistrar</code> methods to empty constraints.
+     * <code>getPRegistrar</code> methods to empty constraints.
      *
      * @param url the URL to use
      * @param constraints the constraints to apply to unicast discovery, or
@@ -152,7 +160,7 @@ public final class ConstrainableLookupLo
      * rethrown.
      *
      * <p>A <code>null constraints</code> value is interpreted as mapping both
-     * <code>getRegistrar</code> methods to empty constraints. The
+     * <code>getPRegistrar</code> methods to empty constraints. The
      * <code>host</code> and <code>port</code> must satisfy the requirements of
      * the <code>LookupLocator(String, int)</code> constructor.
      *
@@ -174,10 +182,10 @@ public final class ConstrainableLookupLo
 
     /**
      * Performs unicast discovery as specified by 
-     * <code>LookupLocator.getRegistrar()</code> with the following differences.
+     * <code>LookupLocator.getPRegistrar()</code> with the following differences.
      * <ul>
      * <li> It applies the supplied constraints (if any) for this method.
-     * <li> It does not invoke the <code>getRegistrar(int)</code> method.
+     * <li> It does not invoke the <code>getPRegistrar(int)</code> method.
      * <li> If no timeout constraints are specified, this method assumes a
      * default timeout of 60 seconds.  A non default timeout can only be
      * specified through the supplied constraints, the
@@ -189,25 +197,69 @@ public final class ConstrainableLookupLo
      * @throws net.jini.io.UnsupportedConstraintException if the
      * discovery-related constraints contain conflicts, or otherwise cannot be
      * processed
+     * @deprecated replaced by {@link #getStreamRegistrar()}
      */
+    @Deprecated
+    @Override
     public ServiceRegistrar getRegistrar()
 	throws IOException, ClassNotFoundException
     {
-	return getRegistrar((constraints != null) ?
+	PortableServiceRegistrar psr = getRegistrar((constraints != null) ?
 	    constraints.getConstraints(getRegistrarMethod) :
 	    InvocationConstraints.EMPTY);
+        if ( psr instanceof ServiceRegistrar){
+            return (ServiceRegistrar) psr;
+        }
+        return new ServiceRegistrarFacade(psr);
     }
-
+    
+    /**
+     * Performs unicast discovery as specified by 
+     * <code>LookupLocator.getStreeamRegistrar()</code> with the following differences.
+     * <ul>
+     * <li> It applies the supplied constraints (if any) for this method.
+     * <li> It does not invoke the <code>getPRegistrar(int)</code> method.
+     * <li> If no timeout constraints are specified, this method assumes a
+     * default timeout of 60 seconds.  A non default timeout can only be
+     * specified through the supplied constraints, the
+     * <code>net.jini.discovery.timeout</code> system property is ignored.
+     * </ul>
+     * <code>ConstrainableLookupLocator</code> implements this method to use the
+     * values of the <code>host</code> and <code>port</code> field in
+     * determining the host and port to connect to.
+     * @throws java.io.IOException 
+     * @throws java.lang.ClassNotFoundException 
+     * @throws net.jini.io.UnsupportedConstraintException if the
+     * discovery-related constraints contain conflicts, or otherwise cannot be
+     * processed
+     * @since 2.2.0
+     */
+    @Override
+    public StreamServiceRegistrar getStreamRegistrar()
+	throws IOException, ClassNotFoundException
+    {
+	PortableServiceRegistrar psr = getRegistrar((constraints != null) ?
+	    constraints.getConstraints(getStreamRegistrarMethod) :
+	    InvocationConstraints.EMPTY);
+        if ( psr instanceof StreamServiceRegistrar){
+            return (StreamServiceRegistrar) psr;
+        }
+        return new StreamServiceRegistrarFacade(psr);
+    }
+    
     /**
      * Performs unicast discovery as specified by 
-     * <code>LookupLocator.getRegistrar(int)</code>, additionally applying the
+     * <code>LookupLocator.getPRegistrar(int)</code>, additionally applying the
      * supplied discovery constraints. The <code>timeout</code> is considered a
      * requirement with respect to other constraints specified for this
      * instance.
      * @throws net.jini.io.UnsupportedConstraintException if the
      * discovery-related constraints contain conflicts, or otherwise cannot be
      * processed
+     * @deprecated replaced by {@link #getStreamRegistrar(int)}
      */
+    @Deprecated
+    @Override
     public ServiceRegistrar getRegistrar(int timeout)
 	throws IOException, ClassNotFoundException
     {
@@ -216,7 +268,42 @@ public final class ConstrainableLookupLo
 	    InvocationConstraints.EMPTY;
 	Collection reqs = new ArrayList(ic.requirements());
 	reqs.add(new UnicastSocketTimeout(timeout));
-	return getRegistrar(new InvocationConstraints(reqs, ic.preferences()));
+	PortableServiceRegistrar psr =
+                getRegistrar(new InvocationConstraints(reqs, ic.preferences()));
+        if ( psr instanceof ServiceRegistrar){
+            return (ServiceRegistrar) psr;
+        }
+        return new ServiceRegistrarFacade(psr);
+    }
+    
+    /**
+     * Performs unicast discovery as specified by 
+     * <code>LookupLocator.getStreamRegistrar(int)</code>, additionally applying the
+     * supplied discovery constraints. The <code>timeout</code> is considered a
+     * requirement with respect to other constraints specified for this
+     * instance.
+     * @throws java.io.IOException 
+     * @throws java.lang.ClassNotFoundException 
+     * @throws net.jini.io.UnsupportedConstraintException if the
+     * discovery-related constraints contain conflicts, or otherwise cannot be
+     * processed
+     * @since 2.2.0
+     */
+    @Override
+    public StreamServiceRegistrar getStreamRegistrar(int timeout)
+	throws IOException, ClassNotFoundException
+    {
+	InvocationConstraints ic = (constraints != null) ?
+	    constraints.getConstraints(getStreamRegistrarTimeoutMethod) :
+	    InvocationConstraints.EMPTY;
+	Collection reqs = new ArrayList(ic.requirements());
+	reqs.add(new UnicastSocketTimeout(timeout));
+	PortableServiceRegistrar psr =
+                getRegistrar(new InvocationConstraints(reqs, ic.preferences()));
+        if ( psr instanceof StreamServiceRegistrar){
+            return (StreamServiceRegistrar) psr;
+        }
+        return new StreamServiceRegistrarFacade(psr);
     }
 
     /**
@@ -238,7 +325,7 @@ public final class ConstrainableLookupLo
 	return constraints;
     }
 
-    private ServiceRegistrar getRegistrar(InvocationConstraints constraints)
+    private PortableServiceRegistrar getRegistrar(InvocationConstraints constraints)
 	throws IOException, ClassNotFoundException
     {
 	UnicastResponse resp = new MultiIPDiscovery() {	    
@@ -251,6 +338,6 @@ public final class ConstrainableLookupLo
 		    s, dc.getUnfulfilledConstraints(), null, null, null);
 	    }
 	}.getResponse(host, port, constraints);
-	return resp.getRegistrar();
+	return resp.getPRegistrar();
     }
 }
\ No newline at end of file

Added: incubator/river/jtsk/trunk/src/net/jini/discovery/DiscMan2Facade.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/DiscMan2Facade.java?rev=937157&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/DiscMan2Facade.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/DiscMan2Facade.java Fri Apr 23 05:14:10 2010
@@ -0,0 +1,95 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package net.jini.discovery;
+
+import net.jini.core.lookup.PortableServiceRegistrar;
+import net.jini.core.lookup.ServiceRegistrar;
+
+/**
+ * This facade is intended to wrap a DiscoveryManagement2 for existing
+ * applications that utilise DiscoveryManagement.
+ * 
+ * DiscoveryManagement wont be supported on Java CDC, it is depreciated. It is
+ * intended to allow a transition period to DiscoveryManagement2 for existing software.
+ * 
+ * @param DiscoveryListenerManagement 
+ * @author Peter Firmstone
+ * @since 2.2.0
+ */
+public class DiscMan2Facade 
+        implements DiscoveryManagement2, Facade<DiscoveryListenerManagement> {
+    private final DiscoveryListenerManagement dlm;
+    @SuppressWarnings("unchecked")
+    public DiscMan2Facade(DiscoveryListenerManagement dm){
+        if (dm == null) throw new NullPointerException("DiscoveryManager cannot be null");
+        while (dm instanceof Facade){
+            Facade f = (Facade) dm;
+            dm = (DiscoveryListenerManagement) f.reveal();
+        }
+        dlm = dm;
+    }
+
+    public PortableServiceRegistrar[] getPRegistrars() {
+        try {
+            if (dlm instanceof DiscoveryManagement){
+                ServiceRegistrar[] psr = 
+                        ((DiscoveryManagement)dlm).getRegistrars();
+                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;
+            }
+        } catch (NoClassDefFoundError er){
+            // This is expected for Java CDC.
+        }
+        if (dlm instanceof DiscoveryManagement2){
+            DiscoveryManagement2 dm = (DiscoveryManagement2) dlm;
+            return dm.getPRegistrars();
+        }
+        throw new UnsupportedOperationException("Not supported.");
+    }
+
+    public void discard(PortableServiceRegistrar proxy) {
+        try {
+            if (dlm instanceof DiscoveryManagement){
+                if ( proxy instanceof ServiceRegistrar){
+                    ((DiscoveryManagement) dlm).discard((ServiceRegistrar)proxy);
+                } else {
+                    ((DiscoveryManagement) dlm).discard(new ServiceRegistrarFacade(proxy));
+                }
+            }
+        } catch (NoClassDefFoundError er){
+            // This is expected for Java CDC.
+        }
+        if (dlm instanceof DiscoveryManagement2){
+            DiscoveryManagement2 dm = (DiscoveryManagement2) dlm;
+            dm.discard(proxy);
+        }
+        throw new UnsupportedOperationException("Not supported.");
+    }
+
+    public void addDiscoveryListener(DiscoveryListener listener) {
+        dlm.addDiscoveryListener(listener);
+    }
+
+    public void removeDiscoveryListener(DiscoveryListener listener) {
+        dlm.removeDiscoveryListener(listener);
+    }
+
+    public void terminate() {
+        dlm.terminate();
+    }
+
+    public DiscoveryListenerManagement reveal() {
+        return dlm;
+    }
+}

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

Added: incubator/river/jtsk/trunk/src/net/jini/discovery/DiscManFacade.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/DiscManFacade.java?rev=937157&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/DiscManFacade.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/DiscManFacade.java Fri Apr 23 05:14:10 2010
@@ -0,0 +1,75 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package net.jini.discovery;
+
+import net.jini.core.lookup.PortableServiceRegistrar;
+import net.jini.core.lookup.ServiceRegistrar;
+
+/**
+ *
+ * @param DiscoveryListenerManagement 
+ * @author Peter Firmstone
+ * @since 2.2.0
+ */
+@SuppressWarnings("deprecation")
+public class DiscManFacade 
+        implements DiscoveryManagement, Facade<DiscoveryListenerManagement> {
+    private final DiscoveryListenerManagement dlm;
+    private final boolean isDiscoveryManagement2;
+    @SuppressWarnings("unchecked")
+    public DiscManFacade(DiscoveryListenerManagement dm){
+        if (dm == null) throw new NullPointerException("DiscoveryManager cannot be null");
+        while (dm instanceof Facade){
+            Facade f = (Facade) dm;
+            dm = (DiscoveryListenerManagement) f.reveal();
+        }
+        dlm = dm;
+        isDiscoveryManagement2 = (dm instanceof DiscoveryManagement2);
+    }
+
+    public ServiceRegistrar[] getRegistrars() {
+        if (isDiscoveryManagement2){
+            PortableServiceRegistrar[] psr = 
+                    ((DiscoveryManagement2)dlm).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;
+        }
+        throw new UnsupportedOperationException("Not supported.");
+    }
+
+    public void discard(ServiceRegistrar proxy) {
+        if (isDiscoveryManagement2){
+            ((DiscoveryManagement2) dlm).discard(proxy);
+        }
+        throw new UnsupportedOperationException("Not supported.");
+    }
+
+    public void addDiscoveryListener(DiscoveryListener listener) {
+        dlm.addDiscoveryListener(listener);
+    }
+
+    public void removeDiscoveryListener(DiscoveryListener listener) {
+        dlm.removeDiscoveryListener(listener);
+    }
+
+    public void terminate() {
+        dlm.terminate();
+
+    }
+
+    public DiscoveryListenerManagement reveal() {
+        return dlm;
+    }
+
+}

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

Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryEvent.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryEvent.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryEvent.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryEvent.java Fri Apr 23 05:14:10 2010
@@ -17,9 +17,13 @@
  */
 package net.jini.discovery;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.EventObject;
 import java.util.Map;
+import net.jini.core.lookup.PortableServiceRegistrar;
 import net.jini.core.lookup.ServiceRegistrar;
+import net.jini.core.lookup.StreamServiceRegistrar;
 
 /**
  * Event object passed (via either the <code>DiscoveryListener</code>
@@ -44,7 +48,7 @@ public class DiscoveryEvent extends Even
      *
      * @serial
      */
-    protected ServiceRegistrar[] regs;
+    private PortableServiceRegistrar[] regs;
 
     /**
      * Map from the registrars of this event to the groups in which each
@@ -52,21 +56,38 @@ public class DiscoveryEvent extends Even
      *
      * @serial
      */
-    protected Map groups;
+    private Map groups;
 
     /**
      * Construct a new <code>DiscoveryEvent</code> object, with the given
      * source and set of registrars.  The set of registrars should not be
-     * empty.
+     * empty. This constructor has been left in place to maintain binary
+     * compatibility.
      *
      * @param source the source of this event
      * @param regs   the registrars to which this event applies
+     * @deprecated 
      */
+    @Deprecated
     public DiscoveryEvent(Object source, ServiceRegistrar[] regs) {
 	super(source);
 	this.regs = regs;
 	this.groups = null;
     }
+    
+    /**
+     * Construct a new <code>DiscoveryEvent</code> object, with the given
+     * source and set of registrars.  The set of registrars should not be
+     * empty.
+     *
+     * @param source the source of this event
+     * @param regs   the registrars to which this event applies
+     */
+    public DiscoveryEvent(Object source, PortableServiceRegistrar[] regs) {
+	super(source);
+	this.regs = regs;
+	this.groups = null;
+    }
 
     /**
      * Construct a new <code>DiscoveryEvent</code> object, with the given
@@ -81,19 +102,69 @@ public class DiscoveryEvent extends Even
     public DiscoveryEvent(Object source, Map groups) {
 	super(source);
 	this.groups = groups;
-        this.regs   = (ServiceRegistrar[])(groups.keySet()).toArray
-                                       (new ServiceRegistrar[groups.size()]);
+        this.regs   = (PortableServiceRegistrar[])(groups.keySet()).toArray
+                                       (new PortableServiceRegistrar[groups.size()]);
     }
 
     /**
      * Return the set of registrars to which this event applies.
      * The same array is returned on every call; a copy is not made.
+     * 
+     * I'm going to experiment with returning a copy to see if anything
+     * breaks.
+     * 
      * @return the set of registrars to which this event applies.
      */
     public ServiceRegistrar[] getRegistrars() {
-	return regs;
+        int l = regs.length;
+        ArrayList<ServiceRegistrar> sr = new ArrayList<ServiceRegistrar>(l);
+        for ( int i = 0; i < l; i++ ){
+            if (regs[i] instanceof ServiceRegistrar) {
+                sr.add( (ServiceRegistrar) regs[i]);
+            } else {
+                sr.add( new ServiceRegistrarFacade(regs[i]));
+            }
+        }
+        ServiceRegistrar[] sra = new ServiceRegistrar[sr.size()];
+        return sr.toArray(sra);
     }
-
+    
+    /**
+     * Return the set of registrars to which this event applies.
+     * The same array is returned on every call; a copy is not made.
+     * 
+     * I'm going to experiment with returning a copy to see if anything
+     * breaks.
+     * 
+     * @return the set of registrars to which this event applies.
+     */
+    public StreamServiceRegistrar[] getStreamRegistrars() {
+        int l = regs.length;
+        ArrayList<StreamServiceRegistrar> sr = new ArrayList<StreamServiceRegistrar>(l);
+        for ( int i = 0; i < l; i++ ){
+            if (regs[i] instanceof StreamServiceRegistrar) {
+                sr.add( (StreamServiceRegistrar) regs[i]);
+            } else {
+                sr.add( new StreamServiceRegistrarFacade(regs[i]));
+            }
+        }
+        StreamServiceRegistrar[] sra = new StreamServiceRegistrar[sr.size()];
+        return sr.toArray(sra);
+    }
+    
+    /**
+     * Return the set of registrars to which this event applies.
+     * The same array is returned on every call; a copy is not made.
+     * 
+     * I'm going to experiment with returning a copy to see if anything
+     * breaks.
+     * 
+     * @return the set of registrars to which this event applies.
+     */
+    public PortableServiceRegistrar[] getPRegistrars() {
+        return Arrays.copyOf(regs, regs.length);      
+    }
+    
     /**
      * Returns a set that maps to each registrar referenced by this event,
      * the current set of groups in which each registrar is a member.

Added: incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryListenerManagement.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryListenerManagement.java?rev=937157&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryListenerManagement.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryListenerManagement.java Fri Apr 23 05:14:10 2010
@@ -0,0 +1,63 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package net.jini.discovery;
+
+/**
+ *
+ * @author Peter Firmstone.
+ */
+public interface DiscoveryListenerManagement {
+
+    /**
+     * Adds an instance of <code>DiscoveryListener</code> to the set of
+     * objects listening for discovery events. Once the listener is
+     * registered, it will be notified of all lookup services discovered
+     * to date, and will then be notified as new lookup services are
+     * discovered or existing lookup services are discarded.
+     * <p>
+     * If <code>null</code> is input to this method, a
+     * <code>NullPointerException</code> is thrown. If the listener
+     * input to this method duplicates (using the <code>equals</code>
+     * method) another element in the current set of listeners, no action
+     * is taken.
+     *
+     * @param listener an instance of <code>DiscoveryListener</code>
+     * corresponding to the listener to add to the set of
+     * listeners.
+     *
+     * @throws java.lang.NullPointerException if <code>null</code> is
+     * input to the <code>listener</code> parameter
+     *
+     * @see #removeDiscoveryListener
+     * @see net.jini.discovery.DiscoveryListener
+     */
+    void addDiscoveryListener(DiscoveryListener listener);
+
+    /**
+     * Removes a listener from the set of objects listening for discovery
+     * events. If the listener object input to this method does not exist
+     * in the set of listeners, then this method will take no action.
+     *
+     * @param listener an instance of <code>DiscoveryListener</code>
+     * corresponding to the listener to remove from the set
+     * of listeners.
+     *
+     * @see #addDiscoveryListener
+     * @see net.jini.discovery.DiscoveryListener
+     */
+    void removeDiscoveryListener(DiscoveryListener listener);
+
+    /**
+     * Ends all discovery processing being performed by the current
+     * implementation of this interface. After this method is invoked,
+     * no new lookup services will be discovered, and the effect of any
+     * new operations performed on the current implementation object are
+     * undefined. Any additional termination semantics must be defined
+     * by the implementation class itself.
+     */
+    void terminate();
+
+}

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

Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryManagement.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryManagement.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryManagement.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryManagement.java Fri Apr 23 05:14:10 2010
@@ -28,47 +28,10 @@ import net.jini.core.lookup.ServiceRegis
  * or terminate the discovery process.
  *
  * @author Sun Microsystems, Inc.
+ * @deprecated replaced by {@link net.jini.discovery.DiscoveryManagement2}
  */
-public interface DiscoveryManagement {
-
-    /**
-     * Adds an instance of <code>DiscoveryListener</code> to the set of
-     * objects listening for discovery events. Once the listener is
-     * registered, it will be notified of all lookup services discovered
-     * to date, and will then be notified as new lookup services are
-     * discovered or existing lookup services are discarded.
-     * <p>
-     * If <code>null</code> is input to this method, a
-     * <code>NullPointerException</code> is thrown. If the listener
-     * input to this method duplicates (using the <code>equals</code>
-     * method) another element in the current set of listeners, no action
-     * is taken.
-     *
-     * @param listener an instance of <code>DiscoveryListener</code> 
-     *                 corresponding to the listener to add to the set of
-     *                 listeners.
-     *
-     * @throws java.lang.NullPointerException if <code>null</code> is
-     *         input to the <code>listener</code> parameter
-     *
-     * @see #removeDiscoveryListener
-     * @see net.jini.discovery.DiscoveryListener
-     */
-    public void addDiscoveryListener(DiscoveryListener listener);
-
-    /**
-     * Removes a listener from the set of objects listening for discovery
-     * events. If the listener object input to this method does not exist
-     * in the set of listeners, then this method will take no action.
-     *
-     * @param listener an instance of <code>DiscoveryListener</code>
-     *                 corresponding to the listener to remove from the set
-     *                 of listeners.
-     *
-     * @see #addDiscoveryListener
-     * @see net.jini.discovery.DiscoveryListener
-     */
-    public void removeDiscoveryListener(DiscoveryListener listener);
+@Deprecated
+public interface DiscoveryManagement extends DiscoveryListenerManagement {
 
     /**
      * Returns an array of instances of <code>ServiceRegistrar</code>, each
@@ -90,21 +53,16 @@ public interface DiscoveryManagement {
      * 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.
+     * 
+     * Changing the Parameter to PortableServiceRegistrar doesn't break client
+     * code, but it may break implementation code if that code utilises
+     * the nofify method from ServiceRegistrar
      *
-     * @param proxy the instance of <code>ServiceRegistrar</code> to remove
+     * @param proxy the instance of <code>PortableServiceRegistrar</code> to remove
      *              from the managed set of lookup services
      *
+     * @see net.jini.core.lookup.PortableServiceRegistrar
      * @see net.jini.core.lookup.ServiceRegistrar
      */
    public void discard(ServiceRegistrar proxy);
-
-    /**
-     * Ends all discovery processing being performed by the current
-     * implementation of this interface. After this method is invoked,
-     * no new lookup services will be discovered, and the effect of any
-     * new operations performed on the current implementation object are
-     * undefined. Any additional termination semantics must be defined
-     * by the implementation class itself.
-     */
-    public void terminate();
 }

Added: incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryManagement2.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryManagement2.java?rev=937157&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryManagement2.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryManagement2.java Fri Apr 23 05:14:10 2010
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.jini.discovery;
+
+import net.jini.core.lookup.PortableServiceRegistrar;
+import net.jini.discovery.DiscoveryListener;
+
+/**
+ * This interface defines methods related to the discovery event mechanism
+ * and discovery process termination. Through this interface an entity can
+ * register or un-register for discovery events, discard a lookup service,
+ * or terminate the discovery process.
+ *
+ * @author Peter Firmstone.
+ * @since 2.2.0
+ */
+public interface DiscoveryManagement2 extends DiscoveryListenerManagement {
+
+    /**
+     * 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
+     *
+     * @see net.jini.core.lookup.ServiceRegistrar
+     */
+    public PortableServiceRegistrar[] getPRegistrars();
+
+    /**
+     * 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.
+     * 
+     * Changing the Parameter to PortableServiceRegistrar doesn't break client
+     * code, but it may break implementation code if that code utilises
+     * the nofify method from ServiceRegistrar
+     * 
+     * Implementer beware check for Facade and unwrap before using equals
+     * comparison to remove.
+     *
+     * @param proxy the instance of <code>PortableServiceRegistrar</code> to remove
+     *              from the managed set of lookup services
+     *
+     * @see net.jini.core.lookup.PortableServiceRegistrar
+     * @see net.jini.core.lookup.ServiceRegistrar
+     * @see net.jini.core.lookup.StreamServiceRegistrar
+     * @see net.jini.core.lookup.Facade;
+     */
+   public void discard(PortableServiceRegistrar proxy);
+}

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

Added: incubator/river/jtsk/trunk/src/net/jini/discovery/Facade.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/Facade.java?rev=937157&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/Facade.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/Facade.java Fri Apr 23 05:14:10 2010
@@ -0,0 +1,36 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package net.jini.discovery;
+
+/**
+ * @author Peter Firmstone.
+ * @since 2.2.0
+ */
+public interface Facade<T> {
+    public T reveal();
+    /**
+     * Equals must be implemented to check against another Facade by utilising
+     * reveal, so the underlaying parameter objects can be compared.
+     * It must not return true if comparing the Facade against a
+     * non-Facade object, otherwise the equals contract would not be symmetrical
+     * and would violate the equals contract.
+     * 
+     * A Facade must not be allowed to contain another Facade implementation as
+     * this too would voilate the equals contract.  The constructor should throw
+     * an IllegalArgumentException.
+     * 
+     * @param o
+     * @return
+     */
+    @Override
+    public boolean equals(Object o);
+    /**
+     * The hashcode from T.hashCode();
+     * @return hashCode for underlying parameter T.
+     */
+    @Override
+    public int hashCode();
+}

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

Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/IncomingUnicastResponse.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/IncomingUnicastResponse.java?rev=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/IncomingUnicastResponse.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/IncomingUnicastResponse.java Fri Apr 23 05:14:10 2010
@@ -20,8 +20,11 @@ package net.jini.discovery;
 import java.io.InputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
-import java.rmi.MarshalledObject;
+import net.jini.core.lookup.PortableServiceRegistrar;
 import net.jini.core.lookup.ServiceRegistrar;
+import net.jini.core.lookup.StreamServiceRegistrar;
+import net.jini.io.MarshalledInstance;
+import net.jini.io.MoToMiInputStream;
 
 /**
  * This class encapsulates the details of unmarshaling an incoming
@@ -34,17 +37,23 @@ import net.jini.core.lookup.ServiceRegis
 public class IncomingUnicastResponse {
     /**
      * The registrar we have discovered.
+     * Changed from protected to private in 2.2.0
      */
-    protected ServiceRegistrar registrar;
+    private PortableServiceRegistrar registrar;
     /**
      * The groups the lookup service was a member of, at the time
      * discovery was performed.  This may be out of date.
+     * Changed from protected to private in 2.2.0
      */
-    protected String[] groups;
+    private String[] groups;
     
     /**
      * Construct a new object, initialized by unmarshaling the
      * contents of an input stream.
+     * 
+     * This class remains backward compatible with earlier releases of Jini
+     * since 2.0, however it will be eventually dropped and only support
+     * versions 2.2.0 and later.
      *
      * @param str the stream from which to unmarshal the response
      * @exception IOException an error occurred while unmarshaling the
@@ -55,9 +64,11 @@ public class IncomingUnicastResponse {
     public IncomingUnicastResponse(InputStream str)
 	throws IOException, ClassNotFoundException
     {
-	ObjectInputStream istr = new ObjectInputStream(str);
+	ObjectInputStream istr = new MoToMiInputStream(str);
+        // need to look at configurable option for verify codebase integrity.
+        boolean verifyCodebaseIntegrity = false;
 	registrar =
-	    (ServiceRegistrar)((MarshalledObject)istr.readObject()).get();
+	    (PortableServiceRegistrar)((MarshalledInstance)istr.readObject()).get(verifyCodebaseIntegrity);
 	int grpCount = istr.readInt();
 	groups = new String[grpCount];
 	for (int i = 0; i < groups.length; i++) {
@@ -67,11 +78,28 @@ public class IncomingUnicastResponse {
 
     /**
      * Return the lookup service registrar we have discovered.
+     * This method won't be available on Java CDC.
      *
      * @return the lookup service registrar we have discovered
+     * @deprecated replaced by {@link #getPRegistrar()}
      */
+    @Deprecated
     public ServiceRegistrar getRegistrar() {
-	return registrar;
+	if (registrar instanceof ServiceRegistrar ) return (ServiceRegistrar) registrar;
+        return new ServiceRegistrarFacade(registrar);
+    }
+    
+    /**
+     * Return the lookup portable service registrar we have discovered.
+     * 
+     * For maximum platform compatbility don't downcast to ServiceRegistrar,
+     * use PortableServiceRegistrar where possible.
+     *
+     * @return the lookup service registrar we have discovered
+     * @since 2.2.0
+     */
+    public PortableServiceRegistrar getPRegistrar () {
+        return registrar;
     }
 
     /**

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=937157&r1=937156&r2=937157&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java Fri Apr 23 05:14:10 2010
@@ -72,8 +72,10 @@ 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;
@@ -693,7 +695,7 @@ import net.jini.security.SecurityContext
  * @see DiscoveryEvent
  * @see DiscoveryPermission
  */
-public class LookupDiscovery implements DiscoveryManagement,
+public class LookupDiscovery implements DiscoveryManagement, DiscoveryManagement2,
                                         DiscoveryGroupManagement
 {
     /* Name of this component; used in config entry retrieval and the logger.*/
@@ -735,7 +737,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 registrars = new HashMap(11);
+    private Map<ServiceID,UnicastResponse> registrars = new HashMap<ServiceID,UnicastResponse>(11);
     /** 
      * Set that takes one of the following:
      * <p><ul>
@@ -947,7 +949,7 @@ public class LookupDiscovery implements 
                                        new String[]{"discovered",
                                                     "discarded",
                                                     "changed"}[task.eventType];
-                                ServiceRegistrar[] regs = e.getRegistrars();
+                                PortableServiceRegistrar[] regs = e.getPRegistrars();
                                 logger.finest(eType+" event  -- "+regs.length
                                                                 +" lookup(s)");
                                 Map groupsMap = e.getGroups();
@@ -1480,13 +1482,13 @@ public class LookupDiscovery implements 
 	}
 
 	public int hashCode() {
-	    return response.getRegistrar().hashCode();
+	    return response.getPRegistrar().hashCode();
 	}
 
 	public boolean equals(Object obj) {
 	    return obj instanceof CheckReachabilityMarker &&
-		   response.getRegistrar().equals(
-		      ((CheckReachabilityMarker) obj).response.getRegistrar());
+		   response.getPRegistrar().equals(
+		      ((CheckReachabilityMarker) obj).response.getPRegistrar());
 	}
     }
 
@@ -1973,7 +1975,7 @@ public class LookupDiscovery implements 
 	    Iterator iter = registrars.values().iterator();
 	    while (iter.hasNext()) {
                 UnicastResponse resp = (UnicastResponse)iter.next();
-                groupsMap.put(resp.getRegistrar(),resp.getGroups());
+                groupsMap.put(resp.getPRegistrar(),resp.getGroups());
 	    }
 	    ArrayList list = new ArrayList(1);
 	    list.add(l);
@@ -2029,13 +2031,91 @@ public class LookupDiscovery implements 
             Iterator iter = registrars.values().iterator();
             ServiceRegistrar[] regs = new ServiceRegistrar[registrars.size()];
             for (int i=0;iter.hasNext();i++) {
-                regs[i] = ((UnicastResponse)iter.next()).getRegistrar();
+                PortableServiceRegistrar psr = ((UnicastResponse)iter.next()).getPRegistrar();
+                if ( psr instanceof ServiceRegistrar){
+                    regs[i] = (ServiceRegistrar) psr;
+                } else {
+                    regs[i] = new ServiceRegistrarFacade(psr);
+                }
             }
             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
@@ -2051,9 +2131,9 @@ public class LookupDiscovery implements 
      *         this method is called after the <code>terminate</code>
      *         method has been called.
      * 
-     * @see DiscoveryListener#discarded
+     * @see DiscoveryListener2#discarded
      */
-    public void discard(ServiceRegistrar reg) {
+    public void discard(PortableServiceRegistrar reg) {
         synchronized (registrars) {
             if (terminated) {
                 throw new IllegalStateException("discovery terminated");
@@ -2062,6 +2142,10 @@ 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() {
@@ -2452,7 +2536,7 @@ public class LookupDiscovery implements 
 					   UnicastResponse resp2)
     {
 	return resp1 != null && resp2 != null &&
-	       resp2.getRegistrar().equals(resp1.getRegistrar());
+	       resp2.getPRegistrar().equals(resp1.getPRegistrar());
     }//end registrarsEqual
 
     /**
@@ -2592,9 +2676,9 @@ public class LookupDiscovery implements 
          * that object is not accessed by any other thread.
          */
         try {
-	    final ServiceRegistrar srcReg = resp.getRegistrar();
-            ServiceRegistrar prepReg
-		= (ServiceRegistrar)AccessController.doPrivileged
+	    final PortableServiceRegistrar srcReg = resp.getPRegistrar();
+            PortableServiceRegistrar prepReg
+		= (PortableServiceRegistrar)AccessController.doPrivileged
 		    ( securityContext.wrap( new PrivilegedExceptionAction() {
                         public Object run() throws RemoteException {
                             Object proxy = registrarPreparer.prepareProxy
@@ -2627,7 +2711,7 @@ public class LookupDiscovery implements 
 	    if(groupsOverlap(resp.getGroups()) &&
 	       !registrarsEqual(resp,
 				(UnicastResponse) registrars.put
-				   (resp.getRegistrar().getServiceID(), resp)))
+				   (resp.getPRegistrar().getServiceID(), resp)))
 	    {
                 /* Time stamp the service ID and store its current sequence 
 		 * number. The first time stamp associated
@@ -2648,11 +2732,11 @@ public class LookupDiscovery implements 
                  * cause the lookup to be discovered before the first
                  * announcement arrives.
                  */
-                regInfo.put(resp.getRegistrar().getServiceID(),
+                regInfo.put(resp.getPRegistrar().getServiceID(),
 			 new AnnouncementInfo(System.currentTimeMillis(), -1));
                 if(!listeners.isEmpty()) {
 		    addNotify((ArrayList)listeners.clone(),
-                              mapRegToGroups(resp.getRegistrar(),
+                              mapRegToGroups(resp.getPRegistrar(),
 					     resp.getGroups()),
                               DISCOVERED);
                 }//endif
@@ -2670,8 +2754,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.getRegistrar(),ent.getGroups());
-                    regInfo.remove(ent.getRegistrar().getServiceID());
+                    groupsMap.put(ent.getPRegistrar(),ent.getGroups());
+                    regInfo.remove(ent.getPRegistrar().getServiceID());
 		    iter.remove(); // remove (srvcID,response) mapping
 		}//endif
 	    }//end loop
@@ -2809,7 +2893,7 @@ public class LookupDiscovery implements 
      *                  possible change)
      */
     private void maybeSendEvent(UnicastResponse response, String[] newGroups) {
-        ServiceRegistrar reg = response.getRegistrar();
+        PortableServiceRegistrar reg = response.getPRegistrar();
         boolean getActual    = true;
         if(newGroups == null) { // newGroups null means get actual groups now
             newGroups = getActualGroups(reg);
@@ -2870,7 +2954,7 @@ public class LookupDiscovery implements 
      *                  member groups of the <code>reg</code> parameter
      *                  (just after a possible change)
      */
-    private void notifyOnGroupChange(ServiceRegistrar reg,
+    private void notifyOnGroupChange(PortableServiceRegistrar reg,
                                      String[]         oldGroups,
                                      String[]         newGroups)
     {
@@ -2895,7 +2979,7 @@ public class LookupDiscovery implements 
      *                   member groups of the registrar referenced by the 
      *                   <code>reg</code> parameter
      */
-    private void sendDiscarded(ServiceRegistrar reg, String[] curGroups) {
+    private void sendDiscarded(PortableServiceRegistrar reg, String[] curGroups) {
         ServiceID srvcID = reg.getServiceID();
         if(curGroups == null) { // discard request is from external source
             UnicastResponse resp = (UnicastResponse)registrars.get(srvcID);
@@ -2923,7 +3007,7 @@ public class LookupDiscovery implements 
      *                   member groups of the registrar referenced by the 
      *                   <code>reg</code> parameter
      */
-    private void sendChanged(ServiceRegistrar reg, String[] curGroups) {
+    private void sendChanged(PortableServiceRegistrar reg, String[] curGroups) {
         /* replace old groups with new; prevents repeated changed events */
         UnicastResponse resp = 
                    (UnicastResponse)registrars.get(reg.getServiceID());
@@ -2931,7 +3015,7 @@ public class LookupDiscovery implements 
 		       new UnicastResponse(resp.getHost(),
 					   resp.getPort(),
 					   curGroups,
-					   resp.getRegistrar()));
+					   resp.getPRegistrar()));
         if( !listeners.isEmpty() ) {
             addNotify((ArrayList)listeners.clone(), 
                        mapRegToGroups(reg,curGroups), CHANGED);
@@ -2973,7 +3057,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 ServiceRegistrar reg) {
+    private String[] getActualGroups(final PortableServiceRegistrar 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.
@@ -3020,7 +3104,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(ServiceRegistrar reg, String[] curGroups) {
+    private Map mapRegToGroups(PortableServiceRegistrar reg, String[] curGroups) {
         HashMap groupsMap = new HashMap(1);
         groupsMap.put(reg,curGroups);
         return groupsMap;