diff options
author | Mark Wielaard <mark@klomp.org> | 2002-10-31 18:35:20 +0000 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2002-10-31 18:35:20 +0000 |
commit | cd7775b47a1f77eb774ff6ecfc6518a4231b636e (patch) | |
tree | f12da6efc0976abdd9afcb1a48191c87f7cbd603 | |
parent | 16932d0c5c2cccf533af93f66464b7836b3bb269 (diff) | |
download | classpath-cd7775b47a1f77eb774ff6ecfc6518a4231b636e.tar.gz |
Merge Orp RMI patches from Wu Gansha <gansha.wu@intel.com>
* configure.in (AC_OUTPUT): Add javax/rmi/Makefile,
* gnu/javax/Makefile, gnu/javax/rmi/Makefile,
javax/rmi/CORBA/Makefile and gnu/javax/rmi/CORBA/Makefile.
* javax/.cvsignore: New File.
* javax/Makefile.am (SUBDIRS): Add rmi.
* javax/rmi/.cvsignore: New File.
* javax/rmi/Makefile.am: New file.
* javax/rmi/CORBA/.cvsignore: New file.
* javax/rmi/CORBA/Makefile.am: New file.
* gnu/Makefile.am (SUBDIRS): Add javax.
* gnu/javax/.cvsignore: New file.
* gnu/javax/Makefile.am: New file.
* gnu/javax/rmi/.cvsignore: New file.
* gnu/javax/rmi/Makefile.am: New file.
* gnu/javax/rmi/CORBA/.cvsignore: New file.
* gnu/javax/rmi/CORBA/Makefile.am: New file.
* java/rmi/MarshalledObject.java (equals): Check hashcode first.
* java/rmi/server/RMIClassLoader.java (MyClassLoader): Create/Use
annotation.
(loadClass): Take String as codebases.
(getClassAnnotation): Use MyClassLoader annotations.
* java/rmi/server/UnicastRemoteObject.java (UnicastRemoteObject):
call exportObject(this).
* gnu/java/rmi/RMIMarshalledObjectOutputStream.java
(RMIMarshalledObjectOutputStream): set locBytesStream and locStream.
(setAnnotation): Don't set locBytesStream and locStream.
(replaceObject): Removed.
(flush): Don't test locStream.
(getLocButes): LikeWise.
* gnu/java/rmi/dgc/DGCImpl.java: extends UnicastServerRef.
(leaseCache): New field.
(dirty): Use leaseCache.
(LeaseRecord): New inner class.
* gnu/java/rmi/registry/RegistryImpl.java (RegistryImpl): Don't
explicitly call exportObject().
* gnu/java/rmi/registry/RegistryImpl_Stub.java: set useNewInvoke to
false to communicate with Sun JDK130.
* gnu/java/rmi/server/ConnectionRunnerPool.java: Add CPU comment.
* gnu/java/rmi/server/RMIObjectInputStream.java
(UnicastConnectionManager): Removed field.
* gnu/java/rmi/server/RMIObjectOutputStream.java (replaceObject):
Use UnicastServer.getExportedRef().
* gnu/java/rmi/server/UnicastConnection.java (reviveTime): New field.
(expireTime): Likewise.
(CONNECTION_TIMEOUT): Likewise.
(disconnect): Call sock.close().
(isExpired): New method.
(resetTime): Likewise.
(run): Use do while loop and catch Exception for discardConnection().
* gnu/java/rmi/server/UnicastConnectionManager.java: Pool connections.
* gnu/java/rmi/server/UnicastRef.java: Lots of changes.
* gnu/java/rmi/server/UnicastRemoteCall.java: Lots of changes.
* gnu/java/rmi/server/UnicastServer.java (refcache): New field.
(exportObject): Use refcache.
(unexportObject): Likewise.
(getExportedRef): New method.
* gnu/java/rmi/server/UnicastServerRef.java (UnicastServerRef): New
constructor.
(exportObject): Save manager.serverobj.
(getStub): New method.
* javax/rmi/PortableRemoteObject.java: New file.
* gnu/javax/rmi/PortableServer.java: Likewise.
* javax/rmi/CORBA/ClassDesc.java: New file.
* javax/rmi/CORBA/PortableRemoteObjectDelegate.java: Likewise.
* javax/rmi/CORBA/Stub.java: Likewise.
* javax/rmi/CORBA/StubDelegate.java: Likewise.
* javax/rmi/CORBA/Tie.java: Likewise.
* javax/rmi/CORBA/Util.java: Likewise.
* javax/rmi/CORBA/UtilDelegate.java: Likewise.
* javax/rmi/CORBA/ValueHandler.java: Likewise.
* gnu/javax/rmi/CORBA/DelegateFactory.java: Likewise.
* gnu/javax/rmi/CORBA/GetDelegateInstanceException.java: Likewise.
* gnu/javax/rmi/CORBA/PortableRemoteObjectDelegateImpl.java: Likewise.
* gnu/javax/rmi/CORBA/StubDelegateImpl.java: Likewise.
* gnu/javax/rmi/CORBA/UtilDelegateImpl.java: Likewise.
* gnu/javax/rmi/CORBA/ValueHandlerImpl.java: Likewise.
* javax/rmi/BAD_OPERATION.java: Stub class.
* javax/rmi/ORB.java: Likewise
* javax/rmi/CORBA/ObjectImpl.java: Likewise
* javax/rmi/CORBA/SystemException.java: Likewise.
50 files changed, 2340 insertions, 333 deletions
@@ -1,3 +1,93 @@ +2002-10-31 Mark Wielaard <mark@klomp.org>: + + Merge Orp RMI patches from Wu Gansha <gansha.wu@intel.com> + * configure.in (AC_OUTPUT): Add javax/rmi/Makefile, + * gnu/javax/Makefile, gnu/javax/rmi/Makefile, + javax/rmi/CORBA/Makefile and gnu/javax/rmi/CORBA/Makefile. + * javax/.cvsignore: New File. + * javax/Makefile.am (SUBDIRS): Add rmi. + * javax/rmi/.cvsignore: New File. + * javax/rmi/Makefile.am: New file. + * javax/rmi/CORBA/.cvsignore: New file. + * javax/rmi/CORBA/Makefile.am: New file. + * gnu/Makefile.am (SUBDIRS): Add javax. + * gnu/javax/.cvsignore: New file. + * gnu/javax/Makefile.am: New file. + * gnu/javax/rmi/.cvsignore: New file. + * gnu/javax/rmi/Makefile.am: New file. + * gnu/javax/rmi/CORBA/.cvsignore: New file. + * gnu/javax/rmi/CORBA/Makefile.am: New file. + + * java/rmi/MarshalledObject.java (equals): Check hashcode first. + + * java/rmi/server/RMIClassLoader.java (MyClassLoader): Create/Use + annotation. + (loadClass): Take String as codebases. + (getClassAnnotation): Use MyClassLoader annotations. + * java/rmi/server/UnicastRemoteObject.java (UnicastRemoteObject): + call exportObject(this). + + * gnu/java/rmi/RMIMarshalledObjectOutputStream.java + (RMIMarshalledObjectOutputStream): set locBytesStream and locStream. + (setAnnotation): Don't set locBytesStream and locStream. + (replaceObject): Removed. + (flush): Don't test locStream. + (getLocButes): LikeWise. + * gnu/java/rmi/dgc/DGCImpl.java: extends UnicastServerRef. + (leaseCache): New field. + (dirty): Use leaseCache. + (LeaseRecord): New inner class. + * gnu/java/rmi/registry/RegistryImpl.java (RegistryImpl): Don't + explicitly call exportObject(). + * gnu/java/rmi/registry/RegistryImpl_Stub.java: set useNewInvoke to + false to communicate with Sun JDK130. + * gnu/java/rmi/server/ConnectionRunnerPool.java: Add CPU comment. + * gnu/java/rmi/server/RMIObjectInputStream.java + (UnicastConnectionManager): Removed field. + * gnu/java/rmi/server/RMIObjectOutputStream.java (replaceObject): + Use UnicastServer.getExportedRef(). + * gnu/java/rmi/server/UnicastConnection.java (reviveTime): New field. + (expireTime): Likewise. + (CONNECTION_TIMEOUT): Likewise. + (disconnect): Call sock.close(). + (isExpired): New method. + (resetTime): Likewise. + (run): Use do while loop and catch Exception for discardConnection(). + * gnu/java/rmi/server/UnicastConnectionManager.java: Pool connections. + * gnu/java/rmi/server/UnicastRef.java: Lots of changes. + * gnu/java/rmi/server/UnicastRemoteCall.java: Lots of changes. + * gnu/java/rmi/server/UnicastServer.java (refcache): New field. + (exportObject): Use refcache. + (unexportObject): Likewise. + (getExportedRef): New method. + * gnu/java/rmi/server/UnicastServerRef.java (UnicastServerRef): New + constructor. + (exportObject): Save manager.serverobj. + (getStub): New method. + + * javax/rmi/PortableRemoteObject.java: New file. + * gnu/javax/rmi/PortableServer.java: Likewise. + + * javax/rmi/CORBA/ClassDesc.java: New file. + * javax/rmi/CORBA/PortableRemoteObjectDelegate.java: Likewise. + * javax/rmi/CORBA/Stub.java: Likewise. + * javax/rmi/CORBA/StubDelegate.java: Likewise. + * javax/rmi/CORBA/Tie.java: Likewise. + * javax/rmi/CORBA/Util.java: Likewise. + * javax/rmi/CORBA/UtilDelegate.java: Likewise. + * javax/rmi/CORBA/ValueHandler.java: Likewise. + * gnu/javax/rmi/CORBA/DelegateFactory.java: Likewise. + * gnu/javax/rmi/CORBA/GetDelegateInstanceException.java: Likewise. + * gnu/javax/rmi/CORBA/PortableRemoteObjectDelegateImpl.java: Likewise. + * gnu/javax/rmi/CORBA/StubDelegateImpl.java: Likewise. + * gnu/javax/rmi/CORBA/UtilDelegateImpl.java: Likewise. + * gnu/javax/rmi/CORBA/ValueHandlerImpl.java: Likewise. + + * javax/rmi/BAD_OPERATION.java: Stub class. + * javax/rmi/ORB.java: Likewise + * javax/rmi/CORBA/ObjectImpl.java: Likewise + * javax/rmi/CORBA/SystemException.java: Likewise. + 2002-10-30 Sascha Brawer <brawer@acm.org> * java/util/logging/Level.java (isStandardLevel): New package-private diff --git a/configure.in b/configure.in index 76ea7ae17..a62953d64 100644 --- a/configure.in +++ b/configure.in @@ -281,6 +281,9 @@ gnu/java/security/util/Makefile gnu/java/text/Makefile gnu/java/util/Makefile gnu/java/util/prefs/Makefile +gnu/javax/Makefile +gnu/javax/rmi/Makefile +gnu/javax/rmi/CORBA/Makefile include/jni.h java/Makefile java/applet/Makefile @@ -334,6 +337,8 @@ javax/accessibility/Makefile javax/naming/Makefile javax/naming/directory/Makefile javax/naming/spi/Makefile +javax/rmi/Makefile +javax/rmi/CORBA/Makefile javax/swing/Makefile javax/swing/border/Makefile javax/swing/colorchooser/Makefile diff --git a/gnu/Makefile.am b/gnu/Makefile.am index ff795c355..4ad169a74 100644 --- a/gnu/Makefile.am +++ b/gnu/Makefile.am @@ -1,4 +1,4 @@ ## Input file for automake to generate the Makefile.in used by configure -SUBDIRS = classpath java +SUBDIRS = classpath java javax diff --git a/gnu/java/rmi/RMIMarshalledObjectOutputStream.java b/gnu/java/rmi/RMIMarshalledObjectOutputStream.java index 663929198..a721fc471 100644 --- a/gnu/java/rmi/RMIMarshalledObjectOutputStream.java +++ b/gnu/java/rmi/RMIMarshalledObjectOutputStream.java @@ -61,42 +61,22 @@ public class RMIMarshalledObjectOutputStream extends RMIObjectOutputStream public RMIMarshalledObjectOutputStream(OutputStream objStream) throws IOException { super(objStream); + locBytesStream = new ByteArrayOutputStream(256); + locStream = new ObjectOutputStream(locBytesStream); } //This method overrides RMIObjectOutputStream's. protected void setAnnotation(String annotation) throws IOException{ - synchronized(this){ - if(locStream == null){ - locBytesStream = new ByteArrayOutputStream(); - locStream = new ObjectOutputStream(locBytesStream); - } - } locStream.writeObject(annotation); } - //This method overrides ObjectOutputStream's to replace Remote to RemoteStub - protected Object replaceObject(Object obj) throws IOException - { - if((obj instanceof Remote) && !(obj instanceof RemoteStub)) - { - UnicastServerRef ref = new UnicastServerRef(new ObjID(), 0, null); - try{ - return ref.exportObject((Remote)obj); - }catch(Exception e){} - } - return obj; - } - public void flush() throws IOException { super.flush(); - if(locStream != null) - locStream.flush(); + locStream.flush(); } public byte[] getLocBytes(){ - if(locStream != null) - return locBytesStream.toByteArray(); - return null; + return locBytesStream.toByteArray(); } } // End of RMIMarshalledObjectOutputStream diff --git a/gnu/java/rmi/dgc/DGCImpl.java b/gnu/java/rmi/dgc/DGCImpl.java index fba18c171..4216b6466 100644 --- a/gnu/java/rmi/dgc/DGCImpl.java +++ b/gnu/java/rmi/dgc/DGCImpl.java @@ -1,5 +1,5 @@ /* - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. + Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -46,24 +46,73 @@ import java.rmi.server.UnicastRemoteObject; import java.rmi.server.RMISocketFactory; import gnu.java.rmi.server.UnicastServerRef; +import java.util.Hashtable; + +/** + * I let DGCImpl to extend UnicastServerRef, but not + * UnicastRemoteObject, because UnicastRemoteObject must + * exportObject automatically. + */ public class DGCImpl - extends UnicastRemoteObject implements DGC { + extends UnicastServerRef implements DGC { -private static final long leaseValue = 600000L; + private static final long LEASE_VALUE = 600000L; + // leaseCache caches a LeaseRecord associated with a vmid + private Hashtable leaseCache = new Hashtable(); public DGCImpl() throws RemoteException { - super(new UnicastServerRef(new ObjID(ObjID.DGC_ID), 0, RMISocketFactory.getSocketFactory())); + super(new ObjID(ObjID.DGC_ID), 0, RMISocketFactory.getSocketFactory()); } public Lease dirty(ObjID[] ids, long sequenceNum, Lease lease) throws RemoteException { VMID vmid = lease.getVMID(); + if (vmid == null) + vmid = new VMID(); + long leaseValue = LEASE_VALUE; + //long leaseValue = lease.getValue(); lease = new Lease(vmid, leaseValue); - System.out.println("DGCImpl.dirty - not completely implemented"); + synchronized(leaseCache){ + LeaseRecord lr = (LeaseRecord)leaseCache.get(vmid); + if (lr != null) + lr.reset(leaseValue); + else{ + lr = new LeaseRecord(vmid, leaseValue); + leaseCache.put(vmid, lr); + } + } + return (lease); } public void clean(ObjID[] ids, long sequenceNum, VMID vmid, boolean strong) throws RemoteException { - System.out.println("DGCImpl.clean - not implemented"); + // Not implemented } + + /** + * LeaseRecord associates a vmid to expireTime. + */ + private static class LeaseRecord{ + private VMID vmid; + private long expireTime; + + LeaseRecord(VMID vmid, long leaseValue){ + this.vmid = vmid; + reset(leaseValue); + } + + // reset expireTime + void reset(long leaseValue){ + long l = System.currentTimeMillis(); + expireTime = l + leaseValue; + } -} + boolean isExpired(){ + long l = System.currentTimeMillis(); + if ( l > expireTime) + return true; + return false; + } + + } //End of LeaseRecord + +} //End of DGCImpl diff --git a/gnu/java/rmi/registry/RegistryImpl.java b/gnu/java/rmi/registry/RegistryImpl.java index fdf4506f3..007d5a97d 100644 --- a/gnu/java/rmi/registry/RegistryImpl.java +++ b/gnu/java/rmi/registry/RegistryImpl.java @@ -64,7 +64,8 @@ public RegistryImpl(int port) throws RemoteException { public RegistryImpl(int port, RMIClientSocketFactory cf, RMIServerSocketFactory sf) throws RemoteException { super(new UnicastServerRef(new ObjID(ObjID.REGISTRY_ID), port, sf)); - ((UnicastServerRef)getRef()).exportObject(this); + // The following is unnecessary, because UnicastRemoteObject export itself automatically. + //((UnicastServerRef)getRef()).exportObject(this); } public Remote lookup(String name) throws RemoteException, NotBoundException, AccessException { diff --git a/gnu/java/rmi/registry/RegistryImpl_Stub.java b/gnu/java/rmi/registry/RegistryImpl_Stub.java index 33cb06a4b..45e10c490 100644 --- a/gnu/java/rmi/registry/RegistryImpl_Stub.java +++ b/gnu/java/rmi/registry/RegistryImpl_Stub.java @@ -67,7 +67,7 @@ public final class RegistryImpl_Stub static { try { java.rmi.server.RemoteRef.class.getMethod("invoke", new java.lang.Class[] { java.rmi.Remote.class, java.lang.reflect.Method.class, java.lang.Object[].class, long.class }); - useNewInvoke = true; + useNewInvoke = false; $method_bind_0 = gnu.java.rmi.registry.RegistryImpl.class.getMethod("bind", new java.lang.Class[] {java.lang.String.class, java.rmi.Remote.class}); $method_list_1 = gnu.java.rmi.registry.RegistryImpl.class.getMethod("list", new java.lang.Class[] {}); $method_lookup_2 = gnu.java.rmi.registry.RegistryImpl.class.getMethod("lookup", new java.lang.Class[] {java.lang.String.class}); diff --git a/gnu/java/rmi/server/ConnectionRunnerPool.java b/gnu/java/rmi/server/ConnectionRunnerPool.java index df6363bdc..af7dc0501 100644 --- a/gnu/java/rmi/server/ConnectionRunnerPool.java +++ b/gnu/java/rmi/server/ConnectionRunnerPool.java @@ -91,6 +91,7 @@ class ConnectionRunnerPool } + // Should this value equal to number of CPU? private static int size = 5; private static int max_size = 10; diff --git a/gnu/java/rmi/server/RMIObjectInputStream.java b/gnu/java/rmi/server/RMIObjectInputStream.java index 5913e9221..3e862c3c1 100644 --- a/gnu/java/rmi/server/RMIObjectInputStream.java +++ b/gnu/java/rmi/server/RMIObjectInputStream.java @@ -1,5 +1,5 @@ /* - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. + Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -50,23 +50,13 @@ import java.lang.reflect.Proxy; public class RMIObjectInputStream extends ObjectInputStream { -UnicastConnectionManager manager; - -public RMIObjectInputStream(InputStream strm, UnicastConnectionManager man) throws IOException { +public RMIObjectInputStream(InputStream strm) throws IOException { super(strm); - manager = man; enableResolveObject(true); } -public RMIObjectInputStream(InputStream strm) throws IOException { - this(strm, UnicastConnectionManager.getInstance(0, null)); -} - protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { String annotation = (String)getAnnotation(); - try{ - return super.resolveClass(desc); - }catch(ClassNotFoundException _){}; try { if(annotation == null) @@ -90,24 +80,23 @@ protected Class resolveProxyClass(String intfs[]) throws IOException, ClassNotFoundException { String annotation = (String)getAnnotation(); - try{ - return super.resolveProxyClass(intfs); - }catch(ClassNotFoundException _){}; Class clss[] = new Class[intfs.length]; if(annotation == null) clss[0] = RMIClassLoader.loadClass(intfs[0]); else clss[0] = RMIClassLoader.loadClass(annotation, intfs[0]); + //assume all interfaces can be loaded by the same classloader ClassLoader loader = clss[0].getClassLoader(); - if(loader == null) - for(int i = 1; i < intfs.length; i++) - clss[i] = Class.forName(intfs[i]); - else - for(int i = 1; i < intfs.length; i++) - clss[i] = loader.loadClass(intfs[i]); + for (int i = 0; i < intfs.length; i++) + clss[i] = Class.forName(intfs[i], false, loader); + + try { return Proxy.getProxyClass(loader, clss); + } catch (IllegalArgumentException e) { + throw new ClassNotFoundException(null, e); + } } protected Object readValue(Class valueClass) throws IOException, ClassNotFoundException { @@ -134,4 +123,4 @@ protected Object readValue(Class valueClass) throws IOException, ClassNotFoundEx return readObject(); } -}
\ No newline at end of file +} diff --git a/gnu/java/rmi/server/RMIObjectOutputStream.java b/gnu/java/rmi/server/RMIObjectOutputStream.java index 71a2bac9d..97ac88aab 100644 --- a/gnu/java/rmi/server/RMIObjectOutputStream.java +++ b/gnu/java/rmi/server/RMIObjectOutputStream.java @@ -1,5 +1,5 @@ /* - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. + Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -72,10 +72,9 @@ protected Object replaceObject(Object obj) throws IOException { if((obj instanceof Remote) && !(obj instanceof RemoteStub)){ - UnicastServerRef ref = new UnicastServerRef(new ObjID(), 0, null); - try{ - return ref.exportObject((Remote)obj); - }catch(Exception e){} + UnicastServerRef ref = UnicastServer.getExportedRef((Remote)obj); + if (ref != null) + return ref.getStub(); } return obj; } diff --git a/gnu/java/rmi/server/UnicastConnection.java b/gnu/java/rmi/server/UnicastConnection.java index e13bb6862..14d28f26c 100644 --- a/gnu/java/rmi/server/UnicastConnection.java +++ b/gnu/java/rmi/server/UnicastConnection.java @@ -1,5 +1,5 @@ /* - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. + Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -61,6 +61,10 @@ DataOutputStream dout; ObjectInputStream oin; ObjectOutputStream oout; +// reviveTime and expireTime make UnicastConnection pool-able +long reviveTime = 0; +long expireTime = Long.MAX_VALUE; + UnicastConnection(UnicastConnectionManager man, Socket sock) { this.manager = man; this.sock = sock; @@ -137,7 +141,7 @@ DataOutputStream getDataOutputStream() throws IOException { ObjectInputStream getObjectInputStream() throws IOException { if (oin == null) { - oin = new RMIObjectInputStream(din, manager); + oin = new RMIObjectInputStream(din); } return (oin); } @@ -153,6 +157,7 @@ void disconnect() { try { if(oout != null) oout.close(); + sock.close(); } catch (IOException _) { } @@ -164,17 +169,35 @@ void disconnect() { sock = null; } +public static final long CONNECTION_TIMEOUT = 10000L; + +static boolean isExpired(UnicastConnection conn, long l){ + if (l <= conn.expireTime ) + return false; + return true; +} + +static void resetTime(UnicastConnection conn){ + long l = System.currentTimeMillis(); + conn.reviveTime = l; + conn.expireTime = l + CONNECTION_TIMEOUT; +} + /** * We run connects on the server. Dispatch it then discard it. */ public void run() { + do{ try { UnicastServer.dispatch(this); + //don't discardConnection explicitly, only when + // exception happens or the connection's expireTime + // comes + } catch (Exception e ){ manager.discardConnection(this); + break; } - catch (Exception e) { - e.printStackTrace(); - } + }while(true); } } diff --git a/gnu/java/rmi/server/UnicastConnectionManager.java b/gnu/java/rmi/server/UnicastConnectionManager.java index 64fecdce2..d54dcf1d4 100644 --- a/gnu/java/rmi/server/UnicastConnectionManager.java +++ b/gnu/java/rmi/server/UnicastConnectionManager.java @@ -1,5 +1,5 @@ /* - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. + Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -41,18 +41,25 @@ import java.rmi.server.RMISocketFactory; import java.rmi.server.RMIServerSocketFactory; import java.rmi.server.RMIClientSocketFactory; import java.rmi.RemoteException; -import gnu.java.rmi.server.UnicastConnection; -import java.util.Hashtable; -import java.net.Socket; -import java.net.ServerSocket; import java.io.IOException; import java.io.ObjectOutput; import java.io.ObjectInput; +import java.io.DataInputStream; import java.lang.Thread; import java.lang.Runnable; import java.net.InetAddress; +import java.net.Socket; +import java.net.ServerSocket; import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.ConcurrentModificationException; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; + +import gnu.java.rmi.server.UnicastConnection; + public class UnicastConnectionManager implements Runnable, ProtocolConstants { @@ -60,15 +67,33 @@ private static String localhost; // use different maps for server/client type UnicastConnectionManager private static Hashtable servers = new Hashtable(); private static Hashtable clients = new Hashtable(); +private ArrayList connections; //client connection pool // make serverThread volatile for poll private volatile Thread serverThread; private ServerSocket ssock; String serverName; int serverPort; + +static private Thread scavenger; + +// If client and server are in the same VM, serverobj represents server +Object serverobj; + +private static RMISocketFactory defaultSocketFactory = RMISocketFactory.getSocketFactory(); private RMIServerSocketFactory serverFactory; private RMIClientSocketFactory clientFactory; +// The following is for debug +private static int ncsock = 0; //count of client socket +private static int nssock = 0; //count of server socket +private static int ncmanager = 0; //count of client manager +private static int nsmanager = 0; //count of server manager + +private static final boolean debug = false; + +private static final Object GLOBAL_LOCK = new Object(); + static { try { //Use host address instead of host name to avoid name resolving issues @@ -78,16 +103,73 @@ static { catch (UnknownHostException _) { localhost = "localhost"; } + + +} + +//Only one scavenger thread running globally +private static void startScavenger(){ + scavenger = new Thread(new Runnable(){ + public void run(){ + if (debug) System.out.println("************* start scavenger."); + boolean liveon = true; + while (liveon){ + // Sleep for the expire timeout + try{ + Thread.sleep(UnicastConnection.CONNECTION_TIMEOUT); + }catch(InterruptedException _ie){ + break; + } + liveon = false; + // Scavenge all clients' connections that're expired + Iterator iter = clients.values().iterator(); + long l = System.currentTimeMillis(); + try{ + while(iter.hasNext()){ + UnicastConnectionManager man = (UnicastConnectionManager)iter.next(); + ArrayList conns = man.connections; + synchronized(conns) { // is the lock a little coarser? + for (int last = conns.size() - 1; + last >= 0; + --last) + { + UnicastConnection conn = (UnicastConnection)conns.get(last); + if (UnicastConnection.isExpired(conn, l)){ + conns.remove(last); + conn.disconnect(); + conn = null; + }else + liveon = true; //there're still live connections + } + } + } + }catch(ConcurrentModificationException cme) { + // handle it lazily + liveon = true; + } + } + scavenger = null; + if (debug) System.out.println("************* exit scavenger."); + } + }); + scavenger.start(); } +/** + * Client UnicastConnectionManager constructor + */ private UnicastConnectionManager(String host, int port, RMIClientSocketFactory csf) { ssock = null; serverName = host; serverPort = port; serverFactory = null; clientFactory = csf; + connections = new ArrayList(); } +/** + * Server UnicastConnectionManager constructor + */ private UnicastConnectionManager(int port, RMIServerSocketFactory ssf) { try { ssock = ssf.createServerSocket(port); @@ -115,7 +197,7 @@ private UnicastConnectionManager(int port, RMIServerSocketFactory ssf) { public static synchronized UnicastConnectionManager getInstance(String host, int port, RMIClientSocketFactory csf) { //System.out.println("getInstance: " + host + "," + port + "," + csf); if (csf == null) { - csf = RMISocketFactory.getSocketFactory(); + csf = defaultSocketFactory; } // change host name to host address to avoid name resolving issues try{ @@ -126,7 +208,17 @@ public static synchronized UnicastConnectionManager getInstance(String host, int UnicastConnectionManager man = (UnicastConnectionManager)clients.get(key); if (man == null) { man = new UnicastConnectionManager(host, port, csf); + if (debug) { + ncmanager++; + System.out.println("\n\n ====== " + ncmanager + " client managers.\n\n"); + } clients.put(key, man); + + // Detect if client and server are in the same VM, i.e., their keys are equal + UnicastConnectionManager svrman = (UnicastConnectionManager)servers.get(key); + if(svrman != null){ // server and client are in the same VM + man.serverobj = svrman.serverobj; + } } return (man); } @@ -138,12 +230,16 @@ public static synchronized UnicastConnectionManager getInstance(String host, int public static synchronized UnicastConnectionManager getInstance(int port, RMIServerSocketFactory ssf) { //System.out.println("getInstance: " + port + "," + ssf); if (ssf == null) { - ssf = RMISocketFactory.getSocketFactory(); + ssf = defaultSocketFactory; } TripleKey key = new TripleKey(localhost, port, ssf); UnicastConnectionManager man = (UnicastConnectionManager)servers.get(key); if (man == null) { man = new UnicastConnectionManager(port, ssf); + if (debug) { + nsmanager++; + System.out.println("\n\n ****** " + nsmanager + " server managers.\n\n"); + } // The provided port might not be the set port. key.port = man.serverPort; servers.put(key, man); @@ -168,9 +264,14 @@ public UnicastConnection getConnection() throws IOException { */ private UnicastConnection getServerConnection() throws IOException { Socket sock = ssock.accept(); + sock.setTcpNoDelay(true); //?? UnicastConnection conn = new UnicastConnection(this, sock); conn.acceptConnection(); -//System.out.println("Server connection " + conn); + if (debug){ + nssock++; + System.out.println("\n\n ****** " + nssock + " server socks.\n\n"); + } + //System.out.println("Server connection " + sock); return (conn); } @@ -178,10 +279,38 @@ private UnicastConnection getServerConnection() throws IOException { * Make a conection from this client to the server. */ private UnicastConnection getClientConnection() throws IOException { + ArrayList conns = connections; + UnicastConnection conn; + + synchronized(conns) { + int nconn = conns.size() - 1; + + // if there're free connections in connection pool + if(nconn >= 0) { + conn = (UnicastConnection)conns.get(nconn); + //Should we check if conn is alive using Ping?? + conns.remove(nconn); + + // Check if the connection is already expired + long l = System.currentTimeMillis(); + if (!UnicastConnection.isExpired(conn, l)){ + return conn; + }else { + conn.disconnect(); + conn = null; + } + } + } + Socket sock = clientFactory.createSocket(serverName, serverPort); - UnicastConnection conn = new UnicastConnection(this, sock); + conn = new UnicastConnection(this, sock); conn.makeConnection(DEFAULT_PROTOCOL); -//System.out.println("Client connection " + conn); + + if (debug) { + ncsock++; + System.out.println("\n\n ====== " + ncsock + " client socks.\n\n"); + } + return (conn); } @@ -191,7 +320,19 @@ private UnicastConnection getClientConnection() throws IOException { */ public void discardConnection(UnicastConnection conn) { //System.out.println("Discarding connection " + conn); + //conn.disconnect(); + if (ssock != null) //server connection conn.disconnect(); + else { + // To client connection, we'd like to return back to pool + UnicastConnection.resetTime(conn); + //Ensure there're only one scavenger globally + synchronized(GLOBAL_LOCK) { + connections.add(conn); //borrow this lock to garantee thread safety + if (scavenger == null) + startScavenger(); + } + } } /** @@ -204,6 +345,8 @@ public void startServer() { return; } serverThread = new Thread(this); + // The following is not necessary when java.lang.Thread's constructor do this. + // serverThread.setContextClassLoader(Thread.currentThread().getContextClassLoader()); } serverThread.start(); } @@ -231,11 +374,11 @@ public void run() { //System.out.println("Waiting for connection on " + serverPort); UnicastConnection conn = getServerConnection(); // use a thread pool to improve performance - // (new Thread(conn)).start(); - ConnectionRunnerPool.dispatchConnection(conn); + //ConnectionRunnerPool.dispatchConnection(conn); + (new Thread(conn)).start(); } catch (Exception e) { - // e.printStackTrace(); + e.printStackTrace(); } } } @@ -254,8 +397,9 @@ void write(ObjectOutput out) throws IOException { static UnicastConnectionManager read(ObjectInput in) throws IOException { String host = in.readUTF(); int port = in.readInt(); - RMIClientSocketFactory csf = ((RMIObjectInputStream)in).manager.clientFactory; - return (getInstance(host, port, csf)); + //RMIClientSocketFactory csf = ((RMIObjectInputStream)in).manager.clientFactory; + //return (getInstance(host, port, csf)); + return (getInstance(host, port, null)); } } @@ -288,7 +432,7 @@ public boolean equals(Object obj) { TripleKey other = (TripleKey)obj; if (this.host.equals(other.host) && this.other == other.other && - (this.port == other.port || this.port == 0 || other.port == 0)) { + (this.port == other.port /* || this.port == 0 || other.port == 0*/)) { return (true); } } diff --git a/gnu/java/rmi/server/UnicastRef.java b/gnu/java/rmi/server/UnicastRef.java index d6cda49c6..9ab020db6 100644 --- a/gnu/java/rmi/server/UnicastRef.java +++ b/gnu/java/rmi/server/UnicastRef.java @@ -1,5 +1,5 @@ /* - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. + Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -62,6 +62,8 @@ import java.io.ObjectOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; +import java.lang.reflect.InvocationTargetException; + public class UnicastRef implements RemoteRef, ProtocolConstants { @@ -69,9 +71,10 @@ public ObjID objid; UnicastConnectionManager manager; /** - * Used by serialization. + * Used by serialization, and let subclass capable of having default constructor */ -private UnicastRef() { +//private +UnicastRef() { } public UnicastRef(ObjID objid, String host, int port, RMIClientSocketFactory csf) { @@ -84,6 +87,21 @@ public UnicastRef(ObjID objid) { } public Object invoke(Remote obj, Method method, Object[] params, long opnum) throws Exception { + // Check if client and server are in the same VM, then local call can be used to + // replace remote call, but it's somewhat violating remote semantic. + Object svrobj = manager.serverobj; + if(svrobj != null){ + //local call + Object ret = null; + try{ + ret = method.invoke(svrobj, params); + }catch(InvocationTargetException e){ + throw (Exception)e.getTargetException(); + } + //System.out.println("\n\n ***** local call: " + method + "\nreturn: " + ret + "\n\n"); + return ret; + } + //System.out.println("***************** remote call:" + manager.serverPort); return (invokeCommon(obj, method, params, -1, opnum)); } @@ -107,18 +125,7 @@ private Object invokeCommon(Remote obj, Method method, Object[] params, int opnu objid.write(out); out.writeInt(opnum); out.writeLong(hash); - /* - if (params != null) { - for (int i = 0; i < params.length; i++) { - if (params[i] instanceof UnicastRemoteObject) { - out.writeObject(UnicastRemoteObject.exportObject((UnicastRemoteObject)params[i])); - } - else { - out.writeObject(params[i]); - } - } - } - */ + // must handle primitive class and their wrapper classes Class clss[] = method.getParameterTypes(); for(int i = 0; i < clss.length; i++) @@ -137,26 +144,30 @@ private Object invokeCommon(Remote obj, Method method, Object[] params, int opnu UID ack; try { din = conn.getDataInputStream(); - if (din.readUnsignedByte() != MESSAGE_CALL_ACK) { - throw new RemoteException("Call not acked"); + + if ((returncode = din.readUnsignedByte()) != MESSAGE_CALL_ACK) { + conn.disconnect(); + throw new RemoteException("Call not acked:" + returncode); } in = conn.getObjectInputStream(); - returncode = in.readUnsignedByte(); ack = UID.read(in); - //returnval = in.readObject(); + Class cls = method.getReturnType(); if(cls == Void.TYPE){ returnval = null; + in.readObject(); }else returnval = ((RMIObjectInputStream)in).readValue(cls); + } catch (IOException e3) { + //for debug: e3.printStackTrace(); throw new RemoteException("call return failed: ", e3); } - /* if DGCAck is necessary + /* if DGCAck is necessary?? //According to RMI wire protocol, send a DGCAck // to indicate receiving return value dout.writeByte(MESSAGE_DGCACK); @@ -166,7 +177,7 @@ private Object invokeCommon(Remote obj, Method method, Object[] params, int opnu manager.discardConnection(conn); - if (returncode != RETURN_ACK) { + if (returncode != RETURN_ACK && returnval != null) { throw (Exception)returnval; } @@ -177,7 +188,18 @@ private Object invokeCommon(Remote obj, Method method, Object[] params, int opnu * @deprecated */ public RemoteCall newCall(RemoteObject obj, Operation[] op, int opnum, long hash) throws RemoteException { - return (new UnicastRemoteCall(obj, opnum, hash)); + UnicastConnection conn; + + try { + conn = manager.getConnection(); + } + catch (IOException e1) { + throw new RemoteException("connection failed to host: " + manager.serverName, e1); + } + + //obj: useless? + + return (new UnicastRemoteCall(conn, objid, opnum, hash)); } /** @@ -185,15 +207,19 @@ public RemoteCall newCall(RemoteObject obj, Operation[] op, int opnum, long hash */ public void invoke(RemoteCall call) throws Exception { UnicastRemoteCall c = (UnicastRemoteCall)call; - Object ret = invokeCommon((Remote)c.getObject(), (Method)null, c.getArguments(), c.getOpnum(), c.getHash()); - c.setReturnValue(ret); + call.executeCall(); } /** * @deprecated */ public void done(RemoteCall call) throws RemoteException { - /* Does nothing */ + UnicastRemoteCall c = (UnicastRemoteCall)call; + try{ + c.done(); + } catch(IOException e){} + UnicastConnection conn = c.getConnection(); + manager.discardConnection(conn); } public void writeExternal(ObjectOutput out) throws IOException { diff --git a/gnu/java/rmi/server/UnicastRemoteCall.java b/gnu/java/rmi/server/UnicastRemoteCall.java index 200538d4a..14ff9650c 100644 --- a/gnu/java/rmi/server/UnicastRemoteCall.java +++ b/gnu/java/rmi/server/UnicastRemoteCall.java @@ -38,15 +38,24 @@ exception statement from your version. */ package gnu.java.rmi.server; import java.lang.Exception; +import java.io.DataInputStream; +import java.io.DataOutputStream; import java.io.IOException; import java.io.ObjectOutput; import java.io.ObjectInput; import java.io.StreamCorruptedException; import java.rmi.server.RemoteCall; +import java.rmi.RemoteException; +import java.rmi.MarshalException; +import java.rmi.UnmarshalException; +import java.rmi.server.UID; +import java.rmi.server.ObjID; +import java.rmi.server.RemoteObject; + import java.util.Vector; -public class UnicastRemoteCall implements RemoteCall -{ +public class UnicastRemoteCall + implements RemoteCall, ProtocolConstants { private UnicastConnection conn; private Object result; @@ -56,92 +65,152 @@ public class UnicastRemoteCall implements RemoteCall private Vector vec; private int ptr; +private ObjectOutput oout; +private ObjectInput oin; + /** * Incoming call. */ - UnicastRemoteCall(UnicastConnection conn) - { +UnicastRemoteCall(UnicastConnection conn) { this.conn = conn; } /** * Outgoing call. */ - UnicastRemoteCall(Object obj, int opnum, long hash) - { +/* +UnicastRemoteCall(Object obj, int opnum, long hash) { this.object = obj; this.opnum = opnum; this.hash = hash; } +*/ - public ObjectOutput getOutputStream() throws IOException +UnicastRemoteCall(UnicastConnection conn, ObjID objid, int opnum, long hash) throws RemoteException { + this.conn = conn; + this.opnum = opnum; + this.hash = hash; + + // signal the call when constructing + try{ + DataOutputStream dout = conn.getDataOutputStream(); + dout.write(MESSAGE_CALL); + + oout = conn.getObjectOutputStream(); + objid.write(oout); + oout.writeInt(opnum); + oout.writeLong(hash); + }catch(IOException ex){ + throw new MarshalException("Try to write header but failed.", ex); + } +} + +UnicastConnection getConnection(){ + return conn; +} + +public ObjectOutput getOutputStream() throws IOException { + if (conn != null) { + if(oout == null) + return (oout = conn.getObjectOutputStream()); + else + return oout; + }else{ vec = new Vector(); - return new DummyObjectOutputStream(); + return (new DummyObjectOutputStream()); + } } - public void releaseOutputStream() throws IOException - { - // Does nothing. +public void releaseOutputStream() throws IOException { + if(oout != null) + oout.flush(); } - public ObjectInput getInputStream() throws IOException - { - if (conn != null) - return conn.getObjectInputStream(); +public ObjectInput getInputStream() throws IOException { + if (conn != null) { + if(oin == null) + return (oin = conn.getObjectInputStream()); + else + return oin; + } + else { ptr = 0; - return new DummyObjectInputStream(); + return (new DummyObjectInputStream()); + } } - public void releaseInputStream() throws IOException - { +public void releaseInputStream() throws IOException { // Does nothing. } - public ObjectOutput getResultStream(boolean success) - throws IOException, StreamCorruptedException - { +public ObjectOutput getResultStream(boolean success) throws IOException, StreamCorruptedException { vec = new Vector(); - return new DummyObjectOutputStream(); + return (new DummyObjectOutputStream()); } - public void executeCall() throws Exception - { - throw new Error("Not implemented"); +public void executeCall() throws Exception { + byte returncode; + ObjectInput oin; + try{ + releaseOutputStream(); + DataInputStream din = conn.getDataInputStream(); + if (din.readByte() != MESSAGE_CALL_ACK) { + throw new RemoteException("Call not acked"); + } + oin = getInputStream(); + returncode = oin.readByte(); + UID.read(oin); + }catch(IOException ex){ + throw new UnmarshalException("Try to read header but failed:", ex); } - public void done() throws IOException - { - /* Does nothing */ + //check return code + switch(returncode){ + case RETURN_ACK: //it's ok + return; + case RETURN_NACK:{ + Object returnobj; + try{ + returnobj = oin.readObject(); + } + catch(Exception ex2){ + throw new UnmarshalException("Try to read exception object but failed", ex2); + } + if(!(returnobj instanceof Exception)) + throw new UnmarshalException("Should be Exception type here"); + throw (Exception)returnobj; + } + default: + throw new UnmarshalException("Invalid return code"); + } } - Object returnValue() - { - return vec.elementAt(0); +public void done() throws IOException { + // conn.disconnect(); } - Object[] getArguments() - { - return vec.toArray(); +Object returnValue() { + return (vec.elementAt(0)); } - Object getObject() - { - return object; +Object[] getArguments() { + return (vec.toArray()); } - int getOpnum() - { - return opnum; +Object getObject() { + return (object); } - long getHash() - { - return hash; +int getOpnum() { + return (opnum); } - void setReturnValue(Object obj) - { +long getHash() { + return (hash); +} + +void setReturnValue(Object obj) { vec.removeAllElements(); vec.addElement(obj); } @@ -149,227 +218,176 @@ public class UnicastRemoteCall implements RemoteCall /** * Dummy object output class. */ - private class DummyObjectOutputStream implements ObjectOutput - { - /** - * Non-private constructor to reduce bytecode emitted. - */ - DummyObjectOutputStream() - { - } +private class DummyObjectOutputStream implements ObjectOutput { - public void writeBoolean(boolean v) throws IOException - { +public void writeBoolean(boolean v) throws IOException { vec.addElement(new Boolean(v)); } - public void writeByte(int v) throws IOException - { +public void writeByte(int v) throws IOException { vec.addElement(new Byte((byte) v)); } - public void writeChar(int v) throws IOException - { +public void writeChar(int v) throws IOException { vec.addElement(new Character((char) v)); } - public void writeDouble(double v) throws IOException - { +public void writeDouble(double v) throws IOException { vec.addElement(new Double(v)); } - public void writeFloat(float v) throws IOException - { +public void writeFloat(float v) throws IOException { vec.addElement(new Float(v)); } - public void writeInt(int v) throws IOException - { +public void writeInt(int v) throws IOException { vec.addElement(new Integer(v)); } - public void writeLong(long v) throws IOException - { +public void writeLong(long v) throws IOException { vec.addElement(new Long(v)); } - public void writeShort(int v) throws IOException - { +public void writeShort(int v) throws IOException { vec.addElement(new Short((short) v)); } - public void writeObject(Object obj) throws IOException - { +public void writeObject(Object obj) throws IOException { vec.addElement(obj); } - public void write(byte b[]) throws IOException - { +public void write(byte b[]) throws IOException { throw new IOException("not required"); } - public void write(byte b[], int off, int len) throws IOException - { +public void write(byte b[], int off, int len) throws IOException { throw new IOException("not required"); } - public void write(int b) throws IOException - { +public void write(int b) throws IOException { throw new IOException("not required"); } - public void writeBytes(String s) throws IOException - { +public void writeBytes(String s) throws IOException { throw new IOException("not required"); } - public void writeChars(String s) throws IOException - { +public void writeChars(String s) throws IOException { throw new IOException("not required"); } - public void writeUTF(String str) throws IOException - { +public void writeUTF(String str) throws IOException { throw new IOException("not required"); } - public void flush() throws IOException - { +public void flush() throws IOException { +} + +public void close() throws IOException { } - public void close() throws IOException - { } - } // class DummyObjectOutputStream /** * Dummy object input class. */ - private class DummyObjectInputStream implements ObjectInput - { - /** - * Non-private constructor to reduce bytecode emitted. - */ - DummyObjectInputStream() - { - } +private class DummyObjectInputStream implements ObjectInput { - public boolean readBoolean() throws IOException - { +public boolean readBoolean() throws IOException { Object obj = vec.elementAt(ptr++); - return ((Boolean) obj).booleanValue(); + return (((Boolean)obj).booleanValue()); } - public byte readByte() throws IOException - { +public byte readByte() throws IOException { Object obj = vec.elementAt(ptr++); - return ((Byte) obj).byteValue(); + return (((Byte)obj).byteValue()); } - public char readChar() throws IOException - { +public char readChar() throws IOException { Object obj = vec.elementAt(ptr++); - return ((Character) obj).charValue(); + return (((Character)obj).charValue()); } - public double readDouble() throws IOException - { +public double readDouble() throws IOException { Object obj = vec.elementAt(ptr++); - return ((Double) obj).doubleValue(); + return (((Double)obj).doubleValue()); } - public float readFloat() throws IOException - { +public float readFloat() throws IOException { Object obj = vec.elementAt(ptr++); - return ((Float) obj).floatValue(); + return (((Float)obj).floatValue()); } - public int readInt() throws IOException - { +public int readInt() throws IOException { Object obj = vec.elementAt(ptr++); - return ((Integer) obj).intValue(); + return (((Integer)obj).intValue()); } - public long readLong() throws IOException - { +public long readLong() throws IOException { Object obj = vec.elementAt(ptr++); - return ((Long) obj).longValue(); + return (((Long)obj).longValue()); } - public short readShort() throws IOException - { +public short readShort() throws IOException { Object obj = vec.elementAt(ptr++); - return ((Short) obj).shortValue(); + return (((Short)obj).shortValue()); } - public Object readObject() throws IOException - { - return vec.elementAt(ptr++); +public Object readObject() throws IOException { + return (vec.elementAt(ptr++)); } - public int read(byte b[]) throws IOException - { +public int read(byte b[]) throws IOException { throw new IOException("not required"); } - public int read(byte b[], int off, int len) throws IOException - { +public int read(byte b[], int off, int len) throws IOException { throw new IOException("not required"); } - public int read() throws IOException - { +public int read() throws IOException { throw new IOException("not required"); } - public long skip(long n) throws IOException - { +public long skip(long n) throws IOException { throw new IOException("not required"); } - public int available() throws IOException - { +public int available() throws IOException { throw new IOException("not required"); } - public void readFully(byte b[]) throws IOException - { +public void readFully(byte b[]) throws IOException { throw new IOException("not required"); } - public void readFully(byte b[], int off, int len) throws IOException - { +public void readFully(byte b[], int off, int len) throws IOException { throw new IOException("not required"); } - public String readLine() throws IOException - { +public String readLine() throws IOException { throw new IOException("not required"); } - public String readUTF() throws IOException - { +public String readUTF() throws IOException { throw new IOException("not required"); } - public int readUnsignedByte() throws IOException - { +public int readUnsignedByte() throws IOException { throw new IOException("not required"); } - public int readUnsignedShort() throws IOException - { +public int readUnsignedShort() throws IOException { throw new IOException("not required"); } - public int skipBytes(int n) throws IOException - { +public int skipBytes(int n) throws IOException { throw new IOException("not required"); } - public void close() throws IOException - { +public void close() throws IOException { +} + } - } // class DummyObjectInputStream } diff --git a/gnu/java/rmi/server/UnicastServer.java b/gnu/java/rmi/server/UnicastServer.java index 15c622f48..baa1ef1aa 100644 --- a/gnu/java/rmi/server/UnicastServer.java +++ b/gnu/java/rmi/server/UnicastServer.java @@ -1,5 +1,5 @@ /* - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. + Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,6 +45,7 @@ import java.io.IOException; import java.net.InetAddress; import java.util.Hashtable; import java.net.UnknownHostException; +import java.rmi.Remote; import java.rmi.server.ObjID; import java.rmi.server.UnicastRemoteObject; import java.rmi.server.UID; @@ -56,27 +57,36 @@ import gnu.java.rmi.dgc.DGCImpl; public class UnicastServer implements ProtocolConstants { -static private Hashtable objects = new Hashtable(); +static private Hashtable objects = new Hashtable(); //mapping OBJID to server ref +static private Hashtable refcache = new Hashtable(); //mapping obj itself to server ref static private DGCImpl dgc; public static void exportObject(UnicastServerRef obj) { startDGC(); objects.put(obj.objid, obj); + refcache.put(obj.myself, obj); obj.manager.startServer(); } // FIX ME: I haven't handle force parameter public static boolean unexportObject(UnicastServerRef obj, boolean force) { objects.remove(obj.objid); + refcache.remove(obj.myself); obj.manager.stopServer(); return true; } +public static UnicastServerRef getExportedRef(Remote remote){ + return (UnicastServerRef)refcache.get(remote); +} + private static synchronized void startDGC() { if (dgc == null) { try { dgc = new DGCImpl(); - ((UnicastServerRef)dgc.getRef()).exportObject(dgc); + // Changed DGCImpl to inherit UnicastServerRef directly + //((UnicastServerRef)dgc.getRef()).exportObject(dgc); + dgc.exportObject(dgc); } catch (RemoteException e) { e.printStackTrace(); diff --git a/gnu/java/rmi/server/UnicastServerRef.java b/gnu/java/rmi/server/UnicastServerRef.java index 196f969d2..4f64452b1 100644 --- a/gnu/java/rmi/server/UnicastServerRef.java +++ b/gnu/java/rmi/server/UnicastServerRef.java @@ -1,5 +1,5 @@ /* - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. + Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -63,6 +63,8 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.util.Hashtable; public class UnicastServerRef @@ -71,11 +73,18 @@ public class UnicastServerRef final static private Class[] stubprototype = new Class[] { RemoteRef.class }; -Remote myself; +Remote myself; //save the remote object itself private Skeleton skel; private RemoteStub stub; private Hashtable methods = new Hashtable(); +/** + * Used by serialization. + */ +UnicastServerRef() +{ +} + public UnicastServerRef(ObjID id, int port, RMIServerSocketFactory ssf) { super(id); manager = UnicastConnectionManager.getInstance(port, ssf); @@ -84,6 +93,9 @@ public UnicastServerRef(ObjID id, int port, RMIServerSocketFactory ssf) { public RemoteStub exportObject(Remote obj) throws RemoteException { if (myself == null) { myself = obj; + // Save it to server manager, to let client calls in the same VM to issue + // local call + manager.serverobj = obj; // Find and install the stub Class cls = obj.getClass(); @@ -112,6 +124,10 @@ public RemoteStub exportObject(Remote remote, Object obj) return exportObject(remote); } +public RemoteStub getStub(){ + return stub; +} + public boolean unexportObject(Remote obj, boolean force) throws RemoteException { // Remove all hashes of methods which may be called. diff --git a/gnu/javax/.cvsignore b/gnu/javax/.cvsignore new file mode 100644 index 000000000..3dda72986 --- /dev/null +++ b/gnu/javax/.cvsignore @@ -0,0 +1,2 @@ +Makefile.in +Makefile diff --git a/gnu/javax/Makefile.am b/gnu/javax/Makefile.am new file mode 100644 index 000000000..7e81c8805 --- /dev/null +++ b/gnu/javax/Makefile.am @@ -0,0 +1,4 @@ +## Input file for automake to generate the Makefile.in used by configure + + +SUBDIRS = rmi diff --git a/gnu/javax/rmi/.cvsignore b/gnu/javax/rmi/.cvsignore new file mode 100644 index 000000000..3dda72986 --- /dev/null +++ b/gnu/javax/rmi/.cvsignore @@ -0,0 +1,2 @@ +Makefile.in +Makefile diff --git a/gnu/javax/rmi/CORBA/.cvsignore b/gnu/javax/rmi/CORBA/.cvsignore new file mode 100644 index 000000000..3dda72986 --- /dev/null +++ b/gnu/javax/rmi/CORBA/.cvsignore @@ -0,0 +1,2 @@ +Makefile.in +Makefile diff --git a/gnu/javax/rmi/CORBA/DelegateFactory.java b/gnu/javax/rmi/CORBA/DelegateFactory.java new file mode 100644 index 000000000..c98549b40 --- /dev/null +++ b/gnu/javax/rmi/CORBA/DelegateFactory.java @@ -0,0 +1,74 @@ +/* DelegateFactory.java -- + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.rmi.CORBA; + +import java.util.HashMap; +import javax.rmi.CORBA.Util; + +public class DelegateFactory +{ + private static HashMap cache = new HashMap(4); + + public static synchronized Object getInstance(String type) + throws GetDelegateInstanceException + { + Object r = cache.get(type); + if (r != null) + return r; + String dcname = System.getProperty("javax.rmi.CORBA." + type + "Class"); + if (dcname == null) + { + //throw new DelegateException + // ("no javax.rmi.CORBA.XXXClass property sepcified."); + dcname = "gnu.javax.rmi.CORBA." + type + "DelegateImpl"; + } + try + { + Class dclass = Class.forName(dcname); + r = dclass.newInstance(); + cache.put(type, r); + return r; + } + catch(Exception e) + { + throw new GetDelegateInstanceException + ("Exception when trying to get delegate instance:" + dcname, e); + } + } +} diff --git a/gnu/javax/rmi/CORBA/GetDelegateInstanceException.java b/gnu/javax/rmi/CORBA/GetDelegateInstanceException.java new file mode 100644 index 000000000..27b84f122 --- /dev/null +++ b/gnu/javax/rmi/CORBA/GetDelegateInstanceException.java @@ -0,0 +1,58 @@ +/* GetDelegateInstanceException.java -- + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.rmi.CORBA; + +import java.io.PrintStream; +import java.io.PrintWriter; + +public class GetDelegateInstanceException + extends Exception +{ + private Throwable next; + + public GetDelegateInstanceException(String msg) + { + super(msg); + } + + public GetDelegateInstanceException(String msg, Throwable next) + { + super(msg, next); + } +} diff --git a/gnu/javax/rmi/CORBA/Makefile.am b/gnu/javax/rmi/CORBA/Makefile.am new file mode 100644 index 000000000..baa929af7 --- /dev/null +++ b/gnu/javax/rmi/CORBA/Makefile.am @@ -0,0 +1,9 @@ +## Input file for automake to generate the Makefile.in used by configure + +EXTRA_DIST = \ +DelegateFactory.java \ +GetDelegateInstanceException.java \ +PortableRemoteObjectDelegateImpl.java \ +StubDelegateImpl.java \ +UtilDelegateImpl.java \ +ValueHandlerImpl.java diff --git a/gnu/javax/rmi/CORBA/PortableRemoteObjectDelegateImpl.java b/gnu/javax/rmi/CORBA/PortableRemoteObjectDelegateImpl.java new file mode 100644 index 000000000..973c4c4f8 --- /dev/null +++ b/gnu/javax/rmi/CORBA/PortableRemoteObjectDelegateImpl.java @@ -0,0 +1,133 @@ +/* PortableRemoteObjectDelegateImpl.java -- + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.rmi.CORBA; + +import java.rmi.*; +import java.rmi.server.*; +import gnu.javax.rmi.*; +import javax.rmi.CORBA.*; + +public class PortableRemoteObjectDelegateImpl + implements PortableRemoteObjectDelegate +{ + + public PortableRemoteObjectDelegateImpl() + { + } + + public void connect(Remote remote, Remote remote1) + throws RemoteException + { + throw new Error("Not implemented for PortableRemoteObjectDelegateImpl"); + } + + public void exportObject(Remote obj) + throws RemoteException + { + PortableServer.exportObject(obj); + } + + public Object narrow(Object narrowFrom, Class narrowTo) + throws ClassCastException + { + if (narrowTo == null) + throw new ClassCastException("Can't narrow to null class"); + if (narrowFrom == null) + return null; + + Class fromClass = narrowFrom.getClass(); + Object result = null; + + try + { + if (narrowTo.isAssignableFrom(fromClass)) + result = narrowFrom; + else + { + System.out.println("We still haven't implement this case: narrow " + + narrowFrom + " of type " + fromClass + " to " + + narrowTo); + Class[] cs = fromClass.getInterfaces(); + for (int i = 0; i < cs.length; i++) + System.out.println(cs[i]); + Exception e1 = new Exception(); + try + { + throw e1; + } + catch(Exception ee) + { + ee.printStackTrace(); + } + System.exit(2); + //throw new Error("We still haven't implement this case: narrow " + // + narrowFrom + " of type " + fromClass + " to " + // + narrowTo); + /* + ObjectImpl objimpl = (ObjectImpl)narrowFrom; + if(objimpl._is_a(PortableServer.getTypeName(narrowTo))) + result = PortableServer.getStubFromObjectImpl(objimpl, narrowTo); + */ + } + } + catch(Exception e) + { + result = null; + } + + if (result == null) + throw new ClassCastException("Can't narrow from " + + fromClass + " to " + narrowTo); + + return result; + } + + public Remote toStub(Remote obj) + throws NoSuchObjectException + { + return PortableServer.toStub(obj); + } + + public void unexportObject(Remote obj) + throws NoSuchObjectException + { + PortableServer.unexportObject(obj); + } + +} diff --git a/gnu/javax/rmi/CORBA/StubDelegateImpl.java b/gnu/javax/rmi/CORBA/StubDelegateImpl.java new file mode 100644 index 000000000..894e50236 --- /dev/null +++ b/gnu/javax/rmi/CORBA/StubDelegateImpl.java @@ -0,0 +1,113 @@ +/* StubDelegateImpl.java -- + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.rmi.CORBA; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +//import org.omg.CORBA.portable.Delegate; +//import org.omg.CORBA.portable.InputStream; +//import org.omg.CORBA.portable.OutputStream; +//import org.omg.CORBA_2_3.portable.ObjectImpl; +//import org.omg.CORBA.portable.ObjectImpl; +//import org.omg.CORBA.BAD_OPERATION; +//import org.omg.CORBA.ORB; +import java.rmi.RemoteException; +import javax.rmi.CORBA.Stub; +import javax.rmi.CORBA.StubDelegate; +import javax.rmi.CORBA.Tie; +import javax.rmi.CORBA.StubDelegate; + +public class StubDelegateImpl + implements StubDelegate +{ + + private int hashCode; + + public StubDelegateImpl(){ + hashCode = 0; + } + // XXX javax.rmi.ORB -> org.omg.CORBA.ORB + public void connect(Stub self, javax.rmi.ORB orb) + throws RemoteException + { + throw new Error("Not implemented for StubDelegate"); + } + + public boolean equals(Stub self, Object obj) + { + if(self == null || obj == null) + return self == obj; + if(!(obj instanceof Stub)) + return false; + return self.hashCode() == ((Stub)obj).hashCode(); + } + + public int hashCode(Stub self) + { + //FIX ME + return hashCode; + } + + public String toString(Stub self) + { + try + { + return self._orb().object_to_string(self); + } + // XXX javax.rmi.BAD_OPERATION -> org.omg.CORBA.BAD_OPERATION + catch(javax.rmi.BAD_OPERATION bad_operation) + { + return null; + } + } + + public void readObject(Stub self, ObjectInputStream s) + throws IOException, ClassNotFoundException + { + throw new Error("Not implemented for StubDelegate"); + } + + public void writeObject(Stub self, ObjectOutputStream s) + throws IOException + { + throw new Error("Not implemented for StubDelegate"); + } + +} diff --git a/gnu/javax/rmi/CORBA/UtilDelegateImpl.java b/gnu/javax/rmi/CORBA/UtilDelegateImpl.java new file mode 100644 index 000000000..70b2e60c6 --- /dev/null +++ b/gnu/javax/rmi/CORBA/UtilDelegateImpl.java @@ -0,0 +1,152 @@ +/* UtilDelegateImpl.java -- + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.rmi.CORBA; + +import java.rmi.Remote; +import java.rmi.RemoteException; +import java.rmi.server.RMIClassLoader; +import java.net.MalformedURLException; +import java.io.*; +//import org.omg.CORBA.ORB; +//import org.omg.CORBA.SystemException; +//import org.omg.CORBA.portable.InputStream; +//import org.omg.CORBA.portable.OutputStream; +import javax.rmi.CORBA.*; + +public class UtilDelegateImpl + implements UtilDelegate +{ + // XXX javax.rmi.ORB -> org.omg.CORBA.ORB + public Object copyObject(Object obj, javax.rmi.ORB orb) + throws RemoteException + { + throw new Error("Not implemented for UtilDelegate"); + } + + // XXX javax.rmi.ORB -> org.omg.CORBA.ORB + public Object[] copyObjects(Object obj[], javax.rmi.ORB orb) + throws RemoteException + { + throw new Error("Not implemented for UtilDelegate"); + } + + public ValueHandler createValueHandler() + { + throw new Error("Not implemented for UtilDelegate"); + } + + public String getCodebase(Class clz) + { + throw new Error("Not implemented for UtilDelegate"); + } + + public Tie getTie(Remote target) + { + throw new Error("Not implemented for UtilDelegate"); + } + + public boolean isLocal(Stub stub) + throws RemoteException + { + throw new Error("Not implemented for UtilDelegate"); + } + + public Class loadClass(String className, String remoteCodebase, + ClassLoader loader) + throws ClassNotFoundException + { + try{ + if (remoteCodebase == null) + return RMIClassLoader.loadClass(className); + else + return RMIClassLoader.loadClass(remoteCodebase, className); + } + catch (MalformedURLException e1) + { + throw new ClassNotFoundException(className, e1); + } + catch(ClassNotFoundException e2) + { + if(loader != null) + return loader.loadClass(className); + else + return null; + } + } + + public RemoteException mapSystemException(SystemException ex) + { + throw new Error("Not implemented for UtilDelegate"); + } + + public Object readAny(InputStream in) + { + throw new Error("Not implemented for UtilDelegate"); + } + + public void registerTarget(Tie tie, Remote target) + { + throw new Error("Not implemented for UtilDelegate"); + } + + public void unexportObject(Remote target) + { + throw new Error("Not implemented for UtilDelegate"); + } + + public RemoteException wrapException(Throwable orig) + { + throw new Error("Not implemented for UtilDelegate"); + } + + public void writeAbstractObject(OutputStream out, Object obj) + { + throw new Error("Not implemented for UtilDelegate"); + } + + public void writeAny(OutputStream out, Object obj) + { + throw new Error("Not implemented for UtilDelegate"); + } + + public void writeRemoteObject(OutputStream out, Object obj) + { + throw new Error("Not implemented for UtilDelegate"); + } +} diff --git a/gnu/javax/rmi/CORBA/ValueHandlerImpl.java b/gnu/javax/rmi/CORBA/ValueHandlerImpl.java new file mode 100644 index 000000000..6935aa68c --- /dev/null +++ b/gnu/javax/rmi/CORBA/ValueHandlerImpl.java @@ -0,0 +1,82 @@ +/* ValueHandlerImpl.java -- + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.rmi.CORBA; + +import java.io.*; +//import org.omg.CORBA.portable.InputStream; +//import org.omg.CORBA.portable.OutputStream; +//import org.omg.SendingContext.RunTime; +import javax.rmi.CORBA.ValueHandler; + +public class ValueHandlerImpl + implements ValueHandler +{ + + public String getRMIRepositoryID(Class clz) + { + throw new Error("Not implemented for ValueHandler"); + } + + // XXX - Runtime -> RunTime + public Runtime getRunTimeCodeBase() + { + throw new Error("Not implemented for ValueHandler"); + } + + public boolean isCustomMarshaled(Class clz) + { + throw new Error("Not implemented for ValueHandler"); + } + + // XXX - Runtime -> RunTime + public Serializable readValue(InputStream in, int offset, Class clz, String repositoryID, Runtime sender) + { + throw new Error("Not implemented for ValueHandler"); + } + + public Serializable writeReplace(Serializable value) + { + throw new Error("Not implemented for ValueHandler"); + } + + public void writeValue(OutputStream out, Serializable value) + { + throw new Error("Not implemented for ValueHandler"); + } +} diff --git a/gnu/javax/rmi/Makefile.am b/gnu/javax/rmi/Makefile.am new file mode 100644 index 000000000..c1e10e59c --- /dev/null +++ b/gnu/javax/rmi/Makefile.am @@ -0,0 +1,7 @@ +## Input file for automake to generate the Makefile.in used by configure + + +SUBDIRS = CORBA + +EXTRA_DIST = \ +PortableServer.java diff --git a/gnu/javax/rmi/PortableServer.java b/gnu/javax/rmi/PortableServer.java new file mode 100644 index 000000000..b5022cab7 --- /dev/null +++ b/gnu/javax/rmi/PortableServer.java @@ -0,0 +1,142 @@ +/* PortableServer.java -- + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.rmi; + +import java.util.Hashtable; +import java.rmi.Remote; +import java.rmi.RemoteException; +import java.rmi.NoSuchObjectException; +import java.rmi.server.ExportException; +import java.rmi.server.UnicastRemoteObject; +import java.rmi.server.RemoteStub; +import javax.rmi.CORBA.*; +//import org.omg.CORBA.portable.ObjectImpl; + +/** + * The relationship of PortableRemoteObjectImpl with PortableServer + * is like that of UnicastRemoteObject with UnicastServer + */ +public class PortableServer +{ + static private Hashtable tieCache = new Hashtable(); + static private Object NO_TIE = new Object(); + + public static final synchronized void exportObject(Remote obj) + throws RemoteException + { + if(Util.getTie(obj) != null) + return; + + Tie tie = getTieFromRemote(obj); + if (tie != null) + Util.registerTarget(tie, obj); + else + UnicastRemoteObject.exportObject(obj); + } + + public static final void unexportObject(Remote obj) + { + if (Util.getTie(obj) != null) + Util.unexportObject(obj); + if (tieCache.get(obj) != null) //?? + tieCache.remove(obj); + } + + public static final Remote toStub(Remote obj) + throws NoSuchObjectException + { + if (obj instanceof Stub || obj instanceof RemoteStub) + return obj; + + Tie tie = Util.getTie(obj); + Remote stub; + if (tie != null) + stub = getStubFromTie(tie); + else + throw new NoSuchObjectException("Can't toStub an unexported object"); + return stub; + } + + static synchronized Tie getTieFromRemote(Remote obj) + { + Object tie = tieCache.get(obj); + if (tie == null) + { + tie = getTieFromClass(obj.getClass()); + if(tie == null) + tieCache.put(obj, NO_TIE); + else + tieCache.put(obj, tie); + } + else + if(tie != NO_TIE) + { + try + { + tie = obj.getClass().newInstance(); + } + catch(Exception _) + { + tie = null; + } + } + else //NO_TIE + tie = null; + + return (Tie)tie; + } + + static synchronized Tie getTieFromClass(Class clz) + { + //FIX ME + return null; + } + + public static Remote getStubFromTie(Tie tie) + { + //FIX ME + return null; + } + + public static Remote getStubFromObjectImpl(ObjectImpl objimpl, Class toClass) + { + //FIX ME + return null; + } +} diff --git a/java/rmi/MarshalledObject.java b/java/rmi/MarshalledObject.java index 4c9a9ccdb..9f966b9d9 100644 --- a/java/rmi/MarshalledObject.java +++ b/java/rmi/MarshalledObject.java @@ -78,6 +78,10 @@ public final class MarshalledObject { if(obj == null || !(obj instanceof MarshalledObject) ) return false; + + // hashCode even differs, don't do the time-consuming comparisons + if (obj.hashCode() != hash) + return false; MarshalledObject aobj = (MarshalledObject)obj; if (objBytes == null || aobj.objBytes == null) diff --git a/java/rmi/server/RMIClassLoader.java b/java/rmi/server/RMIClassLoader.java index da8f52c7c..057ca0fd4 100644 --- a/java/rmi/server/RMIClassLoader.java +++ b/java/rmi/server/RMIClassLoader.java @@ -43,39 +43,72 @@ import java.net.URLClassLoader; import java.io.IOException; import java.io.DataInputStream; import java.net.MalformedURLException; -import java.util.StringTokenizer; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Hashtable; import java.util.Map; +import java.util.StringTokenizer; import java.util.WeakHashMap; -import java.util.ArrayList; public class RMIClassLoader { static private class MyClassLoader extends URLClassLoader { + + private MyClassLoader(URL[] urls, ClassLoader parent, String annotation) + { + super(urls, parent); + this.annotation = annotation; + } + private MyClassLoader(URL[] urls, ClassLoader parent) { super (urls, parent); + this.annotation = urlToAnnotation(urls); } - Class defineClass(String name, byte[] data) + public static String urlToAnnotation(URL[] urls) { - return defineClass(name, data, 0, data.length); + if (urls.length == 0) + return null; + + StringBuffer annotation = new StringBuffer(64*urls.length); + for(int i = 0; i < urls.length; i++) + { + annotation.append(urls[i].toExternalForm()); + annotation.append(' '); + } + + return annotation.toString(); + } + + public final String getClassAnnotation(){ + return annotation; } + + private final String annotation; + } private static Map cacheLoaders; //map annotations to loaders - private static Map cacheClasses; //map loader to classes that the loader loaded+ + private static Map cacheAnnotations; //map loaders to annotations + + //defaultAnnotation is got from system property + // "java.rmi.server.defaultAnnotation" private static String defaultAnnotation; + //URL object for defaultAnnotation private static URL defaultCodebase; + //class loader for defaultAnnotation private static MyClassLoader defaultLoader; static { - cacheLoaders = Collections.synchronizedMap(new WeakHashMap(5)); - cacheClasses = Collections.synchronizedMap(new WeakHashMap(5)); + // 89 is a nice prime number for Hashtable initial capacity + cacheLoaders = new Hashtable(89); + cacheAnnotations = new Hashtable(89); + defaultAnnotation = System.getProperty("java.rmi.server.defaultAnnotation"); try { @@ -89,9 +122,8 @@ public class RMIClassLoader if (defaultCodebase != null) { defaultLoader = new MyClassLoader(new URL[]{ defaultCodebase }, - Thread.currentThread().getContextClassLoader()); + null, defaultAnnotation); cacheLoaders.put(defaultAnnotation, defaultLoader); - cacheClasses.put(defaultLoader, Collections.synchronizedMap(new WeakHashMap())); } } @@ -104,91 +136,76 @@ public class RMIClassLoader return (loadClass("", name)); } - public static Class loadClass(URL codebase, String name) + public static Class loadClass(String codebases, String name) throws MalformedURLException, ClassNotFoundException { - URL u = new URL(codebase, name + ".class"); + Class c = null; + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + //try context class loader first try { - URLConnection conn = u.openConnection(); - DataInputStream strm = new DataInputStream(conn.getInputStream()); - byte data[] = new byte[conn.getContentLength()]; - strm.readFully(data); - return (defaultLoader.defineClass(name, data)); - } - catch (IOException _) - { - throw new ClassNotFoundException(name); + c = loader.loadClass(name); } - } - - public static Class loadClass(String codebases, String name) - throws MalformedURLException, ClassNotFoundException - { - ClassLoader loader = (ClassLoader)cacheLoaders.get(codebases); - if (loader == null) + catch(ClassNotFoundException e) {} + + if (c != null) + return c; + + if (codebases.length() == 0) //=="" + loader = defaultLoader; + else { - if (codebases != "") + loader = (ClassLoader)cacheLoaders.get(codebases); + if (loader == null) { - //codebases are separated by " " + //create an entry in cacheLoaders mapping a loader to codebases. + + // codebases are separated by " " StringTokenizer tok = new StringTokenizer(codebases, " "); ArrayList urls = new ArrayList(); while (tok.hasMoreTokens()) urls.add(new URL(tok.nextToken())); - + loader = new MyClassLoader((URL[])urls.toArray(new URL[urls.size()]), - Thread.currentThread().getContextClassLoader()); + null, codebases); cacheLoaders.put(codebases, loader); - cacheClasses.put(loader, Collections.synchronizedMap(new WeakHashMap())); - } - else - { - //if codebases is empty, construct a classloader - // based on current context classloader, - // and we won't cache classloader for empty codebases - loader = new MyClassLoader(new URL[]{ defaultCodebase }, - Thread.currentThread().getContextClassLoader()); } } - Class c = null; - Map classes = (Map)cacheClasses.get(loader); - if (classes != null) - { - c = (Class)classes.get(name); - if (c == null) - { - c = loader.loadClass(name); - classes.put(name, c); - } - }else - c = loader.loadClass(name); - - return c; + return loader.loadClass(name); } public static String getClassAnnotation(Class cl) { ClassLoader loader = cl.getClassLoader(); - if (loader == null) + if (loader == null || loader == ClassLoader.getSystemClassLoader()) { - if (defaultCodebase != null) - return defaultCodebase.toExternalForm(); - else - return null; + return null; //?? + } + + if (loader instanceof MyClassLoader) + { + return ((MyClassLoader)loader).getClassAnnotation(); } + + String s = (String)cacheAnnotations.get(loader); + if (s != null) + return s; + if (loader instanceof URLClassLoader) { URL[] urls = ((URLClassLoader)loader).getURLs(); if(urls.length == 0) return null; - StringBuffer annotation = new StringBuffer(urls[0].toExternalForm()); - for(int i = 1; i < urls.length; i++) + + StringBuffer annotation = new StringBuffer(64*urls.length); + for(int i = 0; i < urls.length; i++) { - annotation.append(' '); annotation.append(urls[i].toExternalForm()); + annotation.append(' '); } - return annotation.toString(); + s = annotation.toString(); + cacheAnnotations.put(loader, s); } return null; } diff --git a/java/rmi/server/UnicastRemoteObject.java b/java/rmi/server/UnicastRemoteObject.java index a9c4f3509..aefe9701e 100644 --- a/java/rmi/server/UnicastRemoteObject.java +++ b/java/rmi/server/UnicastRemoteObject.java @@ -1,5 +1,5 @@ /* - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. + Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -67,16 +67,12 @@ protected UnicastRemoteObject(int port, RMIClientSocketFactory csf, RMIServerSoc //this.csf = csf; //this.ssf = ssf; this.ref = new UnicastServerRef(new ObjID(), port, ssf); - //Should we export it here? - // if we export, we got infinite recursive call: - // UnicastRemoteObject.<init>->...->UnicastServer.startDGC()->UnicastRemoteObject.<init>->... - //exportObject(this); + exportObject(this); } protected UnicastRemoteObject(RemoteRef ref) throws RemoteException { super((UnicastServerRef)ref); - //Should we export it here? - //exportObject(this); + exportObject(this); } public Object clone() throws CloneNotSupportedException { diff --git a/javax/Makefile.am b/javax/Makefile.am index fec7ca8b2..c61f71bda 100644 --- a/javax/Makefile.am +++ b/javax/Makefile.am @@ -1,3 +1,3 @@ ## Input file for automake to generate the Makefile.in used by configure -SUBDIRS = accessibility naming swing +SUBDIRS = accessibility rmi naming swing diff --git a/javax/rmi/.cvsignore b/javax/rmi/.cvsignore new file mode 100644 index 000000000..3dda72986 --- /dev/null +++ b/javax/rmi/.cvsignore @@ -0,0 +1,2 @@ +Makefile.in +Makefile diff --git a/javax/rmi/BAD_OPERATION.java b/javax/rmi/BAD_OPERATION.java new file mode 100644 index 000000000..36081a47c --- /dev/null +++ b/javax/rmi/BAD_OPERATION.java @@ -0,0 +1,4 @@ +package javax.rmi; + +/** XXX - Stub till we have org.omg.CORBA */ +public class BAD_OPERATION extends Exception { } diff --git a/javax/rmi/CORBA/.cvsignore b/javax/rmi/CORBA/.cvsignore new file mode 100644 index 000000000..3dda72986 --- /dev/null +++ b/javax/rmi/CORBA/.cvsignore @@ -0,0 +1,2 @@ +Makefile.in +Makefile diff --git a/javax/rmi/CORBA/ClassDesc.java b/javax/rmi/CORBA/ClassDesc.java new file mode 100644 index 000000000..052046df9 --- /dev/null +++ b/javax/rmi/CORBA/ClassDesc.java @@ -0,0 +1,55 @@ +/* ClassDesc.java -- + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.rmi.CORBA; + +import java.io.Serializable; + +public class ClassDesc + implements Serializable +{ + /* + * The following is serialized form required by Java API Doc + */ + private String repid; + private String codebase; + + public ClassDesc() + { + } +} diff --git a/javax/rmi/CORBA/Makefile.am b/javax/rmi/CORBA/Makefile.am new file mode 100644 index 000000000..dbae509ec --- /dev/null +++ b/javax/rmi/CORBA/Makefile.am @@ -0,0 +1,13 @@ +## Input file for automake to generate the Makefile.in used by configure + +EXTRA_DIST = \ +ClassDesc.java \ +ObjectImpl.java \ +PortableRemoteObjectDelegate.java \ +Stub.java \ +StubDelegate.java \ +SystemException.java \ +Tie.java \ +Util.java \ +UtilDelegate.java \ +ValueHandler.java diff --git a/javax/rmi/CORBA/ObjectImpl.java b/javax/rmi/CORBA/ObjectImpl.java new file mode 100644 index 000000000..d76d673ce --- /dev/null +++ b/javax/rmi/CORBA/ObjectImpl.java @@ -0,0 +1,9 @@ +package javax.rmi.CORBA; + +/** XXX - Stub till we have org.omg.CORBA */ +public class ObjectImpl +{ + public ObjectImpl _orb() { return null; } + public String object_to_string(ObjectImpl o) + throws javax.rmi.BAD_OPERATION { return null; } +} diff --git a/javax/rmi/CORBA/PortableRemoteObjectDelegate.java b/javax/rmi/CORBA/PortableRemoteObjectDelegate.java new file mode 100644 index 000000000..a073cf470 --- /dev/null +++ b/javax/rmi/CORBA/PortableRemoteObjectDelegate.java @@ -0,0 +1,63 @@ +/* PortableRemoteObjectDelegate.java -- Interface supporting PortableRemoteObject + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.rmi.CORBA; + +import java.rmi.*; + +/** + * A delegate is a singleton class that support delegation for method + * implementation in PortableRemoteObject. + */ +public interface PortableRemoteObjectDelegate +{ + void connect(Remote target, Remote source) + throws RemoteException; + + void exportObject(Remote obj) + throws RemoteException; + + Object narrow(Object narrowFrom, Class narrowTo) + throws ClassCastException; + + Remote toStub(Remote obj) + throws NoSuchObjectException; + + void unexportObject(Remote obj) + throws NoSuchObjectException; +} diff --git a/javax/rmi/CORBA/Stub.java b/javax/rmi/CORBA/Stub.java new file mode 100644 index 000000000..c79b85cb4 --- /dev/null +++ b/javax/rmi/CORBA/Stub.java @@ -0,0 +1,120 @@ +/* Stub.java -- + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.rmi.CORBA; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.rmi.RemoteException; +//import org.omg.CORBA.ORB; +//import org.omg.CORBA_2_3.portable.ObjectImpl; +//import org.omg.CORBA.portable.ObjectImpl; +import gnu.javax.rmi.CORBA.DelegateFactory; +import gnu.javax.rmi.CORBA.GetDelegateInstanceException; + +public abstract class Stub extends ObjectImpl + implements Serializable +{ + private transient StubDelegate delegate; + + protected Stub() + { + try + { + delegate = (StubDelegate)DelegateFactory.getInstance("Stub"); + } + catch(GetDelegateInstanceException e) + { + delegate = null; + } + } + + public int hashCode() + { + if(delegate != null) + return delegate.hashCode(this); + else + return 0; + } + + public boolean equals(Object obj) + { + if(delegate != null) + return delegate.equals(this, obj); + else + return false; + } + + public String toString() + { + String s = null; + if(delegate != null) + s = delegate.toString(this); + if(s == null) + s = super.toString(); + return s; + } + + // XXX javax.rmi.ORB -> org.omg.CORBA.ORB + public void connect(javax.rmi.ORB orb) + throws RemoteException + { + if(delegate != null) + delegate.connect(this, orb); + } + + /** + * The following two routines are required by serialized form of Java API doc. + */ + private void readObject(ObjectInputStream stream) + throws IOException, ClassNotFoundException + { + if(delegate != null) + delegate.readObject(this, stream); + } + + private void writeObject(ObjectOutputStream stream) + throws IOException + { + if(delegate != null) + delegate.writeObject(this, stream); + } + +} diff --git a/javax/rmi/CORBA/StubDelegate.java b/javax/rmi/CORBA/StubDelegate.java new file mode 100644 index 000000000..6c7f69fe7 --- /dev/null +++ b/javax/rmi/CORBA/StubDelegate.java @@ -0,0 +1,65 @@ +/* StubDelegate.java -- + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.rmi.CORBA; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.rmi.RemoteException; +//import org.omg.CORBA.ORB; + +public interface StubDelegate +{ + + // XXX javax.rmi.ORB -> org.omg.CORBA.ORB + void connect(Stub self, javax.rmi.ORB orb) + throws RemoteException; + + boolean equals(Stub self, Object obj); + + int hashCode(Stub self); + + void readObject(Stub self, ObjectInputStream s) + throws IOException, ClassNotFoundException; + + String toString(Stub self); + + void writeObject(Stub self, ObjectOutputStream s) + throws IOException; +} diff --git a/javax/rmi/CORBA/SystemException.java b/javax/rmi/CORBA/SystemException.java new file mode 100644 index 000000000..f8afdc35e --- /dev/null +++ b/javax/rmi/CORBA/SystemException.java @@ -0,0 +1,4 @@ +package javax.rmi.CORBA; + +/** XXX - Stub till we have org.omg.CORBA */ +public class SystemException extends Exception { } diff --git a/javax/rmi/CORBA/Tie.java b/javax/rmi/CORBA/Tie.java new file mode 100644 index 000000000..ca14e3d42 --- /dev/null +++ b/javax/rmi/CORBA/Tie.java @@ -0,0 +1,62 @@ +/* Tie.java -- + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.rmi.CORBA; + +import java.rmi.Remote; +//import org.omg.CORBA.ORB; +//import org.omg.CORBA.portable.InvokeHandler; + +public interface Tie // XXX extends InvokeHandler +{ + + void deactivate(); + + Remote getTarget(); + + // XXX javax.rmi.ORB -> org.omg.CORBA.ORB + javax.rmi.ORB orb(); + + // XXX javax.rmi.ORB -> org.omg.CORBA.ORB + void orb(javax.rmi.ORB orb); + + void setTarget(Remote target); + + // XXX Object -> org.omg.CORBA.Object + Object thisObject(); +} diff --git a/javax/rmi/CORBA/Util.java b/javax/rmi/CORBA/Util.java new file mode 100644 index 000000000..45a189d97 --- /dev/null +++ b/javax/rmi/CORBA/Util.java @@ -0,0 +1,187 @@ +/* Util.java -- + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.rmi.CORBA; + +import java.rmi.Remote; +import java.rmi.RemoteException; +import java.lang.Object; +import java.io.*; +//import org.omg.CORBA.*; +//import org.omg.CORBA.portable.InputStream; +//import org.omg.CORBA.portable.OutputStream; +import gnu.javax.rmi.CORBA.DelegateFactory; +import gnu.javax.rmi.CORBA.GetDelegateInstanceException; + +public class Util +{ + + private static UtilDelegate delegate; + static + { + try + { + delegate = (UtilDelegate)DelegateFactory.getInstance("Util"); + } + catch(GetDelegateInstanceException e) + { + delegate = null; + } + } + + private Util() + { + } + + // XXX - javax.rmi.ORB -> org.omg.CORBA.ORB + public static Object copyObject(Object obj, javax.rmi.ORB orb) + throws RemoteException + { + if(delegate != null) + return delegate.copyObject(obj, orb); + else + return null; + } + + // XXX - javax.rmi.ORB -> org.omg.CORBA.ORB + public static Object[] copyObjects(Object obj[], javax.rmi.ORB orb) + throws RemoteException + { + if(delegate != null) + return delegate.copyObjects(obj, orb); + else + return null; + } + + public static ValueHandler createValueHandler() + { + if(delegate != null) + return delegate.createValueHandler(); + else + return null; + } + + public static String getCodebase(Class clz) + { + if(delegate != null) + return delegate.getCodebase(clz); + else + return null; + } + + public static Tie getTie(Remote target) + { + if(delegate != null) + return delegate.getTie(target); + else + return null; + } + + public static boolean isLocal(Stub stub) + throws RemoteException + { + if(delegate != null) + return delegate.isLocal(stub); + else + return false; + } + + public static Class loadClass(String className, String remoteCodebase, ClassLoader loader) + throws ClassNotFoundException + { + if(delegate != null) + return delegate.loadClass(className, remoteCodebase, loader); + else + throw new ClassNotFoundException(className + ": delegate == null"); + } + + public static RemoteException mapSystemException(SystemException ex) + { + if(delegate != null) + return delegate.mapSystemException(ex); + else + return null; + } + + public static Object readAny(InputStream in) + { + if(delegate != null) + return delegate.readAny(in); + else + return null; + } + + public static void registerTarget(Tie tie, Remote target) + { + if(delegate != null) + delegate.registerTarget(tie, target); + } + + public static void unexportObject(Remote target) + { + if(delegate != null) + delegate.unexportObject(target); + } + + public static RemoteException wrapException(Throwable orig) + { + if(delegate != null) + return delegate.wrapException(orig); + else + return null; + } + + public static void writeAbstractObject(OutputStream out, Object obj) + { + if(delegate != null) + delegate.writeAbstractObject(out, obj); + } + + public static void writeAny(OutputStream out, Object obj) + { + if(delegate != null) + delegate.writeAny(out, obj); + } + + public static void writeRemoteObject(OutputStream out, Object obj) + { + if(delegate != null) + delegate.writeRemoteObject(out, obj); + } + +} diff --git a/javax/rmi/CORBA/UtilDelegate.java b/javax/rmi/CORBA/UtilDelegate.java new file mode 100644 index 000000000..4d611bc8b --- /dev/null +++ b/javax/rmi/CORBA/UtilDelegate.java @@ -0,0 +1,84 @@ +/* UtilDelegate.java -- + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.rmi.CORBA; + +import java.rmi.Remote; +import java.rmi.RemoteException; +import java.io.*; +//import org.omg.CORBA.ORB; +//import org.omg.CORBA.SystemException; +//import org.omg.CORBA.portable.InputStream; +//import org.omg.CORBA.portable.OutputStream; + +public interface UtilDelegate +{ + + // XXX javax.rmi.ORB -> org.omg.CORBA.ORB + Object copyObject(Object obj, javax.rmi.ORB orb) throws RemoteException; + + // XXX javax.rmi.ORB -> org.omg.CORBA.ORB + Object[] copyObjects(Object obj[], javax.rmi.ORB orb) throws RemoteException; + + ValueHandler createValueHandler(); + + String getCodebase(Class clz); + + Tie getTie(Remote target); + + boolean isLocal(Stub stub) throws RemoteException; + + Class loadClass(String className, String remoteCodebase, + ClassLoader loader) throws ClassNotFoundException; + + RemoteException mapSystemException(SystemException ex); + + Object readAny(InputStream in); + + void registerTarget(Tie tie, Remote target); + + void unexportObject(Remote target); + + RemoteException wrapException(Throwable orig); + + void writeAbstractObject(OutputStream out, Object obj); + + void writeAny(OutputStream out, Object obj); + + void writeRemoteObject(OutputStream out, Object obj); +} diff --git a/javax/rmi/CORBA/ValueHandler.java b/javax/rmi/CORBA/ValueHandler.java new file mode 100644 index 000000000..3a008f18c --- /dev/null +++ b/javax/rmi/CORBA/ValueHandler.java @@ -0,0 +1,63 @@ +/* ValueHandler.java -- + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.rmi.CORBA; + +import java.io.*; +//import org.omg.CORBA.portable.InputStream; +//import org.omg.CORBA.portable.OutputStream; +//import org.omg.SendingContext.RunTime; + +public interface ValueHandler +{ + + String getRMIRepositoryID(Class clz); + + // XXX Runtime -> RunTime + Runtime getRunTimeCodeBase(); + + boolean isCustomMarshaled(Class clz); + + // XXX Runtime -> RunTime + Serializable readValue(InputStream in, int offset, Class clz, + String repositoryID, Runtime sender); + + Serializable writeReplace(Serializable value); + + void writeValue(OutputStream out, Serializable value); +} diff --git a/javax/rmi/Makefile.am b/javax/rmi/Makefile.am new file mode 100644 index 000000000..509f0e603 --- /dev/null +++ b/javax/rmi/Makefile.am @@ -0,0 +1,8 @@ +## Input file for automake to generate the Makefile.in used by configure + +SUBDIRS = CORBA + +EXTRA_DIST = \ +BAD_OPERATION.java \ +ORB.java \ +PortableRemoteObject.java diff --git a/javax/rmi/ORB.java b/javax/rmi/ORB.java new file mode 100644 index 000000000..be7a894e6 --- /dev/null +++ b/javax/rmi/ORB.java @@ -0,0 +1,4 @@ +package javax.rmi; + +/** XXX - Stub till we have org.omg.CORBA */ +public class ORB { } diff --git a/javax/rmi/PortableRemoteObject.java b/javax/rmi/PortableRemoteObject.java new file mode 100644 index 000000000..ee40d9c9e --- /dev/null +++ b/javax/rmi/PortableRemoteObject.java @@ -0,0 +1,114 @@ +/* PortableRemoteObject.java -- + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.rmi; + +import java.rmi.Remote; +import java.rmi.RemoteException; +import java.rmi.NoSuchObjectException; +import gnu.javax.rmi.CORBA.DelegateFactory; +import gnu.javax.rmi.CORBA.GetDelegateInstanceException; +import javax.rmi.CORBA.PortableRemoteObjectDelegate; +import javax.rmi.CORBA.Util; + +public class PortableRemoteObject + implements Remote /* why doc doesn't say should implement Remote */ +{ + + private static PortableRemoteObjectDelegate delegate; + static + { + try + { + delegate = (PortableRemoteObjectDelegate)DelegateFactory.getInstance + ("PortableRemoteObject"); + } + catch(GetDelegateInstanceException e) + { + e.printStackTrace(); + delegate = null; + } + } + + protected PortableRemoteObject() + throws RemoteException + { + if(delegate != null) + exportObject((Remote)this); + } + + public static void connect(Remote target, Remote source) + throws RemoteException + { + if(delegate != null) + delegate.connect(target, source); + } + + public static void exportObject(Remote obj) + throws RemoteException + { + if(delegate != null) + delegate.exportObject(obj); + } + + public static Object narrow(Object narrowFrom, Class narrowTo) + throws ClassCastException + { + if(delegate != null) + return delegate.narrow(narrowFrom, narrowTo); + else + return null; + } + + public static Remote toStub(Remote obj) + throws NoSuchObjectException + { + if(delegate != null) + return delegate.toStub(obj); + else + return null; + } + + public static void unexportObject(Remote obj) + throws NoSuchObjectException + { + if(delegate != null) + delegate.unexportObject(obj); + } + +} |