Source for java.rmi.activation.ActivationID

   1: /* ActivationID.java -- the object activation identifier
   2:    Copyright (c) 1996, 1997, 1998, 1999, 2006 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: 
  39: package java.rmi.activation;
  40: 
  41: import java.io.IOException;
  42: import java.io.ObjectInputStream;
  43: import java.io.ObjectOutputStream;
  44: import java.io.Serializable;
  45: import java.rmi.Remote;
  46: import java.rmi.RemoteException;
  47: import java.rmi.server.UID;
  48: 
  49: /**
  50:  * Denotes the object that can be activated over time. The instance of the
  51:  * ActivationID for the given object can be obtained in the following ways:
  52:  * <ul>
  53:  * <li>via {@link Activatable#register(ActivationDesc)}</li>
  54:  * <li>via Activatable constructor</li>
  55:  * <li>via Activatable.exportObject
  56:  * <li>
  57:  * </ul>
  58:  * An instance of the ActivationID has the {@link UID} as its component and
  59:  * hence is globally unique.
  60:  * 
  61:  * @author Audrius Meskauskas (audriusa@bioinformatics.org) (from stub)
  62:  */
  63: public class ActivationID
  64:     implements Serializable
  65: {
  66:   /**
  67:    * Use SVUID for interoperability.
  68:    */
  69:   static final long serialVersionUID = - 4608673054848209235L;
  70: 
  71:   /**
  72:    * The activator.
  73:    */
  74:   transient Activator activator;
  75:   
  76:   /**
  77:    * The UID, making this instance unique.
  78:    */
  79:   transient UID uid; 
  80:   
  81:   /**
  82:    * The activation group that has activated the object with this
  83:    * activation id. The field is filled in inside the group and is used
  84:    * to notify the group about the request to inactivated the object.
  85:    */
  86:   transient ActivationGroup group;
  87: 
  88:   /**
  89:    * Create a new instance with the given activator.
  90:    * 
  91:    * @param an_activator tha activator that should activate the object.
  92:    */
  93:   public ActivationID(Activator an_activator)
  94:   {
  95:     activator = an_activator;
  96:     uid = new UID();
  97:   }
  98:    
  99:   /**
 100:    * Activate the object.
 101:    * 
 102:    * @param force if true, always contact the group. Otherwise, the cached value
 103:    *          may be returned.
 104:    * @return the activated object
 105:    * @throws UnknownObjectException if the object is unknown
 106:    * @throws ActivationException if the activation has failed
 107:    * @throws RemoteException if the remote call has failed
 108:    */
 109:   public Remote activate(boolean force) throws ActivationException,
 110:       UnknownObjectException, RemoteException
 111:   {
 112:         try
 113:           {
 114:             return (Remote) activator.activate(this, force).get();
 115:           }
 116:         catch (IOException e)
 117:           {
 118:             ActivationException acex = new ActivationException("id "+uid, e);
 119:             throw acex;            
 120:           }
 121:         catch (ClassNotFoundException e)
 122:           {
 123:             ActivationException acex = new ActivationException("id "+uid, e);
 124:             throw acex;
 125:           }
 126:   }
 127:   
 128:   /**
 129:    * Returns the hash code of the activator.
 130:    */
 131:   public int hashCode()
 132:   {
 133:     return uid == null ? 0 : uid.hashCode();
 134:   }
 135:   
 136:   /**
 137:    * Compares the activators for equality.
 138:    */
 139:   public boolean equals(Object obj)
 140:   {
 141:     if (obj instanceof ActivationID)
 142:       {
 143:         ActivationID that = (ActivationID) obj;
 144:         return eq(uid, that.uid);
 145:       }
 146:     else
 147:       return false;
 148:   }
 149:   
 150:   /**
 151:    * Read the object from the input stream.
 152:    * 
 153:    * @param in the stream to read from
 154:    * 
 155:    * @throws IOException if thrown by the stream
 156:    * @throws ClassNotFoundException
 157:    */
 158:   private void readObject(ObjectInputStream in) throws IOException,
 159:       ClassNotFoundException
 160:   {
 161:      uid = (UID) in.readObject();
 162:      activator = (Activator) in.readObject();
 163:   }
 164:   
 165:   /**
 166:    * Write the object to the output stream.
 167:    * 
 168:    * @param out the stream to write int
 169:    * @throws IOException if thrown by the stream
 170:    * @throws ClassNotFoundException
 171:    */
 172:   private void writeObject(ObjectOutputStream out) throws IOException,
 173:       ClassNotFoundException
 174:   {
 175:     out.writeObject(uid);
 176:     out.writeObject(activator);
 177:   }
 178:   
 179:   /**
 180:    * Compare by .equals if both a and b are not null, compare directly if at
 181:    * least one of them is null.
 182:    */
 183:   static final boolean eq(Object a, Object b)
 184:   {
 185:     if (a == null || b == null)
 186:       return a == b;
 187:     else
 188:       return a.equals(b);
 189:   }  
 190: 
 191:   /**
 192:    * Return the content based string representation.
 193:    */
 194:   public String toString()
 195:   {
 196:     return uid.toString();
 197:   }
 198:   
 199: }