📄 wizardcluster.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.//// The original code and portions created by SMB are// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.//// $Id$package org.ozoneDB.core.storage.wizardStore;import java.io.Externalizable;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.ObjectInput;import java.io.ObjectOutput;import java.io.ObjectStreamException;import java.io.OutputStream;import org.ozoneDB.DxLib.DxArrayBag;import org.ozoneDB.DxLib.DxCollection;import org.ozoneDB.DxLib.DxHashMap;import org.ozoneDB.DxLib.DxIterator;import org.ozoneDB.DxLib.DxLong;import org.ozoneDB.core.Lock;import org.ozoneDB.core.MROWLock;import org.ozoneDB.core.Permissions;import org.ozoneDB.core.Transaction;import org.ozoneDB.core.TransactionID;import org.ozoneDB.core.storage.AbstractCluster;import org.ozoneDB.core.storage.StorageObjectContainer;import org.ozoneDB.core.storage.ClusterID;import org.ozoneDB.util.LogWriter;/** * @author <a href="http://www.softwarebuero.de/">SMB</a> * @author <a href="http://www.medium.net/">Medium.net</a> * @version $Revision$Date$ * TODO: add final modifier when backward compatibility for 1.1 does not have to be maintained */public class WizardCluster extends AbstractCluster implements Externalizable { protected final static long serialVersionUID = 2L; protected final static byte subSerialVersionUID = 1; protected transient Lock lock; protected transient long lastTouched; protected transient int bytesPerContainer; protected long modTime; /** The count of users of this cluster which requested it to be pinned. If a cluster is pinned, it may not be "passivated" (i.e. written to disk and forgotten), it has to stay in memory. This cluster is said to be pinned iff pinCount!=0. Access to this count is only allowed during synchronization on this WizardCluster. */ protected transient int pinCount; /** * Constructor to be used for Externalizable object serialisation. */ public WizardCluster() { this(null, null, null, 0); } public WizardCluster(ClusterID _clusterID, Permissions _permissions, Lock _lock, int _bpc) { // the env and clusterStore will be set by clusterStore clusterID = _clusterID; permissions = _permissions; lock = _lock; bytesPerContainer = _bpc; containers = new DxHashMap(1024); if (lock != null) { ((MROWLock) lock).setDebugInfo("clusterID=" + clusterID); } }// public void finalize() {// if (env.logWriter.hasTarget(LogWriter.DEBUG3)) {// env.logWriter.newEntry(this, "---finalize(): cluster " + clusterID, LogWriter.DEBUG3);// }// } public long modTime() { return modTime; } /** * Priority of this cluster to stay in the cluster cache. Low return value * means low priority. * @return Cache priority of the cluster. */ public DxLong cachePriority() { return new DxLong(lastTouched); } public synchronized void setCurrentSize(int byteSize) { int containerCount = containers.count(); bytesPerContainer = containerCount > 0 ? byteSize / containerCount : clusterStore.currentBytesPerContainer(); } public int size() { return containers.count() * bytesPerContainer; } /** * @return True if at least one container is currently invoked. */ public boolean isInvoked() { //FIXME: should be a bit in the status byte that is directly changed // by clusters when they are changed StorageObjectContainer container; DxIterator it = containers.iterator(); while ((container = (StorageObjectContainer) it.next()) != null) { if (container.isInvoked()) { return true; } } return false; } public synchronized void touch() { lastTouched = clusterStore.touchCount++; } public void registerContainer(StorageObjectContainer container) { synchronized (container) { container.setCluster(this); if (containers.addForKey(container, container.id()) == false) { throw new IllegalStateException("Unable to add id " + container.id() + " to cluster " + clusterID()); } } } public void removeContainer(StorageObjectContainer container) { if (containers.removeForKey(container.id()) == null) { throw new IllegalStateException("Unable to remove container from cluster."); } } /** * Note: This method must not be synchronized. * * @param ta */ public void updateLockLevel(Transaction ta) throws IOException { if (env.logWriter.hasTarget(LogWriter.DEBUG2)) { env.logWriter.newEntry(this, "updateLockLevel(): " + clusterID, LogWriter.DEBUG2); env.logWriter.newEntry(this, " lock: " + lock.level(ta), LogWriter.DEBUG2); } if (lock.level(ta) > Lock.LEVEL_UPGRADE) { saveShadow(); } } public void prepareCommit(Transaction ta) /*throws Exception*/ { if (env.logWriter.hasTarget(LogWriter.DEBUG3)) { env.logWriter.newEntry(this, "prepareCommit()" + clusterID, LogWriter.DEBUG3); } if (lock.level(ta) > Lock.LEVEL_UPGRADE) { synchronized (this) { modTime = System.currentTimeMillis(); } } } public void commit(Transaction ta) throws IOException { if (env.logWriter.hasTarget(LogWriter.DEBUG3)) { env.logWriter.newEntry(this, "commit()" + clusterID, LogWriter.DEBUG3); } if (true || lock != null) { if (lock.level(ta) > Lock.LEVEL_UPGRADE) { deleteShadow(); } lock.release(ta); } else {// env.logWriter.newEntry( this, this+".commit(): lock="+lock+".", LogWriter.DEBUG3 ); throw new NullPointerException(this + ".commit(" + ta + "): lock=" + lock + "."); } } public void abort(Transaction ta) throws IOException { if (env.logWriter.hasTarget(LogWriter.DEBUG3)) { env.logWriter.newEntry(this, "abort()" + clusterID, LogWriter.DEBUG3); } if (true || lock != null) { if (lock.level(ta) > Lock.LEVEL_UPGRADE) { restoreShadow(); deleteShadow(); } lock.release(ta); } else { throw new NullPointerException(this + ".abort(" + ta + "): lock=" + lock + "."); } } // protected void clearContainerStates() { // WizardObjectContainer container; // DxIterator it = containers.iterator(); // while ((container=(WizardObjectContainer)it.next()) != null) { // container.clearState(); // } // }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -