01: // You can redistribute this software and/or modify it under the terms of
02: // the Ozone Core License version 1 published by ozone-db.org.
03: //
04: // The original code and portions created by SMB are
05: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
06: //
07: // $Id: Lock.java,v 1.2 2002/06/08 00:49:38 mediumnet Exp $
08:
09: package org.ozoneDB.core;
10:
11: import java.io.*;
12: import org.ozoneDB.DxLib.*;
13: import org.ozoneDB.*;
14:
15: /**
16: * Locks are created by the {@link TransactionManager} and used by the core
17: * to manage concurrent access to the same containers/objects. There are several
18: * Lock implementations that provide different policies.
19: *
20: *
21: * @author <a href="http://www.softwarebuero.de/">SMB</a>
22: * @version $Revision: 1.2 $Date: 2002/06/08 00:49:38 $
23: */
24: public interface Lock extends Serializable {
25:
26: public final static int NOT_ACQUIRED = -1;
27: public final static int LEVEL_NONE = 0;
28: public final static int LEVEL_READ = 1;
29: public final static int LEVEL_UPGRADE = 2;
30: public final static int LEVEL_WRITE = 4;
31: // levels >= this are not valid
32: public final static int LEVEL_MAX = 5;
33:
34: public void reset();
35:
36: /**
37: * Check for deadlock and throw an exception if a deadlock is detected.
38: * Although the transactions waits for locks and so seems also to be
39: * be a good place for deadlock detection, we do it here because each
40: * Lock implementations should hide the deadlock detection logic.
41: */
42: public void checkDeadlock(Transaction ta) throws TransactionError;
43:
44: /**
45: * Try to aquire this lock. This method returns the previous level of the
46: * specified transaction, if the lock was sucessfully acquired. Otherwise
47: * it returns NOT_ACQUIRED.
48: *
49: *
50: * @return The previous level for the given transaction or NOT_ACQUIRED.
51: */
52: public int tryAcquire(Transaction ta, int level);
53:
54: /**
55: * Release the previously aquired lock.
56: */
57: public void release(Transaction ta);
58:
59: public boolean isAcquiredBy(Transaction ta);
60:
61: /**
62: * Return all transactions that currently hold this lock.
63: */
64: public DxCollection lockerIDs();
65:
66: /**
67: * Returns the lock level for the specified transaction. If ta is null,
68: * then we do not check ta against the transaction that has acquired this
69: * lock.
70: *
71: *
72: * @param ta The transaction that has acquired the lock or null.
73: * @return Lock level for ta if ta has aquired the lock or ta is null. LEVEL_NONE
74: * otherwise.
75: */
76: public int level(Transaction ta);
77:
78: }
|