Lock.java :  » Database-DBMS » Ozone-1.1 » org » ozoneDB » core » Java Open Source

Java Open Source » Database DBMS » Ozone 1.1 
Ozone 1.1 » org » ozoneDB » core » Lock.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: Lock.java,v 1.2 2002/06/08 00:49:38 mediumnet Exp $

package org.ozoneDB.core;

import java.io.*;
import org.ozoneDB.DxLib.*;
import org.ozoneDB.*;


/**
 * Locks are created by the {@link TransactionManager} and used by the core
 * to manage concurrent access to the same containers/objects. There are several
 * Lock implementations that provide different policies.
 * 
 * 
 * @author <a href="http://www.softwarebuero.de/">SMB</a>
 * @version $Revision: 1.2 $Date: 2002/06/08 00:49:38 $
 */
public interface Lock extends Serializable {
    
    public final static int NOT_ACQUIRED = -1;
    public final static int LEVEL_NONE = 0;
    public final static int LEVEL_READ = 1;
    public final static int LEVEL_UPGRADE = 2;
    public final static int LEVEL_WRITE = 4;
    // levels >= this are not valid
    public final static int LEVEL_MAX = 5;
    
    
    public void reset();
    
    
    /**
     * Check for deadlock and throw an exception if a deadlock is detected.
     * Although the transactions waits for locks and so seems also to be
     * be a good place for deadlock detection, we do it here because each
     * Lock implementations should hide the deadlock detection logic.
     */
    public void checkDeadlock( Transaction ta ) throws TransactionError;
    
    /**
     * Try to aquire this lock. This method returns the previous level of the
     * specified transaction, if the lock was sucessfully acquired. Otherwise
     * it returns NOT_ACQUIRED.
     * 
     * 
     * @return The previous level for the given transaction or NOT_ACQUIRED.
     */
    public int tryAcquire( Transaction ta, int level );
    
    
    /**
     * Release the previously aquired lock.
     */
    public void release( Transaction ta );
    
    
    public boolean isAcquiredBy( Transaction ta );
    
    
    /**
     * Return all transactions that currently hold this lock.
     */
    public DxCollection lockerIDs();
    
    /**
     * Returns the lock level for the specified transaction. If ta is null,
     * then we do not check ta against the transaction that has acquired this
     * lock.
     * 
     * 
     * @param ta The transaction that has acquired the lock or null.
     * @return Lock level for ta if ta has aquired the lock or ta is null. LEVEL_NONE
     * otherwise.
     */
    public int level( Transaction ta );
    
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.