harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghar...@apache.org
Subject svn commit: r407625 [14/16] - in /incubator/harmony/enhanced/classlib/trunk/modules/rmi3: ./ doc/ make/ src/ src/common/ src/common/javasrc/ src/common/javasrc/java/ src/common/javasrc/java/rmi/ src/common/javasrc/java/rmi/activation/ src/common/javasr...
Date Thu, 18 May 2006 20:01:30 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/proxy/ProxyConstants.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/proxy/ProxyConstants.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/proxy/ProxyConstants.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/proxy/ProxyConstants.java Thu May 18 13:01:22 2006
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.1 $
+ */
+package org.apache.harmony.rmi.transport.proxy;
+
+import org.apache.harmony.rmi.common.RMILog;
+import org.apache.harmony.rmi.common.RMIProperties;
+
+
+/**
+ * Contains constants usable by RMI HTTP proxy access classes.
+ *
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.1 $
+ */
+interface ProxyConstants extends RMIProperties {
+
+    /**
+     * HTTP end-of-line string.
+     */
+    String EOLN = "\r\n";
+
+    /**
+     * HTTP POST request signature.
+     */
+    String HTTP_REQUEST_SIGNATURE = "POST ";
+
+    /**
+     * Length of {@link #HTTP_REQUEST_SIGNATURE} string.
+     */
+    int HTTP_REQUEST_SIGNATURE_LENGTH = HTTP_REQUEST_SIGNATURE.length();
+
+    /**
+     * HTTP response header signature.
+     */
+    String HTTP_RESPONSE_HEADER_SIGNATURE = "HTTP/1.0 200 ";
+
+    /**
+     * HTTP response header.
+     */
+    String HTTP_RESPONSE_HEADER = HTTP_RESPONSE_HEADER_SIGNATURE + "OK";
+
+    /**
+     * Content-Length header string signature.
+     */
+    String CONTENT_LENGTH_SIGNATURE = "Content-Length:";
+
+    /**
+     * Length of {@link #CONTENT_LENGTH_SIGNATURE} string.
+     */
+    int CONTENT_LENGTH_SIGNATURE_LENGTH = CONTENT_LENGTH_SIGNATURE.length();
+
+    /**
+     * Log for logging proxy connections activities.
+     */
+    RMILog proxyTransportLog = RMILog.getProxyTransportLog();
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/proxy/ProxyConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/proxy/ProxyRMISocketFactory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/proxy/ProxyRMISocketFactory.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/proxy/ProxyRMISocketFactory.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/proxy/ProxyRMISocketFactory.java Thu May 18 13:01:22 2006
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.2 $
+ */
+package org.apache.harmony.rmi.transport.proxy;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.Socket;
+import java.rmi.server.RMISocketFactory;
+
+
+/**
+ * Template of a socket factory for proxy connections.
+ *
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.2 $
+ */
+public abstract class ProxyRMISocketFactory extends RMISocketFactory
+        implements Serializable {
+
+    /**
+     * serialVersionUID
+     */
+    private static final long serialVersionUID = 4993249257557742620L;
+
+    /**
+     * {@inheritDoc}
+     *
+     * Equivalent to <code>createSocket(new Proxy(), host, port)</code>
+     */
+    public final Socket createSocket(String host, int port) throws IOException {
+        return createSocket(new Proxy(), host, port);
+    }
+
+    /**
+     * Creates socket for specified host and port using the specified proxy
+     * configuration.
+     *
+     * @param   proxy
+     *          Proxy configuration.
+     *
+     * @param   host
+     *          Host to connect to.
+     *
+     * @param   port
+     *          Port to connect to.
+     *
+     * @return  Created socket.
+     *
+     * @throws  IOException
+     *          If I/O error occurs.
+     */
+    public abstract Socket createSocket(Proxy proxy, String host, int port)
+        throws IOException;
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/proxy/ProxyRMISocketFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/proxy/package.html
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/proxy/package.html?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/proxy/package.html (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/proxy/package.html Thu May 18 13:01:22 2006
@@ -0,0 +1,25 @@
+<html>
+<!--
+Copyright 2005-2006 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.
+-->
+<!--
+Author:  Vasily Zakharov
+Version: $Revision: 1.1.2.1 $
+-->
+<body>
+Proxy transport implementation classes.
+</body>
+</html>

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/proxy/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/DirectRMISocketFactory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/DirectRMISocketFactory.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/DirectRMISocketFactory.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/DirectRMISocketFactory.java Thu May 18 13:01:22 2006
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.2 $
+ */
+package org.apache.harmony.rmi.transport.tcp;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketTimeoutException;
+import java.rmi.server.RMISocketFactory;
+
+
+/**
+ * RMISocketFactory implementation for direct connections.
+ *
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.2 $
+ *
+ * @see RMISocketFactory;
+ */
+public class DirectRMISocketFactory extends RMISocketFactory
+        implements Serializable {
+
+    /**
+     * serialVersionUID
+     */
+    private static final long serialVersionUID = -779073015476675531L;
+
+    /**
+     * @see RMISocketFactory.createSocket(String, int)
+     */
+    public Socket createSocket(String host, int port) throws IOException {
+        return new Socket(host, port);
+    }
+
+   /**
+     * @see RMISocketFactory.createServerSocket(int)
+     */
+    public ServerSocket createServerSocket(int port) throws IOException {
+        return new ServerSocket(port);
+    }
+
+    /**
+     * Does the same as createSocket(String, int) method does but if during
+     * the given timeout the Socket could not be created it's return null.
+     */
+    public Socket createSocket(String host, int port, int timeout)
+            throws IOException {
+        Socket s = new Socket();
+
+        try {
+            s.connect(new InetSocketAddress(host, port), timeout);
+        } catch (SocketTimeoutException ste) {
+            s = null;
+        }
+        return s;
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/DirectRMISocketFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/TcpConnection.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/TcpConnection.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/TcpConnection.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/TcpConnection.java Thu May 18 13:01:22 2006
@@ -0,0 +1,238 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.2 $
+ */
+package org.apache.harmony.rmi.transport.tcp;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.Socket;
+import java.rmi.ConnectIOException;
+import java.rmi.RemoteException;
+import java.security.AccessController;
+
+import org.apache.harmony.rmi.client.ClientConnection;
+import org.apache.harmony.rmi.client.ClientConnectionManager;
+import org.apache.harmony.rmi.common.GetLongPropAction;
+import org.apache.harmony.rmi.common.RMILog;
+import org.apache.harmony.rmi.common.RMIProperties;
+import org.apache.harmony.rmi.transport.Endpoint;
+
+
+/**
+ * Direct socket connection.
+ *
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.2 $
+ */
+public class TcpConnection extends ClientConnection {
+
+    // status of availability for remote calls
+    private boolean available;
+
+    // lock object for synchtonization
+    private Object lock = new Object();
+
+    // when this connection could be closed (if it's available)
+    private long expiration;
+
+    /** Log for logging tcp connections activity. */
+    protected static final RMILog tcpTransportLog = RMILog.getTcpTransportLog();
+
+    /*
+     * The time which will be used as a socket read timeout when reading
+     * protocol acknowledgement data while establishing a new connection.
+     * The default value is 60000 ms (1 minute).
+     */
+    private static int handshakeTimeout = ((Long) AccessController.doPrivileged(
+            new GetLongPropAction(RMIProperties.HANDSHAKETIMEOUT_PROP,
+                    60000))).intValue();
+
+    /**
+     * @see ClientConnection(Socket, Endpoint)
+     */
+    public TcpConnection(Socket s, Endpoint ep)throws RemoteException {
+        super(s, ep);
+        available = false;
+    }
+
+    /**
+     * Acknowledge protocol with server side.
+     *
+     * @return acknowledged protocol number
+     *
+     * @throws RemoteException if any I/O exception occured during protocol
+     *         acknowledgement
+     */
+    protected int serverProtocolAck() throws RemoteException {
+        try {
+            DataOutputStream dout = new DataOutputStream(out);
+
+            // write RMI header and protocol version
+            writeHeader(dout);
+
+            // write protocol type
+            dout.writeByte(STREAM_PROTOCOL);
+            out.flush();
+
+            if (tcpTransportLog.isLoggable(RMILog.VERBOSE)) {
+                tcpTransportLog.log(RMILog.VERBOSE,
+                        "Using stream RMI protocol");
+            }
+
+            // set handshakeTimeout
+            int origTimeout = 0;
+
+            try {
+                origTimeout = s.getSoTimeout();
+                s.setSoTimeout(handshakeTimeout);
+            } catch (Exception ex) {
+            }
+
+            // read protocol acknoledgement
+            DataInputStream din = new DataInputStream(in);
+            int ack = din.readByte();
+
+            if (ack != PROTOCOL_ACK) {
+                throw new ConnectIOException((ack == PROTOCOL_NOT_SUPPORTED)
+                        ? ("Protocol version " + STREAM_PROTOCOL
+                        + " is not supported.") : ("Unknown protocol response: "
+                        + ack));
+            }
+
+            // read host and port
+            String host = din.readUTF();
+            int port = din.readInt();
+
+            if (tcpTransportLog.isLoggable(RMILog.VERBOSE)) {
+                tcpTransportLog.log(RMILog.VERBOSE,
+                        "Server is seeing us as " + host + ":" + port);
+            }
+
+            // restore original value of soTimeout
+            try {
+                s.setSoTimeout(origTimeout);
+            } catch (Exception ex) {
+            }
+
+            // send our host and port (for Stream protocol they'll be ignored)
+            dout.writeUTF(host);
+            dout.writeInt(port);
+            dout.flush();
+        } catch (RemoteException re) {
+            close();
+            throw re;
+        } catch (IOException ioe) {
+            close();
+            throw new ConnectIOException(
+                    "Unable to acknowledge protocol with server", ioe);
+        }
+
+        // protocol is agreed
+        return STREAM_PROTOCOL;
+    }
+
+    /**
+     * @see ClientConnection.done()
+     */
+    public void done() {
+        synchronized (lock) {
+            available = true;
+            expiration = System.currentTimeMillis()
+                    + ClientConnectionManager.connTimeout;
+        }
+    }
+
+    /**
+     * @see ClientConnection.reuse()
+     */
+    public synchronized boolean reuse() {
+        synchronized (lock) {
+            if (!available) {
+                return false;
+            }
+        }
+        int ackResp = 0;
+
+        try {
+            out.write(PING_MSG);
+            out.flush();
+            ackResp = in.read();
+        } catch (IOException ioe) {
+            if (tcpTransportLog.isLoggable(RMILog.BRIEF)) {
+                tcpTransportLog.log(RMILog.BRIEF,
+                        "Ping request for " + toString() + " failed.");
+            }
+            close(false);
+            return false;
+        }
+
+        if (ackResp != PING_ACK) {
+            if (tcpTransportLog.isLoggable(RMILog.BRIEF)) {
+                tcpTransportLog.log(RMILog.BRIEF,
+                        "Unknown response to ping request for " + toString()
+                        + ": " + ackResp);
+            }
+            close(false);
+            return false;
+        }
+
+        synchronized (lock) {
+            available = false;
+        }
+
+        if (tcpTransportLog.isLoggable(RMILog.BRIEF)) {
+            tcpTransportLog.log(RMILog.BRIEF,
+                    "Reusing " + toString() + "...");
+        }
+        return true;
+    }
+
+    /**
+     * @see ClientConnection.isAvailable()
+     */
+    public boolean isAvailable() {
+        synchronized (lock) {
+            return available;
+        }
+    }
+
+    /**
+     * Returns true because this connection could be reused.
+     *
+     * @see ClientConnection.isReusable()
+     */
+    public boolean isReusable() {
+        return true;
+    }
+
+    /**
+     * @see ClientConnection.getExpiration()
+     */
+    public long getExpiration() {
+        synchronized (lock) {
+            if (!available) {
+                return -1;
+            }
+            return expiration;
+        }
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/TcpConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/TcpServerConnection.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/TcpServerConnection.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/TcpServerConnection.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/TcpServerConnection.java Thu May 18 13:01:22 2006
@@ -0,0 +1,203 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.2 $
+ */
+package org.apache.harmony.rmi.transport.tcp;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.Socket;
+import java.rmi.RemoteException;
+import java.rmi.UnmarshalException;
+import java.rmi.server.UID;
+import java.security.AccessController;
+
+import org.apache.harmony.rmi.common.GetLongPropAction;
+import org.apache.harmony.rmi.common.RMILog;
+import org.apache.harmony.rmi.common.RMIProperties;
+import org.apache.harmony.rmi.server.ServerConnection;
+import org.apache.harmony.rmi.server.ServerConnectionManager;
+
+
+/**
+ * Tcp extension of ServerConnection.
+ *
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.2 $
+ */
+public class TcpServerConnection extends ServerConnection {
+
+    /** Log for logging tcp connections activity. */
+    protected static final RMILog tcpTransportLog = RMILog.getTcpTransportLog();
+
+    /*
+     * The time used as an idle timeout for incomping connections (in ms).
+     * Default value is 2 * 3600 * 1000 ms (2 hours).
+     */
+    private static int readTimeout = ((Long) AccessController.doPrivileged(
+            new GetLongPropAction(RMIProperties.READTIMEOUT_PROP,
+                    2 * 3600 * 1000))).intValue();
+
+    /**
+     * Constructs TcpServerConnection working through socket specified.
+     *
+     * @param s Socket connected to the client
+     * @param mgr ConnectionManager managing this connection
+     *
+     * @throws IOException if an I/O error occured during getting
+     *         input/output streams from specified socket
+     */
+    public TcpServerConnection(Socket s, ServerConnectionManager mgr)
+            throws IOException {
+        super(s, mgr);
+        s.setSoTimeout(readTimeout);
+    }
+
+    /**
+     * @see ServerConnection.clientProtocolAck()
+     */
+    protected int clientProtocolAck() throws IOException {
+        byte data;
+        DataInputStream din = new DataInputStream(in);
+
+        try {
+            // read RMI header
+            int header = din.readInt();
+
+            if (header != RMI_HEADER) {
+                throw new UnmarshalException("Unknown header: " + header);
+            }
+
+            // read RMI protocol version
+            short ver = din.readShort();
+
+            if (ver != PROTOCOL_VER) {
+                throw new UnmarshalException("Unknown RMI protocol version: "
+                        + ver);
+            }
+        } catch (IOException ioe) {
+            throw new UnmarshalException("Unable to read RMI protocol header",
+                    ioe);
+        }
+
+        if (tcpTransportLog.isLoggable(RMILog.VERBOSE)) {
+            tcpTransportLog.log(RMILog.VERBOSE, "Using protocol version "
+                    + PROTOCOL_VER);
+        }
+        DataOutputStream dout = new DataOutputStream(out);
+
+        // read protocol type
+        if (din.readByte() == STREAM_PROTOCOL) {
+            if (tcpTransportLog.isLoggable(RMILog.VERBOSE)) {
+                tcpTransportLog.log(RMILog.VERBOSE,
+                        "Using stream RMI protocol");
+            }
+        } else {
+            dout.writeByte(PROTOCOL_NOT_SUPPORTED);
+            dout.flush();
+            return -1;
+        }
+
+        // send ack msg
+        dout.writeByte(PROTOCOL_ACK);
+
+        // send client's host and port
+        String host = s.getInetAddress().getHostAddress();
+        int port = s.getPort();
+        dout.writeUTF(host);
+        dout.writeInt(port);
+        dout.flush();
+
+        if (tcpTransportLog.isLoggable(RMILog.VERBOSE)) {
+            tcpTransportLog.log(RMILog.VERBOSE,
+                    "Server is seeing client as " + host + ":" + port);
+        }
+
+        // read host and port
+        din.readUTF();
+        din.readInt();
+
+        // protocol is agreed
+        return STREAM_PROTOCOL;
+    }
+
+    /**
+     * @see ServerConnection.waitCallMsg()
+     */
+    protected int waitCallMsg() throws IOException {
+        int data;
+
+        while (true) {
+            try {
+                data = in.read();
+            } catch (IOException ioe) {
+                data = -1;
+            }
+
+            if (data == -1) {
+                if (tcpTransportLog.isLoggable(RMILog.BRIEF)) {
+                    tcpTransportLog.log(RMILog.BRIEF,
+                            "Connection [" + toString() + "] is closed");
+                }
+                return -1;
+            }
+            DataOutputStream dout = new DataOutputStream(out);
+
+            if (data == PING_MSG) {
+                if (tcpTransportLog.isLoggable(RMILog.VERBOSE)) {
+                    tcpTransportLog.log(RMILog.VERBOSE,
+                            "Got ping request");
+                }
+
+                // send ping ack
+                dout.writeByte(PING_ACK);
+                dout.flush();
+            } else if (data == DGCACK_MSG) {
+                if (tcpTransportLog.isLoggable(RMILog.VERBOSE)) {
+                    tcpTransportLog.log(RMILog.VERBOSE,
+                            "Got DGC ack request");
+                }
+                dgcUnregisterUID(UID.read(new DataInputStream(in)));
+            } else if (data == CALL_MSG) {
+                if (tcpTransportLog.isLoggable(RMILog.VERBOSE)) {
+                    tcpTransportLog.log(RMILog.VERBOSE,
+                            "Got call request");
+                }
+                return data;
+            } else {
+                if (tcpTransportLog.isLoggable(RMILog.BRIEF)) {
+                    tcpTransportLog.log(RMILog.BRIEF,
+                            "Unknown request got: " + data);
+                }
+                throw new RemoteException("Unknown message got: " + data);
+            }
+        }
+    }
+
+    /**
+     * Returns string representation of this connection.
+     *
+     * @return string representation of this connection
+     */
+    public String toString() {
+        return "TcpServerConnection: remote endpoint:" + ep;
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/TcpServerConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/package.html
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/package.html?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/package.html (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/package.html Thu May 18 13:01:22 2006
@@ -0,0 +1,25 @@
+<html>
+<!--
+Copyright 2005-2006 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.
+-->
+<!--
+Author:  Vasily Zakharov
+Version: $Revision: 1.1.2.1 $
+-->
+<body>
+TCP transport implementation classes.
+</body>
+</html>

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/src/common/javasrc/org/apache/harmony/rmi/transport/tcp/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/ConnectionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/ConnectionTest.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/ConnectionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/ConnectionTest.java Thu May 18 13:01:22 2006
@@ -0,0 +1,443 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Mikhail A. Markov, Vasily Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+package org.apache.harmony.rmi;
+
+import java.lang.reflect.Proxy;
+
+import java.rmi.RMISecurityManager;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.ServerError;
+
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+
+import java.rmi.server.RemoteObject;
+
+import org.apache.harmony.rmi.common.SubProcess;
+import org.apache.harmony.rmi.test.MyException;
+import org.apache.harmony.rmi.test.MyInvocationHandler;
+import org.apache.harmony.rmi.test.MyRemoteInterface;
+import org.apache.harmony.rmi.test.MyRemoteInterface1;
+import org.apache.harmony.rmi.test.MyRemoteObject;
+import org.apache.harmony.rmi.test.MyRemoteObject1;
+import org.apache.harmony.rmi.test.MyRemoteObject3;
+import org.apache.harmony.rmi.test.MyRemoteObject4;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+/**
+ * Unit test for RMI.
+ *
+ * @author  Mikhail A. Markov, Vasily Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+public class ConnectionTest extends RMITestBase {
+
+    /**
+     * String to identify that a child test process must be started.
+     */
+    private static final String CHILD_ID = "child";
+
+    /**
+     * No-arg constructor to enable serialization.
+     */
+    public ConnectionTest() {
+        super();
+    }
+
+    /**
+     * Constructs this test case with the given name.
+     *
+     * @param   name
+     *          Name for this test case.
+     */
+    public ConnectionTest(String name) {
+        super(name);
+    }
+
+    /**
+     * Tests direct socket RMI data exchange.
+     * with both server and client run on a single VM.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    public void testDirectSocket_SingleVM() throws Exception {
+        System.err.println("testDirectSocket_SingleVM starting");
+        testSingleVM(CONFIG_DIRECT_SOCKET, true);
+    }
+
+    /**
+     * Tests direct HTTP RMI data exchange
+     * with both server and client run on a single VM.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    public void testDirectHTTP_SingleVM() throws Exception {
+        System.err.println("testDirectHTTP_SingleVM starting");
+        testSingleVM(CONFIG_DIRECT_HTTP, true);
+    }
+
+    /**
+     * Tests proxy HTTP RMI data exchange
+     * with both server and client run on a single VM.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    public void testProxyHTTP_SingleVM() throws Exception {
+        if (checkProxy("testProxyHTTP_SingleVM")) {
+            System.err.println("testProxyHTTP_SingleVM starting");
+            testSingleVM(CONFIG_PROXY_HTTP, true);
+        }
+    }
+
+    /**
+     * Tests proxy HTTP-CGI RMI data exchange
+     * with both server and client run on a single VM.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    public void testProxyCGI_SingleVM() throws Exception {
+        if (checkProxy("testProxyCGI_SingleVM")) {
+            System.err.println("testProxyCGI_SingleVM starting");
+            testSingleVM(CONFIG_PROXY_CGI, true);
+        }
+    }
+
+    /**
+     * Tests RMI data exchange in one separate VM.
+     *
+     * @param   config
+     *          Configuration to set environment for.
+     *
+     * @param   endorsed
+     *          If endorsedDirs and bootClassPath
+     *          should be propagated to test VM.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    public void testSingleVM(int config, boolean endorsed) throws Exception {
+        SubProcess server = null;
+
+        try {
+            System.out.println("Starting test server");
+            server = startProcess("org.apache.harmony.rmi.ConnectionTest",
+                            CHILD_ID, config, endorsed);
+            server.pipeError();
+            server.closeOutput();
+            System.out.println("Expecting READY from server");
+            server.expect();
+            server.pipeInput();
+        } catch (Exception e) {
+            System.err.print("Unexpected exception in main thread: ");
+            e.printStackTrace();
+            fail("Unexpected exception in main thread: " + e);
+        } finally {
+            if (server != null) {
+                System.out.println("Destroying server");
+                server.destroy();
+            }
+        }
+    }
+
+    /**
+     * Creates RMI server part.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    private void initServer() throws Exception {
+        MyRemoteObject obj = new MyRemoteObject();
+        System.err.println("Object: " + obj + " created and exported.");
+        Registry reg = LocateRegistry.createRegistry(REGISTRY_PORT);
+        exportedObjects.add(reg);
+        System.err.println("Registry created.");
+        reg.bind("MyRemoteObject", RemoteObject.toStub(obj));
+        exportedObjects.add(obj);
+        System.err.println("Object bound in the registry.");
+    }
+
+    /**
+     * Performs various data exchange tests.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    private void mainTestBody() throws Exception {
+        Registry reg = LocateRegistry.getRegistry(REGISTRY_HOST);
+        System.err.println("Registry located.");
+        MyRemoteInterface mri = (MyRemoteInterface) reg.lookup("MyRemoteObject");
+        System.err.println("Lookup object is: " + mri);
+        Remote obj;
+
+        // test_String_Void
+        System.err.println("Testing test_String_Void...");
+        mri.test_String_Void("Main for test_String_Void.");
+        System.err.println("Done.\n");
+
+        // test_Void_String
+        System.err.println("Testing test_Void_String...");
+        System.err.println("Returned: " + mri.test_Void_String());
+        System.err.println("Done.\n");
+
+        // test_Int_Void
+        System.err.println("Testing test_Int_Void...");
+        mri.test_Int_Void(1234567890);
+        System.err.println("Done.\n");
+
+        // test_Void_Int
+        System.err.println("Testing test_Void_Int...");
+        System.err.println("Returned: " + mri.test_Void_Int());
+        System.err.println("Done.\n");
+
+        //test_Remote_Void
+        System.err.println("Testing test_Remote_Void...");
+        obj = new MyRemoteObject1("Main for test_Remote_Void.");
+        exportedObjects.add(obj);
+        mri.test_Remote_Void(obj);
+        System.err.println("Done.\n");
+
+        //tests remote Object extending another remote object
+        System.err.println("Testing test_Remote_Void with remote object "
+                + "extending another remote object...");
+        obj = new MyRemoteObject4("Main for test_Remote_Void 1.");
+        exportedObjects.add(obj);
+        mri.test_Remote_Void(obj);
+        System.err.println("Done.\n");
+
+        // test_Void_Remote
+        System.err.println("Testing test_Void_Remote...");
+        System.err.println("Returned: " + mri.test_Void_Remote());
+        System.err.println("Done.\n");
+
+        // test_Long_Long
+        System.err.println("Testing test_Long_Long...");
+        System.err.println("Returned: "
+                + mri.test_Long_Long(112233445566778899L));
+        System.err.println("Done.\n");
+
+        // test_String_String
+        System.err.println("Testing test_String_String...");
+        System.err.println("Returned: "
+                + mri.test_String_String("Main for test_String_String."));
+        System.err.println("Done.\n");
+
+        // test_Remote_Remote
+        System.err.println("Testing test_Remote_Remote...");
+        obj = new MyRemoteObject1("Main for test_Remote_Remote.");
+        exportedObjects.add(obj);
+        System.err.println("Returned: " + mri.test_Remote_Remote(obj));
+        System.err.println("Done.\n");
+
+        // test_RemoteString_Void
+        System.err.println("Testing test_RemoteString_Void...");
+        obj = new MyRemoteObject1("Main for test_RemoteString_Void.");
+        exportedObjects.add(obj);
+        mri.test_RemoteString_Void(obj,
+                "Main for test_RemoteString_Void (2).");
+        System.err.println("Done.\n");
+
+        // test_RemoteRemote_Remote
+        System.err.println("Testing test_RemoteRemote_Remote...");
+        obj = new MyRemoteObject1("Main for test_RemoteRemote_Remote.");
+        Remote obj1 = new MyRemoteObject3(
+                "Main for test_RemoteRemote_Remote (2).");
+        exportedObjects.add(obj);
+        exportedObjects.add(obj1);
+        System.err.println("Returned: "
+                + mri.test_RemoteRemote_Remote(obj, obj1));
+        System.err.println("Done.\n");
+
+        // test_BooleanStringRemote_Void
+        System.err.println("Testing test_BooleanStringRemote_Void...");
+        obj = new MyRemoteObject1(
+                "Main for test_BooleanStringRemote_Void (2).");
+        exportedObjects.add(obj);
+        mri.test_BooleanStringRemote_Void(false,
+            "Main for test_BooleanStringRemote_Void.", obj);
+        System.err.println("Done.\n");
+
+        // test_Proxy_Void
+        System.err.println("Testing test_Proxy_Void...");
+        Object proxy = Proxy.newProxyInstance(
+                Thread.currentThread().getContextClassLoader(),
+                new Class[] { MyRemoteInterface1.class },
+                new MyInvocationHandler());
+        mri.test_Proxy_Void(proxy);
+        System.err.println("Done.\n");
+
+        // test_Array_Void
+        System.err.println("Testing test_Array_Void...");
+        mri.test_Array_Void(new String[] { "Main for test_Array_Void 1.",
+               "Main for test_Array_Void 2." });
+        System.err.println("Done.\n");
+
+        // test_Void_Array
+        System.err.println("Testing test_Void_Array...");
+        printArray(mri.test_Void_Array());
+        System.err.println("Done.\n");
+
+        // test_RemoteArray_Void
+        System.err.println("Testing test_RemoteArray_Void...");
+        obj = new MyRemoteObject1("Main for test_RemoteArray_Void 1.");
+        obj1 = new MyRemoteObject1("Main for test_RemoteArray_Void 2.");
+        exportedObjects.add(obj);
+        exportedObjects.add(obj1);
+        mri.test_RemoteArray_Void(new Remote[] { obj, obj1 });
+        System.err.println("Done.\n");
+
+        // test_Void_RemoteArray
+        System.err.println("Testing test_Void_RemoteArray...");
+        printArray(mri.test_Void_RemoteArray());
+        System.err.println("Done.\n");
+
+        // test_Exception
+        System.err.println("Testing test_Exception...");
+        try {
+            mri.test_Exception();
+            fail("test_Exception() should have thrown MyException");
+        } catch (MyException e) {
+            System.err.println(e.toString());
+        }
+        System.err.println("Done.\n");
+
+        // test_Error
+        System.err.println("Testing test_Error...");
+        try {
+            mri.test_Error();
+            fail("test_Error() should have thrown ServerError");
+        } catch (ServerError e) {
+            System.err.println(e.toString());
+        }
+        System.err.println("Done.\n");
+
+        // test_RuntimeException
+        System.err.println("Testing test_RuntimeException...");
+        try {
+            mri.test_RuntimeException();
+            fail("test_RuntimeException() should have thrown RuntimeException");
+        } catch (RuntimeException e) {
+            System.err.println(e.toString());
+        }
+        System.err.println("Done.\n");
+
+        // test_RemoteException
+        System.err.println("Testing test_RemoteException...");
+        try {
+            mri.test_RemoteException();
+            fail("test_RemoteException() should have thrown RemoteException");
+        } catch (RemoteException e) {
+            System.err.println(e.toString());
+        }
+        System.err.println("Done.\n");
+    }
+
+    /**
+     * Runs test server process.
+     *
+     * @param   config
+     *          Number of the configuration to run.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    private void runTestSingle(int config) throws Exception {
+        try {
+            System.err.println("Test server started.");
+            System.setSecurityManager(new RMISecurityManager());
+            setEnvironmentForConfig(config);
+            initServer();
+            mainTestBody();
+            System.err.println("Test server complete.");
+            SubProcess.tellOut();
+        } finally {
+            System.err.println("Test server closing.");
+            try {
+                unexportObjects();
+            } catch (Exception e) {
+                System.err.print("Unexpected exception while unexporting: ");
+                e.printStackTrace();
+            }
+        }
+        System.err.println("Test server exiting.");
+    }
+
+    /**
+     * Returns test suite for this class.
+     *
+     * @return  Test suite for this class.
+     */
+    public static Test suite() {
+        return new TestSuite(ConnectionTest.class);
+    }
+
+    /**
+     * Starts the testing from the command line.
+     *
+     * If first command line parameter exists, the test server is started
+     * instead. The parameter value is used as a suffix of the respective
+     * setEnvironmentXXX method that is called to setup the environment
+     * configuration.
+     *
+     * @param   args
+     *          Command line parameters.
+     */
+    public static void main(String args[]) {
+        switch (args.length) {
+        case 0:
+            // Run tests normally.
+            junit.textui.TestRunner.run(suite());
+            break;
+        case 2:
+            // Run child test server process.
+            String param = args[0];
+            int config = new Integer(args[1]).intValue();
+            ConnectionTest connectionTest = new ConnectionTest();
+
+            try {
+                if (param.equals(CHILD_ID)) {
+                    connectionTest.runTestSingle(config);
+                } else {
+                    System.err.println("Bad parameter: " + param);
+                    abort();
+                }
+            } catch (Exception e) {
+                System.err.print("Child process ("
+                        + param + ", " + config + ") failed: ");
+                e.printStackTrace();
+                abort();
+            }
+            break;
+        default:
+            System.err.println("Bad number of parameters: "
+                    + args.length + ", expected: 2.");
+            abort();
+        }
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/ConnectionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/DGCTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/DGCTest.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/DGCTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/DGCTest.java Thu May 18 13:01:22 2006
@@ -0,0 +1,418 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Mikhail A. Markov, Vasily Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+package org.apache.harmony.rmi;
+
+import java.io.EOFException;
+
+import java.rmi.RMISecurityManager;
+
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+
+import java.rmi.server.RemoteObject;
+import java.rmi.server.UnicastRemoteObject;
+
+import org.apache.harmony.rmi.common.SubProcess;
+import org.apache.harmony.rmi.test.MyRemoteInterface1;
+import org.apache.harmony.rmi.test.TestObject;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+/**
+ * Unit test for RMI Distributed Garbage Collector.
+ *
+ * @author  Mikhail A. Markov, Vasily Zakharov
+ * @version $Revision: 1.1.2.4 $
+ */
+public class DGCTest extends RMITestBase {
+
+    /**
+     * String to identify that a registry process must be started.
+     */
+    private static final String REGISTRY_ID = "registry";
+
+    /**
+     * String to identify that a server process for test 0 must be started.
+     */
+    private static final String SERVER_ID_0 = "server0";
+
+    /**
+     * String to identify that a client process for test 0 must be started.
+     */
+    private static final String CLIENT_ID_0 = "client0";
+
+    /**
+     * String to identify that a server process for test 3 must be started.
+     */
+    private static final String SERVER_ID_3 = "server3";
+
+    /**
+     * Garbage collector tick (in milliseconds).
+     */
+    private static final int GC_TICK = 10000;
+
+    /**
+     * No-arg constructor to enable serialization.
+     */
+    public DGCTest() {
+        super();
+    }
+
+    /**
+     * Constructs this test case with the given name.
+     *
+     * @param   name
+     *          Name for this test case.
+     */
+    public DGCTest(String name) {
+        super(name);
+    }
+
+    /**
+     * Test0
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    public void test0() throws Exception {
+        System.out.println("test0 starting");
+        test0(CONFIG_DIRECT_SOCKET, true,
+              CONFIG_DIRECT_SOCKET, true,
+              CONFIG_DIRECT_SOCKET, true);
+        System.out.println("test0 complete");
+    }
+
+    /**
+     * Test3
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    public void test3() throws Exception {
+        System.out.println("test3 starting");
+        test3(CONFIG_DIRECT_SOCKET, true);
+        System.out.println("test3 complete");
+    }
+
+    /**
+     * Test0
+     *
+     * @param   configServer
+     *          Server configuration to set environment for.
+     *
+     * @param   endorsedServer
+     *          If endorsedDirs and bootClassPath should be propagated to
+     *          server.
+     *
+     * @param   configClient
+     *          Client configuration to set environment for.
+     *
+     * @param   endorsedClient
+     *          If endorsedDirs and bootClassPath should be propagated to
+     *          client.
+     *
+     * @param   configRegistry
+     *          Registry configuration to set environment for.
+     *
+     * @param   endorsedRegistry
+     *          If endorsedDirs and bootClassPath should be propagated to
+     *          registry.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    private void test0(int configServer, boolean endorsedServer,
+            int configClient, boolean endorsedClient, int configRegistry,
+            boolean endorsedRegistry) throws Exception {
+        SubProcess registry = null;
+        SubProcess server = null;
+        SubProcess client = null;
+
+        try {
+            System.out.println("test0: creating registry");
+            registry = startProcess("org.apache.harmony.rmi.DGCTest",
+                    REGISTRY_ID, configRegistry, endorsedRegistry);
+            registry.pipeError();
+            System.out.println("test0: Expecting READY from registry");
+            registry.expect();
+            registry.pipeInput();
+
+            System.out.println("test0: starting server");
+            server = startProcess("org.apache.harmony.rmi.DGCTest",
+                    SERVER_ID_0, configServer, endorsedServer);
+            server.pipeError();
+            server.closeOutput();
+            System.out.println("test0: Expecting READY from server");
+            server.expect();
+
+            System.out.println("test0: starting client");
+            client = startProcess("org.apache.harmony.rmi.DGCTest",
+                    CLIENT_ID_0, configClient, endorsedClient);
+            client.pipeInput();
+            client.pipeError();
+            client.closeOutput();
+
+            System.out.println("test0: Expecting STARTED from server");
+            server.expect("TestObject.test1() started");
+            server.pipeInput();
+
+            System.out.println("test0: destroying registry");
+            registry.destroy();
+
+            System.out.println("test0: destroying client");
+            client.destroy();
+
+            System.out.println("test0: waiting for server to return");
+            assertEquals("Test server return", 0, server.waitFor());
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Unexpected exception: " + e);
+        } finally {
+            if (registry != null) {
+                registry.destroy();
+            }
+            if (client != null) {
+                client.destroy();
+            }
+            if (server != null) {
+                server.destroy();
+            }
+        }
+    }
+
+    /**
+     * Test3
+     *
+     * @param   config
+     *          Configuration to set environment for.
+     *
+     * @param   endorsed
+     *          If endorsedDirs and bootClassPath should be propagated to
+     *          test VM.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    private void test3(int config, boolean endorsed) throws Exception {
+        SubProcess server = null;
+
+        try {
+            System.out.println("test3: starting server");
+            server = startProcess("org.apache.harmony.rmi.DGCTest",
+                    SERVER_ID_3, config, endorsed);
+            server.pipeInput();
+            server.pipeError();
+            server.closeOutput();
+            assertEquals("Test server return", 0, server.waitFor());
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Unexpected exception: " + e);
+        } finally {
+            if (server != null) {
+                server.destroy();
+            }
+        }
+    }
+
+    /**
+     * Runs registry process, wait for READY and exits with export
+     * or stays on if input stream is closed.
+     *
+     * @param   config
+     *          Number of the configuration to run.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    private void runRegistry(int config) throws Exception {
+        System.err.println("Registry starting");
+        System.setSecurityManager(new RMISecurityManager());
+        setEnvironmentForConfig(config);
+        Registry reg = LocateRegistry.createRegistry(REGISTRY_PORT);
+        System.err.println("Registry initialized, telling READY to parent");
+        SubProcess.tellOut();
+        System.err.println("Expecting READY from parent");
+
+        try {
+            SubProcess.expectIn();
+            UnicastRemoteObject.unexportObject(reg, true);
+            System.err.println("Registry exiting");
+        } catch (EOFException e) {
+            System.err.println("EOFException caught, registry stays on");
+        }
+    }
+
+    /**
+     * Runs test server process.
+     *
+     * @param   config
+     *          Number of the configuration to run.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    private void runTestServer0(int config) throws Exception {
+        System.err.println("Test server started");
+        System.setSecurityManager(new RMISecurityManager());
+        setEnvironmentForConfig(config);
+        MyRemoteInterface1 obj = new TestObject();
+        UnicastRemoteObject.exportObject(obj, CUSTOM_PORT_4);
+        LocateRegistry.getRegistry().rebind(
+                TEST_STRING_1, RemoteObject.toStub(obj));
+        GCThread.create();
+        System.err.println("Test server initialized, telling READY to parent");
+        SubProcess.tellOut();
+    }
+
+    /**
+     * Runs test client process.
+     *
+     * @param   config
+     *          Number of the configuration to run.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    private void runTestClient0(int config) throws Exception {
+        System.err.println("Test client started");
+        System.setSecurityManager(new RMISecurityManager());
+        setEnvironmentForConfig(config);
+        Registry reg = LocateRegistry.getRegistry();
+        MyRemoteInterface1 mri = (MyRemoteInterface1) reg.lookup(TEST_STRING_1);
+        mri.test1();
+        System.err.println("Test client completed");
+    }
+
+    /**
+     * Runs test server process.
+     *
+     * @param   config
+     *          Number of the configuration to run.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    private void runTestServer3(int config) throws Exception {
+        System.err.println("Test server started");
+        System.setSecurityManager(new RMISecurityManager());
+        setEnvironmentForConfig(config);
+        Registry reg = LocateRegistry.createRegistry(REGISTRY_PORT);
+        TestObject obj = new TestObject();
+        UnicastRemoteObject.exportObject(obj, REGISTRY_PORT);
+        obj = null;
+        System.gc();
+        System.err.println("Test server exiting");
+    }
+
+    /**
+     * Calls system garbage collector ({@link System#gc()}) periodically.
+     */
+    static class GCThread extends Thread {
+
+        /**
+         * Creates this thread and marks it as daemon thread.
+         */
+        public GCThread() {
+            super();
+            setDaemon(true);
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public void run() {
+            while (true) {
+                try {
+                    sleep(GC_TICK);
+                } catch (InterruptedException e) {}
+
+                System.out.println("GCThread: Calling GC");
+                System.gc();
+            }
+        }
+
+        /**
+         * Creates new GCThread thread.
+         */
+        public static void create() {
+            new GCThread().start();
+        }
+    }
+
+    /**
+     * Returns test suite for this class.
+     *
+     * @return  Test suite for this class.
+     */
+    public static Test suite() {
+        return new TestSuite(DGCTest.class);
+    }
+
+    /**
+     * Starts the testing from the command line.
+     *
+     * @param   args
+     *          Command line parameters.
+     */
+    public static void main(String args[]) {
+        switch (args.length) {
+        case 0:
+            // Run tests normally.
+            junit.textui.TestRunner.run(suite());
+            break;
+        case 2:
+            // Run registry, test server or client process.
+            int config = new Integer(args[1]).intValue();
+            String param = args[0].intern();
+            DGCTest dgcTest = new DGCTest();
+
+            try {
+                if (param == REGISTRY_ID) {
+                    dgcTest.runRegistry(config);
+                } else if (param == SERVER_ID_0) {
+                    dgcTest.runTestServer0(config);
+                } else if (param == CLIENT_ID_0) {
+                    dgcTest.runTestClient0(config);
+                } else if (param == SERVER_ID_3) {
+                    dgcTest.runTestServer3(config);
+                } else {
+                    System.err.println("Bad parameter: " + param);
+                    abort();
+                }
+            } catch (Exception e) {
+                System.err.println("Child process ("
+                        + param + ", " + config + ") failed: " + e);
+                e.printStackTrace();
+                abort();
+            }
+            System.err.println("Child process ("
+                    + param + ", " + config + ") is terminating OK");
+            break;
+        default:
+            System.err.println("Bad number of parameters: "
+                    + args.length + ", expected: 2.");
+            abort();
+        }
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/DGCTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/JavaInvoker.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/JavaInvoker.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/JavaInvoker.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/JavaInvoker.java Thu May 18 13:01:22 2006
@@ -0,0 +1,208 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.5 $
+ */
+package org.apache.harmony.rmi;
+
+import java.io.File;
+import java.io.IOException;
+
+import java.util.Arrays;
+import java.util.Vector;
+
+import org.apache.harmony.rmi.common.SubProcess;
+
+
+/**
+ * Invoker for Virtual Machine.
+ *
+ * More methods running VM in various configurations are welcome.
+ *
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.5 $
+ *
+ * @todo    Probably in future should be replaced by VM-specific calls
+ *          allowing to create VM without using heavy and system-dependent
+ *          <code>exec()</code> calls.
+ */
+public final class JavaInvoker {
+
+    /**
+     * Home path.
+     */
+    private static final String javaHome =
+            System.getProperty("java.home");
+
+    /**
+     * Class path.
+     */
+    private static final String javaClassPath =
+            System.getProperty("java.class.path");
+
+    /**
+     * Security policy file.
+     */
+    private static final String policy =
+            System.getProperty("java.security.policy");
+
+    /**
+     * Endorsed directories.
+     */
+    private static final String javaEndorsedDirs =
+            System.getProperty("java.endorsed.dirs");
+
+    /**
+     * Boot class path, initialized in static block.
+     */
+    private static final String bootClassPath;
+
+    /**
+     * Executable location, initialized in static block.
+     */
+    private static final String executable;
+
+    /**
+     * Static block initializing {@link #bootClassPath} and {@link #executable}.
+     */
+    static {
+        String vmName = System.getProperty("java.vm.name");
+
+        bootClassPath = System.getProperty(vmName.equals("J9")
+                ? "com.ibm.oti.system.class.path" : "sun.boot.class.path");
+
+        executable = new File(new File(javaHome, "bin"), "java").getPath();
+    }
+
+    /**
+     * Creates args array for Java invocation.
+     *
+     * @param   options
+     *          Java options.
+     *
+     * @param   className
+     *          Name of the class to run.
+     *
+     * @param   params
+     *          Parameters to pass to the class.
+     *
+     * @param   useEndorsedDirs
+     *          If endorsed dirs (<code>-Djava.endorsed.dirs</code>)
+     *          from this VM should be applied.
+     *
+     * @param   useBootClassPath
+     *          If bootclasspath (<code>-Xbootclasspath</code>)
+     *          from this VM should be applied.
+     *
+     * @return  Generated args array.
+     */
+    private static String[] createArgsArray(
+            String[] options, String className, String[] params,
+            boolean useEndorsedDirs, boolean useBootClassPath) {
+        Vector args = new Vector();
+        String useJavaClassPath;
+
+        // Add name of Java executable to run.
+        args.add(executable);
+
+        if (useEndorsedDirs) {
+            if (javaEndorsedDirs != null) {
+                // Apply endorsed dirs.
+                args.add("-Djava.endorsed.dirs=" + javaEndorsedDirs);
+            }
+        }
+
+        if (bootClassPath != null) {
+            if (useBootClassPath) {
+                // Apply bootclasspath.
+                args.add("-Xbootclasspath:" + bootClassPath);
+                useJavaClassPath = javaClassPath;
+            } else if (javaClassPath != null) { // Class path is set.
+                // Append bootclasspath to classpath.
+                useJavaClassPath =
+                    (javaClassPath + File.pathSeparator + bootClassPath);
+            } else { // Class path is not set.
+                // Set class path to bootclasspath.
+                useJavaClassPath = bootClassPath;
+            }
+        } else {
+            useJavaClassPath = javaClassPath;
+        }
+
+        // Apply classpath.
+        if (useJavaClassPath != null) {
+            args.add("-classpath");
+            args.add(useJavaClassPath);
+        }
+
+        if (policy != null) {
+            // Apply security policy.
+            args.add("-Djava.security.policy=" + policy);
+        }
+
+        if (options != null) {
+            args.addAll(Arrays.asList(options));
+        }
+
+        if (className != null) {
+            args.add(className);
+        }
+
+        if (params != null) {
+            args.addAll(Arrays.asList(params));
+        }
+
+        return (String[]) args.toArray(new String[args.size()]);
+    }
+
+    /**
+     * Invokes Java machine with configuration similar to the current one.
+     * The properties of current VM are extracted from system properties
+     * and passed to new VM.
+     *
+     * @param   options
+     *          Java options.
+     *
+     * @param   className
+     *          Name of the class to run.
+     *
+     * @param   params
+     *          Parameters to pass to the class.
+     *
+     * @param   useEndorsedDirs
+     *          If endorsed dirs (<code>-Djava.endorsed.dirs</code>)
+     *          from this VM should be applied.
+     *
+     * @param   useBootClassPath
+     *          If bootclasspath (<code>-Xbootclasspath</code>)
+     *          from this VM should be applied.
+     *
+     * @return  The process created.
+     *
+     * @throws  IOException
+     *          If some error occurs.
+     */
+    public static SubProcess invokeSimilar(String[] options, String className,
+            String[] params, boolean useEndorsedDirs, boolean useBootClassPath)
+            throws IOException {
+        // @ToDo: Rewrite with ProcessBuilder for Java 5.0.
+        return new SubProcess(createArgsArray(options, className, params,
+                useEndorsedDirs, useBootClassPath));
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/JavaInvoker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/MarshalledObjectTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/MarshalledObjectTest.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/MarshalledObjectTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/MarshalledObjectTest.java Thu May 18 13:01:22 2006
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.1 $
+ */
+package org.apache.harmony.rmi;
+
+import java.rmi.MarshalledObject;
+
+import java.util.Hashtable;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Unit test for java.rmi.MarshalledObject class.
+ *
+ * @author  Mikhail A. Markov
+ * @version $Revision: 1.1.2.1 $
+ */
+public class MarshalledObjectTest extends TestCase {
+
+    /**
+     * No-arg constructor to enable serialization.
+     */
+    public MarshalledObjectTest() {
+        super();
+    }
+
+    /**
+     * Constructs this test case with the given name.
+     *
+     * @param   name
+     *          Name for this test case.
+     */
+    public MarshalledObjectTest(String name) {
+        super(name);
+    }
+
+    /**
+     * Tests {@link MarshalledObject#equals(Object)} method.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    public void testEquals() throws Exception {
+        String str = new String("TEST");
+        String str1 = new String("TEST");
+        String str2 = new String("TEST2");
+
+        assertTrue(new MarshalledObject(str).equals(
+                new MarshalledObject(str1)));
+        assertTrue(! new MarshalledObject(str).equals(
+                new MarshalledObject(str2)));
+    }
+
+    /**
+     * Tests {@link MarshalledObject#get()} method.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    public void testGet() throws Exception {
+        assertTrue(new MarshalledObject(null).get() == null);
+        String str = new String("TEST");
+        assertEquals(str, new MarshalledObject(str).get());
+        Hashtable ht = new Hashtable();
+        ht.put(new Integer(1), str);
+        ht.put(new Integer(2), "TEST1");
+        MarshalledObject mo = new MarshalledObject(ht);
+        assertEquals(ht, mo.get());
+        ht.put(new Integer(2), "TEST2");
+        assertTrue(! ht.equals(mo.get()));
+    }
+
+    /**
+     * Returns test suite for this class.
+     *
+     * @return  Test suite for this class.
+     */
+    public static Test suite() {
+        return new TestSuite(MarshalledObjectTest.class);
+    }
+
+    /**
+     * Starts the testing from the command line.
+     *
+     * @param   args
+     *          Command line parameters.
+     */
+    public static void main(String args[]) {
+        junit.textui.TestRunner.run(suite());
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/MarshalledObjectTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/RMITestBase.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/RMITestBase.java?rev=407625&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/RMITestBase.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/RMITestBase.java Thu May 18 13:01:22 2006
@@ -0,0 +1,412 @@
+/*
+ * Copyright 2005-2006 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.
+ */
+
+/**
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.5 $
+ */
+package org.apache.harmony.rmi;
+
+import java.io.IOException;
+
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+import java.rmi.Remote;
+
+import java.rmi.server.UnicastRemoteObject;
+
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.apache.harmony.rmi.common.SubProcess;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Base class for RMI unit tests.
+ *
+ * @author  Vasily Zakharov
+ * @version $Revision: 1.1.2.5 $
+ */
+public abstract class RMITestBase extends TestCase {
+
+    /**
+     * Direct socket connection configuration.
+     */
+    protected static final int CONFIG_DIRECT_SOCKET = 0;
+
+    /**
+     * Direct HTTP connection configuration.
+     */
+    protected static final int CONFIG_DIRECT_HTTP = 1;
+
+    /**
+     * Proxy HTTP connection configuration.
+     */
+    protected static final int CONFIG_PROXY_HTTP = 2;
+
+    /**
+     * Proxy CGI connection configuration.
+     */
+    protected static final int CONFIG_PROXY_CGI = 3;
+
+    /**
+     * RMI Registry host.
+     */
+    protected static final String REGISTRY_HOST = "localhost";
+
+    /**
+     * Default RMI registry port.
+     */
+    protected static final int REGISTRY_PORT = 1099;
+
+    /**
+     * Custom port to start RMI registry on.
+     */
+    protected static final int CUSTOM_PORT_1 = 5555;
+
+    /**
+     * Custom port to start RMI registry on.
+     */
+    protected static final int CUSTOM_PORT_2 = 7777;
+
+    /**
+     * Custom port to start RMI registry on.
+     */
+    protected static final int CUSTOM_PORT_3 = 8888;
+
+    /**
+     * Custom port to start RMI registry on.
+     */
+    protected static final int CUSTOM_PORT_4 = 9999;
+
+    /**
+     * Test string.
+     */
+    protected static final String TEST_STRING_1 = "TEST_1_STRING";
+
+    /**
+     * Test string.
+     */
+    protected static final String TEST_STRING_2 = "TEST_2_STRING";
+
+    /**
+     * Test string.
+     */
+    protected static final String TEST_STRING_3 = "TEST_3_STRING";
+
+    /**
+     * Test string.
+     */
+    protected static final String TEST_STRING_4 = "TEST_4_STRING";
+
+    /**
+     * HTTP Proxy host.
+     */
+    protected static final String PROXY_HOST = "your.proxy.host";
+
+    /**
+     * HTTP Proxy port.
+     */
+    protected static final int PROXY_PORT = 3128;
+
+    /**
+     * HTTP Proxy access timeout (in milliseconds)
+     */
+    protected static final int PROXY_TIMEOUT = 3000;
+
+    /**
+     * Timeout tick (in milliseconds).
+     */
+    protected static final int TIMEOUT_TICK = 1000;
+
+    /**
+     * Default connection timeout.
+     */
+    protected static final long CONNECTION_TIMEOUT = 0;
+
+    /**
+     * Garbage collector timeout (in milliseconds).
+     */
+    protected static final int GC_TIMEOUT = 20000;
+
+    /**
+     * If verbose logging need to be turned on.
+     */
+    protected static final boolean VERBOSE = false;
+
+    /**
+     * List of exported objects.
+     */
+    protected HashSet exportedObjects = new HashSet();
+
+    /**
+     * No-arg constructor to enable serialization.
+     */
+    protected RMITestBase() {
+        super();
+    }
+
+    /**
+     * Constructs this test case with the given name.
+     *
+     * @param   name
+     *          Name for this test case.
+     */
+    protected RMITestBase(String name) {
+        super(name);
+    }
+
+    /**
+     * Sets environment to system properties.
+     *
+     * @param disableHttp
+     * @param eagerHttpFallback
+     * @param disableDirectSocket
+     * @param enableDirectHTTP
+     * @param disablePlainHTTP
+     * @param useProxy
+     * @param connectionTimeout
+     * @param logging
+     */
+    protected static void setEnvironment(boolean disableHttp,
+            boolean eagerHttpFallback, boolean disableDirectSocket,
+            boolean enableDirectHTTP, boolean disablePlainHTTP,
+            boolean useProxy, long connectionTimeout, boolean logging) {
+        System.setProperty("java.rmi.dgc.leaseValue",
+                                        Integer.toString(GC_TIMEOUT));
+        System.setProperty("java.rmi.server.disableHttp",
+                                        Boolean.toString(disableHttp));
+        System.setProperty("harmony.rmi.transport.proxy.eagerHttpFallback",
+                                        Boolean.toString(eagerHttpFallback));
+        System.setProperty("harmony.rmi.transport.disableDirectSocket",
+                                        Boolean.toString(disableDirectSocket));
+        System.setProperty("harmony.rmi.transport.proxy.enableDirectHTTP",
+                                        Boolean.toString(enableDirectHTTP));
+        System.setProperty("harmony.rmi.transport.proxy.disablePlainHTTP",
+                                        Boolean.toString(disablePlainHTTP));
+        System.setProperty("http.proxyHost",
+                                        (useProxy ? PROXY_HOST : ""));
+        System.setProperty("http.proxyPort",
+                                (useProxy ? Integer.toString(PROXY_PORT) : ""));
+        System.setProperty("harmony.rmi.transport.connectionTimeout",
+                                ((connectionTimeout > 0)
+                                    ? Long.toString(connectionTimeout) : ""));
+        System.setProperty("harmony.rmi.dgc.logLevel", "VERBOSE");
+        System.setProperty("harmony.rmi.transport.logLevel",
+                                        (logging ? "VERBOSE" : ""));
+        System.setProperty("harmony.rmi.transport.tcp.logLevel",
+                                        (logging ? "VERBOSE" : ""));
+        System.setProperty("harmony.rmi.transport.proxy.logLevel",
+                                        (logging ? "VERBOSE" : ""));
+    }
+
+    /**
+     * Sets environment for direct socket connections.
+     *
+     * @param   config
+     *          Configuration to set environment for.
+     */
+    protected static void setEnvironmentForConfig(int config) {
+        switch (config) {
+        case CONFIG_DIRECT_SOCKET:
+            setEnvironment(
+                    false,  // disableHttp
+                    false,  // eagerHttpFallback
+                    false,  // disableDirectSocket
+                    false,  // enableDirectHTTP
+                    false,  // disablePlainHTTP
+                    false,  // useProxy
+                    CONNECTION_TIMEOUT,  // connectionTimeout
+                    VERBOSE // Logging
+                    );
+            break;
+        case CONFIG_DIRECT_HTTP:
+            setEnvironment(
+                    false,  // disableHttp
+                    false,  // eagerHttpFallback
+                    true,   // disableDirectSocket
+                    true,   // enableDirectHTTP
+                    false,  // disablePlainHTTP
+                    false,  // useProxy
+                    CONNECTION_TIMEOUT,  // connectionTimeout
+                    VERBOSE // Logging
+                    );
+            break;
+        case CONFIG_PROXY_HTTP:
+            setEnvironment(
+                    false,  // disableHttp
+                    false,  // eagerHttpFallback
+                    true,   // disableDirectSocket
+                    false,  // enableDirectHTTP
+                    false,  // disablePlainHTTP
+                    true,   // useProxy
+                    CONNECTION_TIMEOUT,  // connectionTimeout
+                    VERBOSE // Logging
+                    );
+            break;
+        case CONFIG_PROXY_CGI:
+            setEnvironment(
+                    false,  // disableHttp
+                    false,  // eagerHttpFallback
+                    true,   // disableDirectSocket
+                    false,  // enableDirectHTTP
+                    true,   // disablePlainHTTP
+                    true,   // useProxy
+                    CONNECTION_TIMEOUT,  // connectionTimeout
+                    VERBOSE // Logging
+                    );
+            break;
+        default:
+            assert false : ("Bad config number: " + config);
+        }
+    }
+
+    /**
+     * Starts process in a separate JVM.
+     *
+     * @param   className
+     *          Name of the class to run in process created.
+     *
+     * @param   id
+     *          Identifier of function to run (class specific).
+     *
+     * @param   config
+     *          Number of the configuration to run.
+     *
+     * @param   endorsed
+     *          If endorsedDirs and bootClassPath should be propagated.
+     *
+     * @return  Subprocess created.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    protected static SubProcess startProcess(String className,
+            String id, int config, boolean endorsed) throws Exception {
+        return JavaInvoker.invokeSimilar(null, className,
+                new String[] { id, Integer.toString(config) },
+                endorsed, endorsed);
+    }
+
+    /**
+     * Checks if the specified socket/port is available.
+     *
+     * @param   host
+     *          Host to check.
+     *
+     * @param   port
+     *          Port to check.
+     *
+     * @param   timeout
+     *          Time (in milliseconds) to wait for response.
+     *
+     * @return  <code>true</code> if the specified host/port is available,
+     *          <code>false</code> otherwise.
+     */
+    protected static boolean checkSocket(String host, int port, int timeout) {
+        try {
+            Socket socket = new Socket();
+            socket.connect(new InetSocketAddress(host, port), timeout);
+            socket.close();
+            return true;
+        } catch (IOException e) {
+            return false;
+        }
+    }
+
+    /**
+     * Checks if proxy is available.
+     *
+     * @return  <code>true</code> if proxy is available,
+     *          <code>false</code> otherwise.
+     */
+    protected static boolean checkProxy() {
+        return checkSocket(PROXY_HOST, PROXY_PORT, PROXY_TIMEOUT);
+    }
+
+    /**
+     * Checks if proxy is available.
+     *
+     * @param   testName
+     *          Test name (for diagnostics purposes).
+     *
+     * @return  <code>true</code> if proxy is available,
+     *          <code>false</code> otherwise.
+     */
+    protected static boolean checkProxy(String testName) {
+        boolean ret = checkProxy();
+
+        if (!ret) {
+            System.out.println("WARNING: " + testName + " is skipped "
+                    + "because proxy (" + PROXY_HOST + ':' + PROXY_PORT
+                    + ") is not accessible.");
+        }
+        return ret;
+    }
+
+    /**
+     * Prints the specified array to standard output.
+     *
+     * @param   array
+     *          Array to print.
+     */
+    protected static void printArray(Object[] array) {
+        if (array == null) {
+            System.out.println("    Array is NULL.");
+        }
+
+        for (int i = 0; i < array.length; ++i) {
+            System.out.println("    " + array[i]);
+        }
+    }
+
+    /**
+     * Aborts current process with the specified code.
+     * Really calls {@link System#exit(int) System.exit(exitCode)}.
+     *
+     * @param   exitCode
+     */
+    protected static void abort(int exitCode) {
+        System.exit(exitCode);
+    }
+
+    /**
+     * Aborts current process.
+     * Really calls {@link System#exit(int) System.exit(-1)}.
+     */
+    protected static void abort() {
+        abort(-1);
+    }
+
+    /**
+     * Unexports exported objects.
+     *
+     * @throws  Exception
+     *          If some error occurs.
+     */
+    protected void unexportObjects() throws Exception {
+        for (Iterator i = exportedObjects.iterator(); i.hasNext(); ) {
+            Remote obj = (Remote) i.next();
+            System.err.println("Unexporting " + obj + " ...");
+            UnicastRemoteObject.unexportObject(obj, true);
+            System.err.println("Done.\n");
+        }
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi3/test/common/unit/org/apache/harmony/rmi/RMITestBase.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message