KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > unitTests > services > T_L1


1 /*
2
3    Derby - Class org.apache.derbyTesting.unitTests.services.T_L1
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyTesting.unitTests.services;
23
24 import org.apache.derby.iapi.services.locks.*;
25
26 import org.apache.derby.iapi.services.sanity.SanityManager;
27 import java.util.Hashtable JavaDoc;
28
29 /**
30     Unit test Lockable
31     <BR>
32     A simple Lockable that allows a single locker, but that locker
33     can lock the object multiple times, standard Lockable behaviour.
34 */

35
36 class T_L1 implements Lockable {
37
38     long value = 0;
39     int count = 0;
40
41     Latch latch;
42
43     T_L1() {
44     }
45
46     /*
47     ** Lockable methods (Simple, qualifier assumed to be null).
48     */

49
50     /**
51         Qualififier is assumed to be null.
52     @see Lockable#lockEvent
53     */

54     public void lockEvent(Latch lockInfo) {
55         if (SanityManager.DEBUG)
56             SanityManager.ASSERT(lockInfo.getQualifier() == null);
57
58         latch = lockInfo;
59
60         count++;
61     }
62
63     public boolean requestCompatible(Object JavaDoc requestedQualifier, Object JavaDoc grantedQualifier) {
64         return false;
65     }
66
67     public boolean lockerAlwaysCompatible() {
68         return true;
69     }
70
71     /**
72         Qualififier is assumed to be null.
73     @see Lockable#unlockEvent
74     */

75     public void unlockEvent(Latch lockInfo) {
76         if (SanityManager.DEBUG)
77             SanityManager.ASSERT(lockInfo.getQualifier() == null);
78         
79         count--;
80         if (SanityManager.DEBUG)
81             SanityManager.ASSERT(count >= 0);
82         latch = null;
83     }
84
85     public boolean lockAttributes(int flag, Hashtable JavaDoc t)
86     {
87         return false;
88     }
89 }
90
Popular Tags