1 8 package org.ozoneDB.core.storage.gammaStore; 9 10 import java.io.Externalizable ; 11 import java.io.IOException ; 12 import java.io.ObjectInput ; 13 import java.io.ObjectOutput ; 14 import java.util.Iterator ; 15 import java.util.LinkedHashSet ; 16 import java.util.Map ; 17 import javax.naming.Reference ; 18 import org.ozoneDB.OzoneCompatible; 19 import org.ozoneDB.DxLib.DxArrayBag; 20 import org.ozoneDB.DxLib.DxCollection; 21 import org.ozoneDB.DxLib.DxIterator; 22 import org.ozoneDB.core.AbstractObjectContainer; 23 import org.ozoneDB.core.Env; 24 import org.ozoneDB.core.Lock; 25 import org.ozoneDB.core.MROWLock; 26 import org.ozoneDB.core.ObjectContainer; 27 import org.ozoneDB.core.ObjectID; 28 import org.ozoneDB.core.Permissions; 29 import org.ozoneDB.core.Transaction; 30 import org.ozoneDB.core.TransactionID; 31 import org.ozoneDB.core.storage.Cache; 32 import org.ozoneDB.util.LogWriter; 33 34 35 36 37 41 public final class GammaContainer extends AbstractObjectContainer implements Externalizable { 42 43 private static final long serialVersionUID = 1L; 44 45 private OzoneCompatible target; 46 47 private ObjectID objectID; 48 49 private String name; 50 51 private Lock lock; 52 53 private transient GammaStore gammaStore; 54 55 private Permissions permissions; 56 57 58 69 private int garbageCollectionLevel; 70 71 77 public GammaContainer(ObjectID objectID, GammaStore gammaStore) { 78 state = STATE_CREATED; 79 this.objectID = objectID; 80 setGammaStore(gammaStore); 81 lock = new MROWLock(); 82 permissions = new Permissions(); 83 } 84 85 private void setGammaStore(GammaStore gammaStore) { 86 this.gammaStore = gammaStore; 87 } 88 89 private GammaStore getGammaStore() { 90 return gammaStore; 91 } 92 93 public long modTime() { 94 return 0; 95 } 96 97 98 protected boolean isDeleted() { 99 return (state() & ObjectContainer.STATE_DELETED) > 0; 100 } 101 102 103 protected boolean isCreated() { 104 return (state() & ObjectContainer.STATE_CREATED) > 0; 105 } 106 107 108 112 public Class targetClass() { 113 return getTarget().getClass(); 114 } 115 116 117 public synchronized void setTarget(OzoneCompatible target) { 118 if (getTarget() != null) { 119 getTarget().setContainer(null); 120 } 121 this.target = target; 122 target.setContainer(this); 123 } 124 125 126 public OzoneCompatible target() { 127 return getTarget(); 128 } 129 130 public OzoneCompatible getTarget() { 131 return target; 132 } 133 134 135 public void touch() { 136 getGammaStore().getContainerCache().get(getObjectId()); 137 } 138 139 140 public Lock lock() { 141 return lock; 142 } 143 144 145 public void updateLockLevel(Transaction ta) throws Exception { 146 } 148 149 150 public synchronized void notifyAllTAs(Transaction ta) { 151 lock.notifyAll(); 152 } 153 154 155 public Permissions permissions() { 156 return permissions; 157 } 158 159 160 public int lockLevel(Transaction ta) { 161 return lock.level(ta); 162 } 163 164 165 public boolean isInvoked() { 166 return true; 168 } 169 170 public void deleteTarget() { 171 if (Env.currentEnv().logWriter.hasTarget(LogWriter.DEBUG3)) { 172 Env.currentEnv().logWriter.newEntry(this, "deleteTarget(): ", LogWriter.DEBUG3); 173 } 174 raiseState(STATE_DELETED); 175 } 176 177 178 public synchronized void nameTarget(String name) { 179 this.name = name; 180 } 181 182 183 public DxCollection allLockers() { 184 DxCollection lockerIDs = lock.lockerIDs(); 185 186 DxArrayBag result = new DxArrayBag(lockerIDs.count()); 187 DxIterator it = lockerIDs.iterator(); 188 while (it.next() != null) { 189 result.add(Env.currentEnv().transactionManager.taForID((TransactionID) it.object())); 190 } 191 192 return result; 193 } 194 195 196 public boolean equals(Object object) { 197 if (object != null && object instanceof GammaContainer) { 198 GammaContainer gammaContainer = (GammaContainer) object; 199 return objectID.equals(gammaContainer.objectID); 200 } 201 return false; 202 } 203 204 205 public ObjectID id() { 206 return objectID; 207 } 208 209 public ObjectID getObjectId() { 210 return objectID; 211 } 212 213 214 public String name() { 215 return name; 216 } 217 218 219 public void setName(String name) { 220 this.name = name; 221 } 222 223 224 public final void writeExternal(ObjectOutput out) throws IOException { 225 out.writeObject(target); 233 out.writeByte((byte) state); 234 out.writeInt(garbageCollectionLevel); 235 } 236 237 238 public final void readExternal(ObjectInput in) throws IOException , ClassNotFoundException { 239 target = (OzoneCompatible) in.readObject(); 242 if (target != null) { 243 target.setContainer(this); 244 } 245 state = (int) in.readByte(); 246 garbageCollectionLevel = in.readInt(); 247 } 248 249 262 public int ensureGarbageCollectionLevel(int newGarbageCollectionLevel) { 263 int difference = this.garbageCollectionLevel - newGarbageCollectionLevel; 264 265 if (difference < 0) { this.garbageCollectionLevel = newGarbageCollectionLevel; 267 } 269 270 return difference; 271 } 272 273 274 277 public int getGarbageCollectionLevel() { 278 return garbageCollectionLevel; 279 } 280 281 284 public void pin() { 285 } 286 287 290 public void unpin() { 291 } 292 293 296 public boolean isPinned() { 297 return true; 298 } 299 300 public String toString() { 301 return "GammaContainer[" + objectID + ", " + name + ", " + target + "]"; 302 } 303 304 } 305 | Popular Tags |