KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > Lock


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Core License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: Lock.java,v 1.4 2002/09/18 06:54:15 per_nyfelt Exp $
8

9 package org.ozoneDB.core;
10
11 import org.ozoneDB.DxLib.DxCollection;
12
13 import java.io.Serializable JavaDoc;
14
15
16 /**
17  * Locks are created by the {@link TransactionManager} and used by the core
18  * to manage concurrent access to the same containers/objects. There are several
19  * Lock implementations that provide different policies.
20  *
21  *
22  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
23  * @version $Revision: 1.4 $Date: 2002/09/18 06:54:15 $
24  */

25 public interface Lock extends Serializable JavaDoc {
26
27     public final static int NOT_ACQUIRED = -1;
28     public final static int LEVEL_NONE = 0;
29     public final static int LEVEL_READ = 1;
30     public final static int LEVEL_UPGRADE = 2;
31     public final static int LEVEL_WRITE = 4;
32     // levels >= this are not valid
33
public final static int LEVEL_MAX = 5;
34
35
36     public void reset();
37
38
39     /**
40      * Check for deadlock and throw an exception if a deadlock is detected.
41      * Although the transactions waits for locks and so seems also to be
42      * be a good place for deadlock detection, we do it here because each
43      * Lock implementations should hide the deadlock detection logic.
44      */

45     public void checkDeadlock( Transaction ta ) throws TransactionError;
46
47     /**
48      * Try to aquire this lock. This method returns the previous level of the
49      * specified transaction, if the lock was sucessfully acquired. Otherwise
50      * it returns NOT_ACQUIRED.
51      *
52      *
53      * @return The previous level for the given transaction or NOT_ACQUIRED.
54      */

55     public int tryAcquire( Transaction ta, int level );
56
57
58     /**
59      * Release the previously aquired lock.
60      */

61     public void release( Transaction ta );
62
63
64     public boolean isAcquiredBy( Transaction ta );
65
66
67     /**
68      * Return all transactions that currently hold this lock.
69      */

70     public DxCollection lockerIDs();
71
72     /**
73      * Returns the lock level for the specified transaction. If ta is null,
74      * then we do not check ta against the transaction that has acquired this
75      * lock.
76      *
77      *
78      * @param ta The transaction that has acquired the lock or null.
79      * @return Lock level for ta if ta has aquired the lock or ta is null. LEVEL_NONE
80      * otherwise.
81      */

82     public int level( Transaction ta );
83
84 }
85
Popular Tags