harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r406944 [12/30] - in /incubator/harmony/enhanced/classlib/trunk/modules/rmi2: ./ build/ doc/ doc/testing/ doc/testing/rmi http tunneling/ doc/testing/rmi http tunneling/Results - ITC/ doc/testing/rmi http tunneling/Results - SUN/ doc/testin...
Date Tue, 16 May 2006 13:52:07 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteObject.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteObject.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteObject.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteObject.java Tue May 16 06:51:00 2006
@@ -0,0 +1,190 @@
+/* 
+*  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 java.rmi.server;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Proxy;
+import java.rmi.NoSuchObjectException;
+import java.rmi.Remote;
+
+import ar.org.fitc.rmi.runtime.RemoteReferenceManager;
+import ar.org.fitc.rmi.server.ReferenceTypes;
+import ar.org.fitc.rmi.server.UnicastRemoteRef2Impl;
+import ar.org.fitc.rmi.server.UnicastRemoteRefImpl;
+import ar.org.fitc.rmi.server.UnicastServerRef2Impl;
+import ar.org.fitc.rmi.server.UnicastServerRefImpl;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * 
+ */
+public abstract class RemoteObject implements Remote, Serializable {
+
+    private static final long serialVersionUID = -3215090123894869218L;
+
+    protected transient RemoteRef ref;
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    protected RemoteObject() {
+        super();
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    protected RemoteObject(RemoteRef newRef) {
+    	if (newRef == null) {
+    		throw new NullPointerException(); 
+    	}
+        ref = newRef;
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    @Override
+	public int hashCode() {
+        if (ref != null) {
+            return ref.remoteHashCode();
+        } else {
+            return super.hashCode();
+        }
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    @Override
+	public boolean equals(Object obj) {
+        if (obj != null) {
+            if (obj == this) {
+                return true;
+            }
+            if (obj instanceof RemoteObject) {
+                if (ref == null) {
+                    return false;
+                }
+                return ref.remoteEquals(((RemoteObject) obj).getRef());
+            } else {
+                return obj.equals(this);
+            }
+        }
+        return false;
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    @Override
+	public String toString() {
+        if (ref != null) {
+            return "[" + this.getClass().getName() + " " + ref.remoteToString()
+                    + "]";
+        } else {
+            return super.toString();
+        }
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public RemoteRef getRef() {
+        return ref;
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public static Remote toStub(Remote obj) throws NoSuchObjectException {
+        if (obj == null) {
+            throw new NoSuchObjectException(
+                    "Invalid (null) Remote server object.");
+        }
+        if (obj instanceof RemoteStub) {
+            return obj;
+        }
+        if (Proxy.isProxyClass(obj.getClass())) {
+            if (Proxy.getInvocationHandler(obj).getClass().equals(
+                    RemoteObjectInvocationHandler.class)) {
+                return obj;
+            }
+        }
+        RemoteReferenceManager rrm = RemoteReferenceManager
+                .getRemoteReferenceManager();
+        return rrm.getStub(obj);
+    }
+
+    /**
+     * 
+     * 
+     */
+    private void writeObject(ObjectOutputStream out) throws IOException {
+        out.defaultWriteObject();
+        if (ref != null) {
+            String externalRefTypeName = ref.getRefClass(out);
+            if (externalRefTypeName != null && externalRefTypeName.length() > 0) {
+                out.writeUTF(externalRefTypeName);
+                ref.writeExternal(out);
+            } else {
+                out.writeUTF("");
+                out.writeObject(ref);
+            }
+        }
+    }
+
+    /**
+     * 
+     * 
+     */
+    private void readObject(ObjectInputStream in) throws IOException,
+            ClassNotFoundException {
+        in.defaultReadObject();
+        String externalRefTypeName = in.readUTF();
+        if (externalRefTypeName.length() == 0) {
+            ref = (RemoteRef) in.readObject();
+        } else {
+            if (externalRefTypeName.equals(ReferenceTypes.UNICAST_REF
+                    .toString())) {
+                ref = new UnicastRemoteRefImpl();
+            } else if (externalRefTypeName.equals(ReferenceTypes.UNICAST_REF2
+                    .toString())) {
+                ref = new UnicastRemoteRef2Impl();
+            } else if (externalRefTypeName
+                    .equals(ReferenceTypes.UNICAST_SERVER_REF.toString())) {
+                ref = new UnicastServerRefImpl();
+            } else if (externalRefTypeName
+                    .equals(ReferenceTypes.UNICAST_SERVER_REF2.toString())) {
+                ref = new UnicastServerRef2Impl();
+            } else {
+                throw new ClassNotFoundException(
+                        "Invalid external ref type name");
+            }
+            ref.readExternal(in);
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteObjectInvocationHandler.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteObjectInvocationHandler.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteObjectInvocationHandler.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteObjectInvocationHandler.java Tue May 16 06:51:00 2006
@@ -0,0 +1,88 @@
+/* 
+*  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 java.rmi.server;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.rmi.Remote;
+import java.rmi.UnexpectedException;
+import ar.org.fitc.rmi.utils.MethodHashGenerator;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * 
+ */
+public class RemoteObjectInvocationHandler extends RemoteObject implements
+        InvocationHandler {
+
+    private static final long serialVersionUID = 2L;
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public RemoteObjectInvocationHandler(RemoteRef ref) {
+        super(ref);
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public Object invoke(Object proxy, Method method, Object[] args)
+            throws Throwable {
+
+        Method hashCode = Object.class.getMethod("hashCode", (Class[]) null);
+        Method equals = Object.class.getMethod("equals", Object.class);
+        Method toString = Object.class.getMethod("toString", (Class[]) null);
+
+        if (method.equals(hashCode)) {
+            return ref.remoteHashCode();
+        }
+        if (method.equals(equals)) {
+            if ((args[0] != null)
+                    && (Proxy.isProxyClass(args[0].getClass()))
+                    && (this.equals(Proxy.getInvocationHandler(args[0])))) {
+                return true;
+            } else {
+                return false;
+            }
+        }
+        if (method.equals(toString)) {
+            return "[" + "Proxy " + ref.remoteToString() + "]";
+        }
+        if (!(proxy instanceof Remote)) {
+            throw new IllegalArgumentException(
+                    "Proxy must be an instance of java.rmi.Remote");
+        }
+
+        long methodHash = MethodHashGenerator.getMethodHash(method);
+        try {
+            return ref.invoke((Remote) proxy, method, args, methodHash);
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Exception e) {
+            Class[] exceptions = method.getExceptionTypes();
+            for (Class<Exception> exception : exceptions) {
+                if (exception.isAssignableFrom(e.getClass())) {
+                    throw e;
+                }
+            }
+            throw new UnexpectedException("undeclared checked exception", e);
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteRef.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteRef.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteRef.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteRef.java Tue May 16 06:51:00 2006
@@ -0,0 +1,84 @@
+/* 
+*  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 java.rmi.server;
+
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.lang.reflect.Method;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * 
+ */
+public interface RemoteRef extends Externalizable {
+
+    static final long serialVersionUID = 3632638527362204081L;
+
+    static final String packagePrefix = "ar.org.fitc.rmi.server";
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    String getRefClass(ObjectOutput out);
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    boolean remoteEquals(RemoteRef obj);
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    int remoteHashCode();
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    String remoteToString();
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    RemoteCall newCall(RemoteObject obj, Operation[] op, int opnum, long hash)
+            throws RemoteException;
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    Object invoke(Remote obj, Method method, Object[] params, long opnum)
+            throws Exception;
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    void invoke(RemoteCall call) throws Exception;
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    void done(RemoteCall call) throws RemoteException;
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteServer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteServer.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteServer.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteServer.java Tue May 16 06:51:00 2006
@@ -0,0 +1,131 @@
+/* 
+*  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 java.rmi.server;
+
+import java.io.PrintStream;
+import java.io.OutputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.logging.LoggingPermission;
+
+import ar.org.fitc.rmi.transport.TransportManager;
+import ar.org.fitc.rmi.utils.PrintStreamHandler;
+import ar.org.fitc.rmi.utils.PropertiesReader;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * 
+ */
+public abstract class RemoteServer extends RemoteObject {
+
+	private static final long serialVersionUID = -4100238210092549637L;
+
+	static private PrintStream logStream;
+
+	private static Logger logger;
+
+	private static Logger serverLog;
+
+	private static PrintStreamHandler logHandler;
+
+	// Initialize loggers
+	static {
+		logger = Logger.getLogger("ar.org.fitc.rmi.server");
+		logger.setUseParentHandlers(false);
+		logger.setLevel(Level.ALL);
+
+		String propertyValue = 
+            PropertiesReader.readString("java.rmi.server.logCalls");
+		if (propertyValue != null) {
+			boolean logAllowed = propertyValue.equalsIgnoreCase("true");
+			if (logAllowed) {
+				PrintStreamHandler errHandler = new PrintStreamHandler();
+				errHandler.setLevel(Level.ALL);
+				logger.addHandler(errHandler);
+			}
+		}
+
+		// Implementation-specific logger to log server information
+		serverLog = Logger.getLogger("ar.org.fitc.rmi.server.log");
+        propertyValue = 
+            PropertiesReader.readString("ar.org.fitc.rmi.server.log");
+
+        if (propertyValue  != null
+				&& propertyValue.equalsIgnoreCase("true")) {
+			serverLog.setLevel(Level.ALL);
+		} else {
+			serverLog.setLevel(Level.OFF);
+		}
+
+	}
+
+	/**
+	 * @ar.org.fitc.spec_ref
+	 * 
+	 */
+	protected RemoteServer() {
+		super();
+	}
+
+	/**
+	 * @ar.org.fitc.spec_ref
+	 * 
+	 */
+	protected RemoteServer(RemoteRef ref) {
+		super(ref);
+	}
+
+	/**
+	 * @ar.org.fitc.spec_ref
+	 * 
+	 */
+	public static String getClientHost() throws ServerNotActiveException {
+		TransportManager tm = TransportManager.getTransportManager();
+		return tm.getClientHost();
+	}
+
+	/**
+	 * @ar.org.fitc.spec_ref
+	 * 
+	 */
+	public static PrintStream getLog() {
+		return logStream;
+	}
+
+	/**
+	 * @ar.org.fitc.spec_ref
+	 * 
+	 */
+	public static void setLog(OutputStream out) {
+
+		// Check security permission as stated in specification
+		SecurityManager security = System.getSecurityManager();
+		if (security != null) {
+			security.checkPermission(new LoggingPermission("control", null));
+		}
+
+		logger.removeHandler(logHandler);
+		if (out != null) {
+			logStream = new PrintStream(out);
+			logHandler = new PrintStreamHandler(logStream);
+			logHandler.setLevel(Level.ALL);
+			logger.addHandler(logHandler);
+		} else {
+			logStream = null;
+		}
+		return;
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteStub.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteStub.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteStub.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/RemoteStub.java Tue May 16 06:51:00 2006
@@ -0,0 +1,46 @@
+/* 
+*  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 java.rmi.server;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * 
+ */
+public abstract class RemoteStub extends RemoteObject {
+
+    private static final long serialVersionUID = -1585587260594494182L;
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    protected RemoteStub() {
+        super();
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    protected RemoteStub(RemoteRef ref) {
+        super(ref);
+    }
+
+    @Deprecated
+    protected static void setRef(RemoteStub stub, RemoteRef ref) {
+        throw new UnsupportedOperationException();
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/ServerCloneException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/ServerCloneException.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/ServerCloneException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/ServerCloneException.java Tue May 16 06:51:00 2006
@@ -0,0 +1,52 @@
+/* 
+*  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 java.rmi.server;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * 
+ */
+public class ServerCloneException extends CloneNotSupportedException {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 6617456357664815945L;
+
+    public Exception detail;
+    
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public ServerCloneException(String s) {
+        super(s);
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public ServerCloneException(String s, Exception cause) {
+        super(s + "; nested exception is:\n\t"  + cause.toString());
+        detail = cause;
+    }
+
+    @Override
+    public Throwable getCause() {
+        return detail.getCause();
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/ServerNotActiveException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/ServerNotActiveException.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/ServerNotActiveException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/ServerNotActiveException.java Tue May 16 06:51:00 2006
@@ -0,0 +1,45 @@
+/* 
+*  Copyright 2005 The Apache Software Foundation or its licensors, as applicable. 
+* 
+*  Licensed under the Apache License, Version 2.0 (the "License"); 
+*  you may not use this file except in compliance with the License. 
+*  You may obtain a copy of the License at 
+* 
+*    http://www.apache.org/licenses/LICENSE-2.0 
+* 
+*  Unless required by applicable law or agreed to in writing, software 
+*  distributed under the License is distributed on an "AS IS" BASIS, 
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+*  See the License for the specific language governing permissions and 
+*  limitations under the License. 
+*/
+package java.rmi.server;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * 
+ */
+public class ServerNotActiveException extends Exception {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 4687940720827538231L;
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public ServerNotActiveException() {
+        super();
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public ServerNotActiveException(String s) {
+        super(s);
+    }
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/ServerRef.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/ServerRef.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/ServerRef.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/ServerRef.java Tue May 16 06:51:00 2006
@@ -0,0 +1,41 @@
+/* 
+*  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 java.rmi.server;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * 
+ */
+public interface ServerRef extends RemoteRef {
+
+    static final long serialVersionUID = -4557750989390278438L;
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    RemoteStub exportObject(Remote obj, Object data) throws RemoteException;
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    String getClientHost() throws ServerNotActiveException;
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/Skeleton.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/Skeleton.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/Skeleton.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/Skeleton.java Tue May 16 06:51:00 2006
@@ -0,0 +1,35 @@
+/* 
+*  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 java.rmi.server;
+
+import java.rmi.Remote;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * 
+ */
+public interface Skeleton {
+
+    Operation[] getOperations();
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    void dispatch(Remote obj, RemoteCall theCall, int opnum, long hash)
+            throws Exception;
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/SkeletonMismatchException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/SkeletonMismatchException.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/SkeletonMismatchException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/SkeletonMismatchException.java Tue May 16 06:51:00 2006
@@ -0,0 +1,39 @@
+/* 
+*  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 java.rmi.server;
+
+import java.rmi.RemoteException;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * 
+ */
+public class SkeletonMismatchException extends RemoteException {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -7780460454818859281L;
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public SkeletonMismatchException(String s) {
+        super(s);
+    }
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/SkeletonNotFoundException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/SkeletonNotFoundException.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/SkeletonNotFoundException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/SkeletonNotFoundException.java Tue May 16 06:51:00 2006
@@ -0,0 +1,46 @@
+/* 
+*  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 java.rmi.server;
+
+import java.rmi.RemoteException;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * 
+ */
+public class SkeletonNotFoundException extends RemoteException {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -7860299673822761231L;
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public SkeletonNotFoundException(String s) {
+        super(s);
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public SkeletonNotFoundException(String s, Exception ex) {
+        super(s, ex);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/SocketSecurityException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/SocketSecurityException.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/SocketSecurityException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/SocketSecurityException.java Tue May 16 06:51:00 2006
@@ -0,0 +1,45 @@
+/* 
+*  Copyright 2005 The Apache Software Foundation or its licensors, as applicable. 
+* 
+*  Licensed under the Apache License, Version 2.0 (the "License"); 
+*  you may not use this file except in compliance with the License. 
+*  You may obtain a copy of the License at 
+* 
+*    http://www.apache.org/licenses/LICENSE-2.0 
+* 
+*  Unless required by applicable law or agreed to in writing, software 
+*  distributed under the License is distributed on an "AS IS" BASIS, 
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+*  See the License for the specific language governing permissions and 
+*  limitations under the License. 
+*/
+package java.rmi.server;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * 
+ */
+public class SocketSecurityException extends ExportException {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -7622072999407781979L;
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public SocketSecurityException(String s) {
+        super(s);
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public SocketSecurityException(String s, Exception ex) {
+        super(s, ex);
+    }
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/UID.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/UID.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/UID.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/UID.java Tue May 16 06:51:00 2006
@@ -0,0 +1,134 @@
+/* 
+*  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 java.rmi.server;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.io.Serializable;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * 
+ */
+public final class UID implements Serializable {
+
+    private static final long serialVersionUID = 1086053664494604050L;
+
+    private int unique;
+
+    private long time;
+
+    private short count;
+
+    static private long lastTime;
+
+    static private short counter;
+
+    static private int PID; // Unique identifier inside the host
+
+    /*
+     * REVIEW: Impossible to get a unique identifier inside a host from Java.
+     * This solution seems to be the best until now.
+     */
+    static {
+        PID = new Object().hashCode();
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public UID() {
+        unique = PID;
+        synchronized (UID.class) {
+            time = System.currentTimeMillis();
+            if (lastTime == time) {
+                count = ++counter;
+            } else {
+                count = 0;
+                counter = 0;
+            }
+            lastTime = time;
+        }
+    }
+
+    // Contructor for a well-known UID
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public UID(short num) {
+        unique = 0;
+        time = 0;
+        count = num;
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    @Override
+	public int hashCode() {
+        return (int) (unique + time + count);
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    @Override
+	public boolean equals(Object obj) {
+        if (obj != null && obj instanceof UID) {
+            return (unique == ((UID) obj).unique 
+                    && time == ((UID) obj).time 
+                    && count == ((UID) obj).count);
+        }
+        return false;
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    @Override
+	public String toString() {
+        return "[UID:" + unique + ", " + time + ", " + count + "]";
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public void write(DataOutput out) throws IOException {
+        out.writeInt(unique);
+        out.writeLong(time);
+        out.writeShort(count);
+        return;
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public static UID read(DataInput in) throws IOException {
+        UID tmp = new UID();
+        tmp.unique = in.readInt();
+        tmp.time = in.readLong();
+        tmp.count = in.readShort();
+        return tmp;
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/UnicastRemoteObject.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/UnicastRemoteObject.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/UnicastRemoteObject.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/UnicastRemoteObject.java Tue May 16 06:51:00 2006
@@ -0,0 +1,225 @@
+/* 
+*  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 java.rmi.server;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.NoSuchObjectException;
+
+import ar.org.fitc.rmi.runtime.RemoteReferenceManager;
+import ar.org.fitc.rmi.server.UnicastRemoteRef2Impl;
+import ar.org.fitc.rmi.server.UnicastRemoteRefImpl;
+import ar.org.fitc.rmi.server.UnicastServerRef2Impl;
+import ar.org.fitc.rmi.server.UnicastServerRefImpl;
+import ar.org.fitc.rmi.transport.Endpoint;
+import ar.org.fitc.rmi.transport.TransportManager;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * 
+ */
+public class UnicastRemoteObject extends RemoteServer {
+
+    private static final long serialVersionUID = 4974527148936298033L;
+
+    private transient int port;
+
+    private transient RMIClientSocketFactory csf;
+
+    private transient RMIServerSocketFactory ssf;
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    protected UnicastRemoteObject() throws RemoteException {
+        this(0);
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    protected UnicastRemoteObject(int port) throws RemoteException {
+        this.port = port;
+        RemoteReferenceManager rrm = RemoteReferenceManager
+                .getRemoteReferenceManager();
+        TransportManager tm = TransportManager.getTransportManager();
+        ObjID objID = new ObjID();
+        Endpoint ep = tm.export(objID, port, null, null);
+        UnicastServerRefImpl sref = new UnicastServerRefImpl(this, objID, ep);
+        Remote stub = rrm.createStub(new UnicastRemoteRefImpl(objID, ep), this);
+        this.ref = sref;
+        rrm.storeExportData(this, objID, sref, stub);
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    protected UnicastRemoteObject(int port, RMIClientSocketFactory csf,
+            RMIServerSocketFactory ssf) throws RemoteException {
+        this.port = port;
+        this.csf = csf;
+        this.ssf = ssf;
+        RemoteReferenceManager rrm = RemoteReferenceManager
+                .getRemoteReferenceManager();
+        TransportManager tm = TransportManager.getTransportManager();
+        ObjID objID = new ObjID();
+        Endpoint ep = tm.export(objID, port, ssf, csf);
+        UnicastServerRef2Impl sref = new UnicastServerRef2Impl(this, objID, ep);
+        Remote stub = rrm
+                .createStub(new UnicastRemoteRef2Impl(objID, ep), this);
+        this.ref = sref;
+        rrm.storeExportData(this, objID, sref, stub);
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    @Override
+	public Object clone() throws CloneNotSupportedException {
+        UnicastRemoteObject clon = (UnicastRemoteObject) super.clone();
+        RemoteReferenceManager rrm = RemoteReferenceManager
+                .getRemoteReferenceManager();
+        TransportManager tm = TransportManager.getTransportManager();
+        ObjID objID = new ObjID();
+        try {
+            Endpoint ep = tm.export(objID, this.port, this.ssf, this.csf);
+            UnicastServerRef2Impl sref = new UnicastServerRef2Impl(clon, objID,
+                    ep);
+            Remote stub = rrm.createStub(new UnicastRemoteRef2Impl(objID, ep),
+                    clon);
+            clon.ref = sref;
+            rrm.storeExportData(clon, objID, sref, stub);
+        } catch (RemoteException e) {
+            throw new CloneNotSupportedException(
+                    "Error during clon exportation");
+        }
+        return clon;
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public static RemoteStub exportObject(Remote obj) throws RemoteException {
+        if (obj == null) {
+            throw new RemoteException("Invalid (null) Remote server object.");
+        }
+        RemoteReferenceManager rrm = RemoteReferenceManager
+                .getRemoteReferenceManager();
+        if (rrm.isExported(obj)) {
+            throw new RemoteException("Object already exported.");
+        }
+        TransportManager tm = TransportManager.getTransportManager();
+        ObjID objID = new ObjID();
+        Endpoint ep = tm.export(objID, 0, null, null);
+        UnicastServerRefImpl sref = new UnicastServerRefImpl(obj, objID, ep);
+        RemoteStub stub = rrm.createRegularStub(new UnicastRemoteRefImpl(objID,
+                ep), obj);
+        rrm.storeExportData(obj, objID, sref, stub);
+        return stub;
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public static Remote exportObject(Remote obj, int port)
+            throws RemoteException {
+        if (obj == null) {
+            throw new RemoteException("Invalid (null) Remote server object.");
+        }
+        RemoteReferenceManager rrm = RemoteReferenceManager
+                .getRemoteReferenceManager();
+        if (rrm.isExported(obj)) {
+            throw new RemoteException("Object already exported.");
+        }
+        TransportManager tm = TransportManager.getTransportManager();
+        ObjID objID = new ObjID();
+        Endpoint ep = tm.export(objID, port, null, null);
+        UnicastServerRefImpl sref = new UnicastServerRefImpl(obj, objID, ep);
+        Remote stub = rrm.createStub(new UnicastRemoteRefImpl(objID, ep), obj);
+        rrm.storeExportData(obj, objID, sref, stub);
+        return stub;
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public static Remote exportObject(Remote obj, int port,
+            RMIClientSocketFactory csf, RMIServerSocketFactory ssf)
+            throws RemoteException {
+        if (obj == null) {
+            throw new RemoteException("Invalid (null) Remote server object.");
+        }
+        RemoteReferenceManager rrm = RemoteReferenceManager
+                .getRemoteReferenceManager();
+        if (rrm.isExported(obj)) {
+            throw new RemoteException("Object already exported.");
+        }
+        TransportManager tm = TransportManager.getTransportManager();
+        ObjID objID = new ObjID();
+        Endpoint ep = tm.export(objID, port, ssf, csf);
+        UnicastServerRef2Impl sref = new UnicastServerRef2Impl(obj, objID, ep);
+        Remote stub = rrm.createStub(new UnicastRemoteRef2Impl(objID, ep), obj);
+        rrm.storeExportData(obj, objID, sref, stub);
+        return stub;
+    }
+
+    /**
+     * @ar.org.fitc.spec_ref
+     * 
+     */
+    public static boolean unexportObject(Remote obj, boolean force)
+            throws NoSuchObjectException {
+        RemoteReferenceManager rrm = RemoteReferenceManager
+                .getRemoteReferenceManager();
+        return rrm.unexportObject(obj, force);
+    }
+
+    /**
+     * 
+     * 
+     */
+    private void writeObject(ObjectOutputStream out) throws IOException {
+        out.defaultWriteObject();
+    }
+
+    /**
+     * 
+     * 
+     */
+    private void readObject(ObjectInputStream in) throws IOException,
+            ClassNotFoundException {
+        in.defaultReadObject();
+        RemoteReferenceManager rrm = RemoteReferenceManager
+                .getRemoteReferenceManager();
+        TransportManager tm = TransportManager.getTransportManager();
+        ObjID objID = new ObjID();
+        Endpoint ep = tm.export(objID, 0, null, null);
+        UnicastServerRefImpl sref = new UnicastServerRefImpl(this, objID, ep);
+        Remote stub = rrm.createStub(new UnicastRemoteRefImpl(objID, ep), this);
+        this.ref = sref;
+        rrm.storeExportData(this, objID, sref, stub);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/Unreferenced.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/Unreferenced.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/Unreferenced.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/rmi-1.4.2/src/java/rmi/server/Unreferenced.java Tue May 16 06:51:00 2006
@@ -0,0 +1,26 @@
+/* 
+*  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 java.rmi.server;
+
+/**
+ * @ar.org.fitc.spec_ref
+ * 
+ */
+public interface Unreferenced {
+
+    void unreferenced();
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/DGCScheduledGC.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/DGCScheduledGC.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/DGCScheduledGC.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/DGCScheduledGC.java Tue May 16 06:51:00 2006
@@ -0,0 +1,95 @@
+/* 
+*  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.dgc;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+import ar.org.fitc.rmi.utils.PropertiesReader;
+
+/**
+ * This class schedules calls to the <code>java.lang.System.gc()</code>
+ * method.
+ * 
+ * @author Gustavo Petri
+ */
+public class DGCScheduledGC {
+
+    /**
+     * Timer to schedule the calls
+     */
+    private Timer timer;
+
+    /**
+     * The interval used by the Timer
+     */
+    private static Long gcInterval;
+
+    /**
+     * Flag to indicate the termination of the Thread
+     */
+    private static boolean running = false;
+
+    static {
+        gcInterval = PropertiesReader.readLong(
+                "ar.org.fitc.rmi.dgc.gcInterval", 60000);
+    }
+
+    /**
+     * Schedules the calls to <code>java.lang.System.gc()</code>
+     * 
+     * @see <a
+     *      href="http://archives.java.sun.com/cgi-bin/wa?A2=ind9911&L=rmi-users&F=&S=&P=20099">
+     *      Reference </a>
+     */
+
+    private DGCScheduledGC() {
+        timer = new Timer("rmi.dgc.DGCScheduleGC", true);
+        try {
+            timer.schedule(new RunGCTask(), gcInterval, gcInterval);
+        } catch (Exception e) {
+            // There is no chance that this try will fail unless the runGC
+            // method be errased.
+            throw new AssertionError();
+        }
+        running = true;
+    }
+
+    /**
+     * Schedules and starts the calls to <code>java.lang.System.gc()</code>
+     * 
+     * @see <a
+     *      href="http://archives.java.sun.com/cgi-bin/wa?A2=ind9911&L=rmi-users&F=&S=&P=20099">
+     *      Reference </a>
+     */
+    public static synchronized final void startGC() {
+        if (!running) {
+            new DGCScheduledGC();
+        }
+    }
+
+    /**
+     * Runs the <code>java.lang.System.gc()</code> method.
+     */
+    private class RunGCTask extends TimerTask {
+
+        @Override
+        public void run() {
+            System.gc();
+        }
+    }
+   
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DGCClient.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DGCClient.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DGCClient.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DGCClient.java Tue May 16 06:51:00 2006
@@ -0,0 +1,403 @@
+/* 
+*  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.dgc.client;
+
+import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.rmi.Remote;
+import java.rmi.UnmarshalException;
+import java.rmi.dgc.Lease;
+import java.rmi.dgc.VMID;
+import java.rmi.server.ObjID;
+import java.rmi.server.RemoteObjectInvocationHandler;
+import java.rmi.server.RemoteRef;
+import java.rmi.server.RemoteStub;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Timer;
+import java.util.WeakHashMap;
+import java.util.concurrent.ConcurrentHashMap;
+
+import ar.org.fitc.rmi.dgc.DGCScheduledGC;
+import ar.org.fitc.rmi.transport.Endpoint;
+import ar.org.fitc.rmi.transport.TransportManager;
+import ar.org.fitc.rmi.utils.Pair;
+import ar.org.fitc.rmi.utils.PropertiesReader;
+
+/**
+ * Implements the client's side of the RMI Garbage Collector. This class takes
+ * care of scheduling and sending the dirty and clean calls to the server side
+ * of RMI DGC, when stubs of remote objects are received.
+ * 
+ * @author Gonzalo Ortega
+ * 
+ */
+public final class DGCClient {
+
+	private static DGCClient dgcClient;
+
+    private VMID vmID;
+
+    private long sequenceNumber;
+
+    private long leaseValue;
+
+    private ObjID dgcObjID;
+
+    private Map<Remote, WeakReference<Remote>> stubsCacheTable;
+
+    private Map<RemoteRef, Pair<Endpoint, ObjID>> deserializedRemoteRefTable;
+
+    private ConcurrentHashMap<Pair<Endpoint, ObjID>, Long> liveReferences;
+
+    private Map<Long, DirtyTask> dirtyTaskTable;
+
+    private Timer taskScheduler;
+
+    private DGCQueuePoll unreferencedPoll;
+    
+    /** The method hash for the "clean" method in the DGC */
+    private static final long SEND_CLEAN_OP_NUM = -5803803475088455571L;
+    
+    /** The method hash for the "dirty" method in the DGC */
+    private static final long SEND_DIRTY_OP_NUM = -8139341527526761862L;
+
+    /**
+     * Implements the singleton behavior. If there is an instance of
+     * <code>DGCClient</code> is returned, else a new instance is created and
+     * returned.
+     * 
+     * @return the only <code>DGCClient</code> instance
+     */
+    public static synchronized final DGCClient getDGCClient() {
+        if (dgcClient == null) {
+            dgcClient = new DGCClient();
+        }
+        return dgcClient;
+    }
+
+    /**
+     * Creates a new instance of DGCClient. Launches the scheduler (as a daemon)
+     * that sends the dirty calls, and starts the monitor (as a daemon) that
+     * will look for unreferenced stubs.
+     */
+    @Deprecated
+    private DGCClient() {
+        stubsCacheTable = new WeakHashMap<Remote, WeakReference<Remote>>();
+        deserializedRemoteRefTable = new WeakHashMap<RemoteRef, Pair<Endpoint, ObjID>>();
+        dirtyTaskTable = new HashMap<Long, DirtyTask>();
+        liveReferences = new ConcurrentHashMap<Pair<Endpoint, ObjID>, Long>();
+
+        /*
+         * RMI API states that a client should use a null value if it is unable
+         * to generate a VMID. The only way to know if the generated VMID is
+         * somehow "unique" is calling the deprecated VMID.isUnique() method, as
+         * long the VMID constructor doesn't throw any exception. (it always
+         * success)
+         */
+        if (VMID.isUnique()) {
+            vmID = new VMID();
+        }
+        sequenceNumber = 0;
+        leaseValue = 600000L;
+        dgcObjID = new ObjID(ObjID.DGC_ID);
+
+        
+        
+        String propertyValue = 
+            PropertiesReader.readString("java.rmi.dgc.leaseValue");
+        if (propertyValue != null) {
+            try {
+                leaseValue = Long.parseLong(propertyValue);
+            } catch (NumberFormatException e) {
+            }
+        }
+
+        taskScheduler = new Timer("rmi.dgc.client.DirtyScheduler", true);
+
+        unreferencedPoll = new DGCQueuePoll(this);
+        unreferencedPoll.setDaemon(true);
+        unreferencedPoll.setName("rmi.dgc.client.unreferencedStubPoll");
+        unreferencedPoll.start();
+
+        DGCScheduledGC.startGC();
+    }
+
+    /**
+     * Stores the data received during the deserialization of a stub. The
+     * <code>Endpoint</code> and <code>ObjID</code> from the remote
+     * reference are stored in order to be used to send dirty and clean calls
+     * grouped by Endpoint.
+     * 
+     * @param ref
+     *            The reference received from the stream.
+     * @param ep
+     *            The <code>Endpoint</code> that corresponds to the reference.
+     * @param objID
+     *            The <code>ObjID</code> that corresponds to the reference.
+     */
+    public synchronized final void registerRemoteRef(RemoteRef ref, Endpoint ep,
+            ObjID objID) {
+        if (!deserializedRemoteRefTable.containsKey(ref)) {
+            deserializedRemoteRefTable.put(ref, new Pair<Endpoint, ObjID>(ep,
+                    objID));
+        }
+        return;
+    }
+
+    /**
+     * If the received stub is the first instance of that stub in the client’s
+     * system, it is cached and returned. The method
+     * <code>activateReference</code> is called in order to start the lease
+     * renewal process. If there is a previous instance of this stub in the
+     * system, the received stub is discarded and the cached instance is
+     * returned.
+     * 
+     * @param stub
+     *            The stub received during deserialization process.
+     * @return The unique instance of this stub in the client's system.
+     * @throws UnmarshalException
+     *             If there is missing information or the dirty call for the
+     *             received stub fails.
+     */
+    public synchronized Remote getStubInstance(Remote stub)
+            throws UnmarshalException {
+        // Get internal RemoteRef from stub
+        RemoteRef ref = null;
+        if (stub instanceof RemoteStub) {
+            ref = ((RemoteStub) stub).getRef();
+        }
+        if (Proxy.isProxyClass(stub.getClass())) {
+            InvocationHandler ih = Proxy.getInvocationHandler(stub);
+            if (ih instanceof RemoteObjectInvocationHandler) {
+                ref = ((RemoteObjectInvocationHandler) ih).getRef();
+            }
+        }
+        // Check whether there is a stub already registered in the DGC
+        WeakReference<Remote> weakStub;
+        if ((weakStub = stubsCacheTable.get(stub)) != null) {
+            Remote cachedStub = weakStub.get();
+            if (cachedStub != null) {
+                checkLiveness(ref);
+                return cachedStub;
+            }
+        }
+        Pair<Endpoint, ObjID> data = activateReference(ref);
+        weakStub = unreferencedPoll.addToReferenceQueue(stub, data);
+        stubsCacheTable.put(stub, weakStub);
+        return stub;
+    }
+
+    /**
+     * Sends the first dirty for a received reference in order to get the
+     * appropiate lease time from the server, and then schedules the dirty call
+     * for lease renewal. If the first dirty message fails, a clean "strong"
+     * message is sent for that remote object. If the first dirty call
+     * succeeded, the reference becomes a "live" reference for the client DGC.
+     * 
+     * @param ref
+     *            The reference received inside the stub
+     * @return The <code>Endpoint / ObjID</code> pair contained inside the
+     *         reference
+     * @throws UnmarshalException
+     *             If the first dirty call fails
+     */
+    private final Pair<Endpoint, ObjID> activateReference(RemoteRef ref)
+            throws UnmarshalException {
+        // Get necessary data previously stored during RemoteRef
+        // deserialization.
+        Pair<Endpoint, ObjID> data = deserializedRemoteRefTable.get(ref);
+        if (data == null) {
+            throw new UnmarshalException(
+                    "Impossible to get a stub for this object.");
+        }
+        Lease lease = sendDirty(data.getFirst(),
+                new ObjID[] { data.getSecond() });
+
+        if (lease != null) {
+            enqueueDirtyCall(data, lease.getValue());
+            liveReferences.put(data, new Long(lease.getValue()));
+            return data;
+        } else {
+            sendClean(data.getFirst(), new ObjID[] { data.getSecond() }, true);
+            throw new UnmarshalException(
+                    "Impossible to get a stub for this object.");
+        }
+    }
+
+    /**
+     * Checks whether the received reference is a "live" reference for the
+     * client garbage collector. The client DGC sends dirties for all "live"
+     * references in order to renew the lease with the remote server. If the DGC
+     * is not sending dirties for a reference (because of persistent network
+     * problems, for instance) that reference is no longer considered "live". If
+     * the received reference is not "live", the method
+     * <code>activateReference</code> will be called in order to restart the
+     * lease renewal process.
+     * 
+     * @param ref
+     *            The reference to be tested
+     */
+    public synchronized final void checkLiveness(RemoteRef ref) {
+        Pair<Endpoint, ObjID> dataRef = deserializedRemoteRefTable.get(ref);
+        if (liveReferences.containsKey(dataRef)) {
+            return;
+        }
+        try {
+            activateReference(ref);
+        } catch (UnmarshalException e) {
+            // An Exception was thrown trying to bring the reference back to
+            // life
+        }
+    }
+
+    /**
+     * Schedules a dirty call to be sent periodically. The dirty call will be
+     * sent every <code>period</code> / 2 milliseconds.
+     * 
+     * @param data
+     *            An <code>Endpoint / ObjID</code> pair representing a
+     *            reference.
+     * @param period
+     *            The lease period granted by the server.
+     */
+    void enqueueDirtyCall(Pair<Endpoint, ObjID> data, long period) {
+        synchronized (dirtyTaskTable) {
+            DirtyTask task = dirtyTaskTable.get(new Long(period));
+            if (task != null) {
+                task.scheduleDirty(data);
+            } else {
+                task = new DirtyTask(this, period, taskScheduler,
+                        dirtyTaskTable);
+                task.scheduleDirty(data);
+                taskScheduler.schedule(task, period / 2, period / 2);
+                dirtyTaskTable.put(new Long(period), task);
+            }
+        }
+    }
+
+    /**
+     * Removes the reference represented by the <code>Endpoint / ObjID</code>
+     * pair from the dirty calls scheduler. No more dirties will be sent for
+     * that reference, and the reference is erased from the "live" references
+     * internal table.
+     * 
+     * @param ep
+     *            The <code>Endpoint</code> of the remote reference.
+     * @param objID
+     *            The <code>ObjID</code> of the remote reference.
+     */
+    void cancelDirtyCall(Endpoint ep, ObjID objID) {
+        synchronized (dirtyTaskTable) {
+            Pair<Endpoint, ObjID> dataRef = new Pair<Endpoint, ObjID>(ep, objID);
+            Long period = liveReferences.get(dataRef);
+            DirtyTask task = dirtyTaskTable.get(period);
+            if (task != null) {
+                task.cancelDirty(ep, objID);
+                if (task.isEmpty()) {
+                    task.cancel();
+                    dirtyTaskTable.remove(period);
+                    taskScheduler.purge();
+                }
+            }
+            liveReferences.remove(dataRef);
+        }
+    }
+
+    /**
+     * Removes the reference represented by the <code>Endpoint / ObjID</code>
+     * pair from the "live" references internal table.
+     * 
+     * @param dataRef
+     *            The <code>Endpoint / ObjID</code> pair representing the
+     *            reference
+     */
+    void removeFromLiveReferences(Pair<Endpoint, ObjID> dataRef) {
+        liveReferences.remove(dataRef);
+    }
+
+    /**
+     * Checks whether the reference represented by the
+     * <code>Endpoint / ObjID</code> pair is a "live" reference. The client
+     * DGC sends dirties for all "live" references in order to renew the lease
+     * with the remote server.
+     * 
+     * @param dataRef
+     *            An <code>Endpoint / ObjID</code> pair representing a
+     *            reference
+     * @return true if the received pair is a "live" reference
+     */
+    boolean isLiveReference(Pair<Endpoint, ObjID> dataRef) {
+        return liveReferences.containsKey(dataRef);
+    }
+
+    /**
+     * Sends a clean call to the DGC of the remote server.
+     * 
+     * @param ep
+     *            The <code>Endpoint</code> where the clean call will be sent.
+     * @param obj
+     *            An array containing the object identifiers that will be sent
+     *            in the clean call.
+     * @param strong
+     *            The flag that indicates a 'strong' clean call
+     */
+    void sendClean(Endpoint ep, ObjID[] obj, boolean strong) {
+    	synchronized(dgcObjID) { 
+	        Object[] args = new Object[] { obj, ++sequenceNumber, vmID, strong };
+	        TransportManager tm = TransportManager.getTransportManager();
+	        try {
+	            tm.invoke(dgcObjID, ep, args, SEND_CLEAN_OP_NUM, false);
+	        } catch (Exception e) {
+	            // The clean call has failed.
+	        }
+    	}
+    }
+
+    /**
+     * Sends a dirty call to the DGC of the remote server, and returns the
+     * <code>Lease</code> granted by that DGC.
+     * 
+     * @param ep
+     *            The <code>Endpoint</code> where the dirty call will be sent.
+     * @param obj
+     *            An array containing the object identifiers that will be sent
+     *            in the dirty call.
+     * @return The <code>Lease</code> returned from the server DGC, or
+     *         <code>null</code> if the call has failed.
+     */
+    Lease sendDirty(Endpoint ep, ObjID[] obj) {
+    	synchronized(dgcObjID) { 
+	        Lease lease = new Lease(vmID, leaseValue);
+	        Object[] args = new Object[] { obj, ++sequenceNumber, lease };
+	        TransportManager tm = TransportManager.getTransportManager();
+	        Object response;
+	        try {
+	            response = tm.invoke(dgcObjID, ep, args, SEND_DIRTY_OP_NUM, true);
+	            if (response instanceof Lease) {
+	                if (vmID == null) {
+	                    vmID = ((Lease) response).getVMID();
+	                }
+	                return (Lease) response;
+	            }
+	            return null;
+	        } catch (Exception e) {
+	            return null;
+	        }
+    	}
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DGCClient.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DGCQueuePoll.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DGCQueuePoll.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DGCQueuePoll.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DGCQueuePoll.java Tue May 16 06:51:00 2006
@@ -0,0 +1,147 @@
+/* 
+*  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.dgc.client;
+
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+import java.rmi.Remote;
+import java.rmi.server.ObjID;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import ar.org.fitc.rmi.transport.Endpoint;
+import ar.org.fitc.rmi.utils.Pair;
+
+/**
+ * This class sends the corresponding "clean" call to the remote server’s
+ * garbage collector when a stub with a "live" reference is collected by the
+ * local garbage collector.
+ * 
+ * @author Gonzalo Ortega
+ * 
+ */
+final class DGCQueuePoll extends Thread {
+
+    private ReferenceQueue<Remote> stubsQueue;
+
+    private Map<WeakReference, Pair<Endpoint, ObjID>> referenceDataTable;
+
+    private DGCClient dgc;
+
+    private Map<Endpoint, ArrayList<ObjID>> queuedCleanCalls;
+
+    /**
+     * Creates a new instance of <code>DGCQueuePoll</code>.
+     * 
+     * @param cdgc
+     *            The client garbage collector which has instantiated this
+     *            class.
+     */
+    public DGCQueuePoll(DGCClient cdgc) {
+        stubsQueue = new ReferenceQueue<Remote>();
+//        referenceDataTable = new Hashtable<WeakReference, Pair<Endpoint, ObjID>>();
+        referenceDataTable = new ConcurrentHashMap<WeakReference, Pair<Endpoint, ObjID>>();
+        queuedCleanCalls = new HashMap<Endpoint, ArrayList<ObjID>>();
+        dgc = cdgc;
+    }
+
+    /**
+     * Adds a stub to the internal reference queue, in order to be detected when
+     * it is garbage collected by the local garbage collector.
+     * 
+     * @param stub
+     *            The stub that the clean call will be sent for.
+     * @param data
+     *            The <code>Endpoint / ObjID</code> pair representing the
+     *            internal data of the remote reference contained inside the
+     *            stub.
+     * @return A weak reference to the stub.
+     */
+    public final WeakReference<Remote> addToReferenceQueue(Remote stub,
+            Pair<Endpoint, ObjID> data) {
+        WeakReference<Remote> weakStub;
+        weakStub = new WeakReference<Remote>(stub, stubsQueue);
+        referenceDataTable.put(weakStub, data);
+        return weakStub;
+    }
+
+    /**
+     * Waits for the local garbage collector to collect a stub, and then removes
+     * the reference corresponding to that stub from the Client DGC's "live"
+     * references table, stops sending dirty calls for that reference, and sends
+     * a clean call for that reference to te remote server's garbage collector.
+     * 
+     */
+    @SuppressWarnings("unchecked")
+    public final void run() {
+        while (true) {
+            try {
+                WeakReference<Remote> remove = (WeakReference<Remote>) stubsQueue
+                        .remove();
+                do {
+                    Pair<Endpoint, ObjID> data = referenceDataTable.get(remove);
+                    if (dgc.isLiveReference(data)) {
+                        dgc.cancelDirtyCall(data.getFirst(), data.getSecond());
+                        enqueueCleanCall(data.getFirst(), data.getSecond());
+                    }
+                    referenceDataTable.remove(remove);
+                } while ((remove = (WeakReference<Remote>) stubsQueue.poll()) 
+                        != null);
+                sendQueuedCalls();
+            } catch (InterruptedException e) {
+            }
+        }
+    }
+
+    /**
+     * Groups the clean calls to be sent by <code>Endpoint</code>, in order
+     * to send only one clean call for all the objects exported in the same
+     * <code>Endpoint</code>.
+     * 
+     * @param ep
+     *            The <code>Endpoint</code> of the reference.
+     * @param objID
+     *            The <code>ObjID</code> of the reference.
+     */
+    private final void enqueueCleanCall(Endpoint ep, ObjID objID) {
+        ArrayList<ObjID> objIDList;
+        objIDList = queuedCleanCalls.get(ep);
+        if (objIDList == null) {
+            objIDList = new ArrayList<ObjID>();
+            queuedCleanCalls.put(ep, objIDList);
+        }
+        objIDList.add(objID);
+    }
+
+    /**
+     * Sends all the grouped clean calls to the remote server's garbage
+     * collector.
+     */
+    private final void sendQueuedCalls() {
+        if (!queuedCleanCalls.isEmpty()) {
+            ArrayList<ObjID> objIDList;
+            for (Endpoint ep : queuedCleanCalls.keySet()) {
+                objIDList = queuedCleanCalls.get(ep);
+                ObjID[] objArray = new ObjID[objIDList.size()];
+                objIDList.toArray(objArray);
+                dgc.sendClean(ep, objArray, false);
+            }
+            queuedCleanCalls.clear();
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DGCQueuePoll.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DirtyRetryTask.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DirtyRetryTask.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DirtyRetryTask.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DirtyRetryTask.java Tue May 16 06:51:00 2006
@@ -0,0 +1,116 @@
+/* 
+ *  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.dgc.client;
+
+import java.rmi.server.ObjID;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import ar.org.fitc.rmi.transport.Endpoint;
+import ar.org.fitc.rmi.utils.Pair;
+
+/**
+ * When scheduled dirty calls fail, the dirty retry process uses instances of
+ * this class to attempt to get a lease from the server. A <code>Timer</code>
+ * should run this task in order to send the dirties for renewing the leases
+ * periodically.
+ * 
+ * @author Gonzalo Ortega
+ * 
+ */
+final class DirtyRetryTask extends TimerTask {
+
+	private DGCClient dgc;
+
+	private long originalPeriod;
+
+	private Timer taskScheduler;
+
+	private Endpoint ep;
+
+	private ObjID[] objIDs;
+
+	private int retryNumber;
+
+	private static final int retriesAllowed = 4;
+
+	/**
+	 * Creates a new instance of <code>DirtyRetryTask</code>.
+	 * 
+	 * @param dgc
+	 *            The client DGC.
+	 * @param period
+	 *            The original period in milliseconds of the lease granted to
+	 *            the references grouped in the <code>DirtyTask</code> wich
+	 *            has isntantiated this task.
+	 * @param taskScheduler
+	 *            The <code>Timer</code> object which will run this scheduled
+	 *            <code>DirtyTask</code>.
+	 * @param ep
+	 *            The <code>Endpoint</code> of the references grouped in the
+	 *            failed dirty call.
+	 * @param objIDs
+	 *            The <code>ObjID</code> of the references drouped in the
+	 *            failed dirty call.
+	 * @param retryNumber
+	 *            The number of times the dirty call has been retried.
+	 */
+	public DirtyRetryTask(DGCClient dgc, long period, Timer taskScheduler,
+			Endpoint ep, ObjID[] objIDs, int retryNumber) {
+		this.dgc = dgc;
+		this.originalPeriod = period;
+		this.taskScheduler = taskScheduler;
+		this.ep = ep;
+		this.objIDs = objIDs;
+		this.retryNumber = ++retryNumber;
+	}
+
+	/**
+	 * This <code>DirtyRetryTask</code> will try to re-send the dirty call to
+	 * the detination <code>Endpoint</code>. If this dirty call success, the
+	 * references will be re-scheduled for normal lease renewal. If the dirty
+	 * call fails, a new <code>DirtyRetryTask</code> will be scheduled with an
+	 * exponential delay time for a new retry. If four retry attempts have been
+	 * made and the retry call still hasn't succeeded, no more dirties for those
+	 * references will be sent. The references will be removed from the DGC
+	 * "live" references table and a clean "strong" call will be sent to the
+	 * remote server's DGC.
+	 */
+	@Override
+	public final void run() {
+		if (dgc.sendDirty(ep, objIDs) != null) {
+			for (ObjID objID : objIDs) {
+				dgc.enqueueDirtyCall(new Pair<Endpoint, ObjID>(ep, objID),
+						originalPeriod);
+			}
+		} else {
+			if (retryNumber < retriesAllowed) {
+				DirtyRetryTask retryTask = new DirtyRetryTask(dgc,
+						originalPeriod, taskScheduler, ep, objIDs, retryNumber);
+				taskScheduler.schedule(retryTask, Double.valueOf(
+						(Math.pow(2, retryNumber))).longValue() * 1000);
+			} else {
+				// Giving up on dirties. Sending clean strong call for the
+				// references.
+				for (ObjID objID : objIDs) {
+					dgc.removeFromLiveReferences(new Pair<Endpoint, ObjID>(ep,
+							objID));
+				}
+				dgc.sendClean(ep, objIDs, true);
+			}
+		}
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DirtyRetryTask.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DirtyTask.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DirtyTask.java?rev=406944&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DirtyTask.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DirtyTask.java Tue May 16 06:51:00 2006
@@ -0,0 +1,167 @@
+/* 
+*  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.dgc.client;
+
+import java.rmi.server.ObjID;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import ar.org.fitc.rmi.transport.Endpoint;
+import ar.org.fitc.rmi.utils.Pair;
+
+/**
+ * This class groups all the references with the same granted lease time. A
+ * <code>Timer</code> should run this task in order to send the dirties for
+ * renewing the leases periodically.
+ * 
+ * @author Gonzalo Ortega
+ * 
+ */
+final class DirtyTask extends TimerTask {
+
+    private Map<Endpoint, Set<ObjID>> dirtyDataMap;
+
+    private DGCClient dgc;
+
+    private long period;
+
+    private Timer taskScheduler;
+
+    private Map<Long, DirtyTask> dirtyTaskTable;
+
+    /**
+     * Creates a new instance of DirtyTask.
+     * 
+     * @param dgc
+     *            The client DGC which has instantiated this DirtyTask.
+     * @param period
+     *            The period in milliseconds of the lease granted to the
+     *            references grouped in this task.
+     * @param taskScheduler
+     *            The <code>Timer</code> object which will run this scheduled
+     *            <code>DirtyTask</code>.
+     * @param dirtyTaskTable
+     *            The table where all the <code>DirtyTasks</code> are
+     *            registered, in order to mantain a reference for adding or
+     *            removing references to the scheduled <code>DirtyTask</code>.
+     */
+    public DirtyTask(DGCClient dgc, long period, Timer taskScheduler,
+            Map<Long, DirtyTask> dirtyTaskTable) {
+        dirtyDataMap = new HashMap<Endpoint, Set<ObjID>>();
+        this.dgc = dgc;
+        this.period = period;
+        this.taskScheduler = taskScheduler;
+        this.dirtyTaskTable = dirtyTaskTable;
+    }
+
+    /**
+     * Adds a new reference to this <code>DirtyTask</code>. The lease of all
+     * the references registered in this task will be renewed periodically (a
+     * dirty call to the remote server DGC will be sent for each reference).
+     * 
+     * @param data
+     *            The <code>Endpoint / ObjID</code> pair representing a
+     *            reference.
+     */
+    public final void scheduleDirty(Pair<Endpoint, ObjID> data) {
+        synchronized (this) {
+            Set<ObjID> objIDSet = dirtyDataMap.get(data.getFirst());
+            if (objIDSet == null) {
+                objIDSet = new HashSet<ObjID>();
+                dirtyDataMap.put(data.getFirst(), objIDSet);
+            }
+            objIDSet.add(data.getSecond());
+        }
+    }
+
+    /**
+     * Removes a reference from this <code>DirtyTask</code>. No more dirty
+     * calls will be sent for the removed reference.
+     * 
+     * @param ep
+     *            The <code>Endpoint</code> of the reference.
+     * @param objID
+     *            The <code>ObjID</code> of the reference.
+     */
+    public final void cancelDirty(Endpoint ep, ObjID objID) {
+        synchronized (this) {
+            Set<ObjID> objIDSet = dirtyDataMap.get(ep);
+            if (objIDSet != null) {
+                objIDSet.remove(objID);
+                if (objIDSet.isEmpty()) {
+                    dirtyDataMap.remove(ep);
+                }
+            }
+        }
+    }
+
+    /**
+     * Returns true if this <code>DirtyTask</code> doesn't have any reference.
+     * 
+     * @return true if this <code>DirtyTask</code> doesn't have any
+     *         references, otherwise returns false.
+     */
+    public final boolean isEmpty() {
+        return dirtyDataMap.isEmpty();
+    }
+
+    /**
+     * Sends the dirty calls for all the references grouped by this
+     * <code>DirtyTask</code>. This method should be called by a
+     * <code>Timer</code> that schedules the <code>DirtyTask</code>s by
+     * granted lease time. The dirty calls for the references are sent grouped
+     * by <code>Endpoint</code>. If a dirty call fails, all the references
+     * grouped by that <code>Endpoint</code> are removed from this
+     * <code>DirtyTask</code>, and a new <code>DirtyRetryTask</code> is
+     * instantiated for those references initiating a dirty retry process.
+     * 
+     */
+    @Override
+    public final void run() {
+        synchronized (this) {
+            Iterator<Endpoint> iter = dirtyDataMap.keySet().iterator();
+            while (iter.hasNext()) {
+                Endpoint ep = iter.next();
+                Set<ObjID> objIDSet = dirtyDataMap.get(ep);
+                ObjID[] objArray = new ObjID[objIDSet.size()];
+                objIDSet.toArray(objArray);
+                if (dgc.sendDirty(ep, objArray) == null) {
+                    // If the dirty call has failed, stop sending scheduled
+                    // dirties
+                    // for this Endpoint and initializes the dirty retry
+                    // process.
+                    iter.remove();
+                    DirtyRetryTask retryTask = new DirtyRetryTask(dgc, period,
+                            taskScheduler, ep, objArray, 1);
+                    synchronized (dirtyTaskTable) {
+                        taskScheduler.schedule(retryTask, 2000);
+                        if (dirtyDataMap.isEmpty()) {
+                            this.cancel();
+                            taskScheduler.purge();
+                            dirtyTaskTable.remove(period);
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
+

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/rmi2/src/ar/org/fitc/rmi/dgc/client/DirtyTask.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message