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