Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/rmi/activation/ActivationGroupDesc.java
38918 views
/*1* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.rmi.activation;2627import java.io.IOException;28import java.io.ObjectInputStream;29import java.io.Serializable;30import java.rmi.MarshalledObject;31import java.util.Arrays;32import java.util.Properties;3334/**35* An activation group descriptor contains the information necessary to36* create/recreate an activation group in which to activate objects.37* Such a descriptor contains: <ul>38* <li> the group's class name,39* <li> the group's code location (the location of the group's class), and40* <li> a "marshalled" object that can contain group specific41* initialization data. </ul> <p>42*43* The group's class must be a concrete subclass of44* <code>ActivationGroup</code>. A subclass of45* <code>ActivationGroup</code> is created/recreated via the46* <code>ActivationGroup.createGroup</code> static method that invokes47* a special constructor that takes two arguments: <ul>48*49* <li> the group's <code>ActivationGroupID</code>, and50* <li> the group's initialization data (in a51* <code>java.rmi.MarshalledObject</code>)</ul><p>52*53* @author Ann Wollrath54* @since 1.255* @see ActivationGroup56* @see ActivationGroupID57*/58public final class ActivationGroupDesc implements Serializable {5960/**61* @serial The group's fully package qualified class name.62*/63private String className;6465/**66* @serial The location from where to load the group's class.67*/68private String location;6970/**71* @serial The group's initialization data.72*/73private MarshalledObject<?> data;7475/**76* @serial The controlling options for executing the VM in77* another process.78*/79private CommandEnvironment env;8081/**82* @serial A properties map which will override those set83* by default in the subprocess environment.84*/85private Properties props;8687/** indicate compatibility with the Java 2 SDK v1.2 version of class */88private static final long serialVersionUID = -4936225423168276595L;8990/**91* Constructs a group descriptor that uses the system defaults for group92* implementation and code location. Properties specify Java93* environment overrides (which will override system properties in94* the group implementation's VM). The command95* environment can control the exact command/options used in96* starting the child VM, or can be <code>null</code> to accept97* rmid's default.98*99* <p>This constructor will create an <code>ActivationGroupDesc</code>100* with a <code>null</code> group class name, which indicates the system's101* default <code>ActivationGroup</code> implementation.102*103* @param overrides the set of properties to set when the group is104* recreated.105* @param cmd the controlling options for executing the VM in106* another process (or <code>null</code>).107* @since 1.2108*/109public ActivationGroupDesc(Properties overrides,110CommandEnvironment cmd)111{112this(null, null, null, overrides, cmd);113}114115/**116* Specifies an alternate group implementation and execution117* environment to be used for the group.118*119* @param className the group's package qualified class name or120* <code>null</code>. A <code>null</code> group class name indicates121* the system's default <code>ActivationGroup</code> implementation.122* @param location the location from where to load the group's123* class124* @param data the group's initialization data contained in125* marshalled form (could contain properties, for example)126* @param overrides a properties map which will override those set127* by default in the subprocess environment (will be translated128* into <code>-D</code> options), or <code>null</code>.129* @param cmd the controlling options for executing the VM in130* another process (or <code>null</code>).131* @since 1.2132*/133public ActivationGroupDesc(String className,134String location,135MarshalledObject<?> data,136Properties overrides,137CommandEnvironment cmd)138{139this.props = overrides;140this.env = cmd;141this.data = data;142this.location = location;143this.className = className;144}145146/**147* Returns the group's class name (possibly <code>null</code>). A148* <code>null</code> group class name indicates the system's default149* <code>ActivationGroup</code> implementation.150* @return the group's class name151* @since 1.2152*/153public String getClassName() {154return className;155}156157/**158* Returns the group's code location.159* @return the group's code location160* @since 1.2161*/162public String getLocation() {163return location;164}165166/**167* Returns the group's initialization data.168* @return the group's initialization data169* @since 1.2170*/171public MarshalledObject<?> getData() {172return data;173}174175/**176* Returns the group's property-override list.177* @return the property-override list, or <code>null</code>178* @since 1.2179*/180public Properties getPropertyOverrides() {181return (props != null) ? (Properties) props.clone() : null;182}183184/**185* Returns the group's command-environment control object.186* @return the command-environment object, or <code>null</code>187* @since 1.2188*/189public CommandEnvironment getCommandEnvironment() {190return this.env;191}192193194/**195* Startup options for ActivationGroup implementations.196*197* This class allows overriding default system properties and198* specifying implementation-defined options for ActivationGroups.199* @since 1.2200*/201public static class CommandEnvironment implements Serializable {202private static final long serialVersionUID = 6165754737887770191L;203204/**205* @serial206*/207private String command;208209/**210* @serial211*/212private String[] options;213214/**215* Create a CommandEnvironment with all the necessary216* information.217*218* @param cmdpath the name of the java executable, including219* the full path, or <code>null</code>, meaning "use rmid's default".220* The named program <em>must</em> be able to accept multiple221* <code>-Dpropname=value</code> options (as documented for the222* "java" tool)223*224* @param argv extra options which will be used in creating the225* ActivationGroup. Null has the same effect as an empty226* list.227* @since 1.2228*/229public CommandEnvironment(String cmdpath,230String[] argv)231{232this.command = cmdpath; // might be null233234// Hold a safe copy of argv in this.options235if (argv == null) {236this.options = new String[0];237} else {238this.options = new String[argv.length];239System.arraycopy(argv, 0, this.options, 0, argv.length);240}241}242243/**244* Fetch the configured path-qualified java command name.245*246* @return the configured name, or <code>null</code> if configured to247* accept the default248* @since 1.2249*/250public String getCommandPath() {251return (this.command);252}253254/**255* Fetch the configured java command options.256*257* @return An array of the command options which will be passed258* to the new child command by rmid.259* Note that rmid may add other options before or after these260* options, or both.261* Never returns <code>null</code>.262* @since 1.2263*/264public String[] getCommandOptions() {265return options.clone();266}267268/**269* Compares two command environments for content equality.270*271* @param obj the Object to compare with272* @return true if these Objects are equal; false otherwise.273* @see java.util.Hashtable274* @since 1.2275*/276public boolean equals(Object obj) {277278if (obj instanceof CommandEnvironment) {279CommandEnvironment env = (CommandEnvironment) obj;280return281((command == null ? env.command == null :282command.equals(env.command)) &&283Arrays.equals(options, env.options));284} else {285return false;286}287}288289/**290* Return identical values for similar291* <code>CommandEnvironment</code>s.292* @return an integer293* @see java.util.Hashtable294*/295public int hashCode()296{297// hash command and ignore possibly expensive options298return (command == null ? 0 : command.hashCode());299}300301/**302* <code>readObject</code> for custom serialization.303*304* <p>This method reads this object's serialized form for this305* class as follows:306*307* <p>This method first invokes <code>defaultReadObject</code> on308* the specified object input stream, and if <code>options</code>309* is <code>null</code>, then <code>options</code> is set to a310* zero-length array of <code>String</code>.311*/312private void readObject(ObjectInputStream in)313throws IOException, ClassNotFoundException314{315in.defaultReadObject();316if (options == null) {317options = new String[0];318}319}320}321322/**323* Compares two activation group descriptors for content equality.324*325* @param obj the Object to compare with326* @return true if these Objects are equal; false otherwise.327* @see java.util.Hashtable328* @since 1.2329*/330public boolean equals(Object obj) {331332if (obj instanceof ActivationGroupDesc) {333ActivationGroupDesc desc = (ActivationGroupDesc) obj;334return335((className == null ? desc.className == null :336className.equals(desc.className)) &&337(location == null ? desc.location == null :338location.equals(desc.location)) &&339(data == null ? desc.data == null : data.equals(desc.data)) &&340(env == null ? desc.env == null : env.equals(desc.env)) &&341(props == null ? desc.props == null :342props.equals(desc.props)));343} else {344return false;345}346}347348/**349* Produce identical numbers for similar <code>ActivationGroupDesc</code>s.350* @return an integer351* @see java.util.Hashtable352*/353public int hashCode() {354// hash location, className, data, and env355// but omit props (may be expensive)356return ((location == null357? 0358: location.hashCode() << 24) ^359(env == null360? 0361: env.hashCode() << 16) ^362(className == null363? 0364: className.hashCode() << 8) ^365(data == null366? 0367: data.hashCode()));368}369}370371372