1 9 package org.ozoneDB; 10 11 import java.io.*; 12 13 import org.ozoneDB.DxLib.DxHashMap; 14 import org.ozoneDB.DxLib.DxMap; 15 import org.ozoneDB.core.Env; 16 import org.ozoneDB.core.ObjectID; 17 import org.ozoneDB.core.GarbageCollector; 18 import org.ozoneDB.core.xml.Consts; 19 import org.xml.sax.helpers.AttributesImpl ; 20 21 29 public class OzoneProxy implements OzoneRemote, Externalizable { 30 31 private final static long serialVersionUID = 3L; 32 33 37 public static DxMap linkTable = new DxHashMap(); 38 39 40 public transient OzoneInterface link = null; 41 42 public ObjectID remoteID; 43 44 45 49 public OzoneProxy() { 50 Env env = Env.currentEnv(); 52 if (env != null) { 53 link = env.database; 54 } 55 } 56 57 58 62 public OzoneProxy(ObjectID id, OzoneInterface link) { 63 this.link = link; 64 remoteID = (ObjectID) id.clone(); 65 } 66 67 68 public OzoneProxy(OzoneProxy rhs) { 69 link = rhs.link; 70 remoteID = (ObjectID) rhs.remoteID.clone(); 71 } 72 73 74 public boolean isSame(OzoneProxy proxy) { 75 return remoteID.equals(proxy.remoteID); 76 } 77 78 79 84 public boolean equals(Object obj) { 85 if (obj instanceof OzoneProxy && obj != null) { 86 return isSame((OzoneProxy) obj); 87 } else { 88 return false; 89 } 90 } 91 92 93 98 public int hashCode() { 99 return remoteID.hashCode(); 100 } 101 102 103 127 public String toString() { 128 return getClass().toString() + " remoteID:" + remoteID.toString(); 129 } 130 131 132 public ObjectID remoteID() { 133 return remoteID; 134 } 135 136 147 public ObjectID getObjectID() { 148 return remoteID(); 149 } 150 151 168 public String getHandle() { 169 return remoteID.toString(); 170 } 171 172 175 public String handle() { 176 return getHandle(); 177 } 178 179 185 public void createProxyLinkAttributes(AttributesImpl atts) { 186 atts.addAttribute(Consts.ATTR_XLINK_NAMESPACE, 187 Consts.ATTR_XLINK_TYPE_LOCAL, Consts.ATTR_XLINK_TYPE_RAW, 188 "PCDATA", "simple"); 189 atts.addAttribute(Consts.ATTR_XLINK_NAMESPACE, 190 Consts.ATTR_XLINK_HREF_LOCAL, Consts.ATTR_XLINK_HREF_RAW, 191 "PCDATA", String.valueOf(remoteID)); 192 } 193 194 195 200 public Object invoke(String methodName, int lockLevel) throws Exception { 201 Object [] args = {}; 202 return link.invoke(this, methodName, null, args, lockLevel); 203 } 204 205 206 209 public Object invoke(String methodName, Object arg1, int lockLevel) throws Exception { 210 Object [] args = {arg1}; 211 return link.invoke(this, methodName, null, args, lockLevel); 212 } 213 214 215 218 public Object invoke(String methodName, Object arg1, Object arg2, int lockLevel) throws Exception { 219 Object [] args = {arg1, arg2}; 220 return link.invoke(this, methodName, null, args, lockLevel); 221 } 222 223 224 227 public Object invoke(String methodName, Object arg1, Object arg2, Object arg3, int lockLevel) throws Exception { 228 Object [] args = {arg1, arg2, arg3}; 229 return link.invoke(this, methodName, null, args, lockLevel); 230 } 231 232 235 public void finalize() { 236 if (link!=null) { 237 try { 238 link.notifyProxyDeath(this); 239 } finally { 240 link = null; } 242 } 243 } 244 245 public void writeExternal(ObjectOutput out) throws IOException { 246 if (out instanceof GarbageCollector.GarbageCollectorProxyObjectIdentificationObjectOutputStream) { 247 ((GarbageCollector.GarbageCollectorProxyObjectIdentificationObjectOutputStream) out).notifyOzoneProxyEncountered(this); 248 } 249 250 out.writeLong(remoteID.value()); 251 } 253 254 255 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 256 remoteID = new ObjectID(in.readLong()); 257 259 ExternalDatabase db = (ExternalDatabase) linkTable.elementForKey(in); 260 if (db != null) { 261 link = db.linkForProxy(this); 262 } 265 } 266 267 } 268 | Popular Tags |