001 /* ActivationID.java -- the object activation identifier 002 Copyright (c) 1996, 1997, 1998, 1999, 2006 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 039 package java.rmi.activation; 040 041 import java.io.IOException; 042 import java.io.ObjectInputStream; 043 import java.io.ObjectOutputStream; 044 import java.io.Serializable; 045 import java.rmi.Remote; 046 import java.rmi.RemoteException; 047 import java.rmi.server.UID; 048 049 /** 050 * Denotes the object that can be activated over time. The instance of the 051 * ActivationID for the given object can be obtained in the following ways: 052 * <ul> 053 * <li>via {@link Activatable#register(ActivationDesc)}</li> 054 * <li>via Activatable constructor</li> 055 * <li>via Activatable.exportObject 056 * <li> 057 * </ul> 058 * An instance of the ActivationID has the {@link UID} as its component and 059 * hence is globally unique. 060 * 061 * @author Audrius Meskauskas (audriusa@bioinformatics.org) (from stub) 062 */ 063 public class ActivationID 064 implements Serializable 065 { 066 /** 067 * Use SVUID for interoperability. 068 */ 069 static final long serialVersionUID = - 4608673054848209235L; 070 071 /** 072 * The activator. 073 */ 074 transient Activator activator; 075 076 /** 077 * The UID, making this instance unique. 078 */ 079 transient UID uid; 080 081 /** 082 * The activation group that has activated the object with this 083 * activation id. The field is filled in inside the group and is used 084 * to notify the group about the request to inactivated the object. 085 */ 086 transient ActivationGroup group; 087 088 /** 089 * Create a new instance with the given activator. 090 * 091 * @param an_activator tha activator that should activate the object. 092 */ 093 public ActivationID(Activator an_activator) 094 { 095 activator = an_activator; 096 uid = new UID(); 097 } 098 099 /** 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 }