From f903e73b80ccb078fb4bb8cfb5c4a44ea901a002 Mon Sep 17 00:00:00 2001 From: Norbert Frese Date: Sat, 20 Mar 2004 20:30:56 +0000 Subject: RMIIncomingThread.java: New file. 2004-03-20 Norbert Frese * gnu/java/rmi/server/RMIIncomingThread.java: New file. * gcc/libjava/gnu/java/rmi/server/UnicastConnection.java: Create a new RMIObjectOuputStream/RMIObjectInputStream for every rmi-message. (getObjectInputStream): Return object reference, throw IOException if null. (startObjectInputStream): Create new RMIObjectInputStream on top of 'din'. (getObjectOutputStream): Return object reference, throw IOException if null. (startObjectOutputStream): Create new RMIObjectOutputStream on top of 'dout'. * gcc/libjava/gnu/java/rmi/server/UnicastConnectionManager.java: (UnicastConnectionManager): Throw RemoteException if port is not available. (getInstance): Throw RemoteException. (run): Lookup client host and attach it to new RMIIncomingThread for later retrieval. * gcc/libjava/gnu/java/rmi/server/UnicastRef.java: Start a new RMIObjectInputStream/RMIObjectOutputStream for every rmi-message. Collect Exceptions which are returned by a rmi-call and fix void returns. * gcc/libjava/gnu/java/rmi/server/UnicastRemoteCall.java: Start a new RMIObjectInputStream/RMIObjectOutputStream for every rmi-message. * gcc/libjava/gnu/java/rmi/server/UnicastServer.java: (dispatch): Answer ping messages which are sent by other java implementions. (incomingMessageCall): Start a new RMIObjectInputStream/RMIObjectOutputStream for every rmi-message and fix void return problems. * gcc/libjava/gnu/java/rmi/server/UnicastServerRef.java (UnicastServerRef): Throw RemoteException. (exportObject): Find the class up the class hierarchy which has a _Stub generated by rmic. In some situations it is necessary to export a subclass of the class which has the _Stub. For instance when the class with has the _Stub is abstract. (findStubSkelClass): New method which looks for the class which has the _Stub. (getClientHost): Implementated. * gcc/libjava/java/rmi/server/RemoteServer.java (getClientHost): Implementated. * gcc/libjava/Makefile.am (rmi_java_source_files): Added gnu/java/rmi/server/RMIIncomingThread.java. * Makefile.in: Regenerated. From-SVN: r79755 --- libjava/gnu/java/rmi/server/UnicastServerRef.java | 51 +++++++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'libjava/gnu/java/rmi/server/UnicastServerRef.java') diff --git a/libjava/gnu/java/rmi/server/UnicastServerRef.java b/libjava/gnu/java/rmi/server/UnicastServerRef.java index b004927502f..3e9529c598b 100644 --- a/libjava/gnu/java/rmi/server/UnicastServerRef.java +++ b/libjava/gnu/java/rmi/server/UnicastServerRef.java @@ -46,6 +46,7 @@ import java.rmi.RemoteException; import java.rmi.server.RemoteStub; import java.rmi.server.ObjID; import java.rmi.server.ServerRef; +import java.rmi.server.RemoteServer; import java.rmi.server.RemoteRef; import java.rmi.server.ServerNotActiveException; import java.rmi.server.RMIClientSocketFactory; @@ -85,7 +86,7 @@ UnicastServerRef() { } -public UnicastServerRef(ObjID id, int port, RMIServerSocketFactory ssf) { +public UnicastServerRef(ObjID id, int port, RMIServerSocketFactory ssf) throws RemoteException { super(id); manager = UnicastConnectionManager.getInstance(port, ssf); } @@ -99,13 +100,21 @@ public RemoteStub exportObject(Remote obj) throws RemoteException { // Find and install the stub Class cls = obj.getClass(); - stub = (RemoteStub)getHelperClass(cls, "_Stub"); + Class expCls; + try { + // where ist the _Stub? (check superclasses also) + expCls = findStubSkelClass(cls); + } catch (Exception ex) { + throw new RemoteException("can not find stubs for class: " + cls, ex); + } + + stub = (RemoteStub)getHelperClass(expCls, "_Stub"); if (stub == null) { throw new RemoteException("failed to export: " + cls); } // Find and install the skeleton (if there is one) - skel = (Skeleton)getHelperClass(cls, "_Skel"); + skel = (Skeleton)getHelperClass(expCls, "_Skel"); // Build hash of methods which may be called. buildMethodHash(obj.getClass(), true); @@ -135,6 +144,38 @@ public boolean unexportObject(Remote obj, boolean force) { return UnicastServer.unexportObject(this, force); } +/** +* +* The Subs/Skels might not there for the actual class, but maybe +* for one of the superclasses. +* +*/ +private Class findStubSkelClass(Class startCls) throws Exception { + Class cls = startCls; + + while (true) { + try { + String stubClassname = cls.getName() + "_Stub"; + ClassLoader cl = cls.getClassLoader(); + Class scls = cl == null ? Class.forName(stubClassname) + : cl.loadClass(stubClassname); + return cls; // found it + } catch (ClassNotFoundException e) { + Class superCls = cls.getSuperclass(); + if (superCls == null + || superCls == java.rmi.server.UnicastRemoteObject.class) + { + throw new Exception("Neither " + startCls + + " nor one of their superclasses (like" + cls + ")" + + " has a _Stub"); + } + cls = superCls; + } + } +} + + + private Object getHelperClass(Class cls, String type) { try { String classname = cls.getName(); @@ -176,8 +217,10 @@ private Object getHelperClass(Class cls, String type) { return (null); } + + public String getClientHost() throws ServerNotActiveException { - throw new Error("Not implemented"); + return RemoteServer.getClientHost(); } private void buildMethodHash(Class cls, boolean build) { -- cgit v1.2.3