📄 gammacontainer.java
字号:
// You can redistribute this software and/or modify it under the terms of
// the Ozone Core License version 1 published by ozone-db.org.
//
// Copyright (C) 2003-@year@ Leo Mekenkamp. All rights reserved.
//
// $Id: GammaContainer.java,v 1.2 2004/03/21 21:05:51 leomekenkamp Exp $
package org.ozoneDB.core.storage.gammaStore;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;
import javax.naming.Reference;
import org.ozoneDB.OzoneCompatible;
import org.ozoneDB.DxLib.DxArrayBag;
import org.ozoneDB.DxLib.DxCollection;
import org.ozoneDB.DxLib.DxIterator;
import org.ozoneDB.core.AbstractObjectContainer;
import org.ozoneDB.core.Env;
import org.ozoneDB.core.Lock;
import org.ozoneDB.core.MROWLock;
import org.ozoneDB.core.ObjectContainer;
import org.ozoneDB.core.ObjectID;
import org.ozoneDB.core.Permissions;
import org.ozoneDB.core.Transaction;
import org.ozoneDB.core.TransactionID;
import org.ozoneDB.core.storage.Cache;
import org.ozoneDB.util.LogWriter;
/**
* @author <a href="mailto:leoATmekenkampD0Tcom">Leo Mekenkamp (mind the anti sp@m)</a>
* @version $Id: GammaContainer.java,v 1.2 2004/03/21 21:05:51 leomekenkamp Exp $
*/
public final class GammaContainer extends AbstractObjectContainer implements Externalizable {
private static final long serialVersionUID = 1L;
private OzoneCompatible target;
private ObjectID objectID;
private String name;
private Lock lock;
private transient GammaStore gammaStore;
private Permissions permissions;
/**
* The garbage collection level of this ObjectContainer. This number is
* compared to the currentGarbageCollectionLevel of the database. Is this
* number smaller, then this object may be reachable. Is it equal, then this
* object is reachable, but it's descendants are not yet considered. Is it
* greater, then this object is reachable and this object is processed, it's
* descendants have been considered.
* At the end of the mark-process, every object which still is not reachable
* must be unreachable, so at this and, a smaller garbageCollectionLevel
* than currentGarbageCollectionLevel means that this object may be deleted.
*/
private int garbageCollectionLevel;
// /**
// * Constructor for object serialization via Externalizable.
// */
// public GammaContainer() {
// }
public GammaContainer(ObjectID objectID, GammaStore gammaStore) {
state = STATE_CREATED;
this.objectID = objectID;
setGammaStore(gammaStore);
lock = new MROWLock();
permissions = new Permissions();
}
private void setGammaStore(GammaStore gammaStore) {
this.gammaStore = gammaStore;
}
private GammaStore getGammaStore() {
return gammaStore;
}
public long modTime() {
return 0;
}
protected boolean isDeleted() {
return (state() & ObjectContainer.STATE_DELETED) > 0;
}
protected boolean isCreated() {
return (state() & ObjectContainer.STATE_CREATED) > 0;
}
/**
* Returns the Class for the target object. This method is used by
* AbstractObjectContainer.
*/
public Class targetClass() {
return getTarget().getClass();
}
public synchronized void setTarget(OzoneCompatible target) {
if (getTarget() != null) {
getTarget().setContainer(null);
}
this.target = target;
target.setContainer(this);
}
public OzoneCompatible target() {
return getTarget();
}
public OzoneCompatible getTarget() {
return target;
}
public void touch() {
getGammaStore().getContainerCache().get(getObjectId());
}
public Lock lock() {
return lock;
}
public void updateLockLevel(Transaction ta) throws Exception {
// CRITICAL: what to do here?
}
public synchronized void notifyAllTAs(Transaction ta) {
lock.notifyAll();
}
public Permissions permissions() {
return permissions;
}
public int lockLevel(Transaction ta) {
return lock.level(ta);
}
public boolean isInvoked() {
// CRITICAL: what to do here?
return true;
}
public void deleteTarget() {
if (Env.currentEnv().logWriter.hasTarget(LogWriter.DEBUG3)) {
Env.currentEnv().logWriter.newEntry(this, "deleteTarget(): ", LogWriter.DEBUG3);
}
raiseState(STATE_DELETED);
}
public synchronized void nameTarget(String name) {
this.name = name;
}
public DxCollection allLockers() {
DxCollection lockerIDs = lock.lockerIDs();
DxArrayBag result = new DxArrayBag(lockerIDs.count());
DxIterator it = lockerIDs.iterator();
while (it.next() != null) {
result.add(Env.currentEnv().transactionManager.taForID((TransactionID) it.object()));
}
return result;
}
public boolean equals(Object object) {
if (object != null && object instanceof GammaContainer) {
GammaContainer gammaContainer = (GammaContainer) object;
return objectID.equals(gammaContainer.objectID);
}
return false;
}
public ObjectID id() {
return objectID;
}
public ObjectID getObjectId() {
return objectID;
}
public String name() {
return name;
}
public void setName(String name) {
this.name = name;
}
public final void writeExternal(ObjectOutput out) throws IOException {
// out.writeLong(objectID.value());
// if (name == null) {
// out.writeByte(0);
// } else {
// out.writeByte(1);
// out.writeUTF(name);
// }
out.writeObject(target);
out.writeByte((byte) state);
out.writeInt(garbageCollectionLevel);
}
public final void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
// objectID = new ObjectID(in.readLong());
// name = (in.readByte() == 0) ? null : in.readUTF();
target = (OzoneCompatible) in.readObject();
if (target != null) {
target.setContainer(this);
}
state = (int) in.readByte();
garbageCollectionLevel = in.readInt();
}
/**
Ensures that the garbageCollectionLevel is at least the given currentGarbageCollectionLevel.
The return value is meaningful if the supplied newGarbageCollectionLevel is the currentGarbageCollectionLevel
@return
<=0 if this object still has to be processed.
This is the case if it belongs to the surelyReachable set but not to the processedReachable set
> otherwise
<0 if this object has been updated
=0 if this object has not been updated, it is surelyReachable
>0 if this object has not been updated, it is processedReachable
*/
public int ensureGarbageCollectionLevel(int newGarbageCollectionLevel) {
int difference = this.garbageCollectionLevel - newGarbageCollectionLevel;
if (difference < 0) { // This object's garbageCollectionLevel must be updated
this.garbageCollectionLevel = newGarbageCollectionLevel;
// touch(); TODO: find out if there is need to touch
}
return difference;
}
/**
Returns the garbageCollectionLevel this ObjectContainer has reached due to (not) calling {@link #ensureGarbageCollectionLevel}.
*/
public int getGarbageCollectionLevel() {
return garbageCollectionLevel;
}
/**
* GammaStore does not not care about pin.
*/
public void pin() {
}
/**
* GammaStore does not not care about pin.
*/
public void unpin() {
}
/**
* GammaStore does not not care about pin.
*/
public boolean isPinned() {
return true;
}
public String toString() {
return "GammaContainer[" + objectID + ", " + name + ", " + target + "]";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -