1. /*
  2. * @(#)ActivationGroupDesc.java 1.18 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.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.18, 11/29/01
  37. * @author Ann Wollrath
  38. * @since JDK1.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 className.
  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 JDK 1.2 version of class */
  66. private static final long serialVersionUID = -4936225423168276595L;
  67. /**
  68. * Constructs a group descriptor that uses system default 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. * @param properties the set of properties to set when the group is
  77. * recreated.
  78. * @param cmd the controlling options for executing the VM in
  79. * another process (or null).
  80. * @since JDK1.2
  81. */
  82. public ActivationGroupDesc(Properties overrides,
  83. CommandEnvironment cmd)
  84. {
  85. this("sun.rmi.server.ActivationGroupImpl", null, null, overrides, cmd);
  86. }
  87. /**
  88. * Specifies an alternate group implementation and execution
  89. * environment to be used for the group.
  90. *
  91. * @param className the group's fully package qualified className
  92. * @param location the location from where to load the group's
  93. * class
  94. * @param data the group's initialization data contained in
  95. * marshalled form (could contain properties, for example)
  96. * @param overrides a properties map which will override those set
  97. * by default in the subprocess environment (will be translated
  98. * into <code>-D</code> options), or null.
  99. * @param cmd the controlling options for executing the VM in
  100. * another process (or null).
  101. * @since JDK1.2
  102. */
  103. public ActivationGroupDesc(String className,
  104. String location,
  105. MarshalledObject data,
  106. Properties overrides,
  107. CommandEnvironment cmd)
  108. {
  109. this.props = overrides;
  110. this.env = cmd;
  111. this.data = data;
  112. this.location = location;
  113. this.className = className;
  114. }
  115. /**
  116. * Returns the group's class name.
  117. * @return the group's class name
  118. * @since JDK1.2
  119. */
  120. public String getClassName() {
  121. return className;
  122. }
  123. /**
  124. * Returns the group's code location.
  125. * @return the group's code location
  126. * @since JDK1.2
  127. */
  128. public String getLocation() {
  129. return location;
  130. }
  131. /**
  132. * Returns the group's initialization data.
  133. * @return the group's initialization data
  134. * @since JDK1.2
  135. */
  136. public MarshalledObject getData() {
  137. return data;
  138. }
  139. /**
  140. * Returns the group's property-override list.
  141. * @return the property-override list, or null
  142. * @since JDK1.2
  143. */
  144. public Properties getPropertyOverrides() {
  145. return (props != null) ? (Properties) props.clone() : null;
  146. }
  147. /**
  148. * Returns the group's command-environment control object.
  149. * @return the command-environment object, or null
  150. * @since JDK1.2
  151. */
  152. public CommandEnvironment getCommandEnvironment() {
  153. return this.env;
  154. }
  155. /**
  156. * Startup options for ActivationGroup implementations.
  157. *
  158. * This class allows overriding default system properties and
  159. * specifying implementation-defined options for ActivationGroups.
  160. * @since JDK1.2
  161. */
  162. public static class CommandEnvironment
  163. implements java.io.Serializable
  164. {
  165. /**
  166. * @serial
  167. */
  168. private String command;
  169. /**
  170. * @serial
  171. */
  172. private String[] options;
  173. /**
  174. * Create a CommandEnvironment with all the necessary
  175. * information.
  176. *
  177. * @param cmdpath the name of the java executable, including
  178. * the full path, or null, meaning "use rmid's default". The
  179. * named program <em>must</em> be able to accept multiple
  180. * <code>-Dpropname=value</code> options (as documented for the
  181. * "java" tool)
  182. *
  183. * @param argv extra options which will be used in creating the
  184. * ActivationGroup. Null has the same effect as an empty
  185. * list.
  186. * @since JDK1.2
  187. */
  188. public CommandEnvironment(String cmdpath,
  189. String[] argv)
  190. {
  191. this.command = cmdpath; // might be null
  192. // Hold a safe copy of argv in this.options
  193. if (argv == null) {
  194. this.options = null;
  195. } else {
  196. this.options = new String[argv.length];
  197. System.arraycopy(argv, 0, this.options, 0, argv.length);
  198. }
  199. }
  200. /**
  201. * Fetch the configured path-qualified java command name.
  202. *
  203. * @return the configured name, or null if configured to
  204. * accept the default
  205. * @since JDK1.2
  206. */
  207. public String getCommandPath() {
  208. return (this.command);
  209. }
  210. /**
  211. * Fetch the configured java command options.
  212. *
  213. * @return An array of the command options which will be passed
  214. * to the new child command by rmid.
  215. * Note that rmid may add other options before or after these
  216. * options, or both.
  217. * Never returns null.
  218. * @since JDK1.2
  219. */
  220. public String[] getCommandOptions() {
  221. return (this.options != null
  222. ? (String[]) this.options.clone()
  223. : new String[0]);
  224. }
  225. /**
  226. * Compares two command environments for content equality.
  227. *
  228. * @param obj the Object to compare with
  229. * @return true if these Objects are equal; false otherwise.
  230. * @see java.util.Hashtable
  231. * @since JDK1.2
  232. */
  233. public boolean equals(Object obj) {
  234. if (obj instanceof CommandEnvironment) {
  235. CommandEnvironment env = (CommandEnvironment) obj;
  236. return
  237. ((command == null ? env.command == null :
  238. command.equals(env.command)) &&
  239. Arrays.equals(options, env.options));
  240. } else {
  241. return false;
  242. }
  243. }
  244. /**
  245. * Return identical values for similar <code>CommandEnvironment</code>s
  246. * @return an integer
  247. * @see java.util.Hashtable
  248. */
  249. public int hashCode()
  250. {
  251. // hash command and ignore possibly expensive options
  252. return (command == null ? 0 : command.hashCode());
  253. }
  254. }
  255. /**
  256. * Compares two activation group descriptors for content equality.
  257. *
  258. * @param obj the Object to compare with
  259. * @return true if these Objects are equal; false otherwise.
  260. * @see java.util.Hashtable
  261. * @since JDK1.2
  262. */
  263. public boolean equals(Object obj) {
  264. if (obj instanceof ActivationGroupDesc) {
  265. ActivationGroupDesc desc = (ActivationGroupDesc) obj;
  266. return
  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 : data.equals(desc.data)) &&
  272. (env == null ? desc.env == null : env.equals(desc.env)) &&
  273. (props == null ? desc.props == null :
  274. props.equals(desc.props)));
  275. } else {
  276. return false;
  277. }
  278. }
  279. /**
  280. * Produce identical numbers for similar <code>ActivationGroupDesc</code>s.
  281. * @return an integer
  282. * @see java.util.Hashtable
  283. */
  284. public int hashCode()
  285. {
  286. // hash location, className, data, and env
  287. // but omit props (may be expensive)
  288. return ((location == null
  289. ? 0
  290. : location.hashCode() << 24) ^
  291. (env == null
  292. ? 0
  293. : env.hashCode() << 16) ^
  294. (className == null
  295. ? 0
  296. : className.hashCode() << 8) ^
  297. (data == null
  298. ? 0
  299. : data.hashCode()));
  300. }
  301. }