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 2016/05/02 01:28:18 UTC

svn commit: r1741908 - in /river/jtsk/trunk: ./ src/net/jini/core/discovery/ src/net/jini/core/event/ src/net/jini/core/lookup/ src/net/jini/discovery/

Author: peter_firmstone
Date: Sun May  1 23:28:18 2016
New Revision: 1741908

URL: http://svn.apache.org/viewvc?rev=1741908&view=rev
Log:
Revert breaking changes to protected api.  The changes to RemoteEvent's were originally made to ensure safe publication of remote events, while debugging race conditions.  It was suspected that the sequence id of RemoteEvent's were being read as their default value, causing the event to be ignored.  RemoteEvent's can still be published safely, by ensuring a reference to the RemoteEvent, is final, volatile, or a value in a concurrent collection, or read while synchronized or using a lock.

Modified:
    river/jtsk/trunk/   (props changed)
    river/jtsk/trunk/src/net/jini/core/discovery/LookupLocator.java
    river/jtsk/trunk/src/net/jini/core/event/RemoteEvent.java
    river/jtsk/trunk/src/net/jini/core/lookup/ServiceEvent.java
    river/jtsk/trunk/src/net/jini/discovery/ConstrainableLookupLocator.java
    river/jtsk/trunk/src/net/jini/discovery/RemoteDiscoveryEvent.java

Propchange: river/jtsk/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sun May  1 23:28:18 2016
@@ -15,3 +15,4 @@ NOTICE.txt
 dep-libs
 netbeans
 .*
+tar_release_test

Modified: river/jtsk/trunk/src/net/jini/core/discovery/LookupLocator.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/core/discovery/LookupLocator.java?rev=1741908&r1=1741907&r2=1741908&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/core/discovery/LookupLocator.java (original)
+++ river/jtsk/trunk/src/net/jini/core/discovery/LookupLocator.java Sun May  1 23:28:18 2016
@@ -17,16 +17,13 @@
  */
 package net.jini.core.discovery;
 
-import org.apache.river.discovery.Discovery;
-import org.apache.river.discovery.DiscoveryConstraints;
-import org.apache.river.discovery.DiscoveryProtocolVersion;
-import org.apache.river.discovery.UnicastResponse;
-import org.apache.river.discovery.UnicastSocketTimeout;
-import org.apache.river.discovery.internal.MultiIPDiscovery;
 import java.io.IOException;
+import java.io.InvalidObjectException;
 import java.io.ObjectInputStream;
+import java.io.ObjectInputStream.GetField;
+import java.io.ObjectOutputStream;
+import java.io.ObjectOutputStream.PutField;
 import java.io.Serializable;
-import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.Socket;
 import java.net.URI;
@@ -37,6 +34,12 @@ import net.jini.core.constraint.Invocati
 import net.jini.core.lookup.ServiceRegistrar;
 import net.jini.discovery.ConstrainableLookupLocator;
 import org.apache.river.api.net.Uri;
+import org.apache.river.discovery.Discovery;
+import org.apache.river.discovery.DiscoveryConstraints;
+import org.apache.river.discovery.DiscoveryProtocolVersion;
+import org.apache.river.discovery.UnicastResponse;
+import org.apache.river.discovery.UnicastSocketTimeout;
+import org.apache.river.discovery.internal.MultiIPDiscovery;
 
 /**
  * LookupLocator supports unicast discovery, using either Discovery V1 or V2.
@@ -71,13 +74,13 @@ public class LookupLocator implements Se
      *
      * @serial
      */
-    protected final String host;
+    protected String host;
     /**
      * The port number on the host at which to perform discovery.
      *
      * @serial
      */
-    protected final int port;
+    protected int port;
     
     /**
      * The timeout after which we give up waiting for a response from
@@ -344,7 +347,7 @@ public class LookupLocator implements Se
                 return disco.doUnicastDiscovery(
                         s, dc.getUnfulfilledConstraints(), null, null, null);
             }
-        }.getResponse(host, port, constraints);
+        }.getResponse(getHost(), getPort(), constraints);
         return resp.getRegistrar();
     }
     
@@ -354,7 +357,7 @@ public class LookupLocator implements Se
      */
     public String toString() {
 //	if (port != discoveryPort)
-	    return "jini://" + getHost0(host) + ":" + port + "/";
+	    return "jini://" + getHost0(getHost()) + ":" + getPort() + "/";
 //	return "jini://" + getHost0(host) + "/";
     }
 
@@ -370,7 +373,7 @@ public class LookupLocator implements Se
 	}
 	if (o instanceof LookupLocator) {
 	    LookupLocator oo = (LookupLocator) o;
-	    return port == oo.port && host.equalsIgnoreCase(oo.host);
+	    return getPort() == oo.getPort() && getHost().equalsIgnoreCase(oo.getHost());
 	}
 	return false;
     }
@@ -380,7 +383,7 @@ public class LookupLocator implements Se
      * <code>port</code> field values.
      */
     public int hashCode() {
-	return host.toLowerCase().hashCode() ^ port;
+	return getHost().toLowerCase().hashCode() ^ getPort();
     }
     
     // Checks if the host is an RFC 3513 IPv6 literal and converts it into
@@ -402,6 +405,22 @@ public class LookupLocator implements Se
      * @throws ClassNotFoundException 
      */
     private void readObject(ObjectInputStream oin) throws IOException, ClassNotFoundException{
-        oin.defaultReadObject();
+        GetField fields = oin.readFields();
+	host = (String) fields.get("host", null);
+	if (host == null) throw new InvalidObjectException("host cannot be null");
+	port = fields.get("port", discoveryPort);
+    }
+    
+    /**
+     * Added to allow subclass implementations to be responsible for state, should
+     * they require immutability.
+     * @param out
+     * @throws IOException 
+     */
+    private void writeObject(ObjectOutputStream out) throws IOException {
+	PutField fields = out.putFields();
+	fields.put("host", getHost());
+	fields.put("port", getPort());
+	out.writeFields();
     }
 }

Modified: river/jtsk/trunk/src/net/jini/core/event/RemoteEvent.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/core/event/RemoteEvent.java?rev=1741908&r1=1741907&r2=1741908&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/core/event/RemoteEvent.java (original)
+++ river/jtsk/trunk/src/net/jini/core/event/RemoteEvent.java Sun May  1 23:28:18 2016
@@ -73,8 +73,6 @@ import java.rmi.MarshalledObject;
  * the transaction. This is true even if the event that triggered the
  * RemoteEvent object being sent occurs outside of the scope of the
  * transaction (but is visible within the transaction).
- *
- * Immutable since 3.0.0
  * 
  * @author Sun Microsystems, Inc.
  *
@@ -97,28 +95,28 @@ public class RemoteEvent extends java.ut
      *
      * @serial
      */
-    private final Object source;
+    protected Object source;
 
     /**
      * The event identifier.
      *
      * @serial
      */
-    private final long eventID;
+    protected long eventID;
 
     /**
      * The event sequence number.
      *
      * @serial
      */
-    private final long seqNum;
+    protected long seqNum;
 
     /**
      * The handback object.
      *
      * @serial
      */
-    private final MarshalledObject handback;
+    protected MarshalledObject handback;
 
     /**
      * Constructs a RemoteEvent object.
@@ -200,27 +198,8 @@ public class RemoteEvent extends java.ut
     }
     
     /**
-     * In River 3.0.0, RemoteEvent became immutable and all state made private,
-     * previously all fields were protected and non final.
-     * <p>
-     * This change breaks compatibility for subclasses that access these fields
-     * directly.  For other classes, all fields were accessible
-     * via public API getter methods.
-     * <p>
-     * To allow an upgrade path for subclasses that extend RemoteEvent and
-     * provide public setter methods for these fields, it is recommended to
-     * override all public methods and maintain state independently using 
-     * transient fields.  The subclass should also use RemoteEvent getter 
-     * methods to set these transient fields during de-serialization.
-     * <p>
-     * writeObject, instead of writing RemoteEvent fields, writes the 
-     * result of all getter methods to the ObjectOutputStream, during serialization,
-     * preserving serial form compatibility wither earlier versions, while 
-     * also allowing mutable subclasses to maintain full serial compatibility.
-     * <p>
-     * Mutable subclasses honoring this contract will be compatible with all 
-     * versions since Jini 1.0.
-     * 
+     * All state is retrieved using getter methods and is written to the stream.
+     * @serialData
      * @param stream
      * @throws java.io.IOException 
      */

Modified: river/jtsk/trunk/src/net/jini/core/lookup/ServiceEvent.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/core/lookup/ServiceEvent.java?rev=1741908&r1=1741907&r2=1741908&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/core/lookup/ServiceEvent.java (original)
+++ river/jtsk/trunk/src/net/jini/core/lookup/ServiceEvent.java Sun May  1 23:28:18 2016
@@ -42,13 +42,13 @@ public abstract class ServiceEvent exten
      *
      * @serial
      */
-    protected final ServiceID serviceID;
+    protected ServiceID serviceID;
     /**
      * One of ServiceRegistrar.TRANSITION_*MATCH_*MATCH.
      *
      * @serial
      */
-    protected final int transition;
+    protected int transition;
 
     /**
      * Simple constructor.

Modified: river/jtsk/trunk/src/net/jini/discovery/ConstrainableLookupLocator.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/discovery/ConstrainableLookupLocator.java?rev=1741908&r1=1741907&r2=1741908&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/discovery/ConstrainableLookupLocator.java (original)
+++ river/jtsk/trunk/src/net/jini/discovery/ConstrainableLookupLocator.java Sun May  1 23:28:18 2016
@@ -255,7 +255,7 @@ public final class ConstrainableLookupLo
     
     // documentation inherited from RemoteMethodControl.setConstraints
     public RemoteMethodControl setConstraints(MethodConstraints constraints) {
-	return new ConstrainableLookupLocator(host, port, constraints);
+	return new ConstrainableLookupLocator(getHost(), getPort(), constraints);
     }
 
     // documentation inherited from RemoteMethodControl.getConstraints

Modified: river/jtsk/trunk/src/net/jini/discovery/RemoteDiscoveryEvent.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/discovery/RemoteDiscoveryEvent.java?rev=1741908&r1=1741907&r2=1741908&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/discovery/RemoteDiscoveryEvent.java (original)
+++ river/jtsk/trunk/src/net/jini/discovery/RemoteDiscoveryEvent.java Sun May  1 23:28:18 2016
@@ -110,7 +110,7 @@ public class RemoteDiscoveryEvent extend
      *
      * @serial
      */
-    protected final boolean discarded;
+    protected boolean discarded;
 
     /**
      * List consisting of marshalled proxy objects where each proxy implements
@@ -138,7 +138,7 @@ public class RemoteDiscoveryEvent extend
      *
      * @serial
      */
-    private final List<MarshalledObject> marshalledRegs;
+    protected List<MarshalledObject> marshalledRegs;
 
     /**
      * Array containing a subset of the set of proxies to the lookup
@@ -153,7 +153,7 @@ public class RemoteDiscoveryEvent extend
      *
      * @serial
      */
-    private final ServiceRegistrar[] regs;
+    protected ServiceRegistrar[] regs;
 
     /**
      * <code>Map</code> from the service IDs of the registrars of this event
@@ -161,7 +161,7 @@ public class RemoteDiscoveryEvent extend
      *
      * @serial
      */
-    private final Map<ServiceID,String> groups;
+    protected Map<ServiceID,String> groups;
 
     /**
      * Flag related to the verification of codebase integrity. A value of