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