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 [6/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/transport/AbstractServerConnection.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/AbstractServerConnection.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/AbstractServerConnection.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/AbstractServerConnection.java Thu May 18 23:00:52 2006
@@ -1,366 +1,366 @@
-/* 
-*  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.io.InputStream;
-import java.io.OutputStream;
-import java.net.Socket;
-import java.rmi.MarshalException;
-import java.rmi.server.ObjID;
-import java.rmi.server.UID;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import ar.org.fitc.rmi.runtime.RemoteReferenceManager;
-import ar.org.fitc.rmi.transport.jrmp.Message;
-import ar.org.fitc.rmi.transport.jrmp.ReturnMessage;
-import ar.org.fitc.rmi.transport.jrmp.ServerProtocolHandler;
-import ar.org.fitc.rmi.utils.Pair;
-
-/*
- * NOTE: 
- * This class has been modified in order to support 
- * Java VM 1.4.2 using the javac's target jsr14 
- */
-
-/**
- *
- * The server side view of a Connection. Provides methods to interact with the 
- * {@link AbstractClientConnection} 
- * 
- * @author Gustavo Petri
- */
-abstract class AbstractServerConnection {
-
-	/**
-	 * The local {@link java.io.InputStream} to interact with the client.
-	 */
-	protected DataInputStream in;
-
-	/**
-	 * The local {@link java.io.OutputStream} to interact with the client.
-	 */
-	protected DataOutputStream out;
-
-	/**
-	 * The server protocolHandler neeeded to implement the JRMP protocol.
-	 */
-	protected ServerProtocolHandler protocolHandler;
-
-	/**
-	 * The connection identifier.
-	 */
-	protected int connectionID;
-
-	/**
-	 * The connection identifier generator.
-	 */
-	protected static int connectionIDGenerator = 0;
-
-	/**
-	 * The underlying socket of this connection
-	 */
-	protected Socket sock;
-
-	/**
-	 * The table for storing the {@link java.rmi.server.ObjID} and a counter.
-	 */
-	protected static Map<ObjID, Integer> executingCounters;
-
-	/**
-	 * The table for storing the {@link java.rmi.server.UID} and the result,
-	 * when the message sent to the client in response includes a remote object,
-	 * and a dgcAck message is necessary.
-	 */
-	protected static Map<UID, Pair<Long, Object>> dgcAckWaitingMap;
-
-	/**
-	 * Time for next cleanup check of the table dgcAckWaitingMap
-	 */
-	protected static long dgcAckMapNextCleanup;
-
-	/**
-	 * The min time for dgcAck strong reference maintainance of the result, if
-	 * the corresponing dgcAck has never arrived.
-	 */
-	protected static final long dgcAckMapTimeOut = 30000;
-
-	static {
-		executingCounters = new Hashtable<ObjID, Integer>();
-		dgcAckWaitingMap = new Hashtable<UID, Pair<Long, Object>>();
-		dgcAckMapNextCleanup = System.currentTimeMillis() + dgcAckMapTimeOut;
-	}
-
-	/**
-	 * Creates a new connection to the specified
-	 * {@link ar.org.fitc.rmi.transport.EndpointID}
-	 * 
-	 * @param in
-	 *            the specified {@link java.io.InputStream}
-	 * @param out
-	 *            the specified {@link java.io.OutputStream}
-	 * @param clientEP
-	 *            the specified {@link ar.org.fitc.rmi.transport.EndpointID}
-	 * @param sock
-	 *            the socket of connection
-	 */
-	public AbstractServerConnection(InputStream in, OutputStream out,
-			EndpointID clientEP, Socket sock) {
-		this.connectionID = ++connectionIDGenerator;
-		this.sock = sock;
-		this.out = new DataOutputStream(new BufferedOutputStream(out));
-		this.in = new DataInputStream(new BufferedInputStream(in));
-		this.protocolHandler = new ServerProtocolHandler(this.in, this.out,
-				clientEP);
-		// this.clientEP = clientEP;
-	}
-
-	/**
-	 * Unregisters the thread currently executing a remote call into the
-	 * Transport Manager, noting that the client has finished executing the
-	 * remote method on it.
-	 * 
-	 * @param objID
-	 *            the Object identifier in which the client is currently
-	 *            executing a method.
-	 */
-	private final void unregisterThread(ObjID objID) {
-		Map<ObjID, Set<Integer>> executingThreads = TransportManager
-				.getTransportManager().getExecutingThreads();
-
-		if (objID != null) {
-			synchronized (executingThreads) {
-				if (executingThreads.get(objID).size() <= 1) {
-					executingThreads.remove(objID);
-				} else {
-					executingThreads.get(objID).remove(
-							Thread.currentThread().hashCode());
-				}
-				if (executingCounters.get(objID) == 1) {
-					executingCounters.remove(objID);
-				} else {
-					executingCounters.put(objID,
-							executingCounters.get(objID) - 1);
-				}
-			}
-		}
-	}
-
-	/**
-	 * Registers the thread currently executing a remote call into the Transport
-	 * Manager, in order to know if a client is executing a method, to avoid
-	 * unexporting the object in which the method is being executed, unless the
-	 * <code>force</code> parameter is specified.
-	 * 
-	 * @param objID
-	 *            the Object identifier in which the client is currently
-	 *            executing a method.
-	 */
-	private final void registerThread(ObjID objID) {
-		Map<ObjID, Set<Integer>> executingThreads = TransportManager
-				.getTransportManager().getExecutingThreads();
-
-		synchronized (executingThreads) {
-			if (executingThreads.containsKey(objID)) {
-				executingThreads.get(objID).add(Thread.currentThread().hashCode());
-			} else {
-				Set<Integer> threadSet = new HashSet<Integer>();
-				threadSet.add(Thread.currentThread().hashCode());
-				executingThreads.put(objID, threadSet);
-			}
-		}
-		/*
-         * XXX - Compilance 1.4.2 
-         * Here must use the putIfAbsent method if executingCounters is a 
-         * ConcurrentHashMap (i.e.: executingCounters.putIfAbsent(objID, 0))  
-		 */
-        executingCounters.put(objID, 0);
-        
-		executingCounters.put(objID, executingCounters.get(objID) + 1);
-	}
-
-	/**
-	 * Returns the ID of this connection.
-	 * 
-	 * @return the ID of this connection
-	 */
-	public final int getConnectionID() {
-		return connectionID;
-	}
-
-	/**
-	 * Establishes a connection.
-	 * 
-	 * @throws ProtocolException
-	 *             if there is an error in the underlying protocol
-	 */
-	public abstract void establishConnection() throws ProtocolException;
-
-	/**
-	 * Handles the incoming message.
-	 * 
-	 * @throws Exception If an exception occurs during message handling.
-	 */
-	public abstract void serve() throws Exception;
-
-
-	/**
-	 * Returns a <code>true</code> value if the {@link java.rmi.server.ObjID ObjID}
-	 * exists in the table {@link #executingCounters}, <code>false</code> if
-	 * not.
-	 * 
-	 * @param objID
-	 *            the specified {@link java.rmi.server.ObjID}
-	 * @return a boolean value
-	 */
-	public final static boolean isExcecuting(ObjID objID) {
-		if (executingCounters.containsKey(objID)) {
-			return true;
-		}
-		return false;
-	}
-
-	/**
-	 * Closes the connection.
-	 */
-	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;
-		}
-	}
-
-	/**
-	 * Registers the thread currently executing the remote method, executes the
-	 * call via RemoteReferenceManager, unregisters the thread and returns the
-	 * result of the invocation.
-	 * 
-	 * @param msg
-	 *            the {@link Message} object containing the data for the
-	 *            call.
-	 * @return a {@link ReturnMessage} object containing the result of
-	 *         the invocation.
-	 */
-	protected ReturnMessage executeMethod(Message msg) {
-		ObjID objID;
-		ReturnMessage ret;
-		objID = msg.getObjID();
-		registerThread(objID);
-		RemoteReferenceManager refMgr = RemoteReferenceManager
-				.getRemoteReferenceManager();
-		try {
-			boolean sendReturn = refMgr.sendReturnValue(objID, msg.getHash());
-			Object result = refMgr.executeCall(objID, msg.getHash(), msg
-					.getArguments());
-			ret = new ReturnMessage(result, sendReturn);
-		} catch (Exception e) {
-			ret = new ReturnMessage(e);
-		}
-		unregisterThread(objID);
-		return ret;
-	}
-
-	/**
-	 * It does periodic cleanups in the {@link #dgcAckWaitingMap}, to
-	 * free the memory that could be still allocated due to lost dgcAcks
-	 */
-	protected void doDgcAckWaitingMapCleanUp() {
-		long time = System.currentTimeMillis();
-		synchronized (dgcAckWaitingMap) {
-			if (time > dgcAckMapNextCleanup) {
-				Iterator<Map.Entry<UID, Pair<Long, Object>>> iter = dgcAckWaitingMap
-						.entrySet().iterator();
-				while (iter.hasNext()) {
-					Map.Entry<UID, Pair<Long, Object>> mapEntry = iter.next();
-					if (time > mapEntry.getValue().getFirst()) {
-						iter.remove();
-					}
-				}
-				dgcAckMapNextCleanup = time + dgcAckMapTimeOut;
-			}
-		}
-	}
-
-	/**
-	 * Receives a {@link Message} object containing the method call
-	 * request, executes the call, and writes the results to the client.
-	 * 
-	 * @param msg The {@link Message} object containing the call execution request.
-     *  
-	 * @throws MarshalException if an exception occurs when writing the result
-	 * of the call.
-	 */
-	protected void handleCall(Message msg) throws MarshalException {
-		UID dgcAck = null;
-		ReturnMessage methodExecuted = executeMethod(msg);
-
-		try {
-			dgcAck = methodExecuted.write(out);
-			out.flush();
-		} catch (IOException e) {
-			throw new MarshalException("Error writing method result", e);
-		}
-		if (dgcAck != null) {
-			dgcAckWaitingMap.put(dgcAck, new Pair<Long, Object>(new Long(System
-					.currentTimeMillis()
-					+ dgcAckMapTimeOut), methodExecuted.getResult()));
-		}
-	}
-
-	/**
-	 * Removes the received DGCack message from the {@link #dgcAckWaitingMap}	 
-     *  
-	 * @param msg
-	 *            the received message containing the DGCack
-	 */
-	protected void handleDGCAck(Message msg) {
-		dgcAckWaitingMap.remove(msg.getUID());
-		doDgcAckWaitingMapCleanUp();
-	}
-	
-	/**
-     * sends an exception to the client 
-     * 
-     * @param e 
-     *          the exception to be sent
-     */
-    protected void handleException(Exception e) {
-        try {
-            new ReturnMessage(e).write(out);
-            out.flush();
-        } catch (IOException e1) {
-            /*
-             *  FIXME: May be logging would be useful.
-             *  When a connection on the client is closed due to pool release
-             *  the out.flush method will fail.
-             */ 
-        }
-    }
+/* 
+*  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.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.rmi.MarshalException;
+import java.rmi.server.ObjID;
+import java.rmi.server.UID;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.harmony.rmi.internal.runtime.RemoteReferenceManager;
+import org.apache.harmony.rmi.internal.transport.jrmp.Message;
+import org.apache.harmony.rmi.internal.transport.jrmp.ReturnMessage;
+import org.apache.harmony.rmi.internal.transport.jrmp.ServerProtocolHandler;
+import org.apache.harmony.rmi.internal.utils.Pair;
+
+/*
+ * NOTE: 
+ * This class has been modified in order to support 
+ * Java VM 1.4.2 using the javac's target jsr14 
+ */
+
+/**
+ *
+ * The server side view of a Connection. Provides methods to interact with the 
+ * {@link AbstractClientConnection} 
+ * 
+ * @author Gustavo Petri
+ */
+abstract class AbstractServerConnection {
+
+	/**
+	 * The local {@link java.io.InputStream} to interact with the client.
+	 */
+	protected DataInputStream in;
+
+	/**
+	 * The local {@link java.io.OutputStream} to interact with the client.
+	 */
+	protected DataOutputStream out;
+
+	/**
+	 * The server protocolHandler neeeded to implement the JRMP protocol.
+	 */
+	protected ServerProtocolHandler protocolHandler;
+
+	/**
+	 * The connection identifier.
+	 */
+	protected int connectionID;
+
+	/**
+	 * The connection identifier generator.
+	 */
+	protected static int connectionIDGenerator = 0;
+
+	/**
+	 * The underlying socket of this connection
+	 */
+	protected Socket sock;
+
+	/**
+	 * The table for storing the {@link java.rmi.server.ObjID} and a counter.
+	 */
+	protected static Map<ObjID, Integer> executingCounters;
+
+	/**
+	 * The table for storing the {@link java.rmi.server.UID} and the result,
+	 * when the message sent to the client in response includes a remote object,
+	 * and a dgcAck message is necessary.
+	 */
+	protected static Map<UID, Pair<Long, Object>> dgcAckWaitingMap;
+
+	/**
+	 * Time for next cleanup check of the table dgcAckWaitingMap
+	 */
+	protected static long dgcAckMapNextCleanup;
+
+	/**
+	 * The min time for dgcAck strong reference maintainance of the result, if
+	 * the corresponing dgcAck has never arrived.
+	 */
+	protected static final long dgcAckMapTimeOut = 30000;
+
+	static {
+		executingCounters = new Hashtable<ObjID, Integer>();
+		dgcAckWaitingMap = new Hashtable<UID, Pair<Long, Object>>();
+		dgcAckMapNextCleanup = System.currentTimeMillis() + dgcAckMapTimeOut;
+	}
+
+	/**
+	 * Creates a new connection to the specified
+	 * {@link org.apache.harmony.rmi.internal.transport.EndpointID}
+	 * 
+	 * @param in
+	 *            the specified {@link java.io.InputStream}
+	 * @param out
+	 *            the specified {@link java.io.OutputStream}
+	 * @param clientEP
+	 *            the specified {@link org.apache.harmony.rmi.internal.transport.EndpointID}
+	 * @param sock
+	 *            the socket of connection
+	 */
+	public AbstractServerConnection(InputStream in, OutputStream out,
+			EndpointID clientEP, Socket sock) {
+		this.connectionID = ++connectionIDGenerator;
+		this.sock = sock;
+		this.out = new DataOutputStream(new BufferedOutputStream(out));
+		this.in = new DataInputStream(new BufferedInputStream(in));
+		this.protocolHandler = new ServerProtocolHandler(this.in, this.out,
+				clientEP);
+		// this.clientEP = clientEP;
+	}
+
+	/**
+	 * Unregisters the thread currently executing a remote call into the
+	 * Transport Manager, noting that the client has finished executing the
+	 * remote method on it.
+	 * 
+	 * @param objID
+	 *            the Object identifier in which the client is currently
+	 *            executing a method.
+	 */
+	private final void unregisterThread(ObjID objID) {
+		Map<ObjID, Set<Integer>> executingThreads = TransportManager
+				.getTransportManager().getExecutingThreads();
+
+		if (objID != null) {
+			synchronized (executingThreads) {
+				if (executingThreads.get(objID).size() <= 1) {
+					executingThreads.remove(objID);
+				} else {
+					executingThreads.get(objID).remove(
+							Thread.currentThread().hashCode());
+				}
+				if (executingCounters.get(objID) == 1) {
+					executingCounters.remove(objID);
+				} else {
+					executingCounters.put(objID,
+							executingCounters.get(objID) - 1);
+				}
+			}
+		}
+	}
+
+	/**
+	 * Registers the thread currently executing a remote call into the Transport
+	 * Manager, in order to know if a client is executing a method, to avoid
+	 * unexporting the object in which the method is being executed, unless the
+	 * <code>force</code> parameter is specified.
+	 * 
+	 * @param objID
+	 *            the Object identifier in which the client is currently
+	 *            executing a method.
+	 */
+	private final void registerThread(ObjID objID) {
+		Map<ObjID, Set<Integer>> executingThreads = TransportManager
+				.getTransportManager().getExecutingThreads();
+
+		synchronized (executingThreads) {
+			if (executingThreads.containsKey(objID)) {
+				executingThreads.get(objID).add(Thread.currentThread().hashCode());
+			} else {
+				Set<Integer> threadSet = new HashSet<Integer>();
+				threadSet.add(Thread.currentThread().hashCode());
+				executingThreads.put(objID, threadSet);
+			}
+		}
+		/*
+         * XXX - Compilance 1.4.2 
+         * Here must use the putIfAbsent method if executingCounters is a 
+         * ConcurrentHashMap (i.e.: executingCounters.putIfAbsent(objID, 0))  
+		 */
+        executingCounters.put(objID, 0);
+        
+		executingCounters.put(objID, executingCounters.get(objID) + 1);
+	}
+
+	/**
+	 * Returns the ID of this connection.
+	 * 
+	 * @return the ID of this connection
+	 */
+	public final int getConnectionID() {
+		return connectionID;
+	}
+
+	/**
+	 * Establishes a connection.
+	 * 
+	 * @throws ProtocolException
+	 *             if there is an error in the underlying protocol
+	 */
+	public abstract void establishConnection() throws ProtocolException;
+
+	/**
+	 * Handles the incoming message.
+	 * 
+	 * @throws Exception If an exception occurs during message handling.
+	 */
+	public abstract void serve() throws Exception;
+
+
+	/**
+	 * Returns a <code>true</code> value if the {@link java.rmi.server.ObjID ObjID}
+	 * exists in the table {@link #executingCounters}, <code>false</code> if
+	 * not.
+	 * 
+	 * @param objID
+	 *            the specified {@link java.rmi.server.ObjID}
+	 * @return a boolean value
+	 */
+	public final static boolean isExcecuting(ObjID objID) {
+		if (executingCounters.containsKey(objID)) {
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Closes the connection.
+	 */
+	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;
+		}
+	}
+
+	/**
+	 * Registers the thread currently executing the remote method, executes the
+	 * call via RemoteReferenceManager, unregisters the thread and returns the
+	 * result of the invocation.
+	 * 
+	 * @param msg
+	 *            the {@link Message} object containing the data for the
+	 *            call.
+	 * @return a {@link ReturnMessage} object containing the result of
+	 *         the invocation.
+	 */
+	protected ReturnMessage executeMethod(Message msg) {
+		ObjID objID;
+		ReturnMessage ret;
+		objID = msg.getObjID();
+		registerThread(objID);
+		RemoteReferenceManager refMgr = RemoteReferenceManager
+				.getRemoteReferenceManager();
+		try {
+			boolean sendReturn = refMgr.sendReturnValue(objID, msg.getHash());
+			Object result = refMgr.executeCall(objID, msg.getHash(), msg
+					.getArguments());
+			ret = new ReturnMessage(result, sendReturn);
+		} catch (Exception e) {
+			ret = new ReturnMessage(e);
+		}
+		unregisterThread(objID);
+		return ret;
+	}
+
+	/**
+	 * It does periodic cleanups in the {@link #dgcAckWaitingMap}, to
+	 * free the memory that could be still allocated due to lost dgcAcks
+	 */
+	protected void doDgcAckWaitingMapCleanUp() {
+		long time = System.currentTimeMillis();
+		synchronized (dgcAckWaitingMap) {
+			if (time > dgcAckMapNextCleanup) {
+				Iterator<Map.Entry<UID, Pair<Long, Object>>> iter = dgcAckWaitingMap
+						.entrySet().iterator();
+				while (iter.hasNext()) {
+					Map.Entry<UID, Pair<Long, Object>> mapEntry = iter.next();
+					if (time > mapEntry.getValue().getFirst()) {
+						iter.remove();
+					}
+				}
+				dgcAckMapNextCleanup = time + dgcAckMapTimeOut;
+			}
+		}
+	}
+
+	/**
+	 * Receives a {@link Message} object containing the method call
+	 * request, executes the call, and writes the results to the client.
+	 * 
+	 * @param msg The {@link Message} object containing the call execution request.
+     *  
+	 * @throws MarshalException if an exception occurs when writing the result
+	 * of the call.
+	 */
+	protected void handleCall(Message msg) throws MarshalException {
+		UID dgcAck = null;
+		ReturnMessage methodExecuted = executeMethod(msg);
+
+		try {
+			dgcAck = methodExecuted.write(out);
+			out.flush();
+		} catch (IOException e) {
+			throw new MarshalException("Error writing method result", e);
+		}
+		if (dgcAck != null) {
+			dgcAckWaitingMap.put(dgcAck, new Pair<Long, Object>(new Long(System
+					.currentTimeMillis()
+					+ dgcAckMapTimeOut), methodExecuted.getResult()));
+		}
+	}
+
+	/**
+	 * Removes the received DGCack message from the {@link #dgcAckWaitingMap}	 
+     *  
+	 * @param msg
+	 *            the received message containing the DGCack
+	 */
+	protected void handleDGCAck(Message msg) {
+		dgcAckWaitingMap.remove(msg.getUID());
+		doDgcAckWaitingMapCleanUp();
+	}
+	
+	/**
+     * sends an exception to the client 
+     * 
+     * @param e 
+     *          the exception to be sent
+     */
+    protected void handleException(Exception e) {
+        try {
+            new ReturnMessage(e).write(out);
+            out.flush();
+        } catch (IOException e1) {
+            /*
+             *  FIXME: May be logging would be useful.
+             *  When a connection on the client is closed due to pool release
+             *  the out.flush method will fail.
+             */ 
+        }
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/ClientConnectionFactory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/ClientConnectionFactory.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/ClientConnectionFactory.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/ClientConnectionFactory.java Thu May 18 23:00:52 2006
@@ -1,65 +1,65 @@
-/* 
-*  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.IOException;
-import java.net.Socket;
-import java.rmi.ConnectException;
-import java.rmi.ConnectIOException;
-import java.rmi.UnknownHostException;
-import java.rmi.server.RMIClientSocketFactory;
-import java.rmi.server.RMISocketFactory;
-
-import ar.org.fitc.rmi.transport.http.HttpSocketClientSide;
-import ar.org.fitc.rmi.utils.PropertiesReader;
-
-/**
- * 
- * @author Gustavo Petri
- */
-public final class ClientConnectionFactory {
-
-    private static Integer SO_TIME_OUT;
-
-    static {
-        SO_TIME_OUT = PropertiesReader.readInt(
-                "ar.org.fitc.rmi.transport.readTimeout", 0);
-    }
-
-    static final AbstractClientConnection getClientConnection(Endpoint ep)
-            throws IOException, UnknownHostException, ConnectException,
-            ConnectIOException {
-        Socket sock = null;
-        AbstractClientConnection ret;
-        
-        RMIClientSocketFactory csf = (ep.getCsf() != null) ? ep.getCsf()
-                : RMISocketFactory.getSocketFactory();
-        if (csf == null) {
-            csf = RMISocketFactory.getDefaultSocketFactory();
-        }
-        sock = csf.createSocket(ep.getEndpointID().getHost(), ep.getPort());
-        if (SO_TIME_OUT != 0) {
-            sock.setSoTimeout(SO_TIME_OUT);
-        }
-        sock.setTcpNoDelay(true);
-        if (sock instanceof HttpSocketClientSide) {
-            ret = new SingleOpClientConnection(sock, ep);
-        } else {
-            ret = new StreamClientConnection(sock, ep);
-        }
-        return ret;
-    }
-}
+/* 
+*  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.IOException;
+import java.net.Socket;
+import java.rmi.ConnectException;
+import java.rmi.ConnectIOException;
+import java.rmi.UnknownHostException;
+import java.rmi.server.RMIClientSocketFactory;
+import java.rmi.server.RMISocketFactory;
+
+import org.apache.harmony.rmi.internal.transport.http.HttpSocketClientSide;
+import org.apache.harmony.rmi.internal.utils.PropertiesReader;
+
+/**
+ * 
+ * @author Gustavo Petri
+ */
+public final class ClientConnectionFactory {
+
+    private static Integer SO_TIME_OUT;
+
+    static {
+        SO_TIME_OUT = PropertiesReader.readInt(
+                "org.apache.harmony.rmi.internal.transport.readTimeout", 0);
+    }
+
+    static final AbstractClientConnection getClientConnection(Endpoint ep)
+            throws IOException, UnknownHostException, ConnectException,
+            ConnectIOException {
+        Socket sock = null;
+        AbstractClientConnection ret;
+        
+        RMIClientSocketFactory csf = (ep.getCsf() != null) ? ep.getCsf()
+                : RMISocketFactory.getSocketFactory();
+        if (csf == null) {
+            csf = RMISocketFactory.getDefaultSocketFactory();
+        }
+        sock = csf.createSocket(ep.getEndpointID().getHost(), ep.getPort());
+        if (SO_TIME_OUT != 0) {
+            sock.setSoTimeout(SO_TIME_OUT);
+        }
+        sock.setTcpNoDelay(true);
+        if (sock instanceof HttpSocketClientSide) {
+            ret = new SingleOpClientConnection(sock, ep);
+        } else {
+            ret = new StreamClientConnection(sock, ep);
+        }
+        return ret;
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/ConnectionPool.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/ConnectionPool.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/ConnectionPool.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/ConnectionPool.java Thu May 18 23:00:52 2006
@@ -1,304 +1,304 @@
-/* 
-*  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.IOException;
-import java.rmi.ConnectIOException;
-import java.rmi.UnknownHostException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
-
-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 
- */
-
-/**
- * Reuses the connections that have been created for a specified
- * {@link ar.org.fitc.rmi.transport.Endpoint} and have been released. Maintains
- * a pool of connections by a Map, that contains for each
- * {@link ar.org.fitc.rmi.transport.Endpoint} a corresponding Map with a
- * {@link ar.org.fitc.rmi.transport.AbstractClientConnection}-Time) where
- * <code>Time</code> is the current time in which the connection was released.
- * <br>
- * The Connection Pool is implemented through a  {@link java.util.Timer}. 
- * The keep alive time for which a connection is maintained in the map can be 
- * obtained via the property <EM>ar.org.fitc.rmi.transport.connectionTimeout</EM>, 
- * where the default value is <EM>15000</EM>. <br>
- * When the connections are removed from the table because are evicted, such
- * connection is closed and lets the server know.
- * 
- * @author Marcelo Arcidiacono
- * @author Gustavo Petri
- * @author Diego Raúl Mercado
- */
-public final class ConnectionPool {
-
-    /**
-     * The table used for storing the {@link ar.org.fitc.rmi.transport.Endpoint}
-     * as key and a corresponding list that contains pairs
-     * {@link AbstractClientConnection} and time in
-     * milliseconds at the moment that the connection has been released.
-     */
-    private Map<Endpoint, HashMap<AbstractClientConnection, Long>> storedEpConnections;
-
-    /**
-     * Value of maximum time of the connection keep alive in the table.
-     */
-    private static Long connTimeOut;
-
-    /**
-     * Timer used for schedule tasks for future execution in a background
-     * thread.
-     */
-    private Timer ripperTimer;
-
-    static {
-        connTimeOut = PropertiesReader.readLong(
-                "ar.org.fitc.rmi.transport.connectionTimeout", 15000);
-    }
-
-    /**
-     * Constructor for the {@link ConnectionPool}. In order to guarantee
-     * serial access creates a synchronized (thread-safe) map backed by the
-     * specified map. The timer is set as daemon. The delay before task is to be
-     * executed and the time between successive task executions is the
-     * {@link #connTimeOut}.
-     */
-    public ConnectionPool() {
-        storedEpConnections = 
-            new Hashtable<Endpoint, HashMap<AbstractClientConnection, Long>>();
-        this.ripperTimer = new Timer(true);
-        try {
-            ripperTimer.schedule(new RipperTask(), connTimeOut, connTimeOut);
-        } catch (Exception e) {
-            // Should never happen since the ripperTask method is local.
-            throw new AssertionError(e);
-        }
-    }
-
-    /**
-     * Returns a {@link ar.org.fitc.rmi.transport.AbstractClientConnection} for
-     * the received {@link ar.org.fitc.rmi.transport.Endpoint}.If a
-     * {@link ar.org.fitc.rmi.transport.AbstractClientConnection} exists in the
-     * table for the specified {@link ar.org.fitc.rmi.transport.Endpoint} and
-     * the connection is not evicted, the connection is usable and it is backed.
-     * If no usable connection was found in the pool, a new
-     * {@link ar.org.fitc.rmi.transport.AbstractClientConnection} is created and
-     * backed. The {@link ar.org.fitc.rmi.transport.AbstractClientConnection}
-     * found in the table, usable or not, is removed from the table.
-     * 
-     * @param ep
-     *            the {@link ar.org.fitc.rmi.transport.Endpoint} for which a
-     *            connection is required.
-     * @return a {@link ar.org.fitc.rmi.transport.AbstractClientConnection} for
-     *         the specified {@link ar.org.fitc.rmi.transport.Endpoint}
-     * @throws IOException
-     */
-    public synchronized final AbstractClientConnection getClientConnection(
-            Endpoint ep) throws IOException {
-        AbstractClientConnection returnCC = null;
-
-        if (storedEpConnections.containsKey(ep)) {
-            Long checkTime = System.currentTimeMillis() - connTimeOut;
-
-            Map<Endpoint, Set<AbstractClientConnection>> epConn2clean = 
-                new HashMap<Endpoint, Set<AbstractClientConnection>>();
-
-            Map<AbstractClientConnection, Long> storedCC = 
-                storedEpConnections.get(ep);
-
-            // iterate over the connections of the current EP
-            for (Iterator iter = storedCC.entrySet().iterator(); iter.hasNext();) {
-                Map.Entry pairs = (Map.Entry) iter.next();
-                AbstractClientConnection cc = (AbstractClientConnection) pairs
-                        .getKey();
-                Long ccTime = (Long) pairs.getValue();
-
-                // Anyway (usable or not) must be removed.
-                addConn2clean(epConn2clean, ep, cc);
-
-                if (ccTime < checkTime) {
-                    // Close the Connection and let the server know.
-                    cc.releaseConnection();
-                } else {
-                    returnCC = cc;
-                    try {
-                        returnCC.establishConnection();
-                    } catch (Exception e) {
-                        returnCC.releaseConnection();
-                        returnCC = null;
-                        continue;
-                    }
-                    break; // returnCC must be usable.
-                }
-            }
-            // Clean up the evicted connections from the Pool.
-            removeStoredCC(epConn2clean);
-        }
-        if (returnCC == null) {
-            // No usable connection was found in the Pool.
-            try {
-                returnCC = ClientConnectionFactory.getClientConnection(ep);
-                returnCC.establishConnection();
-            } catch (java.net.UnknownHostException e) {
-                throw new UnknownHostException("The host " + ep.getHost()
-                        + " is unreacheable", e);
-            } catch (java.net.ConnectException e) {
-                throw new java.rmi.ConnectException("Cannot connect to "
-                        + ep.getHost(), e);
-            } catch (IOException e) {
-                throw new ConnectIOException(
-                        "I/O exception Creating Connection", e);
-            }
-        }
-        return returnCC;
-    }
-
-    /**
-     * Adds a {@link ar.org.fitc.rmi.transport.StreamClientConnection} on the
-     * table for a specified {@link ar.org.fitc.rmi.transport.Endpoint} with the
-     * current time in milliseconds. <br>
-     * Notice that is only applicable to StreamOpClientConnection
-     * 
-     * @param ep
-     *            the specific {@link ar.org.fitc.rmi.transport.Endpoint}
-     * @param clConn
-     *            the corresponding
-     *            {@link ar.org.fitc.rmi.transport.StreamClientConnection} to
-     *            the specified {@link ar.org.fitc.rmi.transport.Endpoint}.
-     */
-    public synchronized final void releaseClientConnection(Endpoint ep,
-            StreamClientConnection clConn) { // only applicable to stream
-        // connections
-
-        if (storedEpConnections.containsKey(ep)) {
-            storedEpConnections.get(ep).put(clConn, System.currentTimeMillis());
-        } else {
-            HashMap<AbstractClientConnection, Long> ccMap = new HashMap<AbstractClientConnection, Long>();
-            ccMap.put(clConn, System.currentTimeMillis());
-            storedEpConnections.put(ep, ccMap);
-        }
-    }
-
-    /**
-     * Iterate over <code>epConn2clean</code> and remove it from storedEpConnections. 
-     * If the current endPoint has no more connections available, then removes
-     * it from <code>storedEpConnections</code>
-     * 
-     * @param epConn2clean
-     *            it has all the connections to be remove
-     */
-    @SuppressWarnings("unchecked")
-    private synchronized final void removeStoredCC(
-            Map<Endpoint, Set<AbstractClientConnection>> epConn2clean) {
-        for (Iterator iter = epConn2clean.entrySet().iterator(); iter.hasNext();) {
-            Map.Entry pairs = (Map.Entry) iter.next();
-            Endpoint ep = (Endpoint) pairs.getKey();
-            Set<AbstractClientConnection> cc2remove = (Set<AbstractClientConnection>) pairs
-                    .getValue();
-
-            HashMap<AbstractClientConnection, Long> storedConnectionsMap = storedEpConnections
-                    .get(ep);
-
-            // for each connection in setCC2remove remove it from
-            // storedEpConnections
-            for (AbstractClientConnection cc : cc2remove) {
-                if (storedConnectionsMap.remove(cc) == null) {
-                    throw new AssertionError(); // type - safety
-                }
-            }
-
-            // if EP has not more cc eliminate it from storedEpConnections
-            if (storedConnectionsMap.isEmpty()) {
-                storedEpConnections.remove(ep);
-            }
-        }
-    }
-
-    /**
-     * Verifies that <code>epConn2Clean</code> contains a sets of connections.
-     * If not instantiates it and then adds the <code>cc</code> to this set.
-     * <br>
-     * After that, we insert or update the <code>ep</code> with the set of
-     * connections <code>cc2clean</code>
-     * 
-     * @param epConn2clean
-     *            the map which stores end points' connections to be cleaned
-     * @param ep
-     *            the current end point of the connections
-     * @param cc
-     *            the cc to be inserted in the Set
-     */
-    private static final void addConn2clean(
-            Map<Endpoint, Set<AbstractClientConnection>> epConn2clean,
-            Endpoint ep, AbstractClientConnection cc) {
-        Set<AbstractClientConnection> cc2clean = epConn2clean.get(ep);
-        if (cc2clean == null) {
-            cc2clean = new HashSet<AbstractClientConnection>();
-        }
-        cc2clean.add(cc);
-        epConn2clean.put(ep, cc2clean); // insert or replace the value....
-    }
-
-    /**
-     * Checks the pool for evicted connections.
-     */
-    private final class RipperTask extends TimerTask {
-
-        public synchronized final void run() {
-            Long checkTime = System.currentTimeMillis() - connTimeOut;
-
-            Map<Endpoint, Set<AbstractClientConnection>> epConn2clean = new HashMap<Endpoint, Set<AbstractClientConnection>>();
-
-            // iterate storedEpConnections
-            for (Iterator iter = storedEpConnections.entrySet().iterator(); iter
-                    .hasNext();) {
-
-                Map.Entry pairs = (Map.Entry) iter.next();
-                Endpoint ep = (Endpoint) pairs.getKey();
-                HashMap ccMap = (HashMap) pairs.getValue();
-
-                // iterate over the connection of the current EP
-                for (Iterator iter2 = ccMap.entrySet().iterator(); iter2
-                        .hasNext();) {
-                    Map.Entry pairs2 = (Map.Entry) iter2.next();
-                    AbstractClientConnection cc = (AbstractClientConnection) pairs2
-                            .getKey();
-                    Long time = (Long) pairs2.getValue();
-
-                    // checks cc life...
-                    if (time < checkTime) {
-                        cc.releaseConnection();
-                        addConn2clean(epConn2clean, ep, cc);
-                    }
-                }
-            }
-            if (!epConn2clean.isEmpty()) {
-                removeStoredCC(epConn2clean);
-            }
-        }
-    }
-}
+/* 
+*  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.IOException;
+import java.rmi.ConnectIOException;
+import java.rmi.UnknownHostException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
+
+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 
+ */
+
+/**
+ * Reuses the connections that have been created for a specified
+ * {@link org.apache.harmony.rmi.internal.transport.Endpoint} and have been released. Maintains
+ * a pool of connections by a Map, that contains for each
+ * {@link org.apache.harmony.rmi.internal.transport.Endpoint} a corresponding Map with a
+ * {@link org.apache.harmony.rmi.internal.transport.AbstractClientConnection}-Time) where
+ * <code>Time</code> is the current time in which the connection was released.
+ * <br>
+ * The Connection Pool is implemented through a  {@link java.util.Timer}. 
+ * The keep alive time for which a connection is maintained in the map can be 
+ * obtained via the property <EM>org.apache.harmony.rmi.internal.transport.connectionTimeout</EM>, 
+ * where the default value is <EM>15000</EM>. <br>
+ * When the connections are removed from the table because are evicted, such
+ * connection is closed and lets the server know.
+ * 
+ * @author Marcelo Arcidiacono
+ * @author Gustavo Petri
+ * @author Diego Raúl Mercado
+ */
+public final class ConnectionPool {
+
+    /**
+     * The table used for storing the {@link org.apache.harmony.rmi.internal.transport.Endpoint}
+     * as key and a corresponding list that contains pairs
+     * {@link AbstractClientConnection} and time in
+     * milliseconds at the moment that the connection has been released.
+     */
+    private Map<Endpoint, HashMap<AbstractClientConnection, Long>> storedEpConnections;
+
+    /**
+     * Value of maximum time of the connection keep alive in the table.
+     */
+    private static Long connTimeOut;
+
+    /**
+     * Timer used for schedule tasks for future execution in a background
+     * thread.
+     */
+    private Timer ripperTimer;
+
+    static {
+        connTimeOut = PropertiesReader.readLong(
+                "org.apache.harmony.rmi.internal.transport.connectionTimeout", 15000);
+    }
+
+    /**
+     * Constructor for the {@link ConnectionPool}. In order to guarantee
+     * serial access creates a synchronized (thread-safe) map backed by the
+     * specified map. The timer is set as daemon. The delay before task is to be
+     * executed and the time between successive task executions is the
+     * {@link #connTimeOut}.
+     */
+    public ConnectionPool() {
+        storedEpConnections = 
+            new Hashtable<Endpoint, HashMap<AbstractClientConnection, Long>>();
+        this.ripperTimer = new Timer(true);
+        try {
+            ripperTimer.schedule(new RipperTask(), connTimeOut, connTimeOut);
+        } catch (Exception e) {
+            // Should never happen since the ripperTask method is local.
+            throw new AssertionError(e);
+        }
+    }
+
+    /**
+     * Returns a {@link org.apache.harmony.rmi.internal.transport.AbstractClientConnection} for
+     * the received {@link org.apache.harmony.rmi.internal.transport.Endpoint}.If a
+     * {@link org.apache.harmony.rmi.internal.transport.AbstractClientConnection} exists in the
+     * table for the specified {@link org.apache.harmony.rmi.internal.transport.Endpoint} and
+     * the connection is not evicted, the connection is usable and it is backed.
+     * If no usable connection was found in the pool, a new
+     * {@link org.apache.harmony.rmi.internal.transport.AbstractClientConnection} is created and
+     * backed. The {@link org.apache.harmony.rmi.internal.transport.AbstractClientConnection}
+     * found in the table, usable or not, is removed from the table.
+     * 
+     * @param ep
+     *            the {@link org.apache.harmony.rmi.internal.transport.Endpoint} for which a
+     *            connection is required.
+     * @return a {@link org.apache.harmony.rmi.internal.transport.AbstractClientConnection} for
+     *         the specified {@link org.apache.harmony.rmi.internal.transport.Endpoint}
+     * @throws IOException
+     */
+    public synchronized final AbstractClientConnection getClientConnection(
+            Endpoint ep) throws IOException {
+        AbstractClientConnection returnCC = null;
+
+        if (storedEpConnections.containsKey(ep)) {
+            Long checkTime = System.currentTimeMillis() - connTimeOut;
+
+            Map<Endpoint, Set<AbstractClientConnection>> epConn2clean = 
+                new HashMap<Endpoint, Set<AbstractClientConnection>>();
+
+            Map<AbstractClientConnection, Long> storedCC = 
+                storedEpConnections.get(ep);
+
+            // iterate over the connections of the current EP
+            for (Iterator iter = storedCC.entrySet().iterator(); iter.hasNext();) {
+                Map.Entry pairs = (Map.Entry) iter.next();
+                AbstractClientConnection cc = (AbstractClientConnection) pairs
+                        .getKey();
+                Long ccTime = (Long) pairs.getValue();
+
+                // Anyway (usable or not) must be removed.
+                addConn2clean(epConn2clean, ep, cc);
+
+                if (ccTime < checkTime) {
+                    // Close the Connection and let the server know.
+                    cc.releaseConnection();
+                } else {
+                    returnCC = cc;
+                    try {
+                        returnCC.establishConnection();
+                    } catch (Exception e) {
+                        returnCC.releaseConnection();
+                        returnCC = null;
+                        continue;
+                    }
+                    break; // returnCC must be usable.
+                }
+            }
+            // Clean up the evicted connections from the Pool.
+            removeStoredCC(epConn2clean);
+        }
+        if (returnCC == null) {
+            // No usable connection was found in the Pool.
+            try {
+                returnCC = ClientConnectionFactory.getClientConnection(ep);
+                returnCC.establishConnection();
+            } catch (java.net.UnknownHostException e) {
+                throw new UnknownHostException("The host " + ep.getHost()
+                        + " is unreacheable", e);
+            } catch (java.net.ConnectException e) {
+                throw new java.rmi.ConnectException("Cannot connect to "
+                        + ep.getHost(), e);
+            } catch (IOException e) {
+                throw new ConnectIOException(
+                        "I/O exception Creating Connection", e);
+            }
+        }
+        return returnCC;
+    }
+
+    /**
+     * Adds a {@link org.apache.harmony.rmi.internal.transport.StreamClientConnection} on the
+     * table for a specified {@link org.apache.harmony.rmi.internal.transport.Endpoint} with the
+     * current time in milliseconds. <br>
+     * Notice that is only applicable to StreamOpClientConnection
+     * 
+     * @param ep
+     *            the specific {@link org.apache.harmony.rmi.internal.transport.Endpoint}
+     * @param clConn
+     *            the corresponding
+     *            {@link org.apache.harmony.rmi.internal.transport.StreamClientConnection} to
+     *            the specified {@link org.apache.harmony.rmi.internal.transport.Endpoint}.
+     */
+    public synchronized final void releaseClientConnection(Endpoint ep,
+            StreamClientConnection clConn) { // only applicable to stream
+        // connections
+
+        if (storedEpConnections.containsKey(ep)) {
+            storedEpConnections.get(ep).put(clConn, System.currentTimeMillis());
+        } else {
+            HashMap<AbstractClientConnection, Long> ccMap = new HashMap<AbstractClientConnection, Long>();
+            ccMap.put(clConn, System.currentTimeMillis());
+            storedEpConnections.put(ep, ccMap);
+        }
+    }
+
+    /**
+     * Iterate over <code>epConn2clean</code> and remove it from storedEpConnections. 
+     * If the current endPoint has no more connections available, then removes
+     * it from <code>storedEpConnections</code>
+     * 
+     * @param epConn2clean
+     *            it has all the connections to be remove
+     */
+    @SuppressWarnings("unchecked")
+    private synchronized final void removeStoredCC(
+            Map<Endpoint, Set<AbstractClientConnection>> epConn2clean) {
+        for (Iterator iter = epConn2clean.entrySet().iterator(); iter.hasNext();) {
+            Map.Entry pairs = (Map.Entry) iter.next();
+            Endpoint ep = (Endpoint) pairs.getKey();
+            Set<AbstractClientConnection> cc2remove = (Set<AbstractClientConnection>) pairs
+                    .getValue();
+
+            HashMap<AbstractClientConnection, Long> storedConnectionsMap = storedEpConnections
+                    .get(ep);
+
+            // for each connection in setCC2remove remove it from
+            // storedEpConnections
+            for (AbstractClientConnection cc : cc2remove) {
+                if (storedConnectionsMap.remove(cc) == null) {
+                    throw new AssertionError(); // type - safety
+                }
+            }
+
+            // if EP has not more cc eliminate it from storedEpConnections
+            if (storedConnectionsMap.isEmpty()) {
+                storedEpConnections.remove(ep);
+            }
+        }
+    }
+
+    /**
+     * Verifies that <code>epConn2Clean</code> contains a sets of connections.
+     * If not instantiates it and then adds the <code>cc</code> to this set.
+     * <br>
+     * After that, we insert or update the <code>ep</code> with the set of
+     * connections <code>cc2clean</code>
+     * 
+     * @param epConn2clean
+     *            the map which stores end points' connections to be cleaned
+     * @param ep
+     *            the current end point of the connections
+     * @param cc
+     *            the cc to be inserted in the Set
+     */
+    private static final void addConn2clean(
+            Map<Endpoint, Set<AbstractClientConnection>> epConn2clean,
+            Endpoint ep, AbstractClientConnection cc) {
+        Set<AbstractClientConnection> cc2clean = epConn2clean.get(ep);
+        if (cc2clean == null) {
+            cc2clean = new HashSet<AbstractClientConnection>();
+        }
+        cc2clean.add(cc);
+        epConn2clean.put(ep, cc2clean); // insert or replace the value....
+    }
+
+    /**
+     * Checks the pool for evicted connections.
+     */
+    private final class RipperTask extends TimerTask {
+
+        public synchronized final void run() {
+            Long checkTime = System.currentTimeMillis() - connTimeOut;
+
+            Map<Endpoint, Set<AbstractClientConnection>> epConn2clean = new HashMap<Endpoint, Set<AbstractClientConnection>>();
+
+            // iterate storedEpConnections
+            for (Iterator iter = storedEpConnections.entrySet().iterator(); iter
+                    .hasNext();) {
+
+                Map.Entry pairs = (Map.Entry) iter.next();
+                Endpoint ep = (Endpoint) pairs.getKey();
+                HashMap ccMap = (HashMap) pairs.getValue();
+
+                // iterate over the connection of the current EP
+                for (Iterator iter2 = ccMap.entrySet().iterator(); iter2
+                        .hasNext();) {
+                    Map.Entry pairs2 = (Map.Entry) iter2.next();
+                    AbstractClientConnection cc = (AbstractClientConnection) pairs2
+                            .getKey();
+                    Long time = (Long) pairs2.getValue();
+
+                    // checks cc life...
+                    if (time < checkTime) {
+                        cc.releaseConnection();
+                        addConn2clean(epConn2clean, ep, cc);
+                    }
+                }
+            }
+            if (!epConn2clean.isEmpty()) {
+                removeStoredCC(epConn2clean);
+            }
+        }
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/Endpoint.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/Endpoint.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/Endpoint.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/Endpoint.java Thu May 18 23:00:52 2006
@@ -1,231 +1,231 @@
-/* 
-*  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.net.InetAddress;
-import java.net.UnknownHostException;
-import java.rmi.server.RMIClientSocketFactory;
-
-import ar.org.fitc.rmi.utils.PropertiesReader;
-
-/**
- * This is a simple representation of an TCP/IP, UDP/IP endpoint.
- * 
- * @author Gustavo Petri
- */
-public final class Endpoint {
-
-    /**
-     * The address of the host.
-     */
-    private String host;
-
-    /**
-     * The TCP port.
-     */
-    private int port;
-
-    /**
-     * Client factory to use. If null, use default socket factory.
-     */
-    private RMIClientSocketFactory csf;
-
-    /**
-     * Default constructor needed by the
-     * {@link java.io.Serializable}
-     * interface
-     */
-    protected Endpoint() {
-    }
-
-    /**
-     * Constructs a new {@link ar.org.fitc.rmi.transport.Endpoint} with the specified
-     * port and csf.
-     * 
-     * @param port
-     *            the TCP/IP port
-     * @param csf
-     *            {@link java.rmi.server.RMIClientSocketFactory} instance
-     */
-    public Endpoint(int port, RMIClientSocketFactory csf) {
-
-        this.port = port;
-        this.csf = csf;
-        /*
-         * REVIEW: the exported host according to the java.rmi.server.hostname
-         * property.
-         */
-        this.host = PropertiesReader.readString("java.rmi.server.hostname");
-        if (this.host == null) {
-            try {
-                this.host = 
-                    (PropertiesReader.readString("java.rmi.server.useLocalHostname") != null) 
-                        ? InetAddress.getLocalHost().getHostName()
-                        : InetAddress.getLocalHost().getHostAddress();
-            } catch (UnknownHostException e) {
-                // REVIEW: This is the default value.
-                this.host = "localhost";
-            }
-        }
-    }
-
-    /**
-     * Constructs a new {@link ar.org.fitc.rmi.transport.Endpoint} with the specified
-     * hostname, port and csf.
-     * 
-     * @param host
-     *            The TCP/IP hostname
-     * @param port
-     *            port The TCP/IP port
-     * @param csf
-     *            {@link java.rmi.server.RMIClientSocketFactory} instance
-     */
-    public Endpoint(String host, int port, RMIClientSocketFactory csf) {
-        this.host = host;
-        this.port = port;
-        this.csf = csf;
-    }
-
-    /**
-     * Sets a {@link java.rmi.server.RMIClientSocketFactory} to be used by this
-     * {@link ar.org.fitc.rmi.transport.Endpoint}.
-     * 
-     * @param csf
-     *            csf {@link java.rmi.server.RMIClientSocketFactory} instance to
-     *            be setted
-     */
-    public final void setCsf(RMIClientSocketFactory csf) {
-        this.csf = csf;
-    }
-
-    /**
-     * Sets a the hostname to be used by this
-     * {@link ar.org.fitc.rmi.transport.Endpoint}.
-     * 
-     * @param host
-     *            The hostname to be setted
-     */
-    public final void setHost(String host) {
-        this.host = host;
-    }
-
-    /**
-     * Sets the port used by this {@link ar.org.fitc.rmi.transport.Endpoint}.
-     * 
-     * @param port
-     *            The port to be setted
-     */
-    public final void setPort(int port) {
-        this.port = port;
-    }
-
-    /**
-     * Returns the {@link java.rmi.server.RMIClientSocketFactory} instance used
-     * by this {@link ar.org.fitc.rmi.transport.Endpoint}.
-     * 
-     * @return the {@link java.rmi.server.RMIClientSocketFactory} instance used
-     *         by this {@link ar.org.fitc.rmi.transport.Endpoint}
-     */
-    public final RMIClientSocketFactory getCsf() {
-        return csf;
-    }
-
-    /**
-     * Returns the host used by this {@link ar.org.fitc.rmi.transport.Endpoint}.
-     * 
-     * @return the host used by this {@link ar.org.fitc.rmi.transport.Endpoint}
-     */
-    public final String getHost() {
-        return host;
-    }
-
-    /**
-     * Returns the port used by this {@link ar.org.fitc.rmi.transport.Endpoint}.
-     * 
-     * @return the port used by this {@link ar.org.fitc.rmi.transport.Endpoint}
-     */
-    public final int getPort() {
-        return port;
-    }
-
-    /**
-     * Returns an {@link ar.org.fitc.rmi.transport.Endpoint} identifying this
-     * {@link ar.org.fitc.rmi.transport.Endpoint}.
-     * 
-     * @return the {@link ar.org.fitc.rmi.transport.Endpoint} identifying this
-     *         {@link ar.org.fitc.rmi.transport.Endpoint}
-     */
-    public final EndpointID getEndpointID() {
-        return new EndpointID(host, port);
-    }
-
-    /**
-     * Test the parameter and this {@link ar.org.fitc.rmi.transport.Endpoint} for
-     * equality.
-     * 
-     * @param obj
-     *            the object to test for equality
-     * @return
-     *            <li><code>true</code>: if and only if the parameter and
-     *            this {@link ar.org.fitc.rmi.transport.Endpoint} instance are equal
-     *            <li><code>false</code> for every other case
-     */
-    @Override
-    public final boolean equals(Object obj) {
-        Endpoint castobj;
-
-        if (obj == null)
-            return false;
-        if (obj == this)
-            return true;
-        if (!(obj instanceof Endpoint))
-            return false;
-        castobj = (Endpoint) obj;
-        try {
-            return ((castobj.port == this.port && castobj.host.equals(this.host)) 
-                    && ((this.csf == null && castobj.csf == null) 
-                            || this.csf.equals(castobj.csf)));
-        } catch (NullPointerException e) {
-            return false;
-        }
-    }
-
-    /**
-     * Returns a hashCode for this instance.
-     * 
-     * @return the <code>HashCode</code>.
-     */
-    @Override
-    public final int hashCode() {
-
-        if (this.host != null) {
-            return this.host.hashCode() ^ this.port;
-        }
-        return 0;
-    }
-
-    /**
-     * Returns the <code>String</code> representation of this
-     * {@link ar.org.fitc.rmi.transport.Endpoint}.
-     * 
-     * @return the <code>String</code> representation of this
-     *         {@link ar.org.fitc.rmi.transport.Endpoint}
-     */
-    @Override
-    public final String toString() {
-        return "[" + this.host + ", " + this.port + "]";
-    }
-}
+/* 
+*  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.net.InetAddress;
+import java.net.UnknownHostException;
+import java.rmi.server.RMIClientSocketFactory;
+
+import org.apache.harmony.rmi.internal.utils.PropertiesReader;
+
+/**
+ * This is a simple representation of an TCP/IP, UDP/IP endpoint.
+ * 
+ * @author Gustavo Petri
+ */
+public final class Endpoint {
+
+    /**
+     * The address of the host.
+     */
+    private String host;
+
+    /**
+     * The TCP port.
+     */
+    private int port;
+
+    /**
+     * Client factory to use. If null, use default socket factory.
+     */
+    private RMIClientSocketFactory csf;
+
+    /**
+     * Default constructor needed by the
+     * {@link java.io.Serializable}
+     * interface
+     */
+    protected Endpoint() {
+    }
+
+    /**
+     * Constructs a new {@link org.apache.harmony.rmi.internal.transport.Endpoint} with the specified
+     * port and csf.
+     * 
+     * @param port
+     *            the TCP/IP port
+     * @param csf
+     *            {@link java.rmi.server.RMIClientSocketFactory} instance
+     */
+    public Endpoint(int port, RMIClientSocketFactory csf) {
+
+        this.port = port;
+        this.csf = csf;
+        /*
+         * REVIEW: the exported host according to the java.rmi.server.hostname
+         * property.
+         */
+        this.host = PropertiesReader.readString("java.rmi.server.hostname");
+        if (this.host == null) {
+            try {
+                this.host = 
+                    (PropertiesReader.readString("java.rmi.server.useLocalHostname") != null) 
+                        ? InetAddress.getLocalHost().getHostName()
+                        : InetAddress.getLocalHost().getHostAddress();
+            } catch (UnknownHostException e) {
+                // REVIEW: This is the default value.
+                this.host = "localhost";
+            }
+        }
+    }
+
+    /**
+     * Constructs a new {@link org.apache.harmony.rmi.internal.transport.Endpoint} with the specified
+     * hostname, port and csf.
+     * 
+     * @param host
+     *            The TCP/IP hostname
+     * @param port
+     *            port The TCP/IP port
+     * @param csf
+     *            {@link java.rmi.server.RMIClientSocketFactory} instance
+     */
+    public Endpoint(String host, int port, RMIClientSocketFactory csf) {
+        this.host = host;
+        this.port = port;
+        this.csf = csf;
+    }
+
+    /**
+     * Sets a {@link java.rmi.server.RMIClientSocketFactory} to be used by this
+     * {@link org.apache.harmony.rmi.internal.transport.Endpoint}.
+     * 
+     * @param csf
+     *            csf {@link java.rmi.server.RMIClientSocketFactory} instance to
+     *            be setted
+     */
+    public final void setCsf(RMIClientSocketFactory csf) {
+        this.csf = csf;
+    }
+
+    /**
+     * Sets a the hostname to be used by this
+     * {@link org.apache.harmony.rmi.internal.transport.Endpoint}.
+     * 
+     * @param host
+     *            The hostname to be setted
+     */
+    public final void setHost(String host) {
+        this.host = host;
+    }
+
+    /**
+     * Sets the port used by this {@link org.apache.harmony.rmi.internal.transport.Endpoint}.
+     * 
+     * @param port
+     *            The port to be setted
+     */
+    public final void setPort(int port) {
+        this.port = port;
+    }
+
+    /**
+     * Returns the {@link java.rmi.server.RMIClientSocketFactory} instance used
+     * by this {@link org.apache.harmony.rmi.internal.transport.Endpoint}.
+     * 
+     * @return the {@link java.rmi.server.RMIClientSocketFactory} instance used
+     *         by this {@link org.apache.harmony.rmi.internal.transport.Endpoint}
+     */
+    public final RMIClientSocketFactory getCsf() {
+        return csf;
+    }
+
+    /**
+     * Returns the host used by this {@link org.apache.harmony.rmi.internal.transport.Endpoint}.
+     * 
+     * @return the host used by this {@link org.apache.harmony.rmi.internal.transport.Endpoint}
+     */
+    public final String getHost() {
+        return host;
+    }
+
+    /**
+     * Returns the port used by this {@link org.apache.harmony.rmi.internal.transport.Endpoint}.
+     * 
+     * @return the port used by this {@link org.apache.harmony.rmi.internal.transport.Endpoint}
+     */
+    public final int getPort() {
+        return port;
+    }
+
+    /**
+     * Returns an {@link org.apache.harmony.rmi.internal.transport.Endpoint} identifying this
+     * {@link org.apache.harmony.rmi.internal.transport.Endpoint}.
+     * 
+     * @return the {@link org.apache.harmony.rmi.internal.transport.Endpoint} identifying this
+     *         {@link org.apache.harmony.rmi.internal.transport.Endpoint}
+     */
+    public final EndpointID getEndpointID() {
+        return new EndpointID(host, port);
+    }
+
+    /**
+     * Test the parameter and this {@link org.apache.harmony.rmi.internal.transport.Endpoint} for
+     * equality.
+     * 
+     * @param obj
+     *            the object to test for equality
+     * @return
+     *            <li><code>true</code>: if and only if the parameter and
+     *            this {@link org.apache.harmony.rmi.internal.transport.Endpoint} instance are equal
+     *            <li><code>false</code> for every other case
+     */
+    @Override
+    public final boolean equals(Object obj) {
+        Endpoint castobj;
+
+        if (obj == null)
+            return false;
+        if (obj == this)
+            return true;
+        if (!(obj instanceof Endpoint))
+            return false;
+        castobj = (Endpoint) obj;
+        try {
+            return ((castobj.port == this.port && castobj.host.equals(this.host)) 
+                    && ((this.csf == null && castobj.csf == null) 
+                            || this.csf.equals(castobj.csf)));
+        } catch (NullPointerException e) {
+            return false;
+        }
+    }
+
+    /**
+     * Returns a hashCode for this instance.
+     * 
+     * @return the <code>HashCode</code>.
+     */
+    @Override
+    public final int hashCode() {
+
+        if (this.host != null) {
+            return this.host.hashCode() ^ this.port;
+        }
+        return 0;
+    }
+
+    /**
+     * Returns the <code>String</code> representation of this
+     * {@link org.apache.harmony.rmi.internal.transport.Endpoint}.
+     * 
+     * @return the <code>String</code> representation of this
+     *         {@link org.apache.harmony.rmi.internal.transport.Endpoint}
+     */
+    @Override
+    public final String toString() {
+        return "[" + this.host + ", " + this.port + "]";
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/EndpointID.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/EndpointID.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/EndpointID.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/EndpointID.java Thu May 18 23:00:52 2006
@@ -1,124 +1,124 @@
-/* 
-*  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.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-
-/**
- * Simple representation of a TCP/IP Endpoint.
- * 
- * @author Gustavo Petri
- */
-public final class EndpointID {
-
-    // This class is insipired on
-    // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4674902
-    // Probably this should implement a EdpointID interface, and
-    // should be called TCPEndpointID.
-    /**
-     * The host name.
-     */
-    private String host;
-
-    /**
-     * The port.
-     */
-    private int port;
-
-    /**
-     * Constructor needed by the
-     * {@link java.io.Serializable}
-     * interface.
-     */
-
-    public EndpointID() {
-        host = ""; // This initialization to "" is because the
-        // java.io.ObjectOutputStream.writeUTF
-        // method cannot send a null value.
-        port = -1;
-    }
-
-    /**
-     * Constructor of this class.
-     * 
-     * @param host
-     *            the host of the {@link ar.org.fitc.rmi.transport.Endpoint}
-     * @param port
-     *            the port of the {@link ar.org.fitc.rmi.transport.Endpoint}
-     */
-    public EndpointID(String host, int port) {
-        this.host = host;
-        this.port = port;
-    }
-
-    /**
-     * Returns the host of the {@link ar.org.fitc.rmi.transport.Endpoint}.
-     * 
-     * @return the host of the {@link ar.org.fitc.rmi.transport.Endpoint}.
-     */
-    public final String getHost() {
-
-        return this.host;
-    }
-
-    /**
-     * Returns the port of the {@link ar.org.fitc.rmi.transport.Endpoint}.
-     * 
-     * @return the port of the {@link ar.org.fitc.rmi.transport.Endpoint}.
-     */
-    public final int getPort() {
-
-        return this.port;
-    }
-
-    /**
-     * Writes this {@link ar.org.fitc.rmi.transport.EndpointID} to the specified
-     * <code>ObjectOutputStream</code>.
-     * 
-     * @param out
-     *            the <code>ObjectOutputStream</code> where this
-     *            {@link ar.org.fitc.rmi.transport.EndpointID} will be written.
-     * @throws IOException
-     *             if the write fails
-     */
-    public final void write(DataOutput out) throws IOException {
-
-        out.writeUTF(this.host);
-        out.writeInt(this.port);
-        return;
-    }
-
-    /**
-     * Reads a new {@link ar.org.fitc.rmi.transport.EndpointID} from the specified
-     * <code>ObjectInputStream</code>.
-     * 
-     * @param in
-     *            the <code>ObjectInputStream</code> from where the
-     *            {@link ar.org.fitc.rmi.transport.EndpointID} will be read.
-     * @return a new {@link ar.org.fitc.rmi.transport.EndpointID}
-     * @throws IOException
-     *             if the write fails
-     */
-    public final static EndpointID read(DataInput in) throws IOException {
-
-        EndpointID ep = new EndpointID();
-        ep.host = in.readUTF();
-        ep.port = in.readInt();
-        return ep;
-    }
+/* 
+*  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.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+/**
+ * Simple representation of a TCP/IP Endpoint.
+ * 
+ * @author Gustavo Petri
+ */
+public final class EndpointID {
+
+    // This class is insipired on
+    // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4674902
+    // Probably this should implement a EdpointID interface, and
+    // should be called TCPEndpointID.
+    /**
+     * The host name.
+     */
+    private String host;
+
+    /**
+     * The port.
+     */
+    private int port;
+
+    /**
+     * Constructor needed by the
+     * {@link java.io.Serializable}
+     * interface.
+     */
+
+    public EndpointID() {
+        host = ""; // This initialization to "" is because the
+        // java.io.ObjectOutputStream.writeUTF
+        // method cannot send a null value.
+        port = -1;
+    }
+
+    /**
+     * Constructor of this class.
+     * 
+     * @param host
+     *            the host of the {@link org.apache.harmony.rmi.internal.transport.Endpoint}
+     * @param port
+     *            the port of the {@link org.apache.harmony.rmi.internal.transport.Endpoint}
+     */
+    public EndpointID(String host, int port) {
+        this.host = host;
+        this.port = port;
+    }
+
+    /**
+     * Returns the host of the {@link org.apache.harmony.rmi.internal.transport.Endpoint}.
+     * 
+     * @return the host of the {@link org.apache.harmony.rmi.internal.transport.Endpoint}.
+     */
+    public final String getHost() {
+
+        return this.host;
+    }
+
+    /**
+     * Returns the port of the {@link org.apache.harmony.rmi.internal.transport.Endpoint}.
+     * 
+     * @return the port of the {@link org.apache.harmony.rmi.internal.transport.Endpoint}.
+     */
+    public final int getPort() {
+
+        return this.port;
+    }
+
+    /**
+     * Writes this {@link org.apache.harmony.rmi.internal.transport.EndpointID} to the specified
+     * <code>ObjectOutputStream</code>.
+     * 
+     * @param out
+     *            the <code>ObjectOutputStream</code> where this
+     *            {@link org.apache.harmony.rmi.internal.transport.EndpointID} will be written.
+     * @throws IOException
+     *             if the write fails
+     */
+    public final void write(DataOutput out) throws IOException {
+
+        out.writeUTF(this.host);
+        out.writeInt(this.port);
+        return;
+    }
+
+    /**
+     * Reads a new {@link org.apache.harmony.rmi.internal.transport.EndpointID} from the specified
+     * <code>ObjectInputStream</code>.
+     * 
+     * @param in
+     *            the <code>ObjectInputStream</code> from where the
+     *            {@link org.apache.harmony.rmi.internal.transport.EndpointID} will be read.
+     * @return a new {@link org.apache.harmony.rmi.internal.transport.EndpointID}
+     * @throws IOException
+     *             if the write fails
+     */
+    public final static EndpointID read(DataInput in) throws IOException {
+
+        EndpointID ep = new EndpointID();
+        ep.host = in.readUTF();
+        ep.port = in.readInt();
+        return ep;
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/FallBackType.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/FallBackType.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/FallBackType.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/FallBackType.java Thu May 18 23:00:52 2006
@@ -1,45 +1,45 @@
-/* 
-*  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;
-
-/*
- * NOTE: 
- * This class has been modified in order to support 
- * Java VM 1.4.2 using the javac's target jsr14 
- */
-
-/**
- * This class if for RMIDefaultSocketFactory purposes
- * 
- * @author Diego Raúl Mercado
- */
-class FallBackType {
-    
-    /**
-     * Direct Connection with the server
-     */
-    final static FallBackType DIRECT = new FallBackType(); 
-    
-    /**
-     * Connection traversing a Proxy 
-     */
-    final static FallBackType PROXY = new FallBackType(); 
-    
-    /**
-     * Connection traversing a Proxy and redirecting through a cgi script
-     */
-    final static FallBackType CGI = new FallBackType();
-}
+/* 
+*  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;
+
+/*
+ * NOTE: 
+ * This class has been modified in order to support 
+ * Java VM 1.4.2 using the javac's target jsr14 
+ */
+
+/**
+ * This class if for RMIDefaultSocketFactory purposes
+ * 
+ * @author Diego Raúl Mercado
+ */
+class FallBackType {
+    
+    /**
+     * Direct Connection with the server
+     */
+    final static FallBackType DIRECT = new FallBackType(); 
+    
+    /**
+     * Connection traversing a Proxy 
+     */
+    final static FallBackType PROXY = new FallBackType(); 
+    
+    /**
+     * Connection traversing a Proxy and redirecting through a cgi script
+     */
+    final static FallBackType CGI = new FallBackType();
+}