1. /*
  2. * @(#)RemoteRef.java 1.20 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.rmi.server;
  8. import java.rmi.*;
  9. /**
  10. * <code>RemoteRef</code> represents the handle for a remote object. A
  11. * <code>RemoteStub</code> uses a remote reference to carry out a
  12. * remote method invocation to a remote object.
  13. *
  14. * @version 1.20, 01/23/03
  15. * @author Ann Wollrath
  16. * @since JDK1.1
  17. * @see java.rmi.server.RemoteStub
  18. */
  19. public interface RemoteRef extends java.io.Externalizable {
  20. /** indicate compatibility with JDK 1.1.x version of class. */
  21. static final long serialVersionUID = 3632638527362204081L;
  22. /**
  23. * Initialize the server package prefix: assumes that the
  24. * implementation of server ref classes (e.g., UnicastRef,
  25. * UnicastServerRef) are located in the package defined by the
  26. * prefix.
  27. */
  28. final static String packagePrefix = "sun.rmi.server";
  29. /**
  30. * Invoke a method. This form of delegating method invocation
  31. * to the reference allows the reference to take care of
  32. * setting up the connection to the remote host, marshaling
  33. * some representation for the method and parameters, then
  34. * communicating the method invocation to the remote host.
  35. * This method either returns the result of a method invocation
  36. * on the remote object which resides on the remote host or
  37. * throws a RemoteException if the call failed or an
  38. * application-level exception if the remote invocation throws
  39. * an exception.
  40. *
  41. * @param obj the object that contains the RemoteRef (e.g., the
  42. * RemoteStub for the object.
  43. * @param method the method to be invoked
  44. * @param params the parameter list
  45. * @param opnum a hash that may be used to represent the method
  46. * @return result of remote method invocation
  47. * @exception Exception if any exception occurs during remote method
  48. * invocation
  49. * @since 1.2
  50. */
  51. Object invoke(Remote obj,
  52. java.lang.reflect.Method method,
  53. Object[] params,
  54. long opnum)
  55. throws Exception;
  56. /**
  57. * Creates an appropriate call object for a new remote method
  58. * invocation on this object. Passing operation array and index,
  59. * allows the stubs generator to assign the operation indexes and
  60. * interpret them. The remote reference may need the operation to
  61. * encode in the call.
  62. *
  63. * @since JDK1.1
  64. * @deprecated 1.2 style stubs no longer use this method. Instead of
  65. * using a sequence of method calls on the stub's the remote reference
  66. * (<code>newCall</code>, <code>invoke</code>, and <code>done</code>), a
  67. * stub uses a single method, <code>invoke(Remote, Method, Object[],
  68. * int)</code>, on the remote reference to carry out parameter
  69. * marshalling, remote method executing and unmarshalling of the return
  70. * value.
  71. *
  72. * <p>1.2 stubs are generated using <code>rmic -v1.2</code>. By
  73. * default, <code>rmic</code> generates stubs compatible with JDK1.1 and
  74. * the Java 2 SDK. The compatible stubs can also be generated using
  75. * <code>rmic -vcompat</code>.
  76. * @param obj remote stub through which to make call
  77. * @param op array of stub operations
  78. * @param opnum operation number
  79. * @param hash stub/skeleton interface hash
  80. * @return call object representing remote call
  81. * @throws RemoteException if failed to initiate new remote call
  82. * @see #invoke(Remote,java.lang.reflect.Method,Object[],long)
  83. */
  84. RemoteCall newCall(RemoteObject obj, Operation[] op, int opnum, long hash)
  85. throws RemoteException;
  86. /**
  87. * Executes the remote call.
  88. *
  89. * Invoke will raise any "user" exceptions which
  90. * should pass through and not be caught by the stub. If any
  91. * exception is raised during the remote invocation, invoke should
  92. * take care of cleaning up the connection before raising the
  93. * "user" or remote exception.
  94. *
  95. * @since JDK1.1
  96. * @deprecated 1.2 style stubs no longer use this method. Instead of
  97. * using a sequence of method calls to the remote reference
  98. * (<code>newCall</code>, <code>invoke</code>, and <code>done</code>), a
  99. * stub uses a single method, <code>invoke(Remote, Method, Object[],
  100. * int)</code>, on the remote reference to carry out parameter
  101. * marshalling, remote method executing and unmarshalling of the return
  102. * value.
  103. *
  104. * <p>1.2 stubs are generated using <code>rmic -v1.2</code>. By
  105. * default, <code>rmic</code> generates stubs compatible with JDK1.1 and
  106. * the Java 2 SDK. The compatible stubs can also be generated using
  107. * <code>rmic -vcompat</code>.
  108. * @param call object representing remote call
  109. * @throws Exception if any exception occurs during remote method
  110. * @see #invoke(Remote,java.lang.reflect.Method,Object[],long)
  111. */
  112. void invoke(RemoteCall call) throws Exception;
  113. /**
  114. * Allows the remote reference to clean up (or reuse) the connection.
  115. * Done should only be called if the invoke returns successfully
  116. * (non-exceptionally) to the stub.
  117. *
  118. * @since JDK1.1
  119. * @deprecated 1.2 style stubs no longer use this method. Instead of
  120. * using a sequence of method calls to the remote reference
  121. * (<code>newCall</code>, <code>invoke</code>, and <code>done</code>), a
  122. * stub uses a single method, <code>invoke(Remote, Method, Object[],
  123. * int)</code>, on the remote reference to carry out parameter
  124. * marshalling, remote method executing and unmarshalling of the return
  125. * value.
  126. *
  127. * <p>1.2 stubs are generated using <code>rmic -v1.2</code>. By
  128. * default, <code>rmic</code> generates stubs compatible with JDK1.1 and
  129. * the Java 2 SDK. The compatible stubs can also be generated using <code>rmic
  130. * -vcompat</code>.
  131. * @param call object representing remote call
  132. * @throws RemoteException if remote error occurs during call cleanup
  133. * @see #invoke(Remote,java.lang.reflect.Method,Object[],long)
  134. */
  135. void done(RemoteCall call) throws RemoteException;
  136. /**
  137. * Returns the class name of the ref type to be serialized onto
  138. * the stream 'out'.
  139. * @param out the output stream to which the reference will be serialized
  140. * @return the class name (without package qualification) of the reference
  141. * type
  142. * @since JDK1.1
  143. */
  144. String getRefClass(java.io.ObjectOutput out);
  145. /**
  146. * Returns a hashcode for a remote object. Two remote object stubs
  147. * that refer to the same remote object will have the same hash code
  148. * (in order to support remote objects as keys in hash tables).
  149. *
  150. * @return remote object hashcode
  151. * @see java.util.Hashtable
  152. * @since JDK1.1
  153. */
  154. int remoteHashCode();
  155. /**
  156. * Compares two remote objects for equality.
  157. * Returns a boolean that indicates whether this remote object is
  158. * equivalent to the specified Object. This method is used when a
  159. * remote object is stored in a hashtable.
  160. * @param obj the Object to compare with
  161. * @return true if these Objects are equal; false otherwise.
  162. * @see java.util.Hashtable
  163. * @since JDK1.1
  164. */
  165. boolean remoteEquals(RemoteRef obj);
  166. /**
  167. * Returns a String that represents the reference of this remote
  168. * object.
  169. * @return string representing remote object reference
  170. * @since JDK1.1
  171. */
  172. String remoteToString();
  173. }