KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > rmi > activation > ActivationGroupDesc


1 /*
2  * @(#)ActivationGroupDesc.java 1.28 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.rmi.activation;
9
10 import java.io.IOException JavaDoc;
11 import java.rmi.MarshalledObject JavaDoc;
12 import java.util.Arrays JavaDoc;
13 import java.util.ArrayList JavaDoc;
14 import java.util.Collection JavaDoc;
15 import java.util.Collections JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.List JavaDoc;
18 import java.util.Properties JavaDoc;
19
20
21 /**
22  * An activation group descriptor contains the information necessary to
23  * create/recreate an activation group in which to activate objects.
24  * Such a descriptor contains: <ul>
25  * <li> the group's class name,
26  * <li> the group's code location (the location of the group's class), and
27  * <li> a "marshalled" object that can contain group specific
28  * initialization data. </ul> <p>
29  *
30  * The group's class must be a concrete subclass of
31  * <code>ActivationGroup</code>. A subclass of
32  * <code>ActivationGroup</code> is created/recreated via the
33  * <code>ActivationGroup.createGroup</code> static method that invokes
34  * a special constructor that takes two arguments: <ul>
35  *
36  * <li> the group's <code>ActivationGroupID</code>, and
37  * <li> the group's initialization data (in a
38  * <code>java.rmi.MarshalledObject</code>)</ul><p>
39  *
40  * @version 1.28, 12/19/03
41  * @author Ann Wollrath
42  * @since 1.2
43  * @see ActivationGroup
44  * @see ActivationGroupID
45  */

46 public final class ActivationGroupDesc implements java.io.Serializable JavaDoc {
47
48     /**
49      * @serial The group's fully package qualified class name.
50      */

51     private String JavaDoc className;
52
53     /**
54      * @serial The location from where to load the group's class.
55      */

56     private String JavaDoc location;
57
58     /**
59      * @serial The group's initialization data.
60      */

61     private MarshalledObject JavaDoc data;
62
63     /**
64      * @serial The controlling options for executing the VM in
65      * another process.
66      */

67     private CommandEnvironment env;
68     
69     /**
70      * @serial A properties map which will override those set
71      * by default in the subprocess environment.
72      */

73     private Properties JavaDoc props;
74     
75     /** indicate compatibility with the Java 2 SDK v1.2 version of class */
76     private static final long serialVersionUID = -4936225423168276595L;
77
78     /**
79      * Constructs a group descriptor that uses the system defaults for group
80      * implementation and code location. Properties specify Java
81      * environment overrides (which will override system properties in
82      * the group implementation's VM). The command
83      * environment can control the exact command/options used in
84      * starting the child VM, or can be <code>null</code> to accept
85      * rmid's default.
86      *
87      * <p>This constructor will create an <code>ActivationGroupDesc</code>
88      * with a <code>null</code> group class name, which indicates the system's
89      * default <code>ActivationGroup</code> implementation.
90      *
91      * @param overrides the set of properties to set when the group is
92      * recreated.
93      * @param cmd the controlling options for executing the VM in
94      * another process (or <code>null</code>).
95      * @since 1.2
96      */

97     public ActivationGroupDesc(Properties JavaDoc overrides,
98                                CommandEnvironment cmd)
99     {
100     this(null, null, null, overrides, cmd);
101     }
102
103     /**
104      * Specifies an alternate group implementation and execution
105      * environment to be used for the group.
106      *
107      * @param className the group's package qualified class name or
108      * <code>null</code>. A <code>null</code> group class name indicates
109      * the system's default <code>ActivationGroup</code> implementation.
110      * @param location the location from where to load the group's
111      * class
112      * @param data the group's initialization data contained in
113      * marshalled form (could contain properties, for example)
114      * @param overrides a properties map which will override those set
115      * by default in the subprocess environment (will be translated
116      * into <code>-D</code> options), or <code>null</code>.
117      * @param cmd the controlling options for executing the VM in
118      * another process (or <code>null</code>).
119      * @since 1.2
120      */

121     public ActivationGroupDesc(String JavaDoc className,
122                    String JavaDoc location,
123                    MarshalledObject JavaDoc data,
124                    Properties JavaDoc overrides,
125                                CommandEnvironment cmd)
126     {
127     this.props = overrides;
128     this.env = cmd;
129     this.data = data;
130     this.location = location;
131     this.className = className;
132     }
133
134     /**
135      * Returns the group's class name (possibly <code>null</code>). A
136      * <code>null</code> group class name indicates the system's default
137      * <code>ActivationGroup</code> implementation.
138      * @return the group's class name
139      * @since 1.2
140      */

141     public String JavaDoc getClassName() {
142     return className;
143     }
144
145     /**
146      * Returns the group's code location.
147      * @return the group's code location
148      * @since 1.2
149      */

150     public String JavaDoc getLocation() {
151     return location;
152     }
153
154     /**
155      * Returns the group's initialization data.
156      * @return the group's initialization data
157      * @since 1.2
158      */

159     public MarshalledObject JavaDoc getData() {
160     return data;
161     }
162
163     /**
164      * Returns the group's property-override list.
165      * @return the property-override list, or <code>null</code>
166      * @since 1.2
167      */

168     public Properties JavaDoc getPropertyOverrides() {
169     return (props != null) ? (Properties JavaDoc) props.clone() : null;
170     }
171
172     /**
173      * Returns the group's command-environment control object.
174      * @return the command-environment object, or <code>null</code>
175      * @since 1.2
176      */

177     public CommandEnvironment getCommandEnvironment() {
178     return this.env;
179     }
180
181
182     /**
183      * Startup options for ActivationGroup implementations.
184      *
185      * This class allows overriding default system properties and
186      * specifying implementation-defined options for ActivationGroups.
187      * @since 1.2
188      */

189     public static class CommandEnvironment
190     implements java.io.Serializable JavaDoc
191     {
192     private static final long serialVersionUID = 6165754737887770191L;
193
194     /**
195      * @serial
196      */

197     private String JavaDoc command;
198
199     /**
200      * @serial
201      */

202     private String JavaDoc[] options;
203
204     /**
205      * Create a CommandEnvironment with all the necessary
206      * information.
207      *
208      * @param cmdpath the name of the java executable, including
209      * the full path, or <code>null</code>, meaning "use rmid's default".
210      * The named program <em>must</em> be able to accept multiple
211      * <code>-Dpropname=value</code> options (as documented for the
212      * "java" tool)
213      *
214      * @param argv extra options which will be used in creating the
215      * ActivationGroup. Null has the same effect as an empty
216      * list.
217      * @since 1.2
218      */

219     public CommandEnvironment(String JavaDoc cmdpath,
220                   String JavaDoc[] argv)
221     {
222         this.command = cmdpath; // might be null
223

224         // Hold a safe copy of argv in this.options
225
if (argv == null) {
226         this.options = null;
227         } else {
228         this.options = new String JavaDoc[argv.length];
229         System.arraycopy(argv, 0, this.options, 0, argv.length);
230         }
231     }
232
233     /**
234      * Fetch the configured path-qualified java command name.
235      *
236      * @return the configured name, or <code>null</code> if configured to
237      * accept the default
238      * @since 1.2
239      */

240     public String JavaDoc getCommandPath() {
241         return (this.command);
242     }
243
244     /**
245      * Fetch the configured java command options.
246      *
247      * @return An array of the command options which will be passed
248      * to the new child command by rmid.
249      * Note that rmid may add other options before or after these
250      * options, or both.
251      * Never returns <code>null</code>.
252      * @since 1.2
253      */

254     public String JavaDoc[] getCommandOptions() {
255         return (this.options != null
256             ? (String JavaDoc[]) this.options.clone()
257             : new String JavaDoc[0]);
258     }
259     
260     /**
261      * Compares two command environments for content equality.
262      *
263      * @param obj the Object to compare with
264      * @return true if these Objects are equal; false otherwise.
265      * @see java.util.Hashtable
266      * @since 1.2
267      */

268     public boolean equals(Object JavaDoc obj) {
269     
270         if (obj instanceof CommandEnvironment) {
271         CommandEnvironment env = (CommandEnvironment) obj;
272         return
273             ((command == null ? env.command == null :
274               command.equals(env.command)) &&
275              Arrays.equals(options, env.options));
276         } else {
277         return false;
278         }
279     }
280
281     /**
282      * Return identical values for similar
283      * <code>CommandEnvironment</code>s.
284      * @return an integer
285      * @see java.util.Hashtable
286      */

287     public int hashCode()
288     {
289         // hash command and ignore possibly expensive options
290
return (command == null ? 0 : command.hashCode());
291     }
292     }
293
294     /**
295      * Compares two activation group descriptors for content equality.
296      *
297      * @param obj the Object to compare with
298      * @return true if these Objects are equal; false otherwise.
299      * @see java.util.Hashtable
300      * @since 1.2
301      */

302     public boolean equals(Object JavaDoc obj) {
303     
304     if (obj instanceof ActivationGroupDesc JavaDoc) {
305         ActivationGroupDesc JavaDoc desc = (ActivationGroupDesc JavaDoc) obj;
306         return
307         ((className == null ? desc.className == null :
308           className.equals(desc.className)) &&
309          (location == null ? desc.location == null :
310           location.equals(desc.location)) &&
311          (data == null ? desc.data == null : data.equals(desc.data)) &&
312          (env == null ? desc.env == null : env.equals(desc.env)) &&
313          (props == null ? desc.props == null :
314           props.equals(desc.props)));
315     } else {
316         return false;
317     }
318     }
319
320     /**
321      * Produce identical numbers for similar <code>ActivationGroupDesc</code>s.
322      * @return an integer
323      * @see java.util.Hashtable
324      */

325     public int hashCode()
326     {
327     // hash location, className, data, and env
328
// but omit props (may be expensive)
329
return ((location == null
330             ? 0
331             : location.hashCode() << 24) ^
332         (env == null
333             ? 0
334             : env.hashCode() << 16) ^
335         (className == null
336             ? 0
337             : className.hashCode() << 8) ^
338         (data == null
339             ? 0
340             : data.hashCode()));
341     }
342     
343 }
344
345
Popular Tags