📄 exclusivelock.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: ExclusiveLock.java,v 1.4 2002/09/18 06:54:14 per_nyfelt Exp $
package org.ozoneDB.core;
import org.ozoneDB.DxLib.*;
import org.ozoneDB.util.LogWriter;
/**
* This class implements an exclusive lock policy. Only one transaction can hold
* this lock at one time.
*
*
* @author <a href="http://www.softwarebuero.de/">SMB</a>
* @version $Revision: 1.4 $Date: 2002/09/18 06:54:14 $
*/
public final class ExclusiveLock extends AbstractLock {
protected final static long serialVersionUID = 1;
protected final static byte subSerialVersionUID = 1;
private int level = LEVEL_NONE;
/**
* ID of the Transaction that holds this lock or null.
*/
public TransactionID locker;
public ExclusiveLock() {
reset();
}
public synchronized void reset() {
level = LEVEL_NONE;
locker = null;
}
public int tryAcquire( Transaction ta, int newLevel ) {
if (false&&ta.env.logWriter.hasTarget( LogWriter.DEBUG3 )) {
ta.env.logWriter.newEntry( this, "tryAcquire(): current:" + level + " new:" + newLevel, LogWriter.DEBUG3 );
}
synchronized (this) {
int prevLevel = level( ta );
if (locker == null || isAcquiredBy( ta )) {
locker = ta.taID();
level = newLevel > level ? newLevel : level;
return prevLevel;
} else {
return NOT_ACQUIRED;
}
}
}
public void release( Transaction ta ) {
if (false&&ta.env.logWriter.hasTarget( LogWriter.DEBUG3 )) {
ta.env.logWriter.newEntry( this, "release()", LogWriter.DEBUG3 );
}
synchronized (this) {
if (!isAcquiredBy( ta )) {
ta.env.logWriter.newEntry( this, "release(): specified transaction has not aquired lock.", LogWriter.WARN );
}
locker = null;
level = LEVEL_NONE;
}
}
public boolean isAcquiredBy( Transaction ta ) {
return locker != null ? locker.equals( ta.taID() ) : false;
}
public DxCollection lockerIDs() {
DxBag result = new DxArrayBag();
if (locker != null) {
result.add( locker );
}
return result;
}
public int level( Transaction ta ) {
if (ta != null) {
return isAcquiredBy( ta ) ? level : LEVEL_NONE;
} else {
return level;
}
}
public TransactionID getLocker() {
return locker;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -