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