You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sm...@apache.org on 2006/05/19 08:00:56 UTC

svn commit: r407724 [5/11] - in /incubator/harmony/enhanced/classlib/trunk: make/ modules/rmi/make/ modules/rmi/src/main/java/java/rmi/ modules/rmi/src/main/java/java/rmi/registry/ modules/rmi/src/main/java/java/rmi/server/ modules/rmi/src/main/java/or...

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/ReferenceTypes.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/ReferenceTypes.java?rev=407724&r1=407183&r2=407724&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/ReferenceTypes.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/ReferenceTypes.java Thu May 18 23:00:52 2006
@@ -1,56 +1,56 @@
-/* 
-*  Copyright 2005 The Apache Software Foundation or its licensors, as applicable. 
-* 
-*  Licensed 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 ar.org.fitc.rmi.server;
-
-/*
- * NOTE: 
- * This class has been modified in order to support 
- * Java VM 1.4.2 using the javac's target jsr14 
- */
-
-/**
- * This enum holds the string representation for all the remote reference types
- * 
- * UnicastRef UnicastRef2 UnicastServerRef UnicastServerRef2
- * 
- * @author Gustavo Petri
- * 
- */
-public class ReferenceTypes {
-
-    public static final ReferenceTypes UNICAST_REF = 
-        new ReferenceTypes("UnicastRef"); 
-    
-    public static final ReferenceTypes UNICAST_REF2 = 
-        new ReferenceTypes("UnicastRef2");
-    
-    public static final ReferenceTypes UNICAST_SERVER_REF = 
-        new ReferenceTypes("UnicastServerRef"); 
-    
-    public static final ReferenceTypes UNICAST_SERVER_REF2 = 
-        new ReferenceTypes("UnicastServerRef2");
-
-    private String type;
-
-    private ReferenceTypes(String type) {
-        this.type = type;
-    }
-
-    @Override
-    public final String toString() {
-        return type;
-    }
-}
+/* 
+*  Copyright 2005 The Apache Software Foundation or its licensors, as applicable. 
+* 
+*  Licensed 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 org.apache.harmony.rmi.internal.server;
+
+/*
+ * NOTE: 
+ * This class has been modified in order to support 
+ * Java VM 1.4.2 using the javac's target jsr14 
+ */
+
+/**
+ * This enum holds the string representation for all the remote reference types
+ * 
+ * UnicastRef UnicastRef2 UnicastServerRef UnicastServerRef2
+ * 
+ * @author Gustavo Petri
+ * 
+ */
+public class ReferenceTypes {
+
+    public static final ReferenceTypes UNICAST_REF = 
+        new ReferenceTypes("UnicastRef"); 
+    
+    public static final ReferenceTypes UNICAST_REF2 = 
+        new ReferenceTypes("UnicastRef2");
+    
+    public static final ReferenceTypes UNICAST_SERVER_REF = 
+        new ReferenceTypes("UnicastServerRef"); 
+    
+    public static final ReferenceTypes UNICAST_SERVER_REF2 = 
+        new ReferenceTypes("UnicastServerRef2");
+
+    private String type;
+
+    private ReferenceTypes(String type) {
+        this.type = type;
+    }
+
+    @Override
+    public final String toString() {
+        return type;
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastRemoteRef2Impl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastRemoteRef2Impl.java?rev=407724&r1=407183&r2=407724&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastRemoteRef2Impl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastRemoteRef2Impl.java Thu May 18 23:00:52 2006
@@ -1,129 +1,129 @@
-/* 
-*  Copyright 2005 The Apache Software Foundation or its licensors, as applicable. 
-* 
-*  Licensed 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 ar.org.fitc.rmi.server;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.rmi.server.ObjID;
-import java.rmi.server.RMIClientSocketFactory;
-
-import ar.org.fitc.rmi.dgc.client.DGCClient;
-import ar.org.fitc.rmi.transport.Endpoint;
-
-/**
- * This class is the implementation of the <code>RemoteRef</code> interface
- * for the <code>UnicastRemoteObject</code>, for those remote objects
- * exported with custom socket factories.
- * 
- * @author Gonzalo Ortega
- * 
- */
-public class UnicastRemoteRef2Impl extends UnicastRemoteRefImpl {
-
-    /**
-     * 
-     */
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * Creates a new <code>UnicastRemoteRef2Impl</code>
-     */
-    public UnicastRemoteRef2Impl() {
-    }
-
-    /**
-     * Creates a new <code>UnicastRemoteRefImpl</code> with this
-     * <code>ObjID</code> and <code>Endpoint</code>
-     * 
-     * @param objId
-     *            The object identifier for this remote reference
-     * @param ep
-     *            The endpoint that will be used to contact the remote object
-     */
-    public UnicastRemoteRef2Impl(ObjID objId, Endpoint ep) {
-        super(objId, ep);
-    }
-
-    /**
-     * Returns the string representing the reference type, to be serialized in
-     * the stream <code>out</code>.
-     * 
-     * @param out
-     *            the output stream to which the reference will be serialized
-     * @return the string representing this type of reference
-     */
-    @Override
-	public final String getRefClass(ObjectOutput out) {
-        return ReferenceTypes.UNICAST_REF2.toString();
-    }
-
-    /**
-     * Reads a reference from an <code>inputStream</code> during reference
-     * deserialization.
-     * 
-     * @param in
-     *            the stream to read data from to restore the reference
-     * @throws IOException
-     *             if an I/O Error occur during deserialization
-     * @throws ClassNotFoundException
-     *             If the class for this restored object is not found
-     */
-    @Override
-    public final void readExternal(ObjectInput in) throws IOException,
-            ClassNotFoundException {
-        RMIClientSocketFactory csf = null;
-        int readCsf = in.readByte();
-        String host = in.readUTF();
-        int port = in.readInt();
-        if (readCsf == 0x01) {
-            csf = (RMIClientSocketFactory) in.readObject();
-        }
-        Endpoint ep = new Endpoint(host, port, csf);
-        this.ep = ep;
-        this.objId = ObjID.read(in);
-        // This value is read without any purpose, only because is specified.
-        in.readBoolean();
-        DGCClient dgcClient = DGCClient.getDGCClient();
-        dgcClient.registerRemoteRef(this, ep, objId);
-    }
-
-    /**
-     * Sends the components of the reference during serialization.
-     * 
-     * @param out
-     *            the stream to write the reference to
-     * @throws IOException
-     *             if an I/O Error occur during serialization
-     */
-    @Override
-    public final void writeExternal(ObjectOutput out) throws IOException {
-        RMIClientSocketFactory csf = ep.getCsf();
-        if (csf == null) {
-            out.writeByte(0x00);
-        } else {
-            out.writeByte(0x01);
-        }
-        out.writeUTF(ep.getHost());
-        out.writeInt(ep.getPort());
-        if (csf != null) {
-            out.writeObject(csf);
-        }
-        objId.write(out);
-        // This value is written without any purpose, only because is specified.
-        out.writeBoolean(false);
-    }
-}
+/* 
+*  Copyright 2005 The Apache Software Foundation or its licensors, as applicable. 
+* 
+*  Licensed 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 org.apache.harmony.rmi.internal.server;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.rmi.server.ObjID;
+import java.rmi.server.RMIClientSocketFactory;
+
+import org.apache.harmony.rmi.internal.dgc.client.DGCClient;
+import org.apache.harmony.rmi.internal.transport.Endpoint;
+
+/**
+ * This class is the implementation of the <code>RemoteRef</code> interface
+ * for the <code>UnicastRemoteObject</code>, for those remote objects
+ * exported with custom socket factories.
+ * 
+ * @author Gonzalo Ortega
+ * 
+ */
+public class UnicastRemoteRef2Impl extends UnicastRemoteRefImpl {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Creates a new <code>UnicastRemoteRef2Impl</code>
+     */
+    public UnicastRemoteRef2Impl() {
+    }
+
+    /**
+     * Creates a new <code>UnicastRemoteRefImpl</code> with this
+     * <code>ObjID</code> and <code>Endpoint</code>
+     * 
+     * @param objId
+     *            The object identifier for this remote reference
+     * @param ep
+     *            The endpoint that will be used to contact the remote object
+     */
+    public UnicastRemoteRef2Impl(ObjID objId, Endpoint ep) {
+        super(objId, ep);
+    }
+
+    /**
+     * Returns the string representing the reference type, to be serialized in
+     * the stream <code>out</code>.
+     * 
+     * @param out
+     *            the output stream to which the reference will be serialized
+     * @return the string representing this type of reference
+     */
+    @Override
+	public final String getRefClass(ObjectOutput out) {
+        return ReferenceTypes.UNICAST_REF2.toString();
+    }
+
+    /**
+     * Reads a reference from an <code>inputStream</code> during reference
+     * deserialization.
+     * 
+     * @param in
+     *            the stream to read data from to restore the reference
+     * @throws IOException
+     *             if an I/O Error occur during deserialization
+     * @throws ClassNotFoundException
+     *             If the class for this restored object is not found
+     */
+    @Override
+    public final void readExternal(ObjectInput in) throws IOException,
+            ClassNotFoundException {
+        RMIClientSocketFactory csf = null;
+        int readCsf = in.readByte();
+        String host = in.readUTF();
+        int port = in.readInt();
+        if (readCsf == 0x01) {
+            csf = (RMIClientSocketFactory) in.readObject();
+        }
+        Endpoint ep = new Endpoint(host, port, csf);
+        this.ep = ep;
+        this.objId = ObjID.read(in);
+        // This value is read without any purpose, only because is specified.
+        in.readBoolean();
+        DGCClient dgcClient = DGCClient.getDGCClient();
+        dgcClient.registerRemoteRef(this, ep, objId);
+    }
+
+    /**
+     * Sends the components of the reference during serialization.
+     * 
+     * @param out
+     *            the stream to write the reference to
+     * @throws IOException
+     *             if an I/O Error occur during serialization
+     */
+    @Override
+    public final void writeExternal(ObjectOutput out) throws IOException {
+        RMIClientSocketFactory csf = ep.getCsf();
+        if (csf == null) {
+            out.writeByte(0x00);
+        } else {
+            out.writeByte(0x01);
+        }
+        out.writeUTF(ep.getHost());
+        out.writeInt(ep.getPort());
+        if (csf != null) {
+            out.writeObject(csf);
+        }
+        objId.write(out);
+        // This value is written without any purpose, only because is specified.
+        out.writeBoolean(false);
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastRemoteRefImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastRemoteRefImpl.java?rev=407724&r1=407183&r2=407724&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastRemoteRefImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastRemoteRefImpl.java Thu May 18 23:00:52 2006
@@ -1,269 +1,269 @@
-/* 
-*  Copyright 2005 The Apache Software Foundation or its licensors, as applicable. 
-* 
-*  Licensed 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 ar.org.fitc.rmi.server;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.lang.reflect.Method;
-import java.rmi.Remote;
-import java.rmi.RemoteException;
-import java.rmi.server.ObjID;
-import java.rmi.server.Operation;
-import java.rmi.server.RemoteCall;
-import java.rmi.server.RemoteObject;
-import java.rmi.server.RemoteRef;
-
-import ar.org.fitc.rmi.dgc.client.DGCClient;
-import ar.org.fitc.rmi.transport.Endpoint;
-import ar.org.fitc.rmi.transport.TransportManager;
-
-/**
- * This class is the implementation of the <code>RemoteRef</code> interface
- * for the <code>UnicastRemoteObject</code>, for those remote objects
- * exported without custom socket factories.
- * 
- * @author Gonzalo Ortega
- * 
- */
-public class UnicastRemoteRefImpl implements RemoteRef {
-
-    /**
-     * 
-     */
-    private static final long serialVersionUID = 1L;
-
-    protected ObjID objId;
-
-    protected Endpoint ep;
-
-    private transient boolean localReference;
-
-    /**
-     * Creates a new <code>UnicastRemoteRefImpl</code>
-     */
-    public UnicastRemoteRefImpl() {
-    	super();
-    }
-
-    /**
-     * Creates a new <code>UnicastRemoteRefImpl</code> with this
-     * <code>ObjID</code> and <code>Endpoint</code>
-     * 
-     * @param objId
-     *            The object identifier for this remote reference
-     * @param ep
-     *            The endpoint that will be used to contact the remote object
-     */
-    public UnicastRemoteRefImpl(ObjID objId, Endpoint ep) {
-        this.objId = objId;
-        this.ep = ep;
-        this.localReference = true;
-    }
-
-    @SuppressWarnings("unused")
-    @Deprecated
-    public void done(@SuppressWarnings("unused") RemoteCall call) throws RemoteException {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Returns the string representing the reference type, to be serialized in
-     * the stream <code>out</code>.
-     * 
-     * @param out
-     *            the output stream to which the reference will be serialized
-     * @return the string representing this type of reference
-     */
-    public String getRefClass(@SuppressWarnings("unused") ObjectOutput out) {
-        return ReferenceTypes.UNICAST_REF.toString();
-    }
-
-    /**
-     * Invokes a method in the remote object. This method delegates the
-     * invocation in the RMI Runtime.
-     * 
-     * @param obj
-     *            The object where the method was executed (Probably a stub)
-     * @param method
-     *            The method executed in <code>obj</code>
-     * @param args
-     *            An array containing all the arguments used in the invocation
-     *            of <code>method</code>
-     * @param opnum
-     *            The hash that represents the method
-     * @return The result of the invocation of the method in the remote object
-     * @throws Exception
-     *             if the invocation fails
-     */
-    public Object invoke(@SuppressWarnings("unused") Remote obj, Method method, Object[] args, long opnum)
-            throws Exception {
-
-    	if (args == null) {
-    		if (method.getParameterTypes().length != 0) {
-    			throw new IllegalArgumentException("Wrong requiered arguments.");
-    		}
-    	} else {
-    		if (args.length != method.getParameterTypes().length) {
-    			throw new IllegalArgumentException("Wrong requiered arguments.");
-    		}
-    	}
-    	
-        boolean waitReturn = !(method.getReturnType().equals(Void.TYPE));
-        TransportManager tm = TransportManager.getTransportManager();
-        try {
-            Object response = tm.invoke(objId, ep, args, opnum, waitReturn);
-            if (!localReference) {
-                DGCClient dgcClient = DGCClient.getDGCClient();
-                dgcClient.checkLiveness(this);
-            }
-            return response;
-        } catch (Exception e) {
-            throw e;
-        }
-    }
-
-    @SuppressWarnings("unused") 
-    @Deprecated
-    public void invoke(RemoteCall call) throws Exception {
-        throw new UnsupportedOperationException();
-    }
-
-    @SuppressWarnings("unused")
-    @Deprecated
-    public RemoteCall newCall(RemoteObject obj, Operation[] op, int opnum,
-            long hash) throws RemoteException {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Implements the <code>equals</code> method in a suitable way for remote
-     * references. Two remote references that refer to the same remote object
-     * should return <code>true</code> during equality tests.
-     * 
-     * @param obj
-     *            The remote reference that will be tested
-     * @return <code>true</code> if the <code>obj</code> reference refers to
-     *         the same remote object than this reference.
-     */
-    public boolean remoteEquals(RemoteRef obj) {
-        if (obj == null)
-            return false;
-        if (obj == this)
-            return true;
-        if (obj instanceof UnicastRemoteRefImpl) {
-            if (objId.equals(((UnicastRemoteRefImpl) obj).objId)
-                    && ep.equals(((UnicastRemoteRefImpl) obj).ep)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Returns the hash code for this reference. Two references that refer to
-     * the same remote object will have the same hash code.
-     * 
-     * @return the hash code for this reference
-     */
-    public int remoteHashCode() {
-        return objId.hashCode() ^ ep.hashCode();
-    }
-
-    /**
-     * Returns a String that represents this reference.
-     * 
-     * @return string representing this reference.
-     */
-    public String remoteToString() {
-        return "[" + getRefClass(null) + ": [" + objId.toString() + ", "
-                + ep.toString() + "]]";
-    }
-
-    /**
-     * Implements the <code>equals</code> method in a suitable way for remote
-     * references. Two remote references that refer to the same remote object
-     * should return <code>true</code> during equality tests.
-     * 
-     * @param obj
-     *            The remote reference that will be tested
-     * @return <code>true</code> if the <code>obj</code> reference refers to
-     *         the same remote object than this reference.
-     */
-    @Override
-    public boolean equals(Object obj) {
-        if (obj == null)
-            return false;
-        if (obj == this)
-            return true;
-        if (obj instanceof RemoteRef) {
-            return remoteEquals((RemoteRef) obj);
-        }
-        return false;
-    }
-
-    /**
-     * Returns the hash code for this reference. Two references that refer to
-     * the same remote object will have the same hash code.
-     * 
-     * @return the hash code for this reference
-     */
-    @Override
-    public int hashCode() {
-        return remoteHashCode();
-    }
-
-    /**
-     * Reads a reference from an <code>inputStream</code> during reference
-     * deserialization.
-     * 
-     * @param in
-     *            the stream to read data from to restore the reference
-     * @throws IOException
-     *             if an I/O Error occur during deserialization
-     * @throws ClassNotFoundException
-     *             If the class for this restored object is not found
-     */
-    @SuppressWarnings("unused")
-    public void readExternal(ObjectInput in) throws IOException, 
-            ClassNotFoundException {
-        String host = in.readUTF();
-        int port = in.readInt();
-        Endpoint ep = new Endpoint(host, port, null);
-        this.ep = ep;
-        this.objId = ObjID.read(in);
-        // This value is read without any purpose, only because is specified.
-        in.readBoolean();
-        DGCClient dgcClient = DGCClient.getDGCClient();
-        dgcClient.registerRemoteRef(this, ep, objId);
-    }
-
-    /**
-     * Sends the components of the reference during serialization.
-     * 
-     * @param out
-     *            the stream to write the reference to
-     * @throws IOException
-     *             if an I/O Error occur during serialization
-     */
-    public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeUTF(ep.getHost());
-        out.writeInt(ep.getPort());
-        objId.write(out);
-        // This value is written without any purpose, only because is specified.
-        out.writeBoolean(false);
-    }
-}
+/* 
+*  Copyright 2005 The Apache Software Foundation or its licensors, as applicable. 
+* 
+*  Licensed 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 org.apache.harmony.rmi.internal.server;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.lang.reflect.Method;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.server.ObjID;
+import java.rmi.server.Operation;
+import java.rmi.server.RemoteCall;
+import java.rmi.server.RemoteObject;
+import java.rmi.server.RemoteRef;
+
+import org.apache.harmony.rmi.internal.dgc.client.DGCClient;
+import org.apache.harmony.rmi.internal.transport.Endpoint;
+import org.apache.harmony.rmi.internal.transport.TransportManager;
+
+/**
+ * This class is the implementation of the <code>RemoteRef</code> interface
+ * for the <code>UnicastRemoteObject</code>, for those remote objects
+ * exported without custom socket factories.
+ * 
+ * @author Gonzalo Ortega
+ * 
+ */
+public class UnicastRemoteRefImpl implements RemoteRef {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 1L;
+
+    protected ObjID objId;
+
+    protected Endpoint ep;
+
+    private transient boolean localReference;
+
+    /**
+     * Creates a new <code>UnicastRemoteRefImpl</code>
+     */
+    public UnicastRemoteRefImpl() {
+    	super();
+    }
+
+    /**
+     * Creates a new <code>UnicastRemoteRefImpl</code> with this
+     * <code>ObjID</code> and <code>Endpoint</code>
+     * 
+     * @param objId
+     *            The object identifier for this remote reference
+     * @param ep
+     *            The endpoint that will be used to contact the remote object
+     */
+    public UnicastRemoteRefImpl(ObjID objId, Endpoint ep) {
+        this.objId = objId;
+        this.ep = ep;
+        this.localReference = true;
+    }
+
+    @SuppressWarnings("unused")
+    @Deprecated
+    public void done(@SuppressWarnings("unused") RemoteCall call) throws RemoteException {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Returns the string representing the reference type, to be serialized in
+     * the stream <code>out</code>.
+     * 
+     * @param out
+     *            the output stream to which the reference will be serialized
+     * @return the string representing this type of reference
+     */
+    public String getRefClass(@SuppressWarnings("unused") ObjectOutput out) {
+        return ReferenceTypes.UNICAST_REF.toString();
+    }
+
+    /**
+     * Invokes a method in the remote object. This method delegates the
+     * invocation in the RMI Runtime.
+     * 
+     * @param obj
+     *            The object where the method was executed (Probably a stub)
+     * @param method
+     *            The method executed in <code>obj</code>
+     * @param args
+     *            An array containing all the arguments used in the invocation
+     *            of <code>method</code>
+     * @param opnum
+     *            The hash that represents the method
+     * @return The result of the invocation of the method in the remote object
+     * @throws Exception
+     *             if the invocation fails
+     */
+    public Object invoke(@SuppressWarnings("unused") Remote obj, Method method, Object[] args, long opnum)
+            throws Exception {
+
+    	if (args == null) {
+    		if (method.getParameterTypes().length != 0) {
+    			throw new IllegalArgumentException("Wrong requiered arguments.");
+    		}
+    	} else {
+    		if (args.length != method.getParameterTypes().length) {
+    			throw new IllegalArgumentException("Wrong requiered arguments.");
+    		}
+    	}
+    	
+        boolean waitReturn = !(method.getReturnType().equals(Void.TYPE));
+        TransportManager tm = TransportManager.getTransportManager();
+        try {
+            Object response = tm.invoke(objId, ep, args, opnum, waitReturn);
+            if (!localReference) {
+                DGCClient dgcClient = DGCClient.getDGCClient();
+                dgcClient.checkLiveness(this);
+            }
+            return response;
+        } catch (Exception e) {
+            throw e;
+        }
+    }
+
+    @SuppressWarnings("unused") 
+    @Deprecated
+    public void invoke(RemoteCall call) throws Exception {
+        throw new UnsupportedOperationException();
+    }
+
+    @SuppressWarnings("unused")
+    @Deprecated
+    public RemoteCall newCall(RemoteObject obj, Operation[] op, int opnum,
+            long hash) throws RemoteException {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Implements the <code>equals</code> method in a suitable way for remote
+     * references. Two remote references that refer to the same remote object
+     * should return <code>true</code> during equality tests.
+     * 
+     * @param obj
+     *            The remote reference that will be tested
+     * @return <code>true</code> if the <code>obj</code> reference refers to
+     *         the same remote object than this reference.
+     */
+    public boolean remoteEquals(RemoteRef obj) {
+        if (obj == null)
+            return false;
+        if (obj == this)
+            return true;
+        if (obj instanceof UnicastRemoteRefImpl) {
+            if (objId.equals(((UnicastRemoteRefImpl) obj).objId)
+                    && ep.equals(((UnicastRemoteRefImpl) obj).ep)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Returns the hash code for this reference. Two references that refer to
+     * the same remote object will have the same hash code.
+     * 
+     * @return the hash code for this reference
+     */
+    public int remoteHashCode() {
+        return objId.hashCode() ^ ep.hashCode();
+    }
+
+    /**
+     * Returns a String that represents this reference.
+     * 
+     * @return string representing this reference.
+     */
+    public String remoteToString() {
+        return "[" + getRefClass(null) + ": [" + objId.toString() + ", "
+                + ep.toString() + "]]";
+    }
+
+    /**
+     * Implements the <code>equals</code> method in a suitable way for remote
+     * references. Two remote references that refer to the same remote object
+     * should return <code>true</code> during equality tests.
+     * 
+     * @param obj
+     *            The remote reference that will be tested
+     * @return <code>true</code> if the <code>obj</code> reference refers to
+     *         the same remote object than this reference.
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null)
+            return false;
+        if (obj == this)
+            return true;
+        if (obj instanceof RemoteRef) {
+            return remoteEquals((RemoteRef) obj);
+        }
+        return false;
+    }
+
+    /**
+     * Returns the hash code for this reference. Two references that refer to
+     * the same remote object will have the same hash code.
+     * 
+     * @return the hash code for this reference
+     */
+    @Override
+    public int hashCode() {
+        return remoteHashCode();
+    }
+
+    /**
+     * Reads a reference from an <code>inputStream</code> during reference
+     * deserialization.
+     * 
+     * @param in
+     *            the stream to read data from to restore the reference
+     * @throws IOException
+     *             if an I/O Error occur during deserialization
+     * @throws ClassNotFoundException
+     *             If the class for this restored object is not found
+     */
+    @SuppressWarnings("unused")
+    public void readExternal(ObjectInput in) throws IOException, 
+            ClassNotFoundException {
+        String host = in.readUTF();
+        int port = in.readInt();
+        Endpoint ep = new Endpoint(host, port, null);
+        this.ep = ep;
+        this.objId = ObjID.read(in);
+        // This value is read without any purpose, only because is specified.
+        in.readBoolean();
+        DGCClient dgcClient = DGCClient.getDGCClient();
+        dgcClient.registerRemoteRef(this, ep, objId);
+    }
+
+    /**
+     * Sends the components of the reference during serialization.
+     * 
+     * @param out
+     *            the stream to write the reference to
+     * @throws IOException
+     *             if an I/O Error occur during serialization
+     */
+    public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeUTF(ep.getHost());
+        out.writeInt(ep.getPort());
+        objId.write(out);
+        // This value is written without any purpose, only because is specified.
+        out.writeBoolean(false);
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastServerRef2Impl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastServerRef2Impl.java?rev=407724&r1=407183&r2=407724&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastServerRef2Impl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastServerRef2Impl.java Thu May 18 23:00:52 2006
@@ -1,110 +1,110 @@
-/* 
-*  Copyright 2005 The Apache Software Foundation or its licensors, as applicable. 
-* 
-*  Licensed 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 ar.org.fitc.rmi.server;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.rmi.Remote;
-import java.rmi.server.ObjID;
-
-import ar.org.fitc.rmi.transport.Endpoint;
-
-/**
- * This class is the implementation of the <code>ServerRef</code> interface
- * for the <code>UnicastRemoteObject</code>, for those remote objects
- * exported with custom socket factories.
- * 
- * @author Gonzalo Ortega
- * 
- */
-public final class UnicastServerRef2Impl extends UnicastServerRefImpl {
-
-    /**
-     * 
-     */
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * Creates a new <code>UnicastServerRef2Impl</code> starting from the
-     * object being exported and the <code>ObjID</code> and
-     * <code>Endpoint</code> generated during exportation.
-     * 
-     * @param objectToExport
-     *            The object being exported
-     * @param objID
-     *            The <code>ObjID</code> created during exportation of the
-     *            remote object
-     * @param ep
-     *            The <code>Endpoint</code> generated during exportation of
-     *            the remote object
-     */
-    public UnicastServerRef2Impl(Remote objectToExport, ObjID objID, Endpoint ep) {
-        super(objectToExport, objID, ep);
-    }
-
-    /**
-     * Creates a new empty <code>UnicastServerRef2Impl</code>
-     * 
-     */
-    public UnicastServerRef2Impl() {
-        super();
-    }
-
-    /**
-     * Returns the string representing the reference type, to be serialized in
-     * the stream <code>out</code>.
-     * 
-     * @param out
-     *            the output stream to which the reference will be serialized
-     * @return the string representing this type of reference
-     */
-    public final String getRefClass(ObjectOutput out) {
-        return ReferenceTypes.UNICAST_SERVER_REF2.toString();
-    }
-
-    /**
-     * Reads a reference from an <code>inputStream</code> during reference
-     * deserialization. Since the server references aren't sent to the clients,
-     * this method does nothing. (Simply returns)
-     * 
-     * @param in
-     *            the stream to read data from to restore the reference
-     * @throws IOException
-     *             if an I/O Error occur during deserialization
-     * @throws ClassNotFoundException
-     *             If the class for this restored object is not found
-     */
-    @Override
-    public final void readExternal(ObjectInput in) throws IOException,
-            ClassNotFoundException {
-    }
-
-    /**
-     * Sends the components of the reference during serialization. Since the
-     * server references aren't sent to the clients, this method does nothing.
-     * (Simply returns)
-     * 
-     * @param out
-     *            the stream to write the reference to
-     * @throws IOException
-     *             if an I/O Error occur during serialization
-     */
-    @Override
-    public final void writeExternal(ObjectOutput out) throws IOException {
-    }
-
-}
+/* 
+*  Copyright 2005 The Apache Software Foundation or its licensors, as applicable. 
+* 
+*  Licensed 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 org.apache.harmony.rmi.internal.server;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.rmi.Remote;
+import java.rmi.server.ObjID;
+
+import org.apache.harmony.rmi.internal.transport.Endpoint;
+
+/**
+ * This class is the implementation of the <code>ServerRef</code> interface
+ * for the <code>UnicastRemoteObject</code>, for those remote objects
+ * exported with custom socket factories.
+ * 
+ * @author Gonzalo Ortega
+ * 
+ */
+public final class UnicastServerRef2Impl extends UnicastServerRefImpl {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Creates a new <code>UnicastServerRef2Impl</code> starting from the
+     * object being exported and the <code>ObjID</code> and
+     * <code>Endpoint</code> generated during exportation.
+     * 
+     * @param objectToExport
+     *            The object being exported
+     * @param objID
+     *            The <code>ObjID</code> created during exportation of the
+     *            remote object
+     * @param ep
+     *            The <code>Endpoint</code> generated during exportation of
+     *            the remote object
+     */
+    public UnicastServerRef2Impl(Remote objectToExport, ObjID objID, Endpoint ep) {
+        super(objectToExport, objID, ep);
+    }
+
+    /**
+     * Creates a new empty <code>UnicastServerRef2Impl</code>
+     * 
+     */
+    public UnicastServerRef2Impl() {
+        super();
+    }
+
+    /**
+     * Returns the string representing the reference type, to be serialized in
+     * the stream <code>out</code>.
+     * 
+     * @param out
+     *            the output stream to which the reference will be serialized
+     * @return the string representing this type of reference
+     */
+    public final String getRefClass(ObjectOutput out) {
+        return ReferenceTypes.UNICAST_SERVER_REF2.toString();
+    }
+
+    /**
+     * Reads a reference from an <code>inputStream</code> during reference
+     * deserialization. Since the server references aren't sent to the clients,
+     * this method does nothing. (Simply returns)
+     * 
+     * @param in
+     *            the stream to read data from to restore the reference
+     * @throws IOException
+     *             if an I/O Error occur during deserialization
+     * @throws ClassNotFoundException
+     *             If the class for this restored object is not found
+     */
+    @Override
+    public final void readExternal(ObjectInput in) throws IOException,
+            ClassNotFoundException {
+    }
+
+    /**
+     * Sends the components of the reference during serialization. Since the
+     * server references aren't sent to the clients, this method does nothing.
+     * (Simply returns)
+     * 
+     * @param out
+     *            the stream to write the reference to
+     * @throws IOException
+     *             if an I/O Error occur during serialization
+     */
+    @Override
+    public final void writeExternal(ObjectOutput out) throws IOException {
+    }
+
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastServerRefImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastServerRefImpl.java?rev=407724&r1=407183&r2=407724&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastServerRefImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/server/UnicastServerRefImpl.java Thu May 18 23:00:52 2006
@@ -1,335 +1,335 @@
-/* 
-*  Copyright 2005 The Apache Software Foundation or its licensors, as applicable. 
-* 
-*  Licensed 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 ar.org.fitc.rmi.server;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.lang.ref.WeakReference;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.rmi.NoSuchObjectException;
-import java.rmi.Remote;
-import java.rmi.RemoteException;
-import java.rmi.ServerError;
-import java.rmi.ServerException;
-import java.rmi.UnmarshalException;
-import java.rmi.server.ObjID;
-import java.rmi.server.RemoteServer;
-import java.rmi.server.RemoteStub;
-import java.rmi.server.ServerNotActiveException;
-import java.rmi.server.ServerRef;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import ar.org.fitc.rmi.transport.Endpoint;
-import ar.org.fitc.rmi.transport.TransportManager;
-import ar.org.fitc.rmi.utils.MethodHashGenerator;
-import ar.org.fitc.rmi.utils.RemoteUtils;
-
-/*
- * NOTE: 
- * This class has been modified in order to support 
- * Java VM 1.4.2 using the javac's target jsr14 
- */
-
-/**
- * This class is the implementation of the <code>ServerRef</code> interface
- * for the <code>UnicastRemoteObject</code>, for those remote objects
- * exported without custom socket factories.
- * 
- * @author Gonzalo Ortega
- * 
- */
-public class UnicastServerRefImpl extends UnicastRemoteRefImpl implements
-        ServerRef {
-
-    /**
-     * 
-     */
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * A table for storing the relations between the methods of the remote
-     * object and its hashes.
-     */
-    private Map<Long, Method> methodHashMap;
-
-    /**
-     * The reference to the real object, used for dispatching received calls
-     */
-    private WeakReference<Remote> object; // Weak reference to the "real"
-                                            // server object
-
-    /**
-     * Creates a new <code>UnicastServerRefImpl</code> starting from the
-     * object being exported and the <code>ObjID</code> and
-     * <code>Endpoint</code> generated during exportation.
-     * 
-     * @param objectToExport
-     *            The object being exported
-     * @param objID
-     *            The <code>ObjID</code> created during exportation of the
-     *            remote object
-     * @param ep
-     *            The <code>Endpoint</code> generated during exportation of
-     *            the remote object
-     */
-    public UnicastServerRefImpl(Remote objectToExport, ObjID objID, Endpoint ep) {
-        super(objID, ep);
-        this.object = new WeakReference<Remote>(objectToExport);
-        this.methodHashMap = new HashMap<Long, Method>();
-        buildMethodHashMap(objectToExport);
-    }
-
-    /**
-     * Creates a new empty <code>UnicastServerRefImpl</code>
-     * 
-     */
-    public UnicastServerRefImpl() {
-    }
-
-    /**
-     * Returns the string representing the reference type, to be serialized in
-     * the stream <code>out</code>.
-     * 
-     * @param out
-     *            the output stream to which the reference will be serialized
-     * @return the string representing this type of reference
-     */
-    @Override
-    public String getRefClass(ObjectOutput out) {
-        return ReferenceTypes.UNICAST_SERVER_REF.toString();
-    }
-
-    /**
-     * This method isn't necessary in our design. Is not used at the moment.
-     * 
-     * @param obj
-     *            the object being exported
-     * @param data
-     *            data needed for exportation
-     * @return null
-     * @throws RemoteException
-     *             if exportation fails
-     */
-    public RemoteStub exportObject(Remote obj, Object data)
-            throws RemoteException {
-        // REVIEW: This method isn't necessary in our design. Review...
-        return null;
-    }
-
-    /**
-     * This method isn't necessary in our design. Is not used at the moment.
-     * 
-     * @return null
-     * @throws ServerNotActiveException
-     *             if called outside of servicing a remote method invocation
-     */
-    public String getClientHost() throws ServerNotActiveException {
-        // REVIEW: This method isn't necessary in our design. Review...
-        return null;
-    }
-
-    /**
-     * Dispatches the call received by the Transport Layer to the exported
-     * object
-     * 
-     * @param args
-     *            the arguments for the invocation of the method
-     * @param methodHash
-     *            a hash that represents the method being invoked
-     * @return the result of the invocation in the remote object
-     * @throws Exception
-     *             if any problem arises during execution of the method
-     */
-    public Object executeCall(Object[] args, long methodHash) throws Exception {
-        Object ret = null;
-        Object server = this.object.get();
-        if (server == null) {
-            throw new NoSuchObjectException(
-                    "Invalid Remote server object. (object not found)");
-        }
-
-        Method method = methodHashMap.get(new Long(methodHash));
-        if (method == null) {
-            throw new UnmarshalException(
-                    "Method not found for this Remote Object");
-        }
-
-        logCall(server.getClass().getName() + this.objId + " : "
-                + method);
-        try {
-            ret = method.invoke(server, args);
-        } catch (IllegalArgumentException e) {
-            logException(e);
-            throw e;
-        } catch (IllegalAccessException e) {
-            logException(e);
-            throw e;
-        } catch (InvocationTargetException e) {
-            Throwable t = e.getCause();
-            logException(t);
-            if (t instanceof Error) {
-                throw new ServerError(t.getMessage(), (Error) t);
-            }
-            if (t instanceof Exception) {
-                if (t instanceof RemoteException) {
-                    throw new ServerException(t.getMessage(),
-                            (RemoteException) t);
-                } else {
-                    throw (Exception) t;
-                }
-            }
-        }
-
-        return ret;
-    }
-
-    /**
-     * Returns the number of arguments needed for the invocation of the method
-     * represented by <code>methodHash</code>
-     * 
-     * @param methodHash
-     *            The method identificator received in the request
-     * @return the number of arguments
-     * @throws NoSuchObjectException
-     *             if there is not method for the received hash
-     */
-    public int getArgsCount(long methodHash) throws NoSuchObjectException {
-        Method method = methodHashMap.get(new Long(methodHash));
-        if (method == null) {
-            throw new NoSuchObjectException(
-                    "Method not found for this Remote Object");
-        }
-        return method.getParameterTypes().length;
-    }
-
-    /**
-     * Returns true if the method represented by <code>methodHash</code>
-     * returns any value. (the return type of the method is different than
-     * <code>void</code>)
-     * 
-     * @param methodHash
-     *            The method identificator received in the request
-     * @return true if the return type of the method is different than
-     *         <code>void</code>, otherwise returns false
-     * @throws NoSuchObjectException
-     *             if there is not method for the received hash
-     */
-    public boolean sendReturnValue(long methodHash)
-            throws NoSuchObjectException {
-        Method method = methodHashMap.get(new Long(methodHash));
-        if (method == null) {
-            throw new NoSuchObjectException(
-                    "Method not found for this Remote Object");
-        }
-        return !(method.getReturnType().equals(Void.TYPE));
-    }
-
-    /**
-     * Fills the <code>methodHashMap</code> table with all the remote methods
-     * and its hashes implemented by the object being exported.
-     * 
-     * @param obj
-     *            The object to inspect
-     */
-    private void buildMethodHashMap(Remote obj) {
-        Set<Method> methodsSet = RemoteUtils.getRemoteMethods(obj.getClass());
-        long methodHash;
-        for (Method method : methodsSet) {
-            methodHash = MethodHashGenerator.getMethodHash(method);
-            method.setAccessible(true);
-            methodHashMap.put(new Long(methodHash), method);
-        }
-        return;
-    }
-
-    /**
-     * Sends call information to the logger.
-     * 
-     * @param msg
-     *            The message to be logged
-     */
-    private void logCall(String msg) {
-        Logger logger = Logger.getLogger("ar.org.fitc.rmi.server");
-        try {
-            logger.log(Level.FINER, "RMI "
-                    + TransportManager.getTransportManager()
-                            .getClientConnection() + " ["
-                    + RemoteServer.getClientHost() + " : " + msg + "]");
-        } catch (ServerNotActiveException e) {
-            logger.log(Level.FINER, "RMI (No Connection Info) [" + " : " + msg
-                    + "]");
-        }
-    }
-
-    /**
-     * Sends exception or error information to the logger.
-     * 
-     * @param e
-     *            The exception or error to be logged
-     */
-    private void logException(Throwable e) {
-        Logger logger = Logger.getLogger("ar.org.fitc.rmi.server");
-        try {
-            logger.log(Level.FINE, "RMI "
-                    + TransportManager.getTransportManager()
-                            .getClientConnection() + " ["
-                    + RemoteServer.getClientHost() + "] exception: " + e);
-        } catch (ServerNotActiveException e1) {
-            logger.log(Level.FINE, "RMI (No Connection Info) ["
-                    + "] exception: " + e);
-        }
-
-    }
-
-    /**
-     * Reads a reference from an <code>inputStream</code> during reference
-     * deserialization. Since the server references aren't sent to the clients,
-     * this method does nothing. (Simply returns)
-     * 
-     * @param in
-     *            the stream to read data from to restore the reference
-     * @throws IOException
-     *             if an I/O Error occur during deserialization
-     * @throws ClassNotFoundException
-     *             If the class for this restored object is not found
-     */
-    @Override
-    public void readExternal(ObjectInput in) throws IOException,
-            ClassNotFoundException {
-        return;
-    }
-
-    /**
-     * Sends the components of the reference during serialization. Since the
-     * server references aren't sent to the clients, this method does nothing.
-     * (Simply returns)
-     * 
-     * @param out
-     *            the stream to write the reference to
-     * @throws IOException
-     *             if an I/O Error occur during serialization
-     */
-    @Override
-    public void writeExternal(ObjectOutput out) throws IOException {
-        return;
-    }
-}
+/* 
+*  Copyright 2005 The Apache Software Foundation or its licensors, as applicable. 
+* 
+*  Licensed 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 org.apache.harmony.rmi.internal.server;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.rmi.NoSuchObjectException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.ServerError;
+import java.rmi.ServerException;
+import java.rmi.UnmarshalException;
+import java.rmi.server.ObjID;
+import java.rmi.server.RemoteServer;
+import java.rmi.server.RemoteStub;
+import java.rmi.server.ServerNotActiveException;
+import java.rmi.server.ServerRef;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.harmony.rmi.internal.transport.Endpoint;
+import org.apache.harmony.rmi.internal.transport.TransportManager;
+import org.apache.harmony.rmi.internal.utils.MethodHashGenerator;
+import org.apache.harmony.rmi.internal.utils.RemoteUtils;
+
+/*
+ * NOTE: 
+ * This class has been modified in order to support 
+ * Java VM 1.4.2 using the javac's target jsr14 
+ */
+
+/**
+ * This class is the implementation of the <code>ServerRef</code> interface
+ * for the <code>UnicastRemoteObject</code>, for those remote objects
+ * exported without custom socket factories.
+ * 
+ * @author Gonzalo Ortega
+ * 
+ */
+public class UnicastServerRefImpl extends UnicastRemoteRefImpl implements
+        ServerRef {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * A table for storing the relations between the methods of the remote
+     * object and its hashes.
+     */
+    private Map<Long, Method> methodHashMap;
+
+    /**
+     * The reference to the real object, used for dispatching received calls
+     */
+    private WeakReference<Remote> object; // Weak reference to the "real"
+                                            // server object
+
+    /**
+     * Creates a new <code>UnicastServerRefImpl</code> starting from the
+     * object being exported and the <code>ObjID</code> and
+     * <code>Endpoint</code> generated during exportation.
+     * 
+     * @param objectToExport
+     *            The object being exported
+     * @param objID
+     *            The <code>ObjID</code> created during exportation of the
+     *            remote object
+     * @param ep
+     *            The <code>Endpoint</code> generated during exportation of
+     *            the remote object
+     */
+    public UnicastServerRefImpl(Remote objectToExport, ObjID objID, Endpoint ep) {
+        super(objID, ep);
+        this.object = new WeakReference<Remote>(objectToExport);
+        this.methodHashMap = new HashMap<Long, Method>();
+        buildMethodHashMap(objectToExport);
+    }
+
+    /**
+     * Creates a new empty <code>UnicastServerRefImpl</code>
+     * 
+     */
+    public UnicastServerRefImpl() {
+    }
+
+    /**
+     * Returns the string representing the reference type, to be serialized in
+     * the stream <code>out</code>.
+     * 
+     * @param out
+     *            the output stream to which the reference will be serialized
+     * @return the string representing this type of reference
+     */
+    @Override
+    public String getRefClass(ObjectOutput out) {
+        return ReferenceTypes.UNICAST_SERVER_REF.toString();
+    }
+
+    /**
+     * This method isn't necessary in our design. Is not used at the moment.
+     * 
+     * @param obj
+     *            the object being exported
+     * @param data
+     *            data needed for exportation
+     * @return null
+     * @throws RemoteException
+     *             if exportation fails
+     */
+    public RemoteStub exportObject(Remote obj, Object data)
+            throws RemoteException {
+        // REVIEW: This method isn't necessary in our design. Review...
+        return null;
+    }
+
+    /**
+     * This method isn't necessary in our design. Is not used at the moment.
+     * 
+     * @return null
+     * @throws ServerNotActiveException
+     *             if called outside of servicing a remote method invocation
+     */
+    public String getClientHost() throws ServerNotActiveException {
+        // REVIEW: This method isn't necessary in our design. Review...
+        return null;
+    }
+
+    /**
+     * Dispatches the call received by the Transport Layer to the exported
+     * object
+     * 
+     * @param args
+     *            the arguments for the invocation of the method
+     * @param methodHash
+     *            a hash that represents the method being invoked
+     * @return the result of the invocation in the remote object
+     * @throws Exception
+     *             if any problem arises during execution of the method
+     */
+    public Object executeCall(Object[] args, long methodHash) throws Exception {
+        Object ret = null;
+        Object server = this.object.get();
+        if (server == null) {
+            throw new NoSuchObjectException(
+                    "Invalid Remote server object. (object not found)");
+        }
+
+        Method method = methodHashMap.get(new Long(methodHash));
+        if (method == null) {
+            throw new UnmarshalException(
+                    "Method not found for this Remote Object");
+        }
+
+        logCall(server.getClass().getName() + this.objId + " : "
+                + method);
+        try {
+            ret = method.invoke(server, args);
+        } catch (IllegalArgumentException e) {
+            logException(e);
+            throw e;
+        } catch (IllegalAccessException e) {
+            logException(e);
+            throw e;
+        } catch (InvocationTargetException e) {
+            Throwable t = e.getCause();
+            logException(t);
+            if (t instanceof Error) {
+                throw new ServerError(t.getMessage(), (Error) t);
+            }
+            if (t instanceof Exception) {
+                if (t instanceof RemoteException) {
+                    throw new ServerException(t.getMessage(),
+                            (RemoteException) t);
+                } else {
+                    throw (Exception) t;
+                }
+            }
+        }
+
+        return ret;
+    }
+
+    /**
+     * Returns the number of arguments needed for the invocation of the method
+     * represented by <code>methodHash</code>
+     * 
+     * @param methodHash
+     *            The method identificator received in the request
+     * @return the number of arguments
+     * @throws NoSuchObjectException
+     *             if there is not method for the received hash
+     */
+    public int getArgsCount(long methodHash) throws NoSuchObjectException {
+        Method method = methodHashMap.get(new Long(methodHash));
+        if (method == null) {
+            throw new NoSuchObjectException(
+                    "Method not found for this Remote Object");
+        }
+        return method.getParameterTypes().length;
+    }
+
+    /**
+     * Returns true if the method represented by <code>methodHash</code>
+     * returns any value. (the return type of the method is different than
+     * <code>void</code>)
+     * 
+     * @param methodHash
+     *            The method identificator received in the request
+     * @return true if the return type of the method is different than
+     *         <code>void</code>, otherwise returns false
+     * @throws NoSuchObjectException
+     *             if there is not method for the received hash
+     */
+    public boolean sendReturnValue(long methodHash)
+            throws NoSuchObjectException {
+        Method method = methodHashMap.get(new Long(methodHash));
+        if (method == null) {
+            throw new NoSuchObjectException(
+                    "Method not found for this Remote Object");
+        }
+        return !(method.getReturnType().equals(Void.TYPE));
+    }
+
+    /**
+     * Fills the <code>methodHashMap</code> table with all the remote methods
+     * and its hashes implemented by the object being exported.
+     * 
+     * @param obj
+     *            The object to inspect
+     */
+    private void buildMethodHashMap(Remote obj) {
+        Set<Method> methodsSet = RemoteUtils.getRemoteMethods(obj.getClass());
+        long methodHash;
+        for (Method method : methodsSet) {
+            methodHash = MethodHashGenerator.getMethodHash(method);
+            method.setAccessible(true);
+            methodHashMap.put(new Long(methodHash), method);
+        }
+        return;
+    }
+
+    /**
+     * Sends call information to the logger.
+     * 
+     * @param msg
+     *            The message to be logged
+     */
+    private void logCall(String msg) {
+        Logger logger = Logger.getLogger("org.apache.harmony.rmi.internal.server");
+        try {
+            logger.log(Level.FINER, "RMI "
+                    + TransportManager.getTransportManager()
+                            .getClientConnection() + " ["
+                    + RemoteServer.getClientHost() + " : " + msg + "]");
+        } catch (ServerNotActiveException e) {
+            logger.log(Level.FINER, "RMI (No Connection Info) [" + " : " + msg
+                    + "]");
+        }
+    }
+
+    /**
+     * Sends exception or error information to the logger.
+     * 
+     * @param e
+     *            The exception or error to be logged
+     */
+    private void logException(Throwable e) {
+        Logger logger = Logger.getLogger("org.apache.harmony.rmi.internal.server");
+        try {
+            logger.log(Level.FINE, "RMI "
+                    + TransportManager.getTransportManager()
+                            .getClientConnection() + " ["
+                    + RemoteServer.getClientHost() + "] exception: " + e);
+        } catch (ServerNotActiveException e1) {
+            logger.log(Level.FINE, "RMI (No Connection Info) ["
+                    + "] exception: " + e);
+        }
+
+    }
+
+    /**
+     * Reads a reference from an <code>inputStream</code> during reference
+     * deserialization. Since the server references aren't sent to the clients,
+     * this method does nothing. (Simply returns)
+     * 
+     * @param in
+     *            the stream to read data from to restore the reference
+     * @throws IOException
+     *             if an I/O Error occur during deserialization
+     * @throws ClassNotFoundException
+     *             If the class for this restored object is not found
+     */
+    @Override
+    public void readExternal(ObjectInput in) throws IOException,
+            ClassNotFoundException {
+        return;
+    }
+
+    /**
+     * Sends the components of the reference during serialization. Since the
+     * server references aren't sent to the clients, this method does nothing.
+     * (Simply returns)
+     * 
+     * @param out
+     *            the stream to write the reference to
+     * @throws IOException
+     *             if an I/O Error occur during serialization
+     */
+    @Override
+    public void writeExternal(ObjectOutput out) throws IOException {
+        return;
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/AbstractClientConnection.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/AbstractClientConnection.java?rev=407724&r1=407183&r2=407724&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/AbstractClientConnection.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/AbstractClientConnection.java Thu May 18 23:00:52 2006
@@ -1,262 +1,262 @@
-/* 
-*  Copyright 2005 The Apache Software Foundation or its licensors, as applicable. 
-* 
-*  Licensed 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 ar.org.fitc.rmi.transport;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.net.Socket;
-import java.rmi.ConnectIOException;
-import java.rmi.MarshalException;
-import java.rmi.server.ObjID;
-import java.rmi.server.UID;
-import java.util.WeakHashMap;
-
-import ar.org.fitc.rmi.transport.jrmp.ClientProtocolHandler;
-import ar.org.fitc.rmi.utils.PropertiesReader;
-
-/*
- * NOTE: 
- * This class has been modified in order to support 
- * Java VM 1.4.2 using the javac's target jsr14 
- */
-
-/**
- * Encapsulates the Client events occurring in the JRMP protocol. It creates a
- * socket for the specified {@link ar.org.fitc.rmi.transport.Endpoint}, it
- * sends all the parameters in the apropriate order and it waits for the
- * results.
- * 
- * @author Gustavo Petri
- */
-abstract class AbstractClientConnection {
-
-    /**
-     * A {@link #clientConnectionID} counter.
-     */
-    static protected int clientConnectionCounter = 0;
-
-    /**
-     * The table for storing the {@link ar.org.fitc.rmi.transport.Endpoint} and
-     * the {@link #lastUsageTime} for the connection.
-     */
-    static protected WeakHashMap<Endpoint, Long> rttTable;
-
-    /**
-     * Used to store the value of the ar.org.fitc.rmi.transport.readTimeout
-     * property.
-     */
-    protected static int SO_TIME_OUT;
-
-    static {
-        SO_TIME_OUT = PropertiesReader.readInt(
-                "ar.org.fitc.rmi.transport.readTimeout", 0);
-        rttTable = new WeakHashMap<Endpoint, Long>();
-    }
-
-    /**
-     * The client connection ID.
-     */
-    protected int clientConnectionID;
-
-    /**
-     * The endpoint of the connexion.
-     */
-    protected Endpoint ep;
-
-    /**
-     * The input stream of the connection
-     */
-    protected DataInputStream in;
-
-    /**
-     * The last usage time for the connection.
-     */
-    protected Long lastUsageTime;
-
-    /**
-     * The output stream of the connection
-     */
-    protected DataOutputStream out;
-
-    /**
-     * The client protocolHandler neeeded to implement the JRMP protocol.
-     */
-    protected ClientProtocolHandler protocolHandler;
-
-    /**
-     * The socket for communication.
-     */
-    protected Socket sock;
-
-    /**
-     * Creates a new connection to the specified
-     * {@link ar.org.fitc.rmi.transport.Endpoint} using the underlying
-     * {@link java.net.Socket}
-     * 
-     * @param sock
-     *            the {@link java.net.Socket} to which the connection belongs
-     * @param ep
-     *            the {@link ar.org.fitc.rmi.transport.Endpoint} for this
-     *            connection
-     * @throws ConnectIOException
-     *             if an IOException occurs while making a connection to the
-     *             remote host
-     */
-    public AbstractClientConnection(Socket sock, Endpoint ep)
-            throws ConnectIOException {
-        this.ep = ep;
-        this.lastUsageTime = null;
-        clientConnectionID = ++clientConnectionCounter;
-        this.sock = sock;
-        try {
-            this.out = new DataOutputStream(new BufferedOutputStream(sock
-                    .getOutputStream()));
-            this.in = new DataInputStream(new BufferedInputStream(sock
-                    .getInputStream()));
-        } catch (IOException e) {
-            throw new ConnectIOException("I/O exception Creating Connection", e);
-        }
-        protocolHandler = new ClientProtocolHandler(this.in, this.out);
-    }
-
-    /**
-     * Writes the call request data into the connection, and reads the results
-     * of the execution in the server.
-     * 
-     * @param objId
-     *            the specified {@link java.rmi.server.ObjID}
-     * @param hash
-     *            the specified hash for the method being invoked
-     * @param args
-     *            the arguments of the invocation
-     * @param waitReturn
-     *            this parameter indicates whether or not to wait for a return
-     *            value
-     * @return the return value of the remote method call
-     * @throws Exception
-     *             if any exception is thrown on the server side
-     */
-    protected abstract Object methodCall(ObjID objId, long hash, Object[] args,
-            boolean waitReturn) throws Exception;
-
-    /**
-     * Sets up the new connection, sending and/or receiving all the data needed
-     * to initialize the connection.
-     * 
-     * @throws MarshalException
-     *             if an exception occurs while marshalling parameters
-     * @throws IOException
-     *             if the socket is closed
-     * @throws ProtocolException
-     *             if there is an error in the underlying protocol
-     */
-    protected abstract void establishConnection() throws MarshalException,
-            IOException, ProtocolException;
-
-    /**
-     * Returns the ID of this connection.
-     * 
-     * @return the ID of this connection
-     */
-    public final int getClientConnectionID() {
-        return clientConnectionID;
-    }
-
-    /**
-     * Executes the remote method call. This method accomplishes the handling of
-     * the client side of the JRMP protocol.
-     * 
-     * @param objId
-     *            the {@link java.rmi.server ObjID} to which the call will be
-     *            issued
-     * @param hash
-     *            the hash of the method to be called
-     * @param args
-     *            the arguments of the call
-     * @param waitReturn
-     *            this parameter indicates whether or not to wait for a return
-     *            value
-     * @return the return value of the remote method call
-     * @throws Exception
-     *             if any exception is thrown on the server side
-     */
-    public final Object invoke(ObjID objId, long hash, Object[] args,
-            boolean waitReturn) throws Exception {
-        Object obj = null;
-
-        try {
-            obj = methodCall(objId, hash, args, waitReturn);
-            this.lastUsageTime = new Long(System.currentTimeMillis());
-            return obj;
-        } catch (ProtocolException e) {
-            // This exception can only happen on the unusual case of a DGCAck
-            // failure;
-            return obj;
-        } catch (Exception e) {
-            throw e;
-        }
-    }
-
-    /**
-     * Sends a DGCack message, using the specified {@link java.rmi.server.UID} to
-     * identify it.
-     * 
-     * @param uid
-     *            the identifier used to identify the DGC ack message
-     * @throws ProtocolException
-     *             if a problem occurs when flushing the DGC acknowledge message
-     */
-    public final void acknowledgeDGC(UID uid) throws ProtocolException {
-        protocolHandler.writeDGCAck(uid);
-        try {
-            out.flush();
-        } catch (IOException e) {
-            throw new ProtocolException("Exception flushing a DGCAck", e);
-        }
-    }
-
-    /**
-     * Closes this connection. It also closes the underlying socket.
-     * 
-     */
-    public final void releaseConnection() {
-
-        try {
-            this.sock.shutdownOutput();
-            this.sock.shutdownInput();
-            this.sock.close();
-        } catch (IOException e) {
-            // FIXME REVIEW: What to do when an exception is thrown here. May be
-            // a logger could be useful.
-        } finally {
-            this.sock = null;
-        }
-    }
-
-    /**
-     * Returns <code>true</code> if the connection can be pooled for future
-     * reuse.
-     * 
-     * @return <code>true</code> if the connection can be pooled for future
-     *         reuse, <code>false</code> otherwise.
-     */
-    public boolean isReusable() {
-        return false;
-    }
-}
+/* 
+*  Copyright 2005 The Apache Software Foundation or its licensors, as applicable. 
+* 
+*  Licensed 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 org.apache.harmony.rmi.internal.transport;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.Socket;
+import java.rmi.ConnectIOException;
+import java.rmi.MarshalException;
+import java.rmi.server.ObjID;
+import java.rmi.server.UID;
+import java.util.WeakHashMap;
+
+import org.apache.harmony.rmi.internal.transport.jrmp.ClientProtocolHandler;
+import org.apache.harmony.rmi.internal.utils.PropertiesReader;
+
+/*
+ * NOTE: 
+ * This class has been modified in order to support 
+ * Java VM 1.4.2 using the javac's target jsr14 
+ */
+
+/**
+ * Encapsulates the Client events occurring in the JRMP protocol. It creates a
+ * socket for the specified {@link org.apache.harmony.rmi.internal.transport.Endpoint}, it
+ * sends all the parameters in the apropriate order and it waits for the
+ * results.
+ * 
+ * @author Gustavo Petri
+ */
+abstract class AbstractClientConnection {
+
+    /**
+     * A {@link #clientConnectionID} counter.
+     */
+    static protected int clientConnectionCounter = 0;
+
+    /**
+     * The table for storing the {@link org.apache.harmony.rmi.internal.transport.Endpoint} and
+     * the {@link #lastUsageTime} for the connection.
+     */
+    static protected WeakHashMap<Endpoint, Long> rttTable;
+
+    /**
+     * Used to store the value of the org.apache.harmony.rmi.internal.transport.readTimeout
+     * property.
+     */
+    protected static int SO_TIME_OUT;
+
+    static {
+        SO_TIME_OUT = PropertiesReader.readInt(
+                "org.apache.harmony.rmi.internal.transport.readTimeout", 0);
+        rttTable = new WeakHashMap<Endpoint, Long>();
+    }
+
+    /**
+     * The client connection ID.
+     */
+    protected int clientConnectionID;
+
+    /**
+     * The endpoint of the connexion.
+     */
+    protected Endpoint ep;
+
+    /**
+     * The input stream of the connection
+     */
+    protected DataInputStream in;
+
+    /**
+     * The last usage time for the connection.
+     */
+    protected Long lastUsageTime;
+
+    /**
+     * The output stream of the connection
+     */
+    protected DataOutputStream out;
+
+    /**
+     * The client protocolHandler neeeded to implement the JRMP protocol.
+     */
+    protected ClientProtocolHandler protocolHandler;
+
+    /**
+     * The socket for communication.
+     */
+    protected Socket sock;
+
+    /**
+     * Creates a new connection to the specified
+     * {@link org.apache.harmony.rmi.internal.transport.Endpoint} using the underlying
+     * {@link java.net.Socket}
+     * 
+     * @param sock
+     *            the {@link java.net.Socket} to which the connection belongs
+     * @param ep
+     *            the {@link org.apache.harmony.rmi.internal.transport.Endpoint} for this
+     *            connection
+     * @throws ConnectIOException
+     *             if an IOException occurs while making a connection to the
+     *             remote host
+     */
+    public AbstractClientConnection(Socket sock, Endpoint ep)
+            throws ConnectIOException {
+        this.ep = ep;
+        this.lastUsageTime = null;
+        clientConnectionID = ++clientConnectionCounter;
+        this.sock = sock;
+        try {
+            this.out = new DataOutputStream(new BufferedOutputStream(sock
+                    .getOutputStream()));
+            this.in = new DataInputStream(new BufferedInputStream(sock
+                    .getInputStream()));
+        } catch (IOException e) {
+            throw new ConnectIOException("I/O exception Creating Connection", e);
+        }
+        protocolHandler = new ClientProtocolHandler(this.in, this.out);
+    }
+
+    /**
+     * Writes the call request data into the connection, and reads the results
+     * of the execution in the server.
+     * 
+     * @param objId
+     *            the specified {@link java.rmi.server.ObjID}
+     * @param hash
+     *            the specified hash for the method being invoked
+     * @param args
+     *            the arguments of the invocation
+     * @param waitReturn
+     *            this parameter indicates whether or not to wait for a return
+     *            value
+     * @return the return value of the remote method call
+     * @throws Exception
+     *             if any exception is thrown on the server side
+     */
+    protected abstract Object methodCall(ObjID objId, long hash, Object[] args,
+            boolean waitReturn) throws Exception;
+
+    /**
+     * Sets up the new connection, sending and/or receiving all the data needed
+     * to initialize the connection.
+     * 
+     * @throws MarshalException
+     *             if an exception occurs while marshalling parameters
+     * @throws IOException
+     *             if the socket is closed
+     * @throws ProtocolException
+     *             if there is an error in the underlying protocol
+     */
+    protected abstract void establishConnection() throws MarshalException,
+            IOException, ProtocolException;
+
+    /**
+     * Returns the ID of this connection.
+     * 
+     * @return the ID of this connection
+     */
+    public final int getClientConnectionID() {
+        return clientConnectionID;
+    }
+
+    /**
+     * Executes the remote method call. This method accomplishes the handling of
+     * the client side of the JRMP protocol.
+     * 
+     * @param objId
+     *            the {@link java.rmi.server ObjID} to which the call will be
+     *            issued
+     * @param hash
+     *            the hash of the method to be called
+     * @param args
+     *            the arguments of the call
+     * @param waitReturn
+     *            this parameter indicates whether or not to wait for a return
+     *            value
+     * @return the return value of the remote method call
+     * @throws Exception
+     *             if any exception is thrown on the server side
+     */
+    public final Object invoke(ObjID objId, long hash, Object[] args,
+            boolean waitReturn) throws Exception {
+        Object obj = null;
+
+        try {
+            obj = methodCall(objId, hash, args, waitReturn);
+            this.lastUsageTime = new Long(System.currentTimeMillis());
+            return obj;
+        } catch (ProtocolException e) {
+            // This exception can only happen on the unusual case of a DGCAck
+            // failure;
+            return obj;
+        } catch (Exception e) {
+            throw e;
+        }
+    }
+
+    /**
+     * Sends a DGCack message, using the specified {@link java.rmi.server.UID} to
+     * identify it.
+     * 
+     * @param uid
+     *            the identifier used to identify the DGC ack message
+     * @throws ProtocolException
+     *             if a problem occurs when flushing the DGC acknowledge message
+     */
+    public final void acknowledgeDGC(UID uid) throws ProtocolException {
+        protocolHandler.writeDGCAck(uid);
+        try {
+            out.flush();
+        } catch (IOException e) {
+            throw new ProtocolException("Exception flushing a DGCAck", e);
+        }
+    }
+
+    /**
+     * Closes this connection. It also closes the underlying socket.
+     * 
+     */
+    public final void releaseConnection() {
+
+        try {
+            this.sock.shutdownOutput();
+            this.sock.shutdownInput();
+            this.sock.close();
+        } catch (IOException e) {
+            // FIXME REVIEW: What to do when an exception is thrown here. May be
+            // a logger could be useful.
+        } finally {
+            this.sock = null;
+        }
+    }
+
+    /**
+     * Returns <code>true</code> if the connection can be pooled for future
+     * reuse.
+     * 
+     * @return <code>true</code> if the connection can be pooled for future
+     *         reuse, <code>false</code> otherwise.
+     */
+    public boolean isReusable() {
+        return false;
+    }
+}