01: package org.apache.ojb.odmg.locking;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import java.util.Hashtable;
19:
20: class ObjectLocks {
21: private LockEntry writer;
22:
23: private Hashtable readers;
24:
25: private long m_youngestReader = 0;
26:
27: public LockEntry getWriter() {
28: return writer;
29: }
30:
31: public void setWriter(LockEntry writer) {
32: this .writer = writer;
33: }
34:
35: public Hashtable getReaders() {
36: return readers;
37: }
38:
39: public void addReader(LockEntry reader) {
40: /**
41: * MBAIRD:
42: * we want to track the youngest reader so we can remove all readers at timeout
43: * if the youngestreader is older than the timeoutperiod.
44: */
45: if ((reader.getTimestamp() < m_youngestReader)
46: || (m_youngestReader == 0)) {
47: m_youngestReader = reader.getTimestamp();
48: }
49: this .readers.put(reader.getTransactionId(), reader);
50: }
51:
52: public long getYoungestReader() {
53: return m_youngestReader;
54: }
55:
56: public LockEntry getReader(String transactionId) {
57: return (LockEntry) this .readers.get(transactionId);
58: }
59:
60: ObjectLocks() {
61: writer = null;
62: readers = new Hashtable();
63: }
64:
65: }
|