1 3 4 package org.ozoneDB.core.DbRemote; 5 6 import java.util.HashMap ; 7 import java.util.Iterator ; 8 9 import org.ozoneDB.OzoneProxy; 10 import org.ozoneDB.core.GarbageCollector; 11 import org.ozoneDB.core.ObjectID; 12 13 23 public class ProxyObjectGate { 24 33 protected HashMap objectsReferencesByClient; 34 35 protected GarbageCollector garbageCollectorToBeNotifiedOfExportedReferences; 36 37 40 protected final static Integer one = new Integer (1); 41 42 45 protected ProxyObjectGate() { 46 objectsReferencesByClient = new HashMap (); 47 } 48 49 public void addObjectReferencedByClient(OzoneProxy proxy) { 50 if (proxy!=null) { 51 synchronized (objectsReferencesByClient) { 52 ObjectID id = proxy.remoteID(); 53 54 if (garbageCollectorToBeNotifiedOfExportedReferences!=null) { 55 garbageCollectorToBeNotifiedOfExportedReferences.notifyDatabaseObjectIsAboutToBeExported(id); 56 } 57 58 Object oldEntry = objectsReferencesByClient.put(id,one); 59 60 if (oldEntry!=null) { 61 objectsReferencesByClient.put(id,new Integer (((Integer ) oldEntry).intValue()+1)); 62 } 63 } 64 } 65 } 66 67 protected void removeObjectReferencedByClient(OzoneProxy proxy) { 68 removeObjectReferencedByClient(proxy.remoteID()); 69 } 70 71 protected void removeObjectReferencedByClient(ObjectID id) { 72 synchronized (objectsReferencesByClient) { 73 Object oldEntry = objectsReferencesByClient.remove(id); 74 75 if (oldEntry!=null) { 76 if (oldEntry!=one) { 77 int count = ((Integer ) oldEntry).intValue(); 78 79 count--; 80 81 if (count>0) { 82 if (count>1) { 83 objectsReferencesByClient.put(id,new Integer (count)); 84 } else { 85 objectsReferencesByClient.put(id,one); 86 } 87 } 88 } else { 89 } 91 } else { 92 } 94 } 95 } 96 97 104 public void startFilterDatabaseObjectReferencesExports(GarbageCollector garbageCollector) { 105 106 synchronized (objectsReferencesByClient) { 107 this.garbageCollectorToBeNotifiedOfExportedReferences = garbageCollector; 108 109 Iterator i = objectsReferencesByClient.keySet().iterator(); 110 111 while (i.hasNext()) { 112 garbageCollector.notifyDatabaseObjectIsExported((ObjectID) i.next()); 113 } 114 } 115 } 116 } | Popular Tags |