Source for java.rmi.activation.ActivationDesc

   1: /* ActivationDesc.java -- record with info to activate an object
   2:    Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: package java.rmi.activation;
  39: 
  40: import java.io.Serializable;
  41: import java.rmi.MarshalledObject;
  42: 
  43: /**
  44:  * Contains the information, necessary to activate the object. This information
  45:  * includes:
  46:  * <ul>
  47:  * <li>the object class name</li>
  48:  * <li>the object group identifier</li>
  49:  * <li>the code location (codebase URL) that can be used to load the class
  50:  * remotely</li>
  51:  * <li>the object restart mode</li>
  52:  * <li>the object specific intialization information</li>
  53:  * </ul>
  54:  *
  55:  * @author Audrius Meskauskas (audriusa@bioinformatics.org) (from stub)
  56:  */
  57: public final class ActivationDesc
  58:     implements Serializable
  59: {
  60:   /**
  61:    * Use SVUID for interoperability.
  62:    */
  63:   static final long serialVersionUID = 7455834104417690957L;
  64: 
  65:   /**
  66:    * The group id.
  67:    */
  68:   private ActivationGroupID groupid;
  69: 
  70:   /**
  71:    * The class name.
  72:    */
  73:   private String classname;
  74: 
  75:   /**
  76:    * The code location URL.
  77:    */
  78:   private String location;
  79: 
  80:   /**
  81:    * The object specific intitalization data.
  82:    */
  83:   private MarshalledObject<?> data;
  84: 
  85:   /**
  86:    * The start mode.
  87:    */
  88:   private boolean restart;
  89: 
  90:   /**
  91:    * Create the new activation description, assuming the object group is the
  92:    * {@link ActivationGroup#currentGroupID()}.
  93:    *
  94:    * @param className the object fully qualified class name
  95:    * @param location the code base URL
  96:    * @param data the object initialization data, contained in a marshalled form
  97:    */
  98:   public ActivationDesc(String className, String location, MarshalledObject<?> data)
  99:       throws ActivationException
 100:   {
 101:     this(ActivationGroup.currentGroupID(), className, location, data, false);
 102:   }
 103: 
 104:   /**
 105:    * Create the new activation description, assuming the object group is the
 106:    * {@link ActivationGroup#currentGroupID()}.
 107:    *
 108:    * @param className the object fully qualified class name
 109:    * @param location the code base URL
 110:    * @param data the object initialization data, contained in a marshalled form
 111:    * @param restart specifies reactivation mode after crash. If true, the object
 112:    *          is activated when activator is restarted or the activation group
 113:    *          is restarted. If false, the object is only activated on demand.
 114:    *          This flag does has no effect during the normal operation (the
 115:    *          object is normally activated on demand).
 116:    */
 117:   public ActivationDesc(String className, String location,
 118:                         MarshalledObject<?> data, boolean restart)
 119:       throws ActivationException
 120:   {
 121:     this(ActivationGroup.currentGroupID(), className, location, data, restart);
 122:   }
 123: 
 124:   /**
 125:    * Create the new activation description. Under crash, the object will only
 126:    * be reactivated on demand.
 127:    *
 128:    * @param groupID the object group id.
 129:    * @param className the object fully qualified class name
 130:    * @param location the code base URL
 131:    * @param data the object initialization data, contained in a marshalled form
 132:    */
 133:   public ActivationDesc(ActivationGroupID groupID, String className,
 134:                         String location, MarshalledObject<?> data)
 135:   {
 136:     this(groupID, className, location, data, false);
 137:   }
 138: 
 139:   /**
 140:    * Create the new activation description, providing full information.
 141:    *
 142:    * @param groupID the object group id.
 143:    * @param className the object fully qualified class name
 144:    * @param location the code base URL
 145:    * @param data the object initialization data, contained in a marshalled form
 146:    * @param restart specifies reactivation mode after crash. If true, the object
 147:    *          is activated when activator is restarted or the activation group
 148:    *          is restarted. If false, the object is only activated on demand.
 149:    *          This flag does has no effect during the normal operation (the
 150:    *          object is normally activated on demand).
 151:    */
 152:   public ActivationDesc(ActivationGroupID groupID, String className,
 153:                         String location, MarshalledObject<?> data, boolean restart)
 154:   {
 155:     this.groupid = groupID;
 156:     this.classname = className;
 157:     this.location = location;
 158:     this.data = data;
 159:     this.restart = restart;
 160:   }
 161: 
 162:   public ActivationGroupID getGroupID()
 163:   {
 164:     return groupid;
 165:   }
 166: 
 167:   /**
 168:    * Get the class name of the object being activated
 169:    *
 170:    * @return the fully qualified class name of the object being activated
 171:    */
 172:   public String getClassName()
 173:   {
 174:     return classname;
 175:   }
 176: 
 177:   /**
 178:    * Get the code location URL ("codebase") of the object being activated.
 179:    *
 180:    * @return the codebase of the object being activated.
 181:    */
 182:   public String getLocation()
 183:   {
 184:     return location;
 185:   }
 186: 
 187:   public MarshalledObject<?> getData()
 188:   {
 189:     return data;
 190:   }
 191: 
 192:   /**
 193:    * Get the object reactivation strategy after crash.
 194:    *
 195:    * @return true ir the object is activated when activator is restarted or the
 196:    *         activation group is restarted. False if the object is only
 197:    *         activated on demand. This flag does has no effect during the normal
 198:    *         operation (the object is normally activated on demand).
 199:    */
 200:   public boolean getRestartMode()
 201:   {
 202:     return restart;
 203:   }
 204: 
 205:   /**
 206:    * Compare this object with another activation description for equality.
 207:    *
 208:    * @return true if all fields have the equal values, false otherwise.
 209:    */
 210:   public boolean equals(Object obj)
 211:   {
 212:     if (obj instanceof ActivationDesc)
 213:       {
 214:         ActivationDesc that = (ActivationDesc) obj;
 215:         return eq(groupid, that.groupid) &&
 216:                eq(classname, that.classname) &&
 217:                eq(location, that.location) &&
 218:                eq(data, that.data)
 219:                && restart == that.restart;
 220:       }
 221:     else
 222:       return false;
 223:   }
 224: 
 225:   /**
 226:    * Get the hash code of this object (overridden to make the returned value
 227:    * consistent with .equals(..).
 228:    */
 229:   public int hashCode()
 230:   {
 231:     return hash(groupid) ^ hash(classname) ^
 232:       hash(location) ^ hash(data);
 233:   }
 234: 
 235:   /**
 236:    * Get the hashcode of x or 0 if x == null.
 237:    */
 238:   static final int hash(Object x)
 239:   {
 240:     return x == null ? 0 : x.hashCode();
 241:   }
 242: 
 243:   /**
 244:    * Compare by .equals if both a and b are not null, compare directly if at
 245:    * least one of them is null.
 246:    */
 247:   static final boolean eq(Object a, Object b)
 248:   {
 249:     if (a == null || b == null)
 250:       return a == b;
 251:     else
 252:       return a.equals(b);
 253:   }
 254: }