/[classpath]/classpath/gnu/java/rmi/server/UnicastRef.java
ViewVC logotype

Diff of /classpath/gnu/java/rmi/server/UnicastRef.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by cbj, Thu Mar 21 05:40:11 2002 UTC revision 1.4 by mark, Thu Oct 31 18:35:21 2002 UTC
# Line 1  Line 1 
1  /*  /*
2    Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.    Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 62  import java.io.ObjectOutputStream; Line 62  import java.io.ObjectOutputStream;
62  import java.io.DataInputStream;  import java.io.DataInputStream;
63  import java.io.DataOutputStream;  import java.io.DataOutputStream;
64    
65    import java.lang.reflect.InvocationTargetException;
66    
67  public class UnicastRef  public class UnicastRef
68          implements RemoteRef, ProtocolConstants {          implements RemoteRef, ProtocolConstants {
69    
# Line 69  public ObjID objid; Line 71  public ObjID objid;
71  UnicastConnectionManager manager;  UnicastConnectionManager manager;
72    
73  /**  /**
74   * Used by serialization.   * Used by serialization, and let subclass capable of having default constructor
75   */   */
76  private UnicastRef() {  //private
77    UnicastRef() {
78  }  }
79    
80  public UnicastRef(ObjID objid, String host, int port, RMIClientSocketFactory csf) {  public UnicastRef(ObjID objid, String host, int port, RMIClientSocketFactory csf) {
# Line 84  public UnicastRef(ObjID objid) { Line 87  public UnicastRef(ObjID objid) {
87  }  }
88    
89  public Object invoke(Remote obj, Method method, Object[] params, long opnum) throws Exception {  public Object invoke(Remote obj, Method method, Object[] params, long opnum) throws Exception {
90        // Check if client and server are in the same VM, then local call can be used to
91        // replace remote call, but it's somewhat violating remote semantic.
92        Object svrobj = manager.serverobj;
93        if(svrobj != null){
94            //local call
95                    Object ret = null;
96                    try{
97                        ret = method.invoke(svrobj, params);
98                    }catch(InvocationTargetException e){
99                        throw (Exception)e.getTargetException();
100                    }
101                    //System.out.println("\n\n ***** local call: " + method + "\nreturn: " + ret + "\n\n");
102                    return ret;
103            }
104            //System.out.println("***************** remote call:" + manager.serverPort);
105          return (invokeCommon(obj, method, params, -1, opnum));          return (invokeCommon(obj, method, params, -1, opnum));
106  }  }
107    
# Line 107  private Object invokeCommon(Remote obj, Line 125  private Object invokeCommon(Remote obj,
125                  objid.write(out);                  objid.write(out);
126                  out.writeInt(opnum);                  out.writeInt(opnum);
127                  out.writeLong(hash);                  out.writeLong(hash);
128                  /*                  
                 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]);  
                                 }  
                         }  
                 }  
                 */  
129                  // must handle primitive class and their wrapper classes                  // must handle primitive class and their wrapper classes
130                  Class clss[] = method.getParameterTypes();                  Class clss[] = method.getParameterTypes();
131              for(int i = 0; i < clss.length; i++)              for(int i = 0; i < clss.length; i++)
# Line 137  private Object invokeCommon(Remote obj, Line 144  private Object invokeCommon(Remote obj,
144          UID ack;          UID ack;
145          try {          try {
146                  din = conn.getDataInputStream();                  din = conn.getDataInputStream();
147                  if (din.readUnsignedByte() != MESSAGE_CALL_ACK) {                  
148                          throw new RemoteException("Call not acked");                  if ((returncode = din.readUnsignedByte()) != MESSAGE_CALL_ACK) {
149                        conn.disconnect();
150                            throw new RemoteException("Call not acked:" + returncode);
151                  }                  }
152    
153                  in = conn.getObjectInputStream();                  in = conn.getObjectInputStream();
   
154                  returncode = in.readUnsignedByte();                  returncode = in.readUnsignedByte();
155                  ack = UID.read(in);                  ack = UID.read(in);
156                  //returnval = in.readObject();  
157                  Class cls = method.getReturnType();                  Class cls = method.getReturnType();
158          if(cls == Void.TYPE){          if(cls == Void.TYPE){
159              returnval = null;              returnval = null;
160                in.readObject();
161          }else          }else
162              returnval = ((RMIObjectInputStream)in).readValue(cls);              returnval = ((RMIObjectInputStream)in).readValue(cls);
163    
164          }          }
165          catch (IOException e3) {          catch (IOException e3) {
166                //for debug: e3.printStackTrace();
167                  throw new RemoteException("call return failed: ", e3);                  throw new RemoteException("call return failed: ", e3);
168          }          }
169    
170      /* if DGCAck is necessary      /* if DGCAck is necessary??
171      //According to RMI wire protocol, send a DGCAck      //According to RMI wire protocol, send a DGCAck
172      // to indicate receiving return value      // to indicate receiving return value
173      dout.writeByte(MESSAGE_DGCACK);      dout.writeByte(MESSAGE_DGCACK);
# Line 166  private Object invokeCommon(Remote obj, Line 177  private Object invokeCommon(Remote obj,
177            
178          manager.discardConnection(conn);          manager.discardConnection(conn);
179    
180          if (returncode != RETURN_ACK) {          if (returncode != RETURN_ACK && returnval != null) {
181                  throw (Exception)returnval;                  throw (Exception)returnval;
182          }          }
183    
# Line 177  private Object invokeCommon(Remote obj, Line 188  private Object invokeCommon(Remote obj,
188   * @deprecated   * @deprecated
189   */   */
190  public RemoteCall newCall(RemoteObject obj, Operation[] op, int opnum, long hash) throws RemoteException {  public RemoteCall newCall(RemoteObject obj, Operation[] op, int opnum, long hash) throws RemoteException {
191          return (new UnicastRemoteCall(obj, opnum, hash));      UnicastConnection conn;
192        
193            try {
194                    conn = manager.getConnection();
195            }
196            catch (IOException e1) {
197                    throw new RemoteException("connection failed to host: " + manager.serverName, e1);
198            }
199    
200        //obj: useless?
201    
202            return (new UnicastRemoteCall(conn, objid, opnum, hash));
203  }  }
204    
205  /**  /**
# Line 185  public RemoteCall newCall(RemoteObject o Line 207  public RemoteCall newCall(RemoteObject o
207   */   */
208  public void invoke(RemoteCall call) throws Exception {  public void invoke(RemoteCall call) throws Exception {
209          UnicastRemoteCall c = (UnicastRemoteCall)call;          UnicastRemoteCall c = (UnicastRemoteCall)call;
210          Object ret = invokeCommon((Remote)c.getObject(), (Method)null, c.getArguments(), c.getOpnum(), c.getHash());          call.executeCall();
         c.setReturnValue(ret);  
211  }  }
212    
213  /**  /**
214   * @deprecated   * @deprecated
215   */   */
216  public void done(RemoteCall call) throws RemoteException {  public void done(RemoteCall call) throws RemoteException {
217          /* Does nothing */          UnicastRemoteCall c = (UnicastRemoteCall)call;
218            try{
219                c.done();
220            } catch(IOException e){}
221        UnicastConnection conn = c.getConnection();
222            manager.discardConnection(conn);
223  }  }
224    
225  public void writeExternal(ObjectOutput out) throws IOException {  public void writeExternal(ObjectOutput out) throws IOException {

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26