harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r407724 [7/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...
Date Fri, 19 May 2006 06:00:56 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/MultiThreadedServer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/MultiThreadedServer.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/MultiThreadedServer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/MultiThreadedServer.java Thu May 18 23:00:52 2006
@@ -1,369 +1,369 @@
-/* 
-*  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.ServerSocket;
-import java.net.Socket;
-import java.rmi.server.ExportException;
-import java.rmi.server.RMIFailureHandler;
-import java.rmi.server.RMIServerSocketFactory;
-import java.rmi.server.RMISocketFactory;
-import java.util.Map;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-
-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 
- */
-
-/**
- * Implements a {@link ThreadPoolExecutor} that executes each submitted task using one
- * of possibly several pooled threads. The {@link ThreadPoolExecutor} uses a
- * {@link BlockingQueue} to transfer and hold submitted tasks.
- * <p>
- * <li>The pool size is configured through the property <EM>ar.org.fitc.rmi.server.threadPoolCoreSize</EM>,
- * the default value is <EM>10</EM>.
- * <li>The maximum pool size is configured through the property <EM>ar.org.fitc.rmi.server.threadPoolMaxSize</EM>,
- * the default value is <EM>Integer.MAX_VALUE</EM>.
- * <li>The keep alive time of the thread waiting in the pool is configured
- * through the property <EM>ar.org.fitc.rmi.server.threadPoolKeepAliveTime</EM> ,
- * the default value is <EM>60000</EM> in milliseconds.
- * <li>Finally, the capacity of the queue is configured through the property
- * <EM>ar.org.fitc.rmi.server.threadPoolQueueSize</EM>, the default value is
- * <EM>0</EM>.
- * 
- * <p>
- * This class has an internal class:
- * {@link ar.org.fitc.rmi.transport.MultiThreadedServer.ServerRequestTask}
- * 
- * @author Marcelo Arcidiacono
- * @author Gustavo Petri
- */
-final class MultiThreadedServer extends Thread {
-
-//    /**
-//     * The blocking queue which is used to transfer and hold submitted tasks.
-//     */
-//    private static BlockingQueue<Runnable> queue;
-//
-//    /**
-//     * The thread pool that executes each submitted task.
-//     */
-//    private static ThreadPoolExecutor threadPool = null;
-//
-//    static {
-//        Integer poolSize;
-//        Integer maxPoolSize;
-//        Long keepAliveTime;
-//        Integer queueCapacity;
-//        
-//        poolSize = PropertiesReader.readInt(
-//                "ar.org.fitc.rmi.server.threadPoolCoreSize", 10);
-//
-//        maxPoolSize = PropertiesReader.readInt(
-//                "ar.org.fitc.rmi.server.threadPoolMaxSize", Integer.MAX_VALUE);
-//        
-//        keepAliveTime = PropertiesReader.readLong(
-//                "ar.org.fitc.rmi.server.threadPoolKeepAliveTime", 60000);        
-//
-//        queueCapacity = PropertiesReader.readInt(
-//                "ar.org.fitc.rmi.server.threadPoolQueueSize", 0);
-//
-//        queue = (queueCapacity == 0) ? new SynchronousQueue<Runnable>()
-//                : new ArrayBlockingQueue<Runnable>(queueCapacity);
-//        
-//        threadPool = new ThreadPoolExecutor(poolSize, maxPoolSize,
-//                keepAliveTime, TimeUnit.MILLISECONDS, queue,
-//                new SimpleThreadFactory());
-//        threadPool.prestartAllCoreThreads();
-//    }
-
-    /**
-     * Indicates if the serverSocket will not accept any incoming call, the
-     * default value is <code>true</code>.
-     */
-    private volatile boolean notFinish;
-
-    /**
-     * The specified port number.
-     */
-    private int port;
-
-    /**
-     * The server socket that waits for requests.
-     */
-    private ServerSocket serverSocket;
-
-    /**
-     * Associated with a remote object to obtain the
-     * {@link java.net.ServerSocket} which is used to accept incoming calls from
-     * clients.
-     */
-    private RMIServerSocketFactory ssf;
-
-    /**
-     * Constructor for the {@link MultiThreadedServer}. In order to
-     * guarantee serial access creates a synchronized (thread-safe) map backed
-     * by the specified map.
-     * 
-     * @param ssf
-     *            the specified {@link java.rmi.server.RMIServerSocketFactory}
-     * @param port
-     *            the specified number of port
-     * @throws ExportException
-     *             if the exportation is not successful
-     */
-    public MultiThreadedServer(RMIServerSocketFactory ssf, int port)
-            throws ExportException {
-        this.ssf = ssf;
-        this.port = port;
-        try {
-            this.serverSocket = createServerSocket();
-        } catch (IOException e) {
-            throw new ExportException("Exception happened during exportation",
-                    e);
-        }
-        this.setName("MultiThreadedServer" + serverSocket);
-        this.notFinish = true;
-    }
-
-    /**
-     * Executes a task on one of the several pooled threads.
-     * 
-     * @param client
-     *            the client socket
-     * @param clientEP
-     *            the {@link ar.org.fitc.rmi.transport.EndpointID} associated to
-     *            client
-     * @throws IOException
-     *             if the connection failed
-     */
-    private final void serverRequests(Socket client, EndpointID clientEP)
-            throws IOException {
-        AbstractServerConnection server = ServerConnectionFactory
-                .getServerConnection(client.getInputStream(), 
-                        client.getOutputStream(), clientEP, client);
-//        threadPool.execute(new ServerRequestTask(client, server));
-        Thread thread = new Thread(new ServerRequestTask(client, server));
-        thread.setDaemon(true);
-        thread.start();
-    }
-
-    /**
-     * Implements the retrial of reconnections when a failure occurs in the 
-     * {@link ServerSocket#accept()} method 
-     * 
-     * @see <a href="http://archives.java.sun.com/cgi-bin/wa?A2=ind9909&L=rmi-users&D=0&I=-3&P=22293">User Archives</a>
-     * @param acceptException
-     *            the exception which was thrown when the accept method failed
-     */
-    private final void handleServerSocketFailure(IOException acceptException) {
-        RMIFailureHandler fh = RMISocketFactory.getFailureHandler();
-        if (fh == null) {
-            // There isn't any FailureHandler installed. Retry 10 times every 10
-            // seconds.
-            int retry = 0;
-            while (retry < 10 && notFinish) {
-                try {
-                    Thread.sleep(10000);
-                } catch (InterruptedException e) {
-                }
-                try {
-                    serverSocket = createServerSocket();
-                    break;
-                } catch (IOException e) {
-                    retry++;
-                }
-            }
-            if (retry >= 10) {
-                notFinish = false;
-            }
-        } else {
-            // There is a FailureHandler installed. Ask to FailureHandler for
-            // retries.
-            boolean retry = fh.failure(acceptException);
-            while (retry && notFinish) {
-                try {
-                    serverSocket = createServerSocket();
-                    break;
-                } catch (IOException createSocketException) {
-                    retry = fh.failure(createSocketException);
-                }
-            }
-            if (!retry) {
-                notFinish = false;
-            }
-        }
-    }
-
-    /**
-     * Creates a {@link java.net.ServerSocket}.
-     * 
-     * @return a {@link java.net.ServerSocket}
-     * @throws IOException
-     *             if the creation fails
-     */
-    private final ServerSocket createServerSocket() throws IOException {
-        ServerSocket serverSocket;
-        RMISocketFactory socketFactory;
-        if (ssf == null) {
-            socketFactory = RMISocketFactory.getSocketFactory();
-            if (socketFactory == null) {
-                socketFactory = RMISocketFactory.getDefaultSocketFactory();
-            }
-            serverSocket = socketFactory.createServerSocket(port);
-        } else {
-            serverSocket = ssf.createServerSocket(port);
-        }
-        return serverSocket;
-    }
-
-    /**
-     * Returns the local port number of the {@link java.net.ServerSocket}.
-     * 
-     * @return the local port number of the {@link java.net.ServerSocket}
-     */
-    public final int getLocalPort() {
-        return serverSocket.getLocalPort();
-    }
-
-    /**
-     * Listens for a connection to be made to this socket and accepts it. The
-     * method blocks until a connection is made.
-     * 
-     * @see <a
-     *      href="http://archives.java.sun.com/cgi-bin/wa?A2=ind9909&L=rmi-users&D=0&I=-3&P=22293">User Archives</a>
-     */
-    @Override
-    public void run() {
-        Socket newClient;
-        while (notFinish) {
-            try {
-                newClient = serverSocket.accept();
-                // FIXME Make a private setSocketProperties method
-                newClient.setTcpNoDelay(true);
-                EndpointID clientEndpointID = new EndpointID(newClient
-                        .getInetAddress().getHostAddress(), newClient.getPort());
-                try {
-                    serverRequests(newClient, clientEndpointID);
-                } catch (IOException e) {
-                    if (notFinish) {
-                        /*
-                         * Any recovering acction should be done here if needed
-                         * be.
-                         */
-                    }
-                }
-            } catch (IOException acceptException) {
-                if (notFinish) {
-                    // serversocket.accept() has failed. Ask RMIFailureHandler
-                    // for retries.
-                    try {
-                        serverSocket.close();
-                    } catch (IOException e) {
-                    }
-                    handleServerSocketFailure(acceptException);
-                }
-            }
-        }
-    }
-
-    /**
-     * Close the {@link java.net.ServerSocket}.
-     * 
-     * @throws IOException
-     *             if the {@link java.net.ServerSocket} cannot to close
-     */
-    public final void stopServing() throws IOException {
-        this.serverSocket.close();
-        this.notFinish = false;
-    }
-
-    /**
-     * Defines the task submitted in the Thread Pool
-     * 
-     * @author Marcelo Arcidiacono
-     * @author Gustavo Petri
-     */
-    private final class ServerRequestTask implements Runnable {
-
-        /**
-         * The client socket
-         */
-        private Socket client;
-
-        /**
-         * The server connection.SO_REUSEADDR
-         */
-        private AbstractServerConnection server;
-
-        /**
-         * Constructor for the {@link ServerRequestTask}
-         * 
-         * @param client
-         *            the especified client socket
-         * @param server
-         *            the especified server connection
-         */
-        public ServerRequestTask(Socket client, AbstractServerConnection server) {
-            this.client = client;
-            this.server = server;
-        }
-
-        /**
-         * Serves a connection
-         */
-        public final void run() {
-            Map<Integer, Pair<String, Integer>> clientConnectionMap = 
-                TransportManager.getTransportManager().getClientConnectionMap();
-            
-            clientConnectionMap.put(Thread.currentThread().hashCode(),
-                    new Pair<String, Integer>(client.getInetAddress()
-                            .getHostAddress(), new Integer(server.getConnectionID())));
-            try {
-                server.establishConnection();
-                while (true) {
-                    server.serve();
-                }
-            } catch (Exception e) {
-                server.releaseConnection();
-                server = null;
-                // FIXME REVIEW: May be some logging would be useful here.
-                // Also any recovery action should be called here.
-            }
-        }
-    }
-}
-
-///**
-// * A factory of a simple thread
-// * 
-// * @author Marcelo Arcidiacono
-// * @author Gustavo Petri
-// */
-//final class SimpleThreadFactory implements ThreadFactory {
-//  
-//    public final Thread newThread(Runnable r) {
-//        Thread thread = new Thread(r);
-//        thread.setDaemon(true);
-//        return thread;
-//    }
+/* 
+*  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.ServerSocket;
+import java.net.Socket;
+import java.rmi.server.ExportException;
+import java.rmi.server.RMIFailureHandler;
+import java.rmi.server.RMIServerSocketFactory;
+import java.rmi.server.RMISocketFactory;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+
+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 
+ */
+
+/**
+ * Implements a {@link ThreadPoolExecutor} that executes each submitted task using one
+ * of possibly several pooled threads. The {@link ThreadPoolExecutor} uses a
+ * {@link BlockingQueue} to transfer and hold submitted tasks.
+ * <p>
+ * <li>The pool size is configured through the property <EM>org.apache.harmony.rmi.internal.server.threadPoolCoreSize</EM>,
+ * the default value is <EM>10</EM>.
+ * <li>The maximum pool size is configured through the property <EM>org.apache.harmony.rmi.internal.server.threadPoolMaxSize</EM>,
+ * the default value is <EM>Integer.MAX_VALUE</EM>.
+ * <li>The keep alive time of the thread waiting in the pool is configured
+ * through the property <EM>org.apache.harmony.rmi.internal.server.threadPoolKeepAliveTime</EM> ,
+ * the default value is <EM>60000</EM> in milliseconds.
+ * <li>Finally, the capacity of the queue is configured through the property
+ * <EM>org.apache.harmony.rmi.internal.server.threadPoolQueueSize</EM>, the default value is
+ * <EM>0</EM>.
+ * 
+ * <p>
+ * This class has an internal class:
+ * {@link org.apache.harmony.rmi.internal.transport.MultiThreadedServer.ServerRequestTask}
+ * 
+ * @author Marcelo Arcidiacono
+ * @author Gustavo Petri
+ */
+final class MultiThreadedServer extends Thread {
+
+//    /**
+//     * The blocking queue which is used to transfer and hold submitted tasks.
+//     */
+//    private static BlockingQueue<Runnable> queue;
+//
+//    /**
+//     * The thread pool that executes each submitted task.
+//     */
+//    private static ThreadPoolExecutor threadPool = null;
+//
+//    static {
+//        Integer poolSize;
+//        Integer maxPoolSize;
+//        Long keepAliveTime;
+//        Integer queueCapacity;
+//        
+//        poolSize = PropertiesReader.readInt(
+//                "org.apache.harmony.rmi.internal.server.threadPoolCoreSize", 10);
+//
+//        maxPoolSize = PropertiesReader.readInt(
+//                "org.apache.harmony.rmi.internal.server.threadPoolMaxSize", Integer.MAX_VALUE);
+//        
+//        keepAliveTime = PropertiesReader.readLong(
+//                "org.apache.harmony.rmi.internal.server.threadPoolKeepAliveTime", 60000);        
+//
+//        queueCapacity = PropertiesReader.readInt(
+//                "org.apache.harmony.rmi.internal.server.threadPoolQueueSize", 0);
+//
+//        queue = (queueCapacity == 0) ? new SynchronousQueue<Runnable>()
+//                : new ArrayBlockingQueue<Runnable>(queueCapacity);
+//        
+//        threadPool = new ThreadPoolExecutor(poolSize, maxPoolSize,
+//                keepAliveTime, TimeUnit.MILLISECONDS, queue,
+//                new SimpleThreadFactory());
+//        threadPool.prestartAllCoreThreads();
+//    }
+
+    /**
+     * Indicates if the serverSocket will not accept any incoming call, the
+     * default value is <code>true</code>.
+     */
+    private volatile boolean notFinish;
+
+    /**
+     * The specified port number.
+     */
+    private int port;
+
+    /**
+     * The server socket that waits for requests.
+     */
+    private ServerSocket serverSocket;
+
+    /**
+     * Associated with a remote object to obtain the
+     * {@link java.net.ServerSocket} which is used to accept incoming calls from
+     * clients.
+     */
+    private RMIServerSocketFactory ssf;
+
+    /**
+     * Constructor for the {@link MultiThreadedServer}. In order to
+     * guarantee serial access creates a synchronized (thread-safe) map backed
+     * by the specified map.
+     * 
+     * @param ssf
+     *            the specified {@link java.rmi.server.RMIServerSocketFactory}
+     * @param port
+     *            the specified number of port
+     * @throws ExportException
+     *             if the exportation is not successful
+     */
+    public MultiThreadedServer(RMIServerSocketFactory ssf, int port)
+            throws ExportException {
+        this.ssf = ssf;
+        this.port = port;
+        try {
+            this.serverSocket = createServerSocket();
+        } catch (IOException e) {
+            throw new ExportException("Exception happened during exportation",
+                    e);
+        }
+        this.setName("MultiThreadedServer" + serverSocket);
+        this.notFinish = true;
+    }
+
+    /**
+     * Executes a task on one of the several pooled threads.
+     * 
+     * @param client
+     *            the client socket
+     * @param clientEP
+     *            the {@link org.apache.harmony.rmi.internal.transport.EndpointID} associated to
+     *            client
+     * @throws IOException
+     *             if the connection failed
+     */
+    private final void serverRequests(Socket client, EndpointID clientEP)
+            throws IOException {
+        AbstractServerConnection server = ServerConnectionFactory
+                .getServerConnection(client.getInputStream(), 
+                        client.getOutputStream(), clientEP, client);
+//        threadPool.execute(new ServerRequestTask(client, server));
+        Thread thread = new Thread(new ServerRequestTask(client, server));
+        thread.setDaemon(true);
+        thread.start();
+    }
+
+    /**
+     * Implements the retrial of reconnections when a failure occurs in the 
+     * {@link ServerSocket#accept()} method 
+     * 
+     * @see <a href="http://archives.java.sun.com/cgi-bin/wa?A2=ind9909&L=rmi-users&D=0&I=-3&P=22293">User Archives</a>
+     * @param acceptException
+     *            the exception which was thrown when the accept method failed
+     */
+    private final void handleServerSocketFailure(IOException acceptException) {
+        RMIFailureHandler fh = RMISocketFactory.getFailureHandler();
+        if (fh == null) {
+            // There isn't any FailureHandler installed. Retry 10 times every 10
+            // seconds.
+            int retry = 0;
+            while (retry < 10 && notFinish) {
+                try {
+                    Thread.sleep(10000);
+                } catch (InterruptedException e) {
+                }
+                try {
+                    serverSocket = createServerSocket();
+                    break;
+                } catch (IOException e) {
+                    retry++;
+                }
+            }
+            if (retry >= 10) {
+                notFinish = false;
+            }
+        } else {
+            // There is a FailureHandler installed. Ask to FailureHandler for
+            // retries.
+            boolean retry = fh.failure(acceptException);
+            while (retry && notFinish) {
+                try {
+                    serverSocket = createServerSocket();
+                    break;
+                } catch (IOException createSocketException) {
+                    retry = fh.failure(createSocketException);
+                }
+            }
+            if (!retry) {
+                notFinish = false;
+            }
+        }
+    }
+
+    /**
+     * Creates a {@link java.net.ServerSocket}.
+     * 
+     * @return a {@link java.net.ServerSocket}
+     * @throws IOException
+     *             if the creation fails
+     */
+    private final ServerSocket createServerSocket() throws IOException {
+        ServerSocket serverSocket;
+        RMISocketFactory socketFactory;
+        if (ssf == null) {
+            socketFactory = RMISocketFactory.getSocketFactory();
+            if (socketFactory == null) {
+                socketFactory = RMISocketFactory.getDefaultSocketFactory();
+            }
+            serverSocket = socketFactory.createServerSocket(port);
+        } else {
+            serverSocket = ssf.createServerSocket(port);
+        }
+        return serverSocket;
+    }
+
+    /**
+     * Returns the local port number of the {@link java.net.ServerSocket}.
+     * 
+     * @return the local port number of the {@link java.net.ServerSocket}
+     */
+    public final int getLocalPort() {
+        return serverSocket.getLocalPort();
+    }
+
+    /**
+     * Listens for a connection to be made to this socket and accepts it. The
+     * method blocks until a connection is made.
+     * 
+     * @see <a
+     *      href="http://archives.java.sun.com/cgi-bin/wa?A2=ind9909&L=rmi-users&D=0&I=-3&P=22293">User Archives</a>
+     */
+    @Override
+    public void run() {
+        Socket newClient;
+        while (notFinish) {
+            try {
+                newClient = serverSocket.accept();
+                // FIXME Make a private setSocketProperties method
+                newClient.setTcpNoDelay(true);
+                EndpointID clientEndpointID = new EndpointID(newClient
+                        .getInetAddress().getHostAddress(), newClient.getPort());
+                try {
+                    serverRequests(newClient, clientEndpointID);
+                } catch (IOException e) {
+                    if (notFinish) {
+                        /*
+                         * Any recovering acction should be done here if needed
+                         * be.
+                         */
+                    }
+                }
+            } catch (IOException acceptException) {
+                if (notFinish) {
+                    // serversocket.accept() has failed. Ask RMIFailureHandler
+                    // for retries.
+                    try {
+                        serverSocket.close();
+                    } catch (IOException e) {
+                    }
+                    handleServerSocketFailure(acceptException);
+                }
+            }
+        }
+    }
+
+    /**
+     * Close the {@link java.net.ServerSocket}.
+     * 
+     * @throws IOException
+     *             if the {@link java.net.ServerSocket} cannot to close
+     */
+    public final void stopServing() throws IOException {
+        this.serverSocket.close();
+        this.notFinish = false;
+    }
+
+    /**
+     * Defines the task submitted in the Thread Pool
+     * 
+     * @author Marcelo Arcidiacono
+     * @author Gustavo Petri
+     */
+    private final class ServerRequestTask implements Runnable {
+
+        /**
+         * The client socket
+         */
+        private Socket client;
+
+        /**
+         * The server connection.SO_REUSEADDR
+         */
+        private AbstractServerConnection server;
+
+        /**
+         * Constructor for the {@link ServerRequestTask}
+         * 
+         * @param client
+         *            the especified client socket
+         * @param server
+         *            the especified server connection
+         */
+        public ServerRequestTask(Socket client, AbstractServerConnection server) {
+            this.client = client;
+            this.server = server;
+        }
+
+        /**
+         * Serves a connection
+         */
+        public final void run() {
+            Map<Integer, Pair<String, Integer>> clientConnectionMap = 
+                TransportManager.getTransportManager().getClientConnectionMap();
+            
+            clientConnectionMap.put(Thread.currentThread().hashCode(),
+                    new Pair<String, Integer>(client.getInetAddress()
+                            .getHostAddress(), new Integer(server.getConnectionID())));
+            try {
+                server.establishConnection();
+                while (true) {
+                    server.serve();
+                }
+            } catch (Exception e) {
+                server.releaseConnection();
+                server = null;
+                // FIXME REVIEW: May be some logging would be useful here.
+                // Also any recovery action should be called here.
+            }
+        }
+    }
+}
+
+///**
+// * A factory of a simple thread
+// * 
+// * @author Marcelo Arcidiacono
+// * @author Gustavo Petri
+// */
+//final class SimpleThreadFactory implements ThreadFactory {
+//  
+//    public final Thread newThread(Runnable r) {
+//        Thread thread = new Thread(r);
+//        thread.setDaemon(true);
+//        return thread;
+//    }
 //}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/ProtocolException.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/ProtocolException.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/ProtocolException.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/ProtocolException.java Thu May 18 23:00:52 2006
@@ -1,61 +1,61 @@
-/* 
-*  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.rmi.RemoteException;
-
-/**
- * @author Gustavo Petri
- */
-public class ProtocolException extends RemoteException {
-
-    /**
-     * Serial number 1L
-     */
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * Constructor of <code>ProtocolException</code>
-     */
-    public ProtocolException() {
-        super();
-    }
-
-    /**
-     * Constructor of <code>ProtocolException</code>, receives a <code>
-     * String</code>
-     * 
-     * @param message
-     *            message of the <code>ProtocolException</code>
-     */
-    public ProtocolException(String message) {
-        super(message);
-    }
-
-    /**
-     * Constructor of <code>ProtocolException</code>, receives a <code>
-     * String</code>
-     * and <code>Throwable</code>
-     * 
-     * @param message
-     *            message of the <code>ProtocolException</code>
-     * @param cause
-     *            that it has generated this exception
-     */
-    public ProtocolException(String message, Throwable cause) {
-        super(message, cause);
-    }
-}
+/* 
+*  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.rmi.RemoteException;
+
+/**
+ * @author Gustavo Petri
+ */
+public class ProtocolException extends RemoteException {
+
+    /**
+     * Serial number 1L
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Constructor of <code>ProtocolException</code>
+     */
+    public ProtocolException() {
+        super();
+    }
+
+    /**
+     * Constructor of <code>ProtocolException</code>, receives a <code>
+     * String</code>
+     * 
+     * @param message
+     *            message of the <code>ProtocolException</code>
+     */
+    public ProtocolException(String message) {
+        super(message);
+    }
+
+    /**
+     * Constructor of <code>ProtocolException</code>, receives a <code>
+     * String</code>
+     * and <code>Throwable</code>
+     * 
+     * @param message
+     *            message of the <code>ProtocolException</code>
+     * @param cause
+     *            that it has generated this exception
+     */
+    public ProtocolException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/RMIDefaultSocketFactory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/RMIDefaultSocketFactory.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/RMIDefaultSocketFactory.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/RMIDefaultSocketFactory.java Thu May 18 23:00:52 2006
@@ -1,353 +1,353 @@
-/* 
-*  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.InetSocketAddress;
-import java.net.NoRouteToHostException;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.SocketException;
-import java.net.SocketTimeoutException;
-import java.net.URL;
-import java.net.UnknownHostException;
-import java.rmi.server.RMISocketFactory;
-import java.util.HashMap;
-import java.util.Map;
-
-import ar.org.fitc.rmi.transport.http.HttpSocketClientSide;
-import ar.org.fitc.rmi.utils.Pair;
-import ar.org.fitc.rmi.utils.PropertiesReader;
-
-/**
- * This is the default {@link java.rmi.server.RMISocketFactory} used by the RMI 
- * Runtime.
- * 
- * @author Gustavo Petri
- * @author Diego Raúl Mercado
- */
-public final class RMIDefaultSocketFactory extends RMISocketFactory {
-
-	/**
-	 * Is true if the system's property <code>java.rmi.server.disableHttp</code>
-	 * and <code>http.proxyHost</code> are true.
-	 */
-	private static boolean enableHttp;
-
-	/**
-	 * Indicates the value returned by the system's property
-	 * <code>ar.org.fitc.rmi.transport.proxy.leaseTime</code>. <br>
-	 * Indicates the maximum value to wait until trying again the fallback
-	 * mechanism.
-	 */
-	private static long leaseTime;
-
-	/**
-	 * Indicates the value returned by the system's property
-	 * <code>ar.org.fitc.rmi.transport.proxy.eagerHttpFallback</code>. <br>
-	 * If the <code>java.rmi.server.disableHttp</code> is false and this
-	 * property is set to true then would try http tunneling if a
-	 * <code>SocketException</code> ocurrs
-	 */
-	private static boolean eagerHttpFallback;
-
-	/**
-	 * Indicates the value returned by the system's property
-	 * <code>http.proxyHost</code>. <br>
-	 * Represents the IP or address name of the host that act as a proxy. Will
-	 * be used to forward the remote call invocation
-	 */
-	private static String proxyHost;
-
-	/**
-	 * Indicates the value returned by the system's property
-	 * <code>http.proxyPort</code>. <br>
-	 * Represents the port of the host that act as a proxy. The default value is
-	 * 80. Will be used to forward the remote call invocation
-	 */
-	private static int proxyPort;
-
-	/**
-	 * Indicates the value returned by the system's property
-	 * <code>ar.org.fitc.rmi.transport.proxy.connectTimeout</code>. <br>
-	 * Sets the maximum time (in milliseconds) that the runtime will wait for a
-	 * direct connection attempt to establish, before trying http tunneling.
-	 * It's used only if <code>java.rmi.server.disableHttp</code> is false and
-	 * <code>http.proxyHost</code> is set.
-	 */
-	private static int connectTimeout;
-
-	/**
-	 * Indicates the value returned by the system's property
-	 * <code>ar.org.fitc.rmi.transport.proxy.httpToPortOnly</code>. <br>
-	 * Setting this value to true will only try to establish a connection
-	 * through the proxy that was specified in <code>http.proxyHost</code>.
-	 * <br>
-	 * This avoid the default fallback mechanism.
-	 */
-	private static boolean proxyOnly;
-
-	/**
-	 * Indicates the value returned by the system's property
-	 * <code>ar.org.fitc.rmi.transport.proxy.httpToCgiOnly</code>. <br>
-	 * Setting this value to true will only try to establish a connection
-	 * through the proxy that was specified in <code>http.proxyHost</code> and
-	 * execute the cgi's script at the web server. <br>
-	 * This avoid the default fallback mechanism.
-	 */
-	private static boolean cgiOnly;
-
-	/**
-	 * For each host and port stores the FallBackType and the last time that a
-	 * socket has been created for that parameters.
-	 */
-	private static Map<Pair<String, Integer>, Pair<FallBackType, Long>> connType;
-
-	static {
-
-		/*
-		 * READING PROPERTIES
-		 */
-
-		leaseTime = PropertiesReader.readLong(
-				"ar.org.fitc.rmi.transport.proxy.leaseTime", 3600000L); // 1
-		// hour
-
-		connectTimeout = PropertiesReader.readInt(
-				"ar.org.fitc.rmi.transport.proxy.connectTimeout", 15000);
-
-		proxyHost = PropertiesReader.readString("http.proxyHost");
-
-		proxyPort = PropertiesReader.readInt("http.proxyPort", 80);
-
-		eagerHttpFallback = PropertiesReader.readBoolean(
-				"ar.org.fitc.rmi.transport.proxy.eagerHttpFallback", false);
-
-		proxyOnly = PropertiesReader.readBoolean(
-				"ar.org.fitc.rmi.transport.proxy.httpToPortOnly", false);
-
-		cgiOnly = PropertiesReader.readBoolean(
-				"ar.org.fitc.rmi.transport.proxy.httpToCgiOnly", false);
-
-		boolean disableHttp = PropertiesReader.readBoolean(
-				"java.rmi.server.disableHttp", false);
-
-		enableHttp = proxyHost != null && !disableHttp;
-
-		connType = new HashMap<Pair<String, Integer>, Pair<FallBackType, Long>>();
-	}
-
-	/**
-	 * Create a socket through a three-tiered approach: first, attempt to create
-	 * a default
-	 * {@link Socket} with the specified host and port. <br>
-	 * If that fails, <code>java.rmi.server.disableHttp</code> is enabled and
-	 * <code>http.proxyHost</code> property is set, attempt to create a
-	 * {@link HttpSocketClientSide} with the specified
-	 * <code>http.proxyHost</code> and <code>http.proxyPort</code>. That
-	 * is, specifying the folowing url:
-	 * <code>http://&#60;host&#62;:&#60;port&#62;</code> <br>
-	 * Finally, attempts to invoke a cgi-script on the specified proxy with the
-	 * following url:
-	 * <code>http://&#60;host&#62;:80/cgi-bin/java-rmi?forward=&#60;port&#62;</code>
-	 * 
-	 * @param host
-	 *            the host to connect the socket
-	 * @param port
-	 *            the port to connect the socket
-	 * @return a new {@link Socket} instance connected to the host and
-	 *         port specified
-	 * @throws IOException
-	 *             if de I/O operation fails
-	 */
-	@Override
-	public final Socket createSocket(String host, int port) throws IOException {
-		Pair<Socket, FallBackType> sockPair = null;
-		Pair<String, Integer> inetAddr = new Pair<String, Integer>(host, port);
-
-		// is there a reference ?
-		Pair<FallBackType, Long> fallBackPair = connType.get(inetAddr);
-		if (fallBackPair != null) {
-			if (fallBackPair.getSecond() < System.currentTimeMillis()
-					- leaseTime) {
-				// the lease time has expired do the fallback ...
-				sockPair = fallBack(host, port);
-			} else {
-				try {
-					sockPair = new Pair<Socket, FallBackType>(connect(
-							fallBackPair.getFirst(), host, port), fallBackPair
-							.getFirst());
-				} catch (IOException e) {
-					// do the fallback...
-					sockPair = fallBack(host, port);
-				}
-			}
-		} else {
-			// do the fallback...
-			sockPair = fallBack(host, port);
-		}
-		// put / update reference
-		connType.put(inetAddr, new Pair<FallBackType, Long>(sockPair
-				.getSecond(), System.currentTimeMillis()));
-
-		return sockPair.getFirst();
-	}
-
-	/**
-	 * Creates a new {@link RMIServerSocket} bound to the specified port.
-	 * 
-	 * @param port
-	 *            the port to bind the server
-	 * @return a new {@link RMIServerSocket} bound to the specified port.
-	 * @throws IOException
-	 *             if de I/O operation fails
-	 */
-	@Override
-	public final ServerSocket createServerSocket(int port) throws IOException {
-		return new RMIServerSocket(port);
-	}
-
-	/**
-	 * Implements the fallback logic, which will attempt all connection types
-	 * until one success.
-	 * 
-	 * @param host
-	 *            The host name of the RMI Server
-	 * @param port
-	 *            The port of the RMI Server
-	 * @return A {@link Pair} object containing a {@link Socket} bound 
-	 * 			to the appropriate server, and the {@link FallBackType} 
-	 * 			object representing the approach used to establish the connection.
-	 * @throws IOException
-	 *             If all connection types have failed.
-	 */
-	private final Pair<Socket, FallBackType> fallBack(String host, int port)
-			throws IOException {
-		FallBackType fbType = null;
-		IOException returnedException = null;
-		Socket newSock = null;
-		boolean isEstablished = false;
-		boolean notFallback = proxyOnly || cgiOnly;
-
-		try {
-			if (enableHttp && notFallback) {
-				if (proxyOnly) {
-					newSock = connect(FallBackType.PROXY, host, port);
-					fbType = FallBackType.PROXY;
-				} else if (cgiOnly) {
-					newSock = connect(FallBackType.CGI, host, port);
-					fbType = FallBackType.CGI;
-				}
-			} else {
-				// DIRECT CONNECTION
-				newSock = connect(FallBackType.DIRECT, host, port);
-				fbType = FallBackType.DIRECT;
-			}
-			isEstablished = true;
-		} catch (UnknownHostException e) {
-			returnedException = e;
-		} catch (NoRouteToHostException e) {
-			returnedException = e;
-		} catch (SocketTimeoutException e) {
-			// this property has to be set and is catched
-			// when newSock tries to connect with a "connectTimeout"
-			returnedException = e;
-		} catch (SocketException e) {
-			// if disableHttp property has not been set (checks this value in
-			// the next if block) and eagerHttpFallback is true...
-			if (!(eagerHttpFallback)) {
-				throw e;
-			}
-			returnedException = e;
-		}
-
-		// HTTP
-		if (!isEstablished && enableHttp && !notFallback) {
-			// PROXY_HOST ON PROXY_PORT USING HTTP
-			try {
-				newSock = connect(FallBackType.PROXY, host, port);
-				fbType = FallBackType.PROXY;
-				isEstablished = true;
-			} catch (NoRouteToHostException e) {
-				returnedException = e;
-			} catch (UnknownHostException e) {
-				returnedException = e;
-			}
-
-			if (!isEstablished) {
-				// CGI ON RMI SERVER ON PORT 80 USING HTTP
-				newSock = connect(FallBackType.CGI, host, port);
-				fbType = FallBackType.CGI;
-				isEstablished = true;
-			}
-		}
-
-		if (!isEstablished) {
-			throw returnedException;
-		}
-		return new Pair<Socket, FallBackType>(newSock, fbType);
-	}
-
-	/**
-	 * Attempts a connection to the appropriate server, depending on the
-	 * specified {@link FallBackType} parameter.
-	 * 
-	 * @param fallBackType
-	 *            The type of connection (Direct, HTTPProxy, HTTPCGI) that will
-	 *            be used.
-	 * @param host
-	 *            The host name of the RMI Server
-	 * @param port
-	 *            The port of the RMI Server
-	 * @return A {@link Socket} bound to the appropriate server.
-	 * @throws IOException
-	 *             If the connection attempt for the specified
-	 *             {@link FallBackType} has failed.
-	 */
-	private final Socket connect(FallBackType fallBackType, String host,
-			int port) throws IOException {
-		Socket newSock = null;
-		if (fallBackType.equals(FallBackType.DIRECT)) {
-
-			// DIRECT CONNECTION with TimeOut
-			if (enableHttp) {
-				newSock = new Socket();
-				newSock.connect(new InetSocketAddress(host, port),
-						connectTimeout);
-			} else {
-				// DIRECT CONNECTION
-				newSock = new Socket();
-				newSock.connect(new InetSocketAddress(host, port));
-			}
-		} else if (fallBackType.equals(FallBackType.PROXY)) {
-
-			// PROXY_HOST ON PROXY_PORT USING HTTP
-			newSock = new HttpSocketClientSide(new URL("http", proxyHost,
-					proxyPort, "http://" + host + ":" + port + "/"));
-
-		} else if (fallBackType.equals(FallBackType.CGI)) {
-
-			// CGI ON RMI SERVER ON PORT 80 USING HTTP
-			newSock = new HttpSocketClientSide(new URL("http", proxyHost,
-					proxyPort, "http://" + host
-							+ ":80/cgi-bin/java-rmi.cgi?forward=" + port));
-
-		} else {
-			throw new AssertionError();
-		}
-		return newSock;
-	}
-}
+/* 
+*  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.InetSocketAddress;
+import java.net.NoRouteToHostException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.rmi.server.RMISocketFactory;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.harmony.rmi.internal.transport.http.HttpSocketClientSide;
+import org.apache.harmony.rmi.internal.utils.Pair;
+import org.apache.harmony.rmi.internal.utils.PropertiesReader;
+
+/**
+ * This is the default {@link java.rmi.server.RMISocketFactory} used by the RMI 
+ * Runtime.
+ * 
+ * @author Gustavo Petri
+ * @author Diego Raúl Mercado
+ */
+public final class RMIDefaultSocketFactory extends RMISocketFactory {
+
+	/**
+	 * Is true if the system's property <code>java.rmi.server.disableHttp</code>
+	 * and <code>http.proxyHost</code> are true.
+	 */
+	private static boolean enableHttp;
+
+	/**
+	 * Indicates the value returned by the system's property
+	 * <code>org.apache.harmony.rmi.internal.transport.proxy.leaseTime</code>. <br>
+	 * Indicates the maximum value to wait until trying again the fallback
+	 * mechanism.
+	 */
+	private static long leaseTime;
+
+	/**
+	 * Indicates the value returned by the system's property
+	 * <code>org.apache.harmony.rmi.internal.transport.proxy.eagerHttpFallback</code>. <br>
+	 * If the <code>java.rmi.server.disableHttp</code> is false and this
+	 * property is set to true then would try http tunneling if a
+	 * <code>SocketException</code> ocurrs
+	 */
+	private static boolean eagerHttpFallback;
+
+	/**
+	 * Indicates the value returned by the system's property
+	 * <code>http.proxyHost</code>. <br>
+	 * Represents the IP or address name of the host that act as a proxy. Will
+	 * be used to forward the remote call invocation
+	 */
+	private static String proxyHost;
+
+	/**
+	 * Indicates the value returned by the system's property
+	 * <code>http.proxyPort</code>. <br>
+	 * Represents the port of the host that act as a proxy. The default value is
+	 * 80. Will be used to forward the remote call invocation
+	 */
+	private static int proxyPort;
+
+	/**
+	 * Indicates the value returned by the system's property
+	 * <code>org.apache.harmony.rmi.internal.transport.proxy.connectTimeout</code>. <br>
+	 * Sets the maximum time (in milliseconds) that the runtime will wait for a
+	 * direct connection attempt to establish, before trying http tunneling.
+	 * It's used only if <code>java.rmi.server.disableHttp</code> is false and
+	 * <code>http.proxyHost</code> is set.
+	 */
+	private static int connectTimeout;
+
+	/**
+	 * Indicates the value returned by the system's property
+	 * <code>org.apache.harmony.rmi.internal.transport.proxy.httpToPortOnly</code>. <br>
+	 * Setting this value to true will only try to establish a connection
+	 * through the proxy that was specified in <code>http.proxyHost</code>.
+	 * <br>
+	 * This avoid the default fallback mechanism.
+	 */
+	private static boolean proxyOnly;
+
+	/**
+	 * Indicates the value returned by the system's property
+	 * <code>org.apache.harmony.rmi.internal.transport.proxy.httpToCgiOnly</code>. <br>
+	 * Setting this value to true will only try to establish a connection
+	 * through the proxy that was specified in <code>http.proxyHost</code> and
+	 * execute the cgi's script at the web server. <br>
+	 * This avoid the default fallback mechanism.
+	 */
+	private static boolean cgiOnly;
+
+	/**
+	 * For each host and port stores the FallBackType and the last time that a
+	 * socket has been created for that parameters.
+	 */
+	private static Map<Pair<String, Integer>, Pair<FallBackType, Long>> connType;
+
+	static {
+
+		/*
+		 * READING PROPERTIES
+		 */
+
+		leaseTime = PropertiesReader.readLong(
+				"org.apache.harmony.rmi.internal.transport.proxy.leaseTime", 3600000L); // 1
+		// hour
+
+		connectTimeout = PropertiesReader.readInt(
+				"org.apache.harmony.rmi.internal.transport.proxy.connectTimeout", 15000);
+
+		proxyHost = PropertiesReader.readString("http.proxyHost");
+
+		proxyPort = PropertiesReader.readInt("http.proxyPort", 80);
+
+		eagerHttpFallback = PropertiesReader.readBoolean(
+				"org.apache.harmony.rmi.internal.transport.proxy.eagerHttpFallback", false);
+
+		proxyOnly = PropertiesReader.readBoolean(
+				"org.apache.harmony.rmi.internal.transport.proxy.httpToPortOnly", false);
+
+		cgiOnly = PropertiesReader.readBoolean(
+				"org.apache.harmony.rmi.internal.transport.proxy.httpToCgiOnly", false);
+
+		boolean disableHttp = PropertiesReader.readBoolean(
+				"java.rmi.server.disableHttp", false);
+
+		enableHttp = proxyHost != null && !disableHttp;
+
+		connType = new HashMap<Pair<String, Integer>, Pair<FallBackType, Long>>();
+	}
+
+	/**
+	 * Create a socket through a three-tiered approach: first, attempt to create
+	 * a default
+	 * {@link Socket} with the specified host and port. <br>
+	 * If that fails, <code>java.rmi.server.disableHttp</code> is enabled and
+	 * <code>http.proxyHost</code> property is set, attempt to create a
+	 * {@link HttpSocketClientSide} with the specified
+	 * <code>http.proxyHost</code> and <code>http.proxyPort</code>. That
+	 * is, specifying the folowing url:
+	 * <code>http://&#60;host&#62;:&#60;port&#62;</code> <br>
+	 * Finally, attempts to invoke a cgi-script on the specified proxy with the
+	 * following url:
+	 * <code>http://&#60;host&#62;:80/cgi-bin/java-rmi?forward=&#60;port&#62;</code>
+	 * 
+	 * @param host
+	 *            the host to connect the socket
+	 * @param port
+	 *            the port to connect the socket
+	 * @return a new {@link Socket} instance connected to the host and
+	 *         port specified
+	 * @throws IOException
+	 *             if de I/O operation fails
+	 */
+	@Override
+	public final Socket createSocket(String host, int port) throws IOException {
+		Pair<Socket, FallBackType> sockPair = null;
+		Pair<String, Integer> inetAddr = new Pair<String, Integer>(host, port);
+
+		// is there a reference ?
+		Pair<FallBackType, Long> fallBackPair = connType.get(inetAddr);
+		if (fallBackPair != null) {
+			if (fallBackPair.getSecond() < System.currentTimeMillis()
+					- leaseTime) {
+				// the lease time has expired do the fallback ...
+				sockPair = fallBack(host, port);
+			} else {
+				try {
+					sockPair = new Pair<Socket, FallBackType>(connect(
+							fallBackPair.getFirst(), host, port), fallBackPair
+							.getFirst());
+				} catch (IOException e) {
+					// do the fallback...
+					sockPair = fallBack(host, port);
+				}
+			}
+		} else {
+			// do the fallback...
+			sockPair = fallBack(host, port);
+		}
+		// put / update reference
+		connType.put(inetAddr, new Pair<FallBackType, Long>(sockPair
+				.getSecond(), System.currentTimeMillis()));
+
+		return sockPair.getFirst();
+	}
+
+	/**
+	 * Creates a new {@link RMIServerSocket} bound to the specified port.
+	 * 
+	 * @param port
+	 *            the port to bind the server
+	 * @return a new {@link RMIServerSocket} bound to the specified port.
+	 * @throws IOException
+	 *             if de I/O operation fails
+	 */
+	@Override
+	public final ServerSocket createServerSocket(int port) throws IOException {
+		return new RMIServerSocket(port);
+	}
+
+	/**
+	 * Implements the fallback logic, which will attempt all connection types
+	 * until one success.
+	 * 
+	 * @param host
+	 *            The host name of the RMI Server
+	 * @param port
+	 *            The port of the RMI Server
+	 * @return A {@link Pair} object containing a {@link Socket} bound 
+	 * 			to the appropriate server, and the {@link FallBackType} 
+	 * 			object representing the approach used to establish the connection.
+	 * @throws IOException
+	 *             If all connection types have failed.
+	 */
+	private final Pair<Socket, FallBackType> fallBack(String host, int port)
+			throws IOException {
+		FallBackType fbType = null;
+		IOException returnedException = null;
+		Socket newSock = null;
+		boolean isEstablished = false;
+		boolean notFallback = proxyOnly || cgiOnly;
+
+		try {
+			if (enableHttp && notFallback) {
+				if (proxyOnly) {
+					newSock = connect(FallBackType.PROXY, host, port);
+					fbType = FallBackType.PROXY;
+				} else if (cgiOnly) {
+					newSock = connect(FallBackType.CGI, host, port);
+					fbType = FallBackType.CGI;
+				}
+			} else {
+				// DIRECT CONNECTION
+				newSock = connect(FallBackType.DIRECT, host, port);
+				fbType = FallBackType.DIRECT;
+			}
+			isEstablished = true;
+		} catch (UnknownHostException e) {
+			returnedException = e;
+		} catch (NoRouteToHostException e) {
+			returnedException = e;
+		} catch (SocketTimeoutException e) {
+			// this property has to be set and is catched
+			// when newSock tries to connect with a "connectTimeout"
+			returnedException = e;
+		} catch (SocketException e) {
+			// if disableHttp property has not been set (checks this value in
+			// the next if block) and eagerHttpFallback is true...
+			if (!(eagerHttpFallback)) {
+				throw e;
+			}
+			returnedException = e;
+		}
+
+		// HTTP
+		if (!isEstablished && enableHttp && !notFallback) {
+			// PROXY_HOST ON PROXY_PORT USING HTTP
+			try {
+				newSock = connect(FallBackType.PROXY, host, port);
+				fbType = FallBackType.PROXY;
+				isEstablished = true;
+			} catch (NoRouteToHostException e) {
+				returnedException = e;
+			} catch (UnknownHostException e) {
+				returnedException = e;
+			}
+
+			if (!isEstablished) {
+				// CGI ON RMI SERVER ON PORT 80 USING HTTP
+				newSock = connect(FallBackType.CGI, host, port);
+				fbType = FallBackType.CGI;
+				isEstablished = true;
+			}
+		}
+
+		if (!isEstablished) {
+			throw returnedException;
+		}
+		return new Pair<Socket, FallBackType>(newSock, fbType);
+	}
+
+	/**
+	 * Attempts a connection to the appropriate server, depending on the
+	 * specified {@link FallBackType} parameter.
+	 * 
+	 * @param fallBackType
+	 *            The type of connection (Direct, HTTPProxy, HTTPCGI) that will
+	 *            be used.
+	 * @param host
+	 *            The host name of the RMI Server
+	 * @param port
+	 *            The port of the RMI Server
+	 * @return A {@link Socket} bound to the appropriate server.
+	 * @throws IOException
+	 *             If the connection attempt for the specified
+	 *             {@link FallBackType} has failed.
+	 */
+	private final Socket connect(FallBackType fallBackType, String host,
+			int port) throws IOException {
+		Socket newSock = null;
+		if (fallBackType.equals(FallBackType.DIRECT)) {
+
+			// DIRECT CONNECTION with TimeOut
+			if (enableHttp) {
+				newSock = new Socket();
+				newSock.connect(new InetSocketAddress(host, port),
+						connectTimeout);
+			} else {
+				// DIRECT CONNECTION
+				newSock = new Socket();
+				newSock.connect(new InetSocketAddress(host, port));
+			}
+		} else if (fallBackType.equals(FallBackType.PROXY)) {
+
+			// PROXY_HOST ON PROXY_PORT USING HTTP
+			newSock = new HttpSocketClientSide(new URL("http", proxyHost,
+					proxyPort, "http://" + host + ":" + port + "/"));
+
+		} else if (fallBackType.equals(FallBackType.CGI)) {
+
+			// CGI ON RMI SERVER ON PORT 80 USING HTTP
+			newSock = new HttpSocketClientSide(new URL("http", proxyHost,
+					proxyPort, "http://" + host
+							+ ":80/cgi-bin/java-rmi.cgi?forward=" + port));
+
+		} else {
+			throw new AssertionError();
+		}
+		return newSock;
+	}
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/RMIObjectInputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/RMIObjectInputStream.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/RMIObjectInputStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/RMIObjectInputStream.java Thu May 18 23:00:52 2006
@@ -1,166 +1,166 @@
-/* 
-*  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.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectStreamClass;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Proxy;
-import java.rmi.Remote;
-import java.rmi.server.RMIClassLoader;
-import java.rmi.server.RemoteObjectInvocationHandler;
-import java.rmi.server.RemoteStub;
-
-import ar.org.fitc.rmi.dgc.client.DGCClient;
-import ar.org.fitc.rmi.utils.Pair;
-import ar.org.fitc.rmi.utils.PropertiesReader;
-
-/**
- * This class is used by the RMI Runtime to serialize and deserialize Remote
- * Objects. For that purpose the {@link #resolveClass} and
- * {@link #resolveProxyClass} methods have been overloaded.
- * 
- * @author Gustavo Petri
- * @author Gonzalo Ortega
- */
-public final class RMIObjectInputStream extends ObjectInputStream {
-
-    private static boolean useCodebaseOnly = 
-        PropertiesReader.readBoolean("java.rmi.server.useCodebaseOnly", false);
-        
-    private boolean readsRemote;
-
-    /**
-     * Delegates the creation of an ObjectInputStream to its parent class.
-     * 
-     * @throws IOException
-     *             if I/O operation fails
-     */
-    public RMIObjectInputStream() throws IOException {
-        super();
-        enableResolveObject(true);
-    }
-
-    /**
-     * Delegates the creation of an ObjectInputStream to its parent class.
-     * 
-     * @param in
-     *            the
-     *            {@link InputStream}
-     *            to which this instance will be attached.
-     * @throws IOException
-     *             if de I/O operation fails
-     */
-    public RMIObjectInputStream(InputStream in) throws IOException {
-        super(in);
-        enableResolveObject(true);
-    }
-
-    /**
-     * Returns a pair (object-boolean) from the read object.
-     * 
-     * @return a pair (object-boolean) from the read object
-     * @throws IOException
-     *             if de I/O operation fails
-     * @throws ClassNotFoundException
-     *             if no definition for the class with the specified name could
-     *             be found
-     */
-    public synchronized final Pair<Object, Boolean> readResultObject()
-            throws IOException, ClassNotFoundException {
-        readsRemote = false;
-        Object obj = this.readObject();
-        return new Pair<Object, Boolean>(obj, new Boolean(readsRemote));
-    }
-
-    /**
-     * Returns the Class that corresponds to the desc argument.
-     * 
-     * @param desc
-     *            the descriptor of the needed Class
-     * @return the Class for the desc descriptor
-     */
-    @SuppressWarnings("deprecation")
-    @Override
-    protected Class<?> resolveClass(ObjectStreamClass desc) 
-            throws IOException, ClassNotFoundException {
-        Class<?> ret = null;
-        Object obj = this.readObject();
-        try {
-            ret = Class.forName(desc.getName(), true, Thread.currentThread()
-                    .getContextClassLoader());
-        } catch (ClassNotFoundException e) {
-            if ((obj != null && obj instanceof String) && (!useCodebaseOnly)) {
-                ret = RMIClassLoader.loadClass((String) obj, desc.getName());
-            } else {
-                ret = RMIClassLoader.loadClass(desc.getName());
-            }
-        } 
-        return ret;
-    }
-
-    /**
-     * Constructs and returns a Proxy class that implements the required
-     * interfaces.
-     * 
-     * @param interfaces
-     *            the interfaces to be implemented
-     * @return a proxy class that implements the specified interfaces
-     * @throws IOException
-     *             if de I/O operation fails
-     */
-    @Override
-    protected Class<?> resolveProxyClass(String[] interfaces)
-            throws IOException, ClassNotFoundException {
-        Object obj = this.readObject();
-        try {
-            return super.resolveProxyClass(interfaces);
-        } catch (Exception e) {
-            return RMIClassLoader
-                    .loadProxyClass((String) obj, interfaces, null);
-        }
-    }
-
-    /**
-     * Transforms a locally exported Remote Object to its corresponding stub in *
-     * for the serialization proces.
-     * 
-     * @param obj
-     *            the specified Object
-     */
-    @Override
-    protected Object resolveObject(Object obj) throws IOException {
-        if (obj instanceof Remote) {
-            if (obj instanceof RemoteStub) {
-                DGCClient dgcClient = DGCClient.getDGCClient();
-                readsRemote = true;
-                return dgcClient.getStubInstance((RemoteStub) obj);
-            }
-            if (Proxy.isProxyClass(obj.getClass())) {
-                InvocationHandler ih = Proxy
-                        .getInvocationHandler(obj);
-                if (ih instanceof RemoteObjectInvocationHandler) {
-                    DGCClient dgcClient = DGCClient.getDGCClient();
-                    readsRemote = true;
-                    return dgcClient.getStubInstance((Remote) obj);
-                }
-            }
-        }
-        return obj;
-    }
-}
+/* 
+*  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.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.rmi.Remote;
+import java.rmi.server.RMIClassLoader;
+import java.rmi.server.RemoteObjectInvocationHandler;
+import java.rmi.server.RemoteStub;
+
+import org.apache.harmony.rmi.internal.dgc.client.DGCClient;
+import org.apache.harmony.rmi.internal.utils.Pair;
+import org.apache.harmony.rmi.internal.utils.PropertiesReader;
+
+/**
+ * This class is used by the RMI Runtime to serialize and deserialize Remote
+ * Objects. For that purpose the {@link #resolveClass} and
+ * {@link #resolveProxyClass} methods have been overloaded.
+ * 
+ * @author Gustavo Petri
+ * @author Gonzalo Ortega
+ */
+public final class RMIObjectInputStream extends ObjectInputStream {
+
+    private static boolean useCodebaseOnly = 
+        PropertiesReader.readBoolean("java.rmi.server.useCodebaseOnly", false);
+        
+    private boolean readsRemote;
+
+    /**
+     * Delegates the creation of an ObjectInputStream to its parent class.
+     * 
+     * @throws IOException
+     *             if I/O operation fails
+     */
+    public RMIObjectInputStream() throws IOException {
+        super();
+        enableResolveObject(true);
+    }
+
+    /**
+     * Delegates the creation of an ObjectInputStream to its parent class.
+     * 
+     * @param in
+     *            the
+     *            {@link InputStream}
+     *            to which this instance will be attached.
+     * @throws IOException
+     *             if de I/O operation fails
+     */
+    public RMIObjectInputStream(InputStream in) throws IOException {
+        super(in);
+        enableResolveObject(true);
+    }
+
+    /**
+     * Returns a pair (object-boolean) from the read object.
+     * 
+     * @return a pair (object-boolean) from the read object
+     * @throws IOException
+     *             if de I/O operation fails
+     * @throws ClassNotFoundException
+     *             if no definition for the class with the specified name could
+     *             be found
+     */
+    public synchronized final Pair<Object, Boolean> readResultObject()
+            throws IOException, ClassNotFoundException {
+        readsRemote = false;
+        Object obj = this.readObject();
+        return new Pair<Object, Boolean>(obj, new Boolean(readsRemote));
+    }
+
+    /**
+     * Returns the Class that corresponds to the desc argument.
+     * 
+     * @param desc
+     *            the descriptor of the needed Class
+     * @return the Class for the desc descriptor
+     */
+    @SuppressWarnings("deprecation")
+    @Override
+    protected Class<?> resolveClass(ObjectStreamClass desc) 
+            throws IOException, ClassNotFoundException {
+        Class<?> ret = null;
+        Object obj = this.readObject();
+        try {
+            ret = Class.forName(desc.getName(), true, Thread.currentThread()
+                    .getContextClassLoader());
+        } catch (ClassNotFoundException e) {
+            if ((obj != null && obj instanceof String) && (!useCodebaseOnly)) {
+                ret = RMIClassLoader.loadClass((String) obj, desc.getName());
+            } else {
+                ret = RMIClassLoader.loadClass(desc.getName());
+            }
+        } 
+        return ret;
+    }
+
+    /**
+     * Constructs and returns a Proxy class that implements the required
+     * interfaces.
+     * 
+     * @param interfaces
+     *            the interfaces to be implemented
+     * @return a proxy class that implements the specified interfaces
+     * @throws IOException
+     *             if de I/O operation fails
+     */
+    @Override
+    protected Class<?> resolveProxyClass(String[] interfaces)
+            throws IOException, ClassNotFoundException {
+        Object obj = this.readObject();
+        try {
+            return super.resolveProxyClass(interfaces);
+        } catch (Exception e) {
+            return RMIClassLoader
+                    .loadProxyClass((String) obj, interfaces, null);
+        }
+    }
+
+    /**
+     * Transforms a locally exported Remote Object to its corresponding stub in *
+     * for the serialization proces.
+     * 
+     * @param obj
+     *            the specified Object
+     */
+    @Override
+    protected Object resolveObject(Object obj) throws IOException {
+        if (obj instanceof Remote) {
+            if (obj instanceof RemoteStub) {
+                DGCClient dgcClient = DGCClient.getDGCClient();
+                readsRemote = true;
+                return dgcClient.getStubInstance((RemoteStub) obj);
+            }
+            if (Proxy.isProxyClass(obj.getClass())) {
+                InvocationHandler ih = Proxy
+                        .getInvocationHandler(obj);
+                if (ih instanceof RemoteObjectInvocationHandler) {
+                    DGCClient dgcClient = DGCClient.getDGCClient();
+                    readsRemote = true;
+                    return dgcClient.getStubInstance((Remote) obj);
+                }
+            }
+        }
+        return obj;
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/RMIObjectOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/RMIObjectOutputStream.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/RMIObjectOutputStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/RMIObjectOutputStream.java Thu May 18 23:00:52 2006
@@ -1,171 +1,171 @@
-/* 
-*  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.io.ObjectOutputStream;
-import java.io.OutputStream;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Proxy;
-import java.rmi.Remote;
-import java.rmi.server.RMIClassLoader;
-import java.rmi.server.RemoteObject;
-import java.rmi.server.RemoteObjectInvocationHandler;
-import java.rmi.server.RemoteStub;
-import ar.org.fitc.rmi.runtime.RemoteReferenceManager;
-
-/*
- * NOTE: 
- * This class has been modified in order to support 
- * Java VM 1.4.2 using the javac's target jsr14 
- */
-
-/**
- * This class is used by the RMI Runtime to serialize and deserialize Remote
- * Objects. For that purpose the {@link #replaceObject}, {@link #annotateClass}
- * and {@link #annotateProxyClass} methods have been overloaded.
- * 
- * @author Gustavo Petri
- */
-
-public final class RMIObjectOutputStream extends ObjectOutputStream {
-
-    /**
-     * This set holds the {@link java.rmi.server.UID} for which a DGCAck is
-     * still pending.
-     */
-    private boolean writesRemote;
-
-    /**
-     * Delegates the creation of an ObjectInputStream to its parent class.
-     * 
-     * @throws IOException
-     *             if the I/O operation fails
-     */
-    protected RMIObjectOutputStream() throws IOException {
-        super();
-        enableReplaceObject(true);
-    }
-
-    /**
-     * Delegates the creation of an ObjectInputStream to its parent class.
-     * 
-     * @param out
-     *            The
-     *            {@link OutputStream}
-     *            from which the new {@link RMIObjectOutputStream} will be created
-     * @throws IOException
-     *             if the I/O operation fails
-     */
-    public RMIObjectOutputStream(OutputStream out) throws IOException {
-
-        super(out);
-//        flush();
-        enableReplaceObject(true);
-    }
-
-    /**
-     * Writes an object and returns true if and only if a
-     * {@link java.rmi.Remote} object has been writtenRMIObjectOutputStream
-     * 
-     * @param obj
-     *            the specified Object
-     * @return true if a {@link java.rmi.Remote} object has been written to the
-     *         {@link ObjectOutputStream}
-     * @throws IOException
-     *             if the I/O operation fails
-     */
-    public synchronized final boolean writeResultObject(Object obj)
-            throws IOException {
-
-        writesRemote = false;
-        this.writeObject(obj);
-        return writesRemote;
-    }
-
-    /**
-     * Returns a stub if the object to be serialized is a
-     * {@link java.rmi.Remote} instance.
-     * 
-     * @param obj
-     *            the object to be replaced if needed be.
-     * @return if the argument was a {@link java.rmi.Remote} object locally
-     *         exported a stub for that object is returned, in case it is not a
-     *         {@link java.rmi.Remote} the object is returned
-     * @throws IOException
-     *             if the I/O operation fails
-     */
-    @Override
-    protected final Object replaceObject(Object obj) throws IOException {
-
-        if (obj instanceof Remote) {
-            RemoteReferenceManager rrm = RemoteReferenceManager
-                    .getRemoteReferenceManager();
-            if (rrm.isExported((Remote) obj)) {
-                writesRemote = true;
-                return RemoteObject.toStub((Remote) obj);
-            }
-            if (obj instanceof RemoteStub) {
-                writesRemote = true;
-                return obj;
-            }
-            if (Proxy.isProxyClass(obj.getClass())) {
-                InvocationHandler ih = Proxy.getInvocationHandler(obj);
-                if (ih instanceof RemoteObjectInvocationHandler) {
-                    writesRemote = true;
-                }
-            }
-        }
-        return obj;
-    }
-
-    /**
-     * Writes the annotation for the class passed as argument on the 
-     * {@link RMIObjectOutputStream}
-     * 
-     * @param cl
-     *            the class to be annotated
-     * @throws IOException
-     *             if the I/O operation fails
-     */
-    protected final void annotateClass(Class cl) throws IOException {
-        Object obj = RMIClassLoader.getClassAnnotation(cl);
-        this.writeObject(obj);
-    }
-
-    /**
-     * Writes the annotation for the Proxy class passed as argument on the
-     * RMIOutputStream.
-     * 
-     * @param cl
-     *            the class to be annotated
-     * @throws IOException
-     *             if the I/O operation fails
-     */
-    @Override
-    protected final void annotateProxyClass(Class<?> cl) throws IOException {
-        Object obj = RMIClassLoader.getClassAnnotation(cl);
-        this.writeObject(obj);
-    }
-    
-    /**
-     * Writes the pending content to the underlying stream.
-     */
-    @Override
-    public final void drain() throws IOException {
-        super.drain();
-    }
-}
+/* 
+*  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.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.rmi.Remote;
+import java.rmi.server.RMIClassLoader;
+import java.rmi.server.RemoteObject;
+import java.rmi.server.RemoteObjectInvocationHandler;
+import java.rmi.server.RemoteStub;
+import org.apache.harmony.rmi.internal.runtime.RemoteReferenceManager;
+
+/*
+ * NOTE: 
+ * This class has been modified in order to support 
+ * Java VM 1.4.2 using the javac's target jsr14 
+ */
+
+/**
+ * This class is used by the RMI Runtime to serialize and deserialize Remote
+ * Objects. For that purpose the {@link #replaceObject}, {@link #annotateClass}
+ * and {@link #annotateProxyClass} methods have been overloaded.
+ * 
+ * @author Gustavo Petri
+ */
+
+public final class RMIObjectOutputStream extends ObjectOutputStream {
+
+    /**
+     * This set holds the {@link java.rmi.server.UID} for which a DGCAck is
+     * still pending.
+     */
+    private boolean writesRemote;
+
+    /**
+     * Delegates the creation of an ObjectInputStream to its parent class.
+     * 
+     * @throws IOException
+     *             if the I/O operation fails
+     */
+    protected RMIObjectOutputStream() throws IOException {
+        super();
+        enableReplaceObject(true);
+    }
+
+    /**
+     * Delegates the creation of an ObjectInputStream to its parent class.
+     * 
+     * @param out
+     *            The
+     *            {@link OutputStream}
+     *            from which the new {@link RMIObjectOutputStream} will be created
+     * @throws IOException
+     *             if the I/O operation fails
+     */
+    public RMIObjectOutputStream(OutputStream out) throws IOException {
+
+        super(out);
+//        flush();
+        enableReplaceObject(true);
+    }
+
+    /**
+     * Writes an object and returns true if and only if a
+     * {@link java.rmi.Remote} object has been writtenRMIObjectOutputStream
+     * 
+     * @param obj
+     *            the specified Object
+     * @return true if a {@link java.rmi.Remote} object has been written to the
+     *         {@link ObjectOutputStream}
+     * @throws IOException
+     *             if the I/O operation fails
+     */
+    public synchronized final boolean writeResultObject(Object obj)
+            throws IOException {
+
+        writesRemote = false;
+        this.writeObject(obj);
+        return writesRemote;
+    }
+
+    /**
+     * Returns a stub if the object to be serialized is a
+     * {@link java.rmi.Remote} instance.
+     * 
+     * @param obj
+     *            the object to be replaced if needed be.
+     * @return if the argument was a {@link java.rmi.Remote} object locally
+     *         exported a stub for that object is returned, in case it is not a
+     *         {@link java.rmi.Remote} the object is returned
+     * @throws IOException
+     *             if the I/O operation fails
+     */
+    @Override
+    protected final Object replaceObject(Object obj) throws IOException {
+
+        if (obj instanceof Remote) {
+            RemoteReferenceManager rrm = RemoteReferenceManager
+                    .getRemoteReferenceManager();
+            if (rrm.isExported((Remote) obj)) {
+                writesRemote = true;
+                return RemoteObject.toStub((Remote) obj);
+            }
+            if (obj instanceof RemoteStub) {
+                writesRemote = true;
+                return obj;
+            }
+            if (Proxy.isProxyClass(obj.getClass())) {
+                InvocationHandler ih = Proxy.getInvocationHandler(obj);
+                if (ih instanceof RemoteObjectInvocationHandler) {
+                    writesRemote = true;
+                }
+            }
+        }
+        return obj;
+    }
+
+    /**
+     * Writes the annotation for the class passed as argument on the 
+     * {@link RMIObjectOutputStream}
+     * 
+     * @param cl
+     *            the class to be annotated
+     * @throws IOException
+     *             if the I/O operation fails
+     */
+    protected final void annotateClass(Class cl) throws IOException {
+        Object obj = RMIClassLoader.getClassAnnotation(cl);
+        this.writeObject(obj);
+    }
+
+    /**
+     * Writes the annotation for the Proxy class passed as argument on the
+     * RMIOutputStream.
+     * 
+     * @param cl
+     *            the class to be annotated
+     * @throws IOException
+     *             if the I/O operation fails
+     */
+    @Override
+    protected final void annotateProxyClass(Class<?> cl) throws IOException {
+        Object obj = RMIClassLoader.getClassAnnotation(cl);
+        this.writeObject(obj);
+    }
+    
+    /**
+     * Writes the pending content to the underlying stream.
+     */
+    @Override
+    public final void drain() throws IOException {
+        super.drain();
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/RMIServerSocket.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/RMIServerSocket.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/RMIServerSocket.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/RMIServerSocket.java Thu May 18 23:00:52 2006
@@ -1,81 +1,81 @@
-/* 
-*  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.io.InputStream;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-import ar.org.fitc.rmi.transport.http.HttpSocketServerSide;
-import ar.org.fitc.rmi.transport.jrmp.ProtocolHeader;
-
-/**
- * The purpose of this class is to be aware of the socket that has to be
- * returned in the {@link #accept()} method. Because of that, it has to
- * read the first 4 bytes of the socket's input stream returned by the 
- * {@link java.net.ServerSocket#accept()} method of the superclass
- * 
- * @author Diego Raúl Mercado
- */
-final class RMIServerSocket extends ServerSocket {
-
-    /**
-     * Constructor. Before establishing the connection set the socket's address
-     * as reusable
-     * 
-     * @param port
-     *            the port of this serverSocket
-     * @throws IOException
-     *             if an I/O error occurs when creating this serverSocket
-     */
-    public RMIServerSocket(int port) throws IOException {
-        super();
-        super.bind(new InetSocketAddress(port));
-    }
-
-    /**
-     * @ar.org.fitc.spec_ref
-     * Read the first 4 bytes of the socket's input stream returned at the 
-     * {@link java.net.ServerSocket#accept()} method of the superclass. Then, 
-     * determine which socket has to be returned or throw an IOException if 
-     * cannot recognize the stream
-     */
-    @Override
-    public final Socket accept() throws IOException {
-        Socket sock;
-        InputStream in;
-        byte[] protocol = new byte[4];
-        ProtocolHeader protHeader;
-        
-        sock = super.accept();
-        in = sock.getInputStream();
-
-        for (int i = 0; i < 4; i++) {
-        	protocol[i] = (byte)in.read();
-		}
-        protHeader = ProtocolHeader.createProtocolHeader(protocol);
-        if (protHeader.equals(ProtocolHeader.JRMI_PROTOCOL_HEADER)) {
-        	return sock;
-        } else if (protHeader.equals(ProtocolHeader.HTTP_PROTOCOL_HEADER)) {
-        	return new HttpSocketServerSide(sock);
-        } else {
-        	//TODO LOG
-            throw new IOException("Unrecognized Header Protocol");
-        }
-    }
+/* 
+*  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.io.InputStream;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+import org.apache.harmony.rmi.internal.transport.http.HttpSocketServerSide;
+import org.apache.harmony.rmi.internal.transport.jrmp.ProtocolHeader;
+
+/**
+ * The purpose of this class is to be aware of the socket that has to be
+ * returned in the {@link #accept()} method. Because of that, it has to
+ * read the first 4 bytes of the socket's input stream returned by the 
+ * {@link java.net.ServerSocket#accept()} method of the superclass
+ * 
+ * @author Diego Raúl Mercado
+ */
+final class RMIServerSocket extends ServerSocket {
+
+    /**
+     * Constructor. Before establishing the connection set the socket's address
+     * as reusable
+     * 
+     * @param port
+     *            the port of this serverSocket
+     * @throws IOException
+     *             if an I/O error occurs when creating this serverSocket
+     */
+    public RMIServerSocket(int port) throws IOException {
+        super();
+        super.bind(new InetSocketAddress(port));
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * Read the first 4 bytes of the socket's input stream returned at the 
+     * {@link java.net.ServerSocket#accept()} method of the superclass. Then, 
+     * determine which socket has to be returned or throw an IOException if 
+     * cannot recognize the stream
+     */
+    @Override
+    public final Socket accept() throws IOException {
+        Socket sock;
+        InputStream in;
+        byte[] protocol = new byte[4];
+        ProtocolHeader protHeader;
+        
+        sock = super.accept();
+        in = sock.getInputStream();
+
+        for (int i = 0; i < 4; i++) {
+        	protocol[i] = (byte)in.read();
+		}
+        protHeader = ProtocolHeader.createProtocolHeader(protocol);
+        if (protHeader.equals(ProtocolHeader.JRMI_PROTOCOL_HEADER)) {
+        	return sock;
+        } else if (protHeader.equals(ProtocolHeader.HTTP_PROTOCOL_HEADER)) {
+        	return new HttpSocketServerSide(sock);
+        } else {
+        	//TODO LOG
+            throw new IOException("Unrecognized Header Protocol");
+        }
+    }
 }



Mime
View raw message