1. /*
  2. * @(#)RemoteRef.java 1.13 01/11/29
  3. *
  4. * Copyright 2002 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.13, 11/29/01
  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. * @exception Exception if any exception occurs during remote method
  47. * invocation
  48. * @since JDK1.2
  49. */
  50. Object invoke(Remote obj,
  51. java.lang.reflect.Method method,
  52. Object[] params,
  53. long opnum)
  54. throws Exception;
  55. /**
  56. * Creates an appropriate call object for a new remote method
  57. * invocation on this object. Passing operation array and index,
  58. * allows the stubs generator to assign the operation indexes and
  59. * interpret them. The remote reference may need the operation to
  60. * encode in the call.
  61. *
  62. * @since JDK1.1
  63. * @deprecated JDK1.2 style stubs no longer use this method. Instead of
  64. * using a sequence of method calls on the stub's the remote reference
  65. * (<code>newCall</code>, <code>invoke</code>, and <code>done</code>), a
  66. * stub uses a single method, <code>invoke(Remote, Method, Object[],
  67. * int)</code>, on the remote reference to carry out parameter
  68. * marshalling, remote method executing and unmarshalling of the return
  69. * value.
  70. *
  71. * <p>JDK1.2 stubs are generated using <code>rmic -v1.2</code>. By
  72. * default, <code>rmic</code> generates stubs compatible with JDK1.1 and
  73. * JDK1.2. The compatible stubs can also be generated using <code>rmic
  74. * -vcompat</code>.
  75. * @see #invoke(Remote,java.lang.reflect.Method,Object[],long)
  76. */
  77. RemoteCall newCall(RemoteObject obj, Operation[] op, int opnum, long hash)
  78. throws RemoteException;
  79. /**
  80. * Executes the remote call.
  81. *
  82. * Invoke will raise any "user" exceptions which
  83. * should pass through and not be caught by the stub. If any
  84. * exception is raised during the remote invocation, invoke should
  85. * take care of cleaning up the connection before raising the
  86. * "user" or remote exception.
  87. *
  88. * @since JDK1.1
  89. * @deprecated JDK1.2 style stubs no longer use this method. Instead of
  90. * using a sequence of method calls to the remote reference
  91. * (<code>newCall</code>, <code>invoke</code>, and <code>done</code>), a
  92. * stub uses a single method, <code>invoke(Remote, Method, Object[],
  93. * int)</code>, on the remote reference to carry out parameter
  94. * marshalling, remote method executing and unmarshalling of the return
  95. * value.
  96. *
  97. * <p>JDK1.2 stubs are generated using <code>rmic -v1.2</code>. By
  98. * default, <code>rmic</code> generates stubs compatible with JDK1.1 and
  99. * JDK1.2. The compatible stubs can also be generated using <code>rmic
  100. * -vcompat</code>.
  101. * @see #invoke(Remote,java.lang.reflect.Method,Object[],long)
  102. */
  103. void invoke(RemoteCall call) throws Exception;
  104. /**
  105. * Allows the remote reference to clean up (or reuse) the connection.
  106. * Done should only be called if the invoke returns successfully
  107. * (non-exceptionally) to the stub.
  108. *
  109. * @since JDK1.1
  110. * @deprecated JDK1.2 style stubs no longer use this method. Instead of
  111. * using a sequence of method calls to the remote reference
  112. * (<code>newCall</code>, <code>invoke</code>, and <code>done</code>), a
  113. * stub uses a single method, <code>invoke(Remote, Method, Object[],
  114. * int)</code>, on the remote reference to carry out parameter
  115. * marshalling, remote method executing and unmarshalling of the return
  116. * value.
  117. *
  118. * <p>JDK1.2 stubs are generated using <code>rmic -v1.2</code>. By
  119. * default, <code>rmic</code> generates stubs compatible with JDK1.1 and
  120. * JDK1.2. The compatible stubs can also be generated using <code>rmic
  121. * -vcompat</code>.
  122. * @see #invoke(Remote,java.lang.reflect.Method,Object[],long)
  123. */
  124. void done(RemoteCall call) throws RemoteException;
  125. /**
  126. * Returns the class name of the ref type to be serialized onto
  127. * the stream 'out'.
  128. * @param out the output stream to which the reference will be serialized
  129. * @return the class name (without package qualification) of the reference
  130. * type
  131. * @since JDK1.1
  132. */
  133. String getRefClass(java.io.ObjectOutput out);
  134. /**
  135. * Returns a hashcode for a remote object. Two remote object stubs
  136. * that refer to the same remote object will have the same hash code
  137. * (in order to support remote objects as keys in hash tables).
  138. *
  139. * @see java.util.Hashtable
  140. * @since JDK1.1
  141. */
  142. int remoteHashCode();
  143. /**
  144. * Compares two remote objects for equality.
  145. * Returns a boolean that indicates whether this remote object is
  146. * equivalent to the specified Object. This method is used when a
  147. * remote object is stored in a hashtable.
  148. * @param obj the Object to compare with
  149. * @return true if these Objects are equal; false otherwise.
  150. * @see java.util.Hashtable
  151. * @since JDK1.1
  152. */
  153. boolean remoteEquals(RemoteRef obj);
  154. /**
  155. * Returns a String that represents the reference of this remote
  156. * object.
  157. * @since JDK1.1
  158. */
  159. String remoteToString();
  160. }