1. /*
  2. * @(#)ActivationGroupDesc.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.io.IOException;
  9. import java.rmi.MarshalledObject;
  10. import java.util.Arrays;
  11. import java.util.ArrayList;
  12. import java.util.Collection;
  13. import java.util.Collections;
  14. import java.util.Iterator;
  15. import java.util.List;
  16. import java.util.Properties;
  17. /**
  18. * An activation group descriptor contains the information necessary to
  19. * create/recreate an activation group in which to activate objects.
  20. * Such a descriptor contains: <ul>
  21. * <li> the group's class name,
  22. * <li> the group's code location (the location of the group's class), and
  23. * <li> a "marshalled" object that can contain group specific
  24. * initialization data. </ul> <p>
  25. *
  26. * The group's class must be a concrete subclass of
  27. * <code>ActivationGroup</code>. A subclass of
  28. * <code>ActivationGroup</code> is created/recreated via the
  29. * <code>ActivationGroup.createGroup</code> static method that invokes
  30. * a special constructor that takes two arguments: <ul>
  31. *
  32. * <li> the group's <code>ActivationGroupID</code>, and
  33. * <li> the group's initialization data (in a
  34. * <code>java.rmi.MarshalledObject</code>)</ul><p>
  35. *
  36. * @version 1.26, 01/23/03
  37. * @author Ann Wollrath
  38. * @since 1.2
  39. * @see ActivationGroup
  40. * @see ActivationGroupID
  41. */
  42. public final class ActivationGroupDesc implements java.io.Serializable {
  43. /**
  44. * @serial The group's fully package qualified class name.
  45. */
  46. private String className;
  47. /**
  48. * @serial The location from where to load the group's class.
  49. */
  50. private String location;
  51. /**
  52. * @serial The group's initialization data.
  53. */
  54. private MarshalledObject data;
  55. /**
  56. * @serial The controlling options for executing the VM in
  57. * another process.
  58. */
  59. private CommandEnvironment env;
  60. /**
  61. * @serial A properties map which will override those set
  62. * by default in the subprocess environment.
  63. */
  64. private Properties props;
  65. /** indicate compatibility with the Java 2 SDK v1.2 version of class */
  66. private static final long serialVersionUID = -4936225423168276595L;
  67. /**
  68. * Constructs a group descriptor that uses the system defaults for group
  69. * implementation and code location. Properties specify Java
  70. * environment overrides (which will override system properties in
  71. * the group implementation's VM). The command
  72. * environment can control the exact command/options used in
  73. * starting the child VM, or can be <code>null</code> to accept
  74. * rmid's default.
  75. *
  76. * <p>This constructor will create an <code>ActivationGroupDesc</code>
  77. * with a <code>null</code> group class name, which indicates the system's
  78. * default <code>ActivationGroup</code> implementation.
  79. *
  80. * @param overrides the set of properties to set when the group is
  81. * recreated.
  82. * @param cmd the controlling options for executing the VM in
  83. * another process (or <code>null</code>).
  84. * @since 1.2
  85. */
  86. public ActivationGroupDesc(Properties overrides,
  87. CommandEnvironment cmd)
  88. {
  89. this(null, null, null, overrides, cmd);
  90. }
  91. /**
  92. * Specifies an alternate group implementation and execution
  93. * environment to be used for the group.
  94. *
  95. * @param className the group's package qualified class name or
  96. * <code>null</code>. A <code>null</code> group class name indicates
  97. * the system's default <code>ActivationGroup</code> implementation.
  98. * @param location the location from where to load the group's
  99. * class
  100. * @param data the group's initialization data contained in
  101. * marshalled form (could contain properties, for example)
  102. * @param overrides a properties map which will override those set
  103. * by default in the subprocess environment (will be translated
  104. * into <code>-D</code> options), or <code>null</code>.
  105. * @param cmd the controlling options for executing the VM in
  106. * another process (or <code>null</code>).
  107. * @since 1.2
  108. */
  109. public ActivationGroupDesc(String className,
  110. String location,
  111. MarshalledObject data,
  112. Properties overrides,
  113. CommandEnvironment cmd)
  114. {
  115. this.props = overrides;
  116. this.env = cmd;
  117. this.data = data;
  118. this.location = location;
  119. this.className = className;
  120. }
  121. /**
  122. * Returns the group's class name (possibly <code>null</code>). A
  123. * <code>null</code> group class name indicates the system's default
  124. * <code>ActivationGroup</code> implementation.
  125. * @return the group's class name
  126. * @since 1.2
  127. */
  128. public String getClassName() {
  129. return className;
  130. }
  131. /**
  132. * Returns the group's code location.
  133. * @return the group's code location
  134. * @since 1.2
  135. */
  136. public String getLocation() {
  137. return location;
  138. }
  139. /**
  140. * Returns the group's initialization data.
  141. * @return the group's initialization data
  142. * @since 1.2
  143. */
  144. public MarshalledObject getData() {
  145. return data;
  146. }
  147. /**
  148. * Returns the group's property-override list.
  149. * @return the property-override list, or <code>null</code>
  150. * @since 1.2
  151. */
  152. public Properties getPropertyOverrides() {
  153. return (props != null) ? (Properties) props.clone() : null;
  154. }
  155. /**
  156. * Returns the group's command-environment control object.
  157. * @return the command-environment object, or <code>null</code>
  158. * @since 1.2
  159. */
  160. public CommandEnvironment getCommandEnvironment() {
  161. return this.env;
  162. }
  163. /**
  164. * Startup options for ActivationGroup implementations.
  165. *
  166. * This class allows overriding default system properties and
  167. * specifying implementation-defined options for ActivationGroups.
  168. * @since 1.2
  169. */
  170. public static class CommandEnvironment
  171. implements java.io.Serializable
  172. {
  173. /**
  174. * @serial
  175. */
  176. private String command;
  177. /**
  178. * @serial
  179. */
  180. private String[] options;
  181. /**
  182. * Create a CommandEnvironment with all the necessary
  183. * information.
  184. *
  185. * @param cmdpath the name of the java executable, including
  186. * the full path, or <code>null</code>, meaning "use rmid's default".
  187. * The named program <em>must</em> be able to accept multiple
  188. * <code>-Dpropname=value</code> options (as documented for the
  189. * "java" tool)
  190. *
  191. * @param argv extra options which will be used in creating the
  192. * ActivationGroup. Null has the same effect as an empty
  193. * list.
  194. * @since 1.2
  195. */
  196. public CommandEnvironment(String cmdpath,
  197. String[] argv)
  198. {
  199. this.command = cmdpath; // might be null
  200. // Hold a safe copy of argv in this.options
  201. if (argv == null) {
  202. this.options = null;
  203. } else {
  204. this.options = new String[argv.length];
  205. System.arraycopy(argv, 0, this.options, 0, argv.length);
  206. }
  207. }
  208. /**
  209. * Fetch the configured path-qualified java command name.
  210. *
  211. * @return the configured name, or <code>null</code> if configured to
  212. * accept the default
  213. * @since 1.2
  214. */
  215. public String getCommandPath() {
  216. return (this.command);
  217. }
  218. /**
  219. * Fetch the configured java command options.
  220. *
  221. * @return An array of the command options which will be passed
  222. * to the new child command by rmid.
  223. * Note that rmid may add other options before or after these
  224. * options, or both.
  225. * Never returns <code>null</code>.
  226. * @since 1.2
  227. */
  228. public String[] getCommandOptions() {
  229. return (this.options != null
  230. ? (String[]) this.options.clone()
  231. : new String[0]);
  232. }
  233. /**
  234. * Compares two command environments for content equality.
  235. *
  236. * @param obj the Object to compare with
  237. * @return true if these Objects are equal; false otherwise.
  238. * @see java.util.Hashtable
  239. * @since 1.2
  240. */
  241. public boolean equals(Object obj) {
  242. if (obj instanceof CommandEnvironment) {
  243. CommandEnvironment env = (CommandEnvironment) obj;
  244. return
  245. ((command == null ? env.command == null :
  246. command.equals(env.command)) &&
  247. Arrays.equals(options, env.options));
  248. } else {
  249. return false;
  250. }
  251. }
  252. /**
  253. * Return identical values for similar
  254. * <code>CommandEnvironment</code>s.
  255. * @return an integer
  256. * @see java.util.Hashtable
  257. */
  258. public int hashCode()
  259. {
  260. // hash command and ignore possibly expensive options
  261. return (command == null ? 0 : command.hashCode());
  262. }
  263. }
  264. /**
  265. * Compares two activation group descriptors for content equality.
  266. *
  267. * @param obj the Object to compare with
  268. * @return true if these Objects are equal; false otherwise.
  269. * @see java.util.Hashtable
  270. * @since 1.2
  271. */
  272. public boolean equals(Object obj) {
  273. if (obj instanceof ActivationGroupDesc) {
  274. ActivationGroupDesc desc = (ActivationGroupDesc) obj;
  275. return
  276. ((className == null ? desc.className == null :
  277. className.equals(desc.className)) &&
  278. (location == null ? desc.location == null :
  279. location.equals(desc.location)) &&
  280. (data == null ? desc.data == null : data.equals(desc.data)) &&
  281. (env == null ? desc.env == null : env.equals(desc.env)) &&
  282. (props == null ? desc.props == null :
  283. props.equals(desc.props)));
  284. } else {
  285. return false;
  286. }
  287. }
  288. /**
  289. * Produce identical numbers for similar <code>ActivationGroupDesc</code>s.
  290. * @return an integer
  291. * @see java.util.Hashtable
  292. */
  293. public int hashCode()
  294. {
  295. // hash location, className, data, and env
  296. // but omit props (may be expensive)
  297. return ((location == null
  298. ? 0
  299. : location.hashCode() << 24) ^
  300. (env == null
  301. ? 0
  302. : env.hashCode() << 16) ^
  303. (className == null
  304. ? 0
  305. : className.hashCode() << 8) ^
  306. (data == null
  307. ? 0
  308. : data.hashCode()));
  309. }
  310. }