incubator-river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter_firmst...@apache.org
Subject svn commit: r935433 - in /incubator/river/jtsk/trunk/src/net/jini: core/event/ core/lookup/ discovery/ io/
Date Mon, 19 Apr 2010 01:29:25 GMT
Author: peter_firmstone
Date: Mon Apr 19 01:29:25 2010
New Revision: 935433

URL: http://svn.apache.org/viewvc?rev=935433&view=rev
Log:
New Interfaces for ServiceRegistrar, one a superinterface called PortableServiceRegistrar and a new StreamingServiceRegistrar that extends PortableServiceRegistrar.

Depreciation of API methods that depend on java.rmi.MarshalledObject and replacments with MarshalledInstance

Replacement of java.rmi.MarshalledObject with MarshalledInstance in class implementations and additional stream conversion utilities to preserve the original Serialized form of those classes.

Added:
    incubator/river/jtsk/trunk/src/net/jini/io/MiToMoOutputStream.java   (with props)
    incubator/river/jtsk/trunk/src/net/jini/io/MoToMiInputStream.java   (with props)
Removed:
    incubator/river/jtsk/trunk/src/net/jini/io/Converter.java
    incubator/river/jtsk/trunk/src/net/jini/io/ToMOOutputStream.java
Modified:
    incubator/river/jtsk/trunk/src/net/jini/core/event/RemoteEvent.java
    incubator/river/jtsk/trunk/src/net/jini/core/lookup/PortableServiceRegistrar.java
    incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamingServiceRegistrar.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/LookupUnmarshalException.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/RemoteDiscoveryEvent.java
    incubator/river/jtsk/trunk/src/net/jini/io/Convert.java

Modified: incubator/river/jtsk/trunk/src/net/jini/core/event/RemoteEvent.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/core/event/RemoteEvent.java?rev=935433&r1=935432&r2=935433&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/core/event/RemoteEvent.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/core/event/RemoteEvent.java Mon Apr 19 01:29:25 2010
@@ -23,10 +23,9 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import net.jini.io.Convert;
-import net.jini.io.Converter;
-import net.jini.io.FromMOInputStream;
 import net.jini.io.MarshalledInstance;
-import net.jini.io.ToMOOutputStream;
+import net.jini.io.MiToMoOutputStream;
+import net.jini.io.MoToMiInputStream;
 
 /**
  * The base class or superclass for remote events.
@@ -118,10 +117,15 @@ public class RemoteEvent extends java.ut
      * is required to be accessed by a subclass, the visibility has been 
      * changed from protected to private, this may break binary compatibility
      * for some.
-     *
+     * 
+     * The serial form of this field is java.rmi.MarshalledObject, this class
+     * uses stream based converters to convert to and from MarshalledObject
+     * during serialization and deserialization.
+     * 
+     * @see MarshalledObject
      * @serial
      */
-    private net.jini.io.MarshalledObject handback;
+    private MarshalledInstance handback;
 
     /**
      * Constructs a RemoteEvent object.
@@ -151,7 +155,7 @@ public class RemoteEvent extends java.ut
 	this.eventID = eventID;
 	this.seqNum = seqNum;
         Convert convert = Convert.getInstance();
-	this.handback = convert.toJiniMarshalledObject(handback);
+	this.handback = convert.toMarshalledInstance(handback);
     }
     /**
      * Constructs a RemoteEvent object.
@@ -177,7 +181,7 @@ public class RemoteEvent extends java.ut
         this.source = source;
         this.eventID = eventID;
         this.seqNum = seqNum;
-        this.handback = Converter.toJiniMarshalledObject(handback);
+        this.handback = handback;
            
     }
 
@@ -216,7 +220,7 @@ public class RemoteEvent extends java.ut
     }
     
     public MarshalledInstance getRegisteredObject() {
-	return Converter.toMarshalledInstance(handback);      
+	return handback;      
     }
 
     /**
@@ -228,7 +232,7 @@ public class RemoteEvent extends java.ut
     private void readObject(java.io.ObjectInputStream stream)
 	throws java.io.IOException, ClassNotFoundException
     {
-	ObjectInputStream newStream = new FromMOInputStream(stream);
+	ObjectInputStream newStream = new MoToMiInputStream(stream);
         newStream.defaultReadObject();
 	super.source = source;
     }
@@ -241,7 +245,7 @@ public class RemoteEvent extends java.ut
      * @throws java.io.IOException
      */
     private void writeObject(java.io.ObjectOutputStream stream) throws IOException{
-        ObjectOutputStream newOutStream = new ToMOOutputStream(stream);
+        ObjectOutputStream newOutStream = new MiToMoOutputStream(stream);
         newOutStream.defaultWriteObject();
     }
 }

Modified: incubator/river/jtsk/trunk/src/net/jini/core/lookup/PortableServiceRegistrar.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/core/lookup/PortableServiceRegistrar.java?rev=935433&r1=935432&r2=935433&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/core/lookup/PortableServiceRegistrar.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/core/lookup/PortableServiceRegistrar.java Mon Apr 19 01:29:25 2010
@@ -21,8 +21,20 @@ import java.rmi.RemoteException;
 import net.jini.core.discovery.LookupLocator;
 
 /**
+ * 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 PortableServiceRegistrar 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 PortableServiceRegistrar and ServiceRegistration)
+ * is atomic with respect to other invocations.
+ * 
+ * 
+ * @see ServiceRegistration
  *
- * @author peter
+ * @since 2.2.0
  */
 public interface PortableServiceRegistrar {
     /**

Modified: 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/StreamingServiceRegistrar.java?rev=935433&r1=935432&r2=935433&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamingServiceRegistrar.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamingServiceRegistrar.java Mon Apr 19 01:29:25 2010
@@ -17,14 +17,35 @@
  */
 package net.jini.core.lookup;
 
+import java.io.ObjectInput;
 import java.rmi.RemoteException;
 import net.jini.core.event.EventRegistration;
 import net.jini.core.event.RemoteEventListener;
 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
+ * 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)
+ * is atomic with respect to other invocations.
+ * 
+ * The StreamingServiceRegistrar 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.
+ * 
+ * @see ServiceRegistrar
+ * @see PortableServiceRegistrar
+ * @see ServiceRegistration
  * @author Peter Firmstone
+ * @since 2.2.0
  */
 public interface StreamingServiceRegistrar extends PortableServiceRegistrar{
     
@@ -53,6 +74,7 @@ public interface StreamingServiceRegistr
      * @return an EventRegistration object to the entity that registered the
      *         specified remote listener
      * @throws java.rmi.RemoteException
+     * @since 2.2.0
      */
     EventRegistration notify(MarshalledInstance handback,
                              ServiceTemplate tmpl,
@@ -60,4 +82,30 @@ public interface StreamingServiceRegistr
 			     RemoteEventListener listener,
 			     long leaseDuration)
 	throws RemoteException;
+
+    /**
+     * Returns the service object (i.e., just ServiceItem.service) from an
+     * item matching the template.  It makes the service object available via
+     * the returned ObjectInput.  
+     * 
+     * If the returned object cannot be deserialized, it can be returned in
+     * marshalled form as a MarshalledInstance.
+     * 
+     * Implementations of this interface should return the Objects in order of
+     * their package implementation version, so that the number of ClassLoaders
+     * 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
+     * memory consumption requirements at the client.
+     *
+     * @param tmpl template to match
+     * @param marshalled if true return objects in marshalled form.
+     * @return an object input that represents a service that matches the
+     * specified template
+     * @throws java.rmi.RemoteException
+     * @see MarshalledInstance
+     * @since 2.2.0
+     */
+    ObjectInput lookup(ServiceTemplate tmpl, boolean marshalled) throws RemoteException;
 }

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=935433&r1=935432&r2=935433&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/LookupUnmarshalException.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/LookupUnmarshalException.java Mon Apr 19 01:29:25 2010
@@ -19,11 +19,19 @@
 package net.jini.discovery;
 
 import net.jini.core.lookup.ServiceRegistrar;
+import net.jini.core.lookup.PortableServiceRegistrar;
 
 import java.io.InvalidObjectException;
 import java.io.IOException;
 import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.rmi.MarshalledObject;
+import java.util.ArrayList;
+import java.util.Arrays;
+import net.jini.io.Convert;
+import net.jini.io.MarshalledInstance;
+import net.jini.io.MiToMoOutputStream;
+import net.jini.io.MoToMiInputStream;
 
 /**
  * When unmarshalling an instance of <code>MarshalledObject</code>, different
@@ -39,22 +47,22 @@ import java.rmi.MarshalledObject;
  * This class provides a mechanism that clients of the lookup discovery 
  * service may use for efficient handling of the exceptions that may 
  * occur when unmarshalling elements of a set of marshalled instances 
- * of the <code>ServiceRegistrar</code> interface. When elements in such
+ * of the <code>PortableServiceRegistrar</code> interface. When elements in such
  * a set are unmarshalled, the <code>LookupUnmarshalException</code> class
  * may be used to collect and report pertinent information generated when
  * failure occurs while unmarshalling the elements of the set.
  * <p>
  * The information that may be of interest to entities that receive this
  * exception class is contained in the following fields: a set of
- * <code>ServiceRegistrar</code> instances in which each element is the
+ * <code>PortableServiceRegistrar</code> instances in which each element is the
  * result of a successful unmarshalling attempt, a set of marshalled instances
- * of <code>ServiceRegistrar</code> in which each element could not be
+ * of <code>PortableServiceRegistrar</code> in which each element could not be
  * successfully unmarshalled, and a set of exceptions (<code>IOException<code>,
  * <code>ClassNotFoundException</code>, or some unchecked exception) in which
  * each element corresponds to one of the unmarshalling failures.
  * <p>
  * Thus, when exceptional conditions occur while unmarshalling a set of 
- * marshalled instances of <code>ServiceRegistrar</code>, this class can
+ * marshalled instances of <code>PortableServiceRegistrar</code>, this class can
  * be used not only to indicate that an exceptional condition has occurred,
  * but also to provide information that can be used to perform error handling 
  * activities such as: determining if it is feasible to continue with 
@@ -62,11 +70,12 @@ import java.rmi.MarshalledObject;
  * <p>
  * Note that this exception class should be used only to report exceptional
  * conditions occurring when unmarshalling a set of marshalled instances 
- * of the <code>ServiceRegistrar</code> interface.
+ * of the <code>PortableServiceRegistrar</code> interface.
  *
  * @author Sun Microsystems, Inc.
  *
  * @see net.jini.core.lookup.ServiceRegistrar
+ * @see net.jini.core.lookup.PortableServiceRegistrar
  */
 public class LookupUnmarshalException extends Exception {
 
@@ -80,16 +89,16 @@ public class LookupUnmarshalException ex
      *
      * @serial
      */
-    private ServiceRegistrar[] registrars = null;
+    private PortableServiceRegistrar[] registrars = null;
 
     /**
-     * Array containing the set of <code>ServiceRegistrar</code> instances
+     * Array containing the set of <code>PortableServiceRegistrar</code> instances
      * that could not be unmarshalled. This set should not be <code>null</code>
      * and should contain at least one element.
      *
      * @serial
      */
-    private MarshalledObject[] marshalledRegistrars = null;
+    private MarshalledInstance[] marshalledRegistrars = null;
 
     /**
      * Array containing the set of exceptions that occurred during the
@@ -97,7 +106,7 @@ public class LookupUnmarshalException ex
      * of <code>IOException</code>, <code>ClassNotFoundException</code>, or
      * some unchecked exception. Furthermore, there should be a one-to-one
      * correspondence between each element in this set and each element in
-     * the set of still-to-be-unmarshalled <code>ServiceRegistrar</code>
+     * the set of still-to-be-unmarshalled <code>PortableServiceRegistrar</code>
      * instances. That is, the element of this set corresponding to index i
      * should be an instance of the exception that occurred while attempting
      * to unmarshal the element at index i of <code>marshalledRegistrars<code>.
@@ -112,11 +121,11 @@ public class LookupUnmarshalException ex
      * Constructs a new instance of <code>LookupUnmarshalException</code>.
      *
      * @param registrars           Array containing the set of instances of
-     *                             <code>ServiceRegistrar</code> that were
+     *                             <code>PortableServiceRegistrar</code> that were
      *                             successfully unmarshalled.
      *                            
      * @param marshalledRegistrars Array containing the set of marshalled
-     *                             <code>ServiceRegistrar</code> instances
+     *                             <code>PortableServiceRegistrar</code> instances
      *                             that could not be unmarshalled.
      *                   
      * @param exceptions           Array containing the set of exceptions that
@@ -145,24 +154,27 @@ public class LookupUnmarshalException ex
      *         either the <code>marshalledRegistrars</code> parameter or the
      *         <code>exceptions</code> parameter has zero length; or when the
      *         lengths of those two parameters are not equal.
+     * @deprecated 
      */
-    public LookupUnmarshalException(ServiceRegistrar[] registrars,
+    @Deprecated
+    public LookupUnmarshalException(PortableServiceRegistrar[] registrars,
                                     MarshalledObject[] marshalledRegistrars,
                                     Throwable[]        exceptions) 
     {
         super();
-        init(registrars,marshalledRegistrars,exceptions);
+        MarshalledInstance[] jmo = asMarshalledInstance(marshalledRegistrars);
+        init(registrars,jmo,exceptions);
     }//end constructor
 
     /**
      * Constructs a new instance of <code>LookupUnmarshalException</code>.
      *
      * @param registrars           Array containing the set of instances of
-     *                             <code>ServiceRegistrar</code> that were
+     *                             <code>PortableServiceRegistrar</code> that were
      *                             successfully unmarshalled.
      *                            
      * @param marshalledRegistrars Array containing the set of marshalled
-     *                             <code>ServiceRegistrar</code> instances
+     *                             <code>PortableServiceRegistrar</code> instances
      *                             that could not be unmarshalled.
      *                   
      * @param exceptions           Array containing the set of exceptions that
@@ -194,17 +206,116 @@ public class LookupUnmarshalException ex
      *         either the <code>marshalledRegistrars</code> parameter or the
      *         <code>exceptions</code> parameter has zero length; or when the
      *         lengths of those two parameters are not equal.
+     * @deprecated 
      */
-    public LookupUnmarshalException(ServiceRegistrar[] registrars,
+    @Deprecated
+    public LookupUnmarshalException(PortableServiceRegistrar[] registrars,
                                     MarshalledObject[] marshalledRegistrars,
                                     Throwable[]        exceptions, 
                                     String             message) 
     {
         super(message);
+        MarshalledInstance[] mi = asMarshalledInstance(marshalledRegistrars);
+        init(registrars,mi,exceptions);
+    }//end constructor
+    
+    /**
+     * Constructs a new instance of <code>LookupUnmarshalException</code>.
+     *
+     * @param registrars           Array containing the set of instances of
+     *                             <code>PortableServiceRegistrar</code> that were
+     *                             successfully unmarshalled.
+     *                            
+     * @param marshalledRegistrars Array containing the set of marshalled
+     *                             <code>PortableServiceRegistrar</code> instances
+     *                             that could not be unmarshalled.
+     *                   
+     * @param exceptions           Array containing the set of exceptions that
+     *                             occurred during the unmarshalling process.
+     *                             Each element in this set should be an
+     *                             instance of <code>IOException</code>,
+     *                             <code>ClassNotFoundException</code>, or
+     *                             some unchecked exception. Furthermore,
+     *                             there should be a one-to-one correspondence
+     *                             between each element in this set and
+     *                             each element in the
+     *                             <code>marshalledRegistrars</code> parameter.
+     * <p>
+     *                             That is, the element of this set
+     *                             corresponding to index i should be an
+     *                             instance of the exception that occurred
+     *                             while attempting to unmarshal the element
+     *                             at index i of the
+     *                             <code>marshalledRegistrars</code> parameter.
+     *
+     * @throws java.lang.NullPointerException this exception occurs
+     *         when <code>null</code> is input for either the
+     *         <code>marshalledRegistrars</code> parameter or the
+     *         <code>exceptions</code> parameter.
+     * @throws java.lang.IllegalArgumentException this exception occurs when
+     *         either the <code>marshalledRegistrars</code> parameter or the
+     *         <code>exceptions</code> parameter has zero length; or when the
+     *         lengths of those two parameters are not equal.
+     */
+    public LookupUnmarshalException(PortableServiceRegistrar[] registrars,
+                                    MarshalledInstance[] marshalledRegistrars,
+                                    Throwable[]        exceptions) 
+    {
+        super();
         init(registrars,marshalledRegistrars,exceptions);
     }//end constructor
 
     /**
+     * Constructs a new instance of <code>LookupUnmarshalException</code>.
+     *
+     * @param registrars           Array containing the set of instances of
+     *                             <code>PortableServiceRegistrar</code> that were
+     *                             successfully unmarshalled.
+     *                            
+     * @param marshalledRegistrars Array containing the set of marshalled
+     *                             <code>PortableServiceRegistrar</code> instances
+     *                             that could not be unmarshalled.
+     *                   
+     * @param exceptions           Array containing the set of exceptions that
+     *                             occurred during the unmarshalling process.
+     *                             Each element in this set should be an
+     *                             instance of <code>IOException</code>,
+     *                             <code>ClassNotFoundException</code>, or
+     *                             some unchecked exception. Furthermore,
+     *                             there should be a one-to-one correspondence
+     *                             between each element in this set and
+     *                             each element in the
+     *                             <code>marshalledRegistrars</code> parameter.
+     * <p>
+     *                             That is, the element of this set
+     *                             corresponding to index i should be an
+     *                             instance of the exception that occurred
+     *                             while attempting to unmarshal the element
+     *                             at index i of the
+     *                             <code>marshalledRegistrars</code> parameter.
+     *
+     * @param message              <code>String</code> describing the nature
+     *                             of the exception
+     *
+     * @throws java.lang.NullPointerException this exception occurs
+     *         when <code>null</code> is input for either the
+     *         <code>marshalledRegistrars</code> parameter or the
+     *         <code>exceptions</code> parameter.
+     * @throws java.lang.IllegalArgumentException this exception occurs when
+     *         either the <code>marshalledRegistrars</code> parameter or the
+     *         <code>exceptions</code> parameter has zero length; or when the
+     *         lengths of those two parameters are not equal.
+     */
+    public LookupUnmarshalException(PortableServiceRegistrar[] registrars,
+                                    MarshalledInstance[] marshalledRegistrars,
+                                    Throwable[]        exceptions, 
+                                    String             message) 
+    {
+        super(message);
+        init(registrars,marshalledRegistrars,exceptions);
+    }//end constructor
+    
+    /**
      * Accessor method that returns an array consisting of instances of 
      * <code>ServiceRegistrar</code>, where each element of the array
      * corresponds to a successfully unmarshalled object. Note that the
@@ -215,25 +326,77 @@ public class LookupUnmarshalException ex
      *         each element corresponds to a successfully unmarshalled object.
      */
     public ServiceRegistrar[] getRegistrars() {
-        return registrars;
+        ArrayList<ServiceRegistrar> sr = new ArrayList<ServiceRegistrar>();
+        int l = registrars.length;
+        for ( int i = 0; i < l; i++){
+            if (registrars[i] instanceof ServiceRegistrar) {
+                sr.add((ServiceRegistrar) registrars[i]);
+            }
+        }
+        ServiceRegistrar[] sra = new ServiceRegistrar[sr.size()];
+        return sr.toArray(sra);
+    }//end getRegistrars
+    
+    /**
+     * Accessor method that returns an array consisting of instances of 
+     * <code>PortableServiceRegistrar</code>, where each element of the array
+     * corresponds to a successfully unmarshalled object. Note that the
+     * same array is returned on each invocation of this method; that is,
+     * a copy is not made.
+     *
+     * @return array of instances of <code>PortableServiceRegistrar</code>, where
+     *         each element corresponds to a successfully unmarshalled object.
+     */
+    public PortableServiceRegistrar[] getPRegistrars() {
+        // Defensive copy.
+        return Arrays.copyOf(registrars, registrars.length);
     }//end getRegistrars
 
     /**
      * Accessor method that returns an array consisting of instances of 
      * <code>MarshalledObject</code>, where each element of the array is a
-     * marshalled instance of the <code>ServiceRegistrar</code> interface,
+     * marshalled instance of the <code>PortableServiceRegistrar</code> interface,
      * and corresponds to an object that could not be successfully
      * unmarshalled. Note that the same array is returned on each invocation
      * of this method; that is, a copy is not made.
      *
-     * @return array of marshalled instances of <code>ServiceRegistrar</code>,
+     * @return array of marshalled instances of <code>PortableServiceRegistrar</code>,
      *         where each element corresponds to an object in which failure
      *         occurred while attempting to unmarshal the object.
      */
+    @Deprecated
     public MarshalledObject[] getMarshalledRegistrars() {
-        return marshalledRegistrars;
+        return asMarshalledObject(marshalledRegistrars);
     }//end getMarshalledRegistrars
-
+    
+    @Deprecated
+    private MarshalledInstance[] asMarshalledInstance(MarshalledObject[] mo) {
+        Convert convert = Convert.getInstance();
+        int l = mo.length;
+        MarshalledInstance[] mi = new MarshalledInstance[l];
+        for (int i = 0; i < l; i++){
+            mi[i] = convert.toMarshalledInstance(mo[i]);
+        }
+        return mi;
+    }
+    
+    @Deprecated
+    @SuppressWarnings("unchecked")
+    private MarshalledObject[] asMarshalledObject(MarshalledInstance[] mi){
+        Convert convert = Convert.getInstance();
+        int l = mi.length;
+        MarshalledObject[] rmiMo = new MarshalledObject[l];
+        for (int i = 0; i < l; i++){
+            rmiMo[i] = convert.toRmiMarshalledObject(mi[i]);
+        }
+        return rmiMo;
+    }
+    
+    public MarshalledInstance[] getMarshalledInstRegistrars(){
+        // Defensive copy.
+         return Arrays.copyOf(marshalledRegistrars, marshalledRegistrars.length);
+    }
+    
     /**
      * Accessor method that returns an array consisting of instances of 
      * <code>Throwable</code>, where each element of the array corresponds
@@ -256,18 +419,19 @@ public class LookupUnmarshalException ex
      *         the unmarshalling process.
      */
     public Throwable[] getExceptions() {
-        return exceptions;
+        // Defensive copy.
+        return Arrays.copyOf(exceptions, exceptions.length);
     }//end getExceptions
 
     /**
      * Initializes the abstract state of this class.
      *
      * @param registrars           Array containing the set of instances of
-     *                             <code>ServiceRegistrar</code> that were
+     *                             <code>PortableServiceRegistrar</code> that were
      *                             successfully unmarshalled.
      *                            
      * @param marshalledRegistrars Array containing the set of marshalled
-     *                             <code>ServiceRegistrar</code> instances
+     *                             <code>PortableServiceRegistrar</code> instances
      *                             that could not be unmarshalled.
      *                   
      * @param exceptions           Array containing the set of exceptions that
@@ -282,8 +446,8 @@ public class LookupUnmarshalException ex
      *         <code>exceptions</code> parameter has zero length; or when the
      *         lengths of those two parameters are not equal.
      */
-    private void init(ServiceRegistrar[] registrars,
-                      MarshalledObject[] marshalledRegistrars,
+    private void init(PortableServiceRegistrar[] registrars,
+                      MarshalledInstance[] marshalledRegistrars,
                       Throwable[]        exceptions) {
         /* Verify the input arguments */
         if(marshalledRegistrars == null) {
@@ -319,7 +483,8 @@ public class LookupUnmarshalException ex
     private void readObject(ObjectInputStream s)  
                                throws IOException, ClassNotFoundException
     {
-        s.defaultReadObject();
+        ObjectInputStream fois = new MoToMiInputStream(s); // convert to java.rmi.MarshalledObject
+        fois.defaultReadObject();
         /* Verify marshalledRegistrars and exceptions fields */
         if(marshalledRegistrars == null) {
             throw new InvalidObjectException
@@ -345,5 +510,17 @@ public class LookupUnmarshalException ex
         }//endif
 
     }//end readObject
+    
+    /**
+     * This method is an interim temporary measure to provide a transition
+     * period for the Serialized form in Apache River versions prior to
+     * 2.2.0
+     * @param stream
+     * @throws java.io.IOException
+     */
+    private void writeObject(java.io.ObjectOutputStream stream) throws IOException{
+        ObjectOutputStream newOutStream = new MiToMoOutputStream(stream); // Convert from java.rmi.MarshalledObject
+        newOutStream.defaultWriteObject();
+    }
 
 }//end class LookupUnmarshalException

Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/RemoteDiscoveryEvent.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/RemoteDiscoveryEvent.java?rev=935433&r1=935432&r2=935433&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/RemoteDiscoveryEvent.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/RemoteDiscoveryEvent.java Mon Apr 19 01:29:25 2010
@@ -23,14 +23,18 @@ import java.io.ObjectInputStream;
 import java.rmi.MarshalledObject;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
 
 import net.jini.core.event.RemoteEvent;
 import net.jini.core.lookup.ServiceRegistrar;
+import net.jini.core.lookup.PortableServiceRegistrar;
 import net.jini.io.MarshalledInstance;
 
 import com.sun.jini.proxy.MarshalledWrapper;
+import java.io.ObjectOutputStream;
+import java.util.Iterator;
+import net.jini.io.MiToMoOutputStream;
+import net.jini.io.MoToMiInputStream;
 
 /**
  * Whenever the lookup discovery service discovers or discards a lookup
@@ -57,7 +61,7 @@ import com.sun.jini.proxy.MarshalledWrap
  * of abstract state: a boolean indicating whether the lookup services
  * referenced by the event have been discovered or discarded; and a set
  * consisting of proxy objects where each proxy is a marshalled instance
- * of the ServiceRegistrar interface, and each is a proxy of one of the
+ * of the PortableServiceRegistrar interface, and each is a proxy of one of the
  * recently discovered or discarded lookup service(s). Methods are defined
  * through which this additional state may be retrieved upon receipt of an
  * instance of this class.
@@ -95,7 +99,8 @@ import com.sun.jini.proxy.MarshalledWrap
  * @author Sun Microsystems, Inc.
  *
  * @see net.jini.core.event.RemoteEvent
- * @see net.jini.core.lookup.ServiceRegistrar
+ * @see net.jini.core.lookup.PortableServiceRegistrar
+ * @see net.jini.core.lookup.
  */
 public class RemoteDiscoveryEvent extends RemoteEvent {
 
@@ -113,7 +118,7 @@ public class RemoteDiscoveryEvent extend
 
     /**
      * List consisting of marshalled proxy objects where each proxy implements
-     * the <code>ServiceRegistrar</code> interface, and each is a proxy of
+     * the <code>PortableServiceRegistrar</code> interface, and each is a proxy of
      * one of the recently discovered or discarded lookup service(s); the
      * lookup service(s) with which this event is associated. 
      * <p>
@@ -137,7 +142,7 @@ public class RemoteDiscoveryEvent extend
      *
      * @serial
      */
-    protected ArrayList marshalledRegs;
+    protected ArrayList<MarshalledInstance> marshalledRegs;
 
     /**
      * Array containing a subset of the set of proxies to the lookup
@@ -152,7 +157,7 @@ public class RemoteDiscoveryEvent extend
      *
      * @serial
      */
-    protected ServiceRegistrar[] regs;
+    protected PortableServiceRegistrar[] regs;
 
     /**
      * <code>Map</code> from the service IDs of the registrars of this event
@@ -197,6 +202,7 @@ public class RemoteDiscoveryEvent extend
      * @throws java.lang.IllegalArgumentException this exception occurs
      *         when an empty set of registrars is input.
      */
+    @Deprecated
     public RemoteDiscoveryEvent(Object source,
                                 long eventID,
                                 long seqNum,
@@ -211,9 +217,90 @@ public class RemoteDiscoveryEvent extend
             if(groups.size() == 0) {
                 throw new IllegalArgumentException("empty input map");
             }
-            ServiceRegistrar[] registrars =
-                          (ServiceRegistrar[])(groups.keySet()).toArray
-                                        (new ServiceRegistrar[groups.size()]);
+            PortableServiceRegistrar[] registrars =
+                          (PortableServiceRegistrar[])(groups.keySet()).toArray
+                                        (new PortableServiceRegistrar[groups.size()]);
+            /* If any elements of the array are null, throw exception */
+            for(int i=0;i<registrars.length;i++) {
+                if(registrars[i] == null) {
+                    throw new NullPointerException("null element ("+i
+                                                   +") in input map");
+                }
+            }
+            /* Create a new marshalled instance of each element of the
+             * registrars array, and place each in the marshalledRegs
+             * ArrayList of this class. Also, construct the groups map that
+             * contains the mappings from the service ID of each registrar
+             * to the registrar's corresponding member groups.
+             *
+             * Drop any element that can't be serialized.
+             */
+            this.groups = new HashMap(groups.size());
+            this.marshalledRegs = new ArrayList<MarshalledInstance>(groups.size());
+            for(int i=0;i<registrars.length;i++) {
+                try {
+                    MarshalledInstance mi = new MarshalledInstance(registrars[i]);
+                    marshalledRegs.add(mi);
+                    (this.groups).put((registrars[i]).getServiceID(),
+                                       groups.get(registrars[i]) );
+		} catch(IOException e) { /* drop if can't serialize */ }
+            }
+            if( !(marshalledRegs.isEmpty()) ) {
+                regs = new PortableServiceRegistrar[marshalledRegs.size()];
+            } else {
+                throw new IOException("failed to serialize any of the "
+                                      +registrars.length+" elements");
+            }
+	} else {
+            throw new NullPointerException("null input map");
+        }
+    }//end constructor
+    
+     /**
+     * Constructs a new instance of <code>RemoteDiscoveryEvent</code>.
+     *
+     * @param source     reference to the lookup discovery service that
+     *                   generated the event
+     * @param eventID    the event identifier that maps a particular
+     *                   registration to its listener and targeted groups
+     *                   and locators
+     * @param seqNum     the sequence number of this event
+     * @param handback   the client handback (null may be input)
+     * @param discarded  flag indicating whether the event being constructed
+     *                   is a discovery event or a discard event
+     * @param groups     mapping from the registrars of this event to the
+     *                   groups in which each registrar is a member
+     *
+     * @throws java.io.IOException when serialization failure occurs on 
+     *         every registrar of this event. That is, if at least one
+     *         registrar is successfully serialized, then this exception
+     *         will not be thrown.
+     *
+     * @throws java.lang.NullPointerException this exception occurs when
+     *         either <code>null</code> is input for the map parameter, or
+     *         at least one element of that map is <code>null</code>.
+     *
+     * @throws java.lang.IllegalArgumentException this exception occurs
+     *         when an empty set of registrars is input.
+     */
+
+    public RemoteDiscoveryEvent(MarshalledInstance handback,
+                                Object source,
+                                long eventID,
+                                long seqNum,
+                                boolean discarded,
+                                Map groups)    throws IOException
+    {
+	super(handback, source, eventID, seqNum);
+	this.discarded = discarded;
+        if(groups != null) {
+            /* If the set of registrars is empty, throw exception */
+            if(groups.size() == 0) {
+                throw new IllegalArgumentException("empty input map");
+            }
+            PortableServiceRegistrar[] registrars =
+                          (PortableServiceRegistrar[])(groups.keySet()).toArray
+                                        (new PortableServiceRegistrar[groups.size()]);
             /* If any elements of the array are null, throw exception */
             for(int i=0;i<registrars.length;i++) {
                 if(registrars[i] == null) {
@@ -233,13 +320,14 @@ public class RemoteDiscoveryEvent extend
             this.marshalledRegs = new ArrayList(groups.size());
             for(int i=0;i<registrars.length;i++) {
                 try {
-                    marshalledRegs.add(new MarshalledObject(registrars[i]));
+                    MarshalledInstance mi = new MarshalledInstance(registrars[i]);
+                    marshalledRegs.add(mi);
                     (this.groups).put((registrars[i]).getServiceID(),
                                        groups.get(registrars[i]) );
 		} catch(IOException e) { /* drop if can't serialize */ }
             }
             if( !(marshalledRegs.isEmpty()) ) {
-                regs = new ServiceRegistrar[marshalledRegs.size()];
+                regs = new PortableServiceRegistrar[marshalledRegs.size()];
             } else {
                 throw new IOException("failed to serialize any of the "
                                       +registrars.length+" elements");
@@ -321,7 +409,82 @@ public class RemoteDiscoveryEvent extend
      *
      * @see net.jini.discovery.LookupUnmarshalException
      */
+    @Deprecated
     public ServiceRegistrar[] getRegistrars() throws LookupUnmarshalException {
+	PortableServiceRegistrar[] psr = getPRegistrars();
+        ArrayList<ServiceRegistrar> sr = new ArrayList<ServiceRegistrar>();
+        int l = psr.length;
+        for ( int i = 0; i < l; i++){
+            if (psr[i] instanceof ServiceRegistrar) {
+                sr.add((ServiceRegistrar) psr[i]);
+            }
+        }
+        ServiceRegistrar[] sra = new ServiceRegistrar[sr.size()];
+        return sr.toArray(sra);
+    }//end getRegistrars
+
+    /**
+     * Returns an array consisting of instances of the PortableServiceRegistrar
+     * interface. Each element in the returned set is a proxy to one of
+     * the newly discovered or discarded lookup service(s) that caused
+     * the current instance of this event class to be sent to the listener
+     * of the client's registration. Note that a new array is returned
+     * on every call.
+     * <p>
+     * When the lookup discovery service sends an instance of this event
+     * class to the listener of a client's registration, the set of lookup
+     * service proxies contained in the event is sent as a set of marshalled
+     * instances of the PortableServiceRegistrar interface. Thus, in order to 
+     * construct the return set, this method attempts to unmarshal each
+     * element of that set of proxies. Should a failure occur while
+     * attempting to unmarshal any of the elements of the set of marshalled
+     * proxy objects contained in the current instance of this class, this
+     * method will throw an exception of type LookupUnmarshalException. 
+     * <p>
+     * When a LookupUnmarshalException is thrown by this method, the
+     * contents of the exception provides the client with the following
+     * useful information: (1) the knowledge that a problem has occurred
+     * while unmarshalling at least one of the as yet unmarshalled proxy
+     * objects, (2) the set consisting of the proxy objects that were
+     * successfully unmarshalled (either on the current invocation of
+     * this method or on some previous invocation), (3) the set consisting
+     * of the marshalled proxy objects that could not be unmarshalled
+     * during the current or any previous invocation of this method, and
+     * (4) the set of exceptions corresponding to each failed attempt at
+     * unmarshalling during the current invocation of this method.
+     * <p>
+     * Typically, the type of exception that occurs when attempting to
+     * unmarshal an element of the set of marshalled proxies is either an
+     * IOException or a ClassNotFoundException. A ClassNotFoundException 
+     * occurs whenever a remote field of the marshalled proxy cannot be
+     * retrieved (usually because the codebase of one of the field's classes
+     * or interfaces is currently 'down'). To address this situation, the
+     * client may wish to invoke this method at some later time when the
+     * 'down' codebase(s) may be accessible. Thus, the client can invoke
+     * this method multiple times until all of the elements of the set of
+     * marshalled proxies can be successfully unmarshalled.
+     * <p>
+     * Note that once an element of the set of marshalled proxy objects has
+     * been successfully unmarshalled on a particular invocation of this
+     * method, the resulting unmarshalled proxy is stored for return on
+     * all future invocations of this method. That is, once successfully
+     * unmarshalled, no attempt will be made to unmarshal that element on
+     * any future invocations of this method. Thus, if this method returns
+     * successfully without throwing a LookupUnmarshalException, the client
+     * is guaranteed that all marshalled proxies have been successfully
+     * unmarshalled; and any future invocations of this method will return
+     * successfully.
+     *
+     * @return an array consisting of references to the discovered or discarded
+     *         lookup service(s) corresponding to this event.
+     * 
+     * @throws net.jini.discovery.LookupUnmarshalException this exception
+     *         occurs when at least one of the set of lookup service
+     *         references cannot be deserialized (unmarshalled).
+     *
+     * @see net.jini.discovery.LookupUnmarshalException
+     */
+    public PortableServiceRegistrar[] getPRegistrars() throws LookupUnmarshalException {
 	synchronized (marshalledRegs) {
             if( marshalledRegs.size() > 0 ) {
                 ArrayList unmarshalledRegs = new ArrayList();
@@ -330,18 +493,24 @@ public class RemoteDiscoveryEvent extend
                 /* Add the un-marshalled elements to the end of regs */
                 insertRegistrars(regs,unmarshalledRegs);
                 if( exceptions.size() > 0 ) {
+                    ArrayList<MarshalledInstance> miRegs = 
+                            new ArrayList<MarshalledInstance>(marshalledRegs.size());
+                    Iterator<MarshalledInstance> moRegsit = marshalledRegs.iterator();
+                    while (moRegsit.hasNext()){
+                        miRegs.add(moRegsit.next());
+                    }
                     throw(new LookupUnmarshalException
                       ( clipNullsFromEnd(regs),
-                        (MarshalledObject[])(marshalledRegs.toArray
-                               (new MarshalledObject[marshalledRegs.size()])),
+                        (MarshalledInstance[])(miRegs.toArray
+                               (new MarshalledInstance[miRegs.size()])),
                         (Throwable[])(exceptions.toArray
                                (new Throwable[exceptions.size()])),
-                        "failed to unmarshal at least one ServiceRegistrar") );
+                        "failed to unmarshal at least one PortableServiceRegistrar") );
                 }//endif
             }//endif
             return clipNullsFromEnd(regs);
         }//end sync(marshalledRegs)
-    }//end getRegistrars
+    }//end getPortableRegistrars
 
     /**
      * Returns a set that maps to the service ID of each registrar referenced
@@ -385,7 +554,7 @@ public class RemoteDiscoveryEvent extend
      * set after all unmarshalling attempts have completed.
      * 
      * @param marshalledRegs   an ArrayList object consisting of marshalled
-     *                         instances of ServiceRegistrar, each 
+     *                         objects of PortableServiceRegistrar, each 
      *                         corresponding to a proxy to a lookup service.
      *
      * @param unmarshalledRegs an ArrayList object consisting of all
@@ -396,8 +565,9 @@ public class RemoteDiscoveryEvent extend
      *         result of attempts to unmarshal each element of the first
      *         argument to this method.
      */
-    private ArrayList unmarshalRegistrars(ArrayList marshalledRegs,
-                                          ArrayList unmarshalledRegs)
+    private ArrayList unmarshalRegistrars(
+            ArrayList<MarshalledInstance> marshalledRegs,
+            ArrayList<PortableServiceRegistrar> unmarshalledRegs)
     {
         ArrayList exceptions = new ArrayList();
        /* Try to un-marshal each element in marshalledRegs; verify codebase
@@ -423,13 +593,10 @@ public class RemoteDiscoveryEvent extend
         int i = 0;
         int nMarshalledRegs = marshalledRegs.size();
         for(int n=0;n<nMarshalledRegs;n++) {
-            MarshalledObject marshalledObj
-                                  = (MarshalledObject)(marshalledRegs.get(i));
-            MarshalledInstance marshalledInstance
-                                  =  new MarshalledInstance(marshalledObj);
+            MarshalledInstance marshalledInstance = marshalledRegs.get(i);
             try {
-                ServiceRegistrar reg =
-                         (ServiceRegistrar)(marshalledInstance.get(integrity));
+                PortableServiceRegistrar reg =
+                         (PortableServiceRegistrar)(marshalledInstance.get(integrity));
                 /* Success: record the un-marshalled element
                  *          delete the corresponding un-marshalled element
                  */
@@ -450,10 +617,10 @@ public class RemoteDiscoveryEvent extend
      * 
      * @param regsArray array that will receive the new references.
      * 
-     * @param regsList ArrayList containing the ServiceRegistrar references
+     * @param regsList ArrayList containing the PortableServiceRegistrar references
      *        to place in regsArray input argument.
      */
-    private static void insertRegistrars(ServiceRegistrar[] regsArray,
+    private static void insertRegistrars(PortableServiceRegistrar[] regsArray,
                                          ArrayList regsList)
     {
         if((regsArray != null) && (regsList != null)) {
@@ -463,7 +630,7 @@ public class RemoteDiscoveryEvent extend
             int beg = indexFirstNull(regsArray);
             int end = ( (beg+lenB) <= lenA ? (beg+lenB) : (lenA) );
             for(int i=beg, j=0; i<end; i++,j++) {
-                regsArray[i] = (ServiceRegistrar)(regsList.get(j));
+                regsArray[i] = (PortableServiceRegistrar)(regsList.get(j));
             }
         }
     }//end insertRegistrars
@@ -476,18 +643,18 @@ public class RemoteDiscoveryEvent extend
      * 
      * @param regsArray array from which to copy elements
      * 
-     * @return array of <code>ServiceRegistrar</code> containing each element
+     * @return array of <code>PortableServiceRegistrar</code> containing each element
      *         of the given array from its first element up to, but not 
      *         including, the <code>null</code> element; and all subsequent
      *         elements. If the first element of the given array is 
      *         <code>null</code>, then this method will return an empty array.
      */
-    private static ServiceRegistrar[] clipNullsFromEnd
-                                               (ServiceRegistrar[] regsArray)
+    private static PortableServiceRegistrar[] clipNullsFromEnd
+                                               (PortableServiceRegistrar[] regsArray)
     {
-        if( regsArray == null) return new ServiceRegistrar[0];
+        if( regsArray == null) return new PortableServiceRegistrar[0];
         int clippedLen = indexFirstNull(regsArray);
-        ServiceRegistrar[] clippedArray = new ServiceRegistrar[clippedLen];
+        PortableServiceRegistrar[] clippedArray = new PortableServiceRegistrar[clippedLen];
         for(int i=0; i<clippedLen; i++) {
             clippedArray[i] = regsArray[i];
         }//end loop
@@ -534,7 +701,8 @@ public class RemoteDiscoveryEvent extend
     private void readObject(ObjectInputStream s)  
                                throws IOException, ClassNotFoundException
     {
-        s.defaultReadObject();
+        ObjectInputStream fois = new MoToMiInputStream(s); // convert to java.rmi.MarshalledObject
+        fois.defaultReadObject();
         /* Verify source */
         if(source == null) {
             throw new InvalidObjectException("RemoteDiscoveryEvent.readObject "
@@ -543,6 +711,18 @@ public class RemoteDiscoveryEvent extend
         /* Retrieve the value of the integrity flag */
         integrity = MarshalledWrapper.integrityEnforced(s);
     }//end readObject
+    
+    /**
+     * This method is an interim temporary measure to provide a transition
+     * period for the Serialized form in Apache River versions prior to
+     * 2.2.0
+     * @param stream
+     * @throws java.io.IOException
+     */
+    private void writeObject(java.io.ObjectOutputStream stream) throws IOException{
+        ObjectOutputStream newOutStream = new MiToMoOutputStream(stream); // Convert from java.rmi.MarshalledObject
+        newOutStream.defaultWriteObject();
+    }//end writeObject  
 
 }//end class RemoteDiscoveryEvent
 

Modified: incubator/river/jtsk/trunk/src/net/jini/io/Convert.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/Convert.java?rev=935433&r1=935432&r2=935433&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/io/Convert.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/io/Convert.java Mon Apr 19 01:29:25 2010
@@ -74,17 +74,17 @@ public class Convert<T> {
 	return mo;
     }
     
-    public net.jini.io.MarshalledInstance<T> toMarshalledInstance(
+    private net.jini.io.MarshalledInstance<T> toMarshalledInstance(
             net.jini.io.MarshalledObject<T> mo){
         return new MarshalledInstance<T>(mo);
     }
     
-    public net.jini.io.MarshalledObject<T> toJiniMarshalledObject(
+    private net.jini.io.MarshalledObject<T> toJiniMarshalledObject(
             net.jini.io.MarshalledInstance<T> instance){
         return instance.asMarshalledObject();
     }
     
-    public net.jini.io.MarshalledObject<T> toJiniMarshalledObject(
+    private net.jini.io.MarshalledObject<T> toJiniMarshalledObject(
             java.rmi.MarshalledObject<T> instance){
         net.jini.io.MarshalledObject<T> privateMO = null;
 	try {
@@ -105,12 +105,6 @@ public class Convert<T> {
     }
     
     public java.rmi.MarshalledObject<T> 
-            toRmiMarshalledObject(CDCMarshalledObject<T> instance){
-        if ( instance == null ) throw new NullPointerException("null reference");
-        return toRmiMarshalledObject(instance.asMarshalledObject());
-    }
-    
-    public java.rmi.MarshalledObject<T> 
             toRmiMarshalledObject(MarshalledInstance<T> instance){    
         if ( instance == null ) throw new NullPointerException("null reference");
 	return toRmiMarshalledObject(instance.asMarshalledObject());
@@ -122,25 +116,5 @@ public class Convert<T> {
         net.jini.io.MarshalledObject obj = toJiniMarshalledObject(instance);
         if ( obj == null ) throw new NullPointerException("null reference");
 	return new MarshalledInstance<T>(obj);
-    }
-    
-    public MarshalledInstance<T> 
-            toMarshalledInstance(CDCMarshalledObject<T> instance){
-        if ( instance == null ) throw new NullPointerException("null reference");
-        return new MarshalledInstance<T>(instance.asMarshalledObject());       
-    }
-    
-    public CDCMarshalledObject<T> 
-            toCDCMarshalledObject(java.rmi.MarshalledObject<T> instance){
-        if ( instance == null ) throw new NullPointerException("null reference");
-        return toCDCMarshalledObject(instance, null);
-    }
-    
-    public CDCMarshalledObject<T> 
-            toCDCMarshalledObject(
-            java.rmi.MarshalledObject<T> instance, PackageVersion version){
-        if ( instance == null ) throw new NullPointerException("null reference");
-	return new CDCMarshalledObject<T>(toJiniMarshalledObject(instance),
-                version); 
-    }   
+    }  
 }

Added: incubator/river/jtsk/trunk/src/net/jini/io/MiToMoOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/MiToMoOutputStream.java?rev=935433&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/io/MiToMoOutputStream.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/io/MiToMoOutputStream.java Mon Apr 19 01:29:25 2010
@@ -0,0 +1,117 @@
+/*
+ * 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.io;
+
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * ToMOOutputStream enables writing a jini MarshalledObject into
+ * an RMI MarshalledObject Serialized form.
+ * 
+ * This is a nasty horrible hack to write the output stream as a 
+ * java.rmi.MarshalledObject, so the CDC PersonalProfile version 1.12
+ * can share this object.
+ * 
+ * Since this class accesses the private state of ObjectStreamClass, it is
+ * tied to it's internal implementation, however since this class also
+ * implements Serializable, its internal state has been publicly published
+ * so must remain compatible.
+ * 
+ * @author Peter Firmstone.
+ */
+public class MiToMoOutputStream extends ObjectOutputStream{
+    private static volatile ObjectStreamClass cachedTempDesc;
+    
+public MiToMoOutputStream(OutputStream out) throws IOException {
+        super(out);
+        useProtocolVersion(PROTOCOL_VERSION_2);
+    }
+    @Override
+    protected void writeClassDescriptor(ObjectStreamClass desc){
+        try {
+            System.out.println(desc.getName());
+            if (desc.getName().equals("net.jini.io.MarshalledInstance") ) {
+                if (cachedTempDesc == null) {
+                    //Duplicate desc so we don't posion our local cache.
+                    Constructor constr = ObjectStreamClass.class.getDeclaredConstructor();
+                    constr.setAccessible(true);
+                    ObjectStreamClass tempDesc = (ObjectStreamClass) constr.newInstance();
+                    Field[] fields = ObjectStreamClass.class.getDeclaredFields();
+                    int l = fields.length;
+                    for (int i = 0; i < l; i++) {
+                        fields[i].setAccessible(true);
+                        if (fields[i].getName().equals("name")) {
+                            fields[i].set(tempDesc, "java.rmi.MarshalledObject");
+                            continue;
+                        }
+                        if (fields[i].getName().equals("hasWriteObjectData")) {
+                            fields[i].setBoolean(tempDesc, false);
+                            continue;
+                        }
+                        if (fields[i].getName().equals("readObjectMethod")) {
+                            fields[i].set(tempDesc, null);
+                            continue;
+                        }
+                        if (fields[i].getName().equals("writeObjectMethod")) {
+                            fields[i].set(tempDesc, null);
+                            continue;
+                        }
+                        if (fields[i].getName().equals("suid")) {
+                            Long moSuid = new Long(8988374069173025854L); //MarshalledObject serialVersionUID
+                            fields[i].set(tempDesc, moSuid);
+                            continue;
+                        }
+                        Object fieldValue = fields[i].get(desc);
+                        try {
+                            fields[i].set(tempDesc, fieldValue);
+                            //If it was static the reference is the same anyway.
+                            // would prefer not to set static fields.
+                            // Alternative is to check and set every wanted field.
+                        } catch (IllegalAccessException ex) {
+                            // final field unmodifiable.
+                            continue;
+                        } 
+                    }// End for loop
+                    if (cachedTempDesc == null){ cachedTempDesc = tempDesc;}
+                }//End if (cachedTempDesc == null)               
+                desc = cachedTempDesc;               
+            }//End if net.jini.io.MarshalledInstance
+            super.writeClassDescriptor(desc);
+        } catch (IllegalArgumentException ex) {
+            ex.printStackTrace();
+            //Logger.getLogger(ToMOOutputStream.class.getName()).log(Level.SEVERE, null, ex);
+        } catch (IllegalAccessException ex) {
+            ex.printStackTrace();
+            //Logger.getLogger(ToMOOutputStream.class.getName()).log(Level.SEVERE, null, ex);
+        } catch (IOException ex) {
+            ex.printStackTrace();
+            //Logger.getLogger(ToMOOutputStream.class.getName()).log(Level.SEVERE, null, ex);
+        } catch (Exception ex){
+            ex.printStackTrace();
+            //Logger.getLogger(ToMOOutputStream.class.getName()).log(Level.SEVERE, null, ex);
+        }
+    }   
+}

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

Added: incubator/river/jtsk/trunk/src/net/jini/io/MoToMiInputStream.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/MoToMiInputStream.java?rev=935433&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/io/MoToMiInputStream.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/io/MoToMiInputStream.java Mon Apr 19 01:29:25 2010
@@ -0,0 +1,103 @@
+/*
+ * 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.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class MoToMiInputStream extends ObjectInputStream {
+
+    public MoToMiInputStream(InputStream in) throws IOException {
+        super(in);
+    }
+    
+    @Override
+    protected final ObjectStreamClass readClassDescriptor() 
+	throws IOException, ClassNotFoundException
+    {
+        ObjectStreamClass desc = null;
+        try {
+            Constructor constr = ObjectStreamClass.class.getDeclaredConstructor();
+            constr.setAccessible(true);
+            desc = (ObjectStreamClass) constr.newInstance();
+            Class[] parameterTypes = new Class[1];
+            parameterTypes[0] = ObjectInputStream.class;
+            Method readNonProxy = ObjectStreamClass.class.getDeclaredMethod("readNonProxy", parameterTypes);
+            readNonProxy.setAccessible(true);
+            readNonProxy.invoke(desc, this);
+            if (desc.getName().equals("java.rmi.MarshalledObject")) {
+                Field[] fields = ObjectStreamClass.class.getDeclaredFields();
+                int l = fields.length;
+                for (int i = 0; i < l; i++) {
+                    fields[i].setAccessible(true);
+                    if (fields[i].getName().equals("name")) {
+                        fields[i].set(desc, "net.jini.io.MarshalledInstance");
+                        continue;
+                    }
+                    if (fields[i].getName().equals("hasWriteObjectData")) {
+                        fields[i].setBoolean(desc, false);
+                        continue;
+                    }
+                    if (fields[i].getName().equals("readObjectMethod")) {
+                        fields[i].set(desc, null);
+                        continue;
+                    }
+                    if (fields[i].getName().equals("writeObjectMethod")) {
+                        fields[i].set(desc, null);
+                        continue;
+                    }
+                    if (fields[i].getName().equals("suid")) {
+                        Long moSuid = new Long(-5187033771082433496L); //MarshalledObject serialVersionUID
+                        fields[i].set(desc, moSuid);
+                        continue;
+                    }
+                }
+            }
+            return desc;
+        } catch (InstantiationException ex) {
+            Logger.getLogger(MoToMiInputStream.class.getName()).log(Level.SEVERE, null, ex);
+        } catch (IllegalAccessException ex) {
+            Logger.getLogger(MoToMiInputStream.class.getName()).log(Level.SEVERE, null, ex);
+        } catch (IllegalArgumentException ex) {
+            Logger.getLogger(MoToMiInputStream.class.getName()).log(Level.SEVERE, null, ex);
+        } catch (InvocationTargetException ex) {
+            Logger.getLogger(MoToMiInputStream.class.getName()).log(Level.SEVERE, null, ex);
+        } catch (NoSuchMethodException ex) {
+            Logger.getLogger(MoToMiInputStream.class.getName()).log(Level.SEVERE, null, ex);
+        } catch (SecurityException ex) {
+            Logger.getLogger(MoToMiInputStream.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        return desc;
+    }
+
+//    @Override
+//    protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+//        if (desc.getName().equals("java.rmi.MarshalledObject")) {
+//            return net.jini.io.MarshalledInstance.class;
+//        }
+//        return super.resolveClass(desc);
+//    }
+}

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



Mime
View raw message