1. /*
  2. * @(#)ActivationDesc.java 1.20 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.activation;
  8. import java.rmi.MarshalledObject;
  9. /**
  10. * An activation descriptor contains the information necessary to
  11. * activate an object: <ul>
  12. * <li> the object's group identifier,
  13. * <li> the object's class name,
  14. * <li> the object's code location (the location of the class), and
  15. * <li> a "marshalled" object that can contain object specific
  16. * initialization data. </ul> <p>
  17. *
  18. * A descriptor registered with the activation system can be used to
  19. * recreate/activate the object specified by the descriptor. The
  20. * <code>MarshalledObject</code> in the object's descriptor is passed
  21. * as the second argument to the remote object's constructor for
  22. * object to use during reinitialization/activation.
  23. *
  24. * @author Ann Wollrath
  25. * @version 1.20, 11/29/01
  26. * @since JDK1.2
  27. * @see java.rmi.activation.Activatable
  28. */
  29. public final class ActivationDesc implements java.io.Serializable
  30. {
  31. /**
  32. * @serial the group's identifier
  33. */
  34. private ActivationGroupID groupID;
  35. /**
  36. * @serial the object's class name
  37. */
  38. private String className;
  39. /**
  40. * @serial the object's code location
  41. */
  42. private String location;
  43. /**
  44. * @serial the object's initialization data
  45. */
  46. private MarshalledObject data;
  47. /**
  48. * @serial indicates whether the object should be restarted
  49. */
  50. private boolean restart;
  51. /** indicate compatibility with JDK 1.2 version of class */
  52. private static final long serialVersionUID = 7455834104417690957L;
  53. /**
  54. * Constructs an object descriptor for an object whose class name
  55. * is <code>className</code>, that can be loaded from the
  56. * code <code>location</code> and whose initialization
  57. * information is <code>data</code>. If this form of the constructor
  58. * is used, the <code>groupID</code> defaults to the current id for
  59. * <code>ActivationGroup</code> for this VM. All objects with the
  60. * same <code>ActivationGroupID</code> are activated in the same VM.
  61. * Objects specified by a descriptor created by this constructor
  62. * will not restart automatically when the RMI activation daemon
  63. * starts, but will be activated on demand (via a method call to
  64. * the activatable object).<p>
  65. *
  66. * This constructor will throw <code>ActivationException</code> if there is
  67. * no current activation group for this VM. To create an
  68. * <code>ActivationGroup</code> use the
  69. * <code>ActivationGroup.createGroup</code> method.
  70. *
  71. * @param className the object's fully package qualified class name
  72. * @param location the object's code location (from where the class is
  73. * loaded)
  74. * @param data the object's initialization (activation) data contained
  75. * in marshalled form.
  76. * @exception ActivationException if the current group is nonexistent
  77. * @since JDK1.2
  78. */
  79. public ActivationDesc(String className,
  80. String location,
  81. MarshalledObject data)
  82. throws ActivationException
  83. {
  84. this(ActivationGroup.internalCurrentGroupID(),
  85. className, location, data, false);
  86. }
  87. /**
  88. * Constructs an object descriptor for an object whose class name
  89. * is <code>className</code>, that can be loaded from the
  90. * code <code>location</code> and whose initialization
  91. * information is <code>data</code>. If this form of the constructor
  92. * is used, the <code>groupID</code> defaults to the current id for
  93. * <code>ActivationGroup</code> for this VM. All objects with the
  94. * same <code>ActivationGroupID</code> are activated in the same VM.<p>
  95. *
  96. * This constructor will throw <code>ActivationException</code> if there is
  97. * no current activation group for this VM. To create an
  98. * <code>ActivationGroup</code> use the
  99. * <code>ActivationGroup.createGroup</code> method.
  100. *
  101. * @param className the object's fully package qualified class name
  102. * @param location the object's code location (from where the class is
  103. * loaded)
  104. * @param data the object's initialization (activation) data contained
  105. * in marshalled form.
  106. * @param restart if true, the object is restarted when the activator
  107. * is restarted; if false, the object is activated on demand.
  108. * @exception ActivationException if the current group is nonexistent
  109. * @since JDK1.2
  110. */
  111. public ActivationDesc(String className,
  112. String location,
  113. MarshalledObject data,
  114. boolean restart)
  115. throws ActivationException
  116. {
  117. this(ActivationGroup.internalCurrentGroupID(),
  118. className, location, data, restart);
  119. }
  120. /**
  121. * Constructs an object descriptor for an object whose class name
  122. * is <code>className</code> that can be loaded from the
  123. * code <code>location</code> and whose initialization
  124. * information is <code>data</code>. All objects with the same
  125. * <code>groupID</code> are activated in the same Java VM.
  126. *
  127. * @param groupID the group's identifier (obtained from registering
  128. * <code>ActivationSystem.registerGroup</code> method). The group
  129. * indicates the VM in which the object should be activated.
  130. * @param className the object's fully package-qualified class name
  131. * @param location the object's code location (from where the class is
  132. * loaded)
  133. * @param data the object's initialization (activation) data contained
  134. * in marshalled form.
  135. * @exception IllegalArgumentException if <code>groupID</code> is null
  136. * @since JDK1.2
  137. */
  138. public ActivationDesc(ActivationGroupID groupID,
  139. String className,
  140. String location,
  141. MarshalledObject data)
  142. {
  143. this(groupID, className, location, data, false);
  144. }
  145. /**
  146. * Constructs an object descriptor for an object whose class name
  147. * is <code>className</code> that can be loaded from the
  148. * code <code>location</code> and whose initialization
  149. * information is <code>data</code>. All objects with the same
  150. * <code>groupID</code> are activated in the same Java VM.
  151. *
  152. * @param groupID the group's identifier (obtained from registering
  153. * <code>ActivationSystem.registerGroup</code> method). The group
  154. * indicates the VM in which the object should be activated.
  155. * @param className the object's fully package-qualified class name
  156. * @param location the object's code location (from where the class is
  157. * loaded)
  158. * @param data the object's initialization (activation) data contained
  159. * in marshalled form.
  160. * @param restart if true, the object is restarted when the activator
  161. * is restarted; if false, the object is activated on demand.
  162. * @exception IllegalArgumentException if <code>groupID</code> is null
  163. * @since JDK1.2
  164. */
  165. public ActivationDesc(ActivationGroupID groupID,
  166. String className,
  167. String location,
  168. MarshalledObject data,
  169. boolean restart)
  170. {
  171. if (groupID == null)
  172. throw new IllegalArgumentException("groupID can't be null");
  173. this.groupID = groupID;
  174. this.className = className;
  175. this.location = location;
  176. this.data = data;
  177. this.restart = restart;
  178. }
  179. /**
  180. * Returns the group identifier for the object specified by this
  181. * descriptor. A group provides a way to aggregate objects into a
  182. * single Java virtual machine. RMI creates/activates objects with
  183. * the same <code>groupID</code> in the same virtual machine.
  184. *
  185. * @return the group identifier
  186. * @since JDK1.2
  187. */
  188. public ActivationGroupID getGroupID() {
  189. return groupID;
  190. }
  191. /**
  192. * Returns the class name for the object specified by this
  193. * descriptor.
  194. * @return the class name
  195. * @since JDK1.2
  196. */
  197. public String getClassName() {
  198. return className;
  199. }
  200. /**
  201. * Returns the code location for the object specified by
  202. * this descriptor.
  203. * @return the code location
  204. * @since JDK1.2
  205. */
  206. public String getLocation() {
  207. return location;
  208. }
  209. /**
  210. * Returns a "marshalled object" containing intialization/activation
  211. * data for the object specified by this descriptor.
  212. * @return the object specific "initialization" data
  213. * @since JDK1.2
  214. */
  215. public MarshalledObject getData() {
  216. return data;
  217. }
  218. /**
  219. * Returns the "restart" mode of the object associated with
  220. * this activation descriptor.
  221. *
  222. * @return true if the activatable object associated with this
  223. * activation descriptor should be restarted via the activation
  224. * daemon when the daemon comes up; otherwise it returns false
  225. * (meaning that the object is only activated on demand via a
  226. * method call).
  227. * @since JDK1.2
  228. */
  229. public boolean getRestartMode() {
  230. return restart;
  231. }
  232. /**
  233. * Compares two activation descriptors for content equality.
  234. *
  235. * @param obj the Object to compare with
  236. * @return true if these Objects are equal; false otherwise.
  237. * @see java.util.Hashtable
  238. * @since JDK1.2
  239. */
  240. public boolean equals(Object obj) {
  241. if (obj instanceof ActivationDesc) {
  242. ActivationDesc desc = (ActivationDesc) obj;
  243. return
  244. ((groupID == null ? desc.groupID == null :
  245. groupID.equals(desc.groupID)) &&
  246. (className == null ? desc.className == null :
  247. className.equals(desc.className)) &&
  248. (location == null ? desc.location == null:
  249. location.equals(desc.location)) &&
  250. (data == null ? desc.data == null :
  251. data.equals(desc.data)) &&
  252. (restart == desc.restart));
  253. } else {
  254. return false;
  255. }
  256. }
  257. /**
  258. * Return the same hashCode for similar <code>ActivationDesc</code>s.
  259. * @return an integer
  260. * @see java.util.Hashtable
  261. */
  262. public int hashCode()
  263. {
  264. return ((location == null
  265. ? 0
  266. : location.hashCode() << 24) ^
  267. (groupID == null
  268. ? 0
  269. : groupID.hashCode() << 16) ^
  270. (className == null
  271. ? 0
  272. : className.hashCode() << 9) ^
  273. (data == null
  274. ? 0
  275. : data.hashCode() << 1) ^
  276. (restart
  277. ? 1
  278. : 0));
  279. }
  280. }