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