KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > services > locks > ShExLockable


1 /*
2
3    Derby - Class org.apache.derby.iapi.services.locks.ShExLockable
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.derby.iapi.services.locks;
23
24 import org.apache.derby.iapi.services.locks.Lockable;
25 import org.apache.derby.iapi.services.locks.Latch;
26 import org.apache.derby.iapi.services.locks.VirtualLockTable;
27
28 import org.apache.derby.iapi.services.sanity.SanityManager;
29
30 import java.util.Hashtable JavaDoc;
31
32 public class ShExLockable implements Lockable
33 {
34
35     public ShExLockable()
36     {
37     }
38
39     /** @see Lockable#lockerAlwaysCompatible */
40     public boolean lockerAlwaysCompatible()
41     {
42         return true;
43     }
44
45     /** @see Lockable#requestCompatible */
46     public boolean requestCompatible(Object JavaDoc requestedQualifier,
47                                             Object JavaDoc grantedQualifier)
48     {
49         if (SanityManager.DEBUG)
50         {
51             if (!(requestedQualifier instanceof ShExQual))
52                 SanityManager.THROWASSERT(
53                 "requestedQualifier is a " +
54                 requestedQualifier.getClass().getName() +
55                 "instead of a ShExQual.");
56
57             if (!(grantedQualifier instanceof ShExQual))
58                 SanityManager.THROWASSERT(
59                 "grantedQualifier is a " +
60                 grantedQualifier.getClass().getName() +
61                 "instead of a ShExQual.");
62         }
63
64         ShExQual requested = (ShExQual) requestedQualifier;
65         ShExQual granted = (ShExQual) grantedQualifier;
66
67         return (requested.getLockState() == ShExQual.SHARED) &&
68                 (granted.getLockState() == ShExQual.SHARED);
69     }
70
71     /** @see Lockable#lockEvent */
72     public void lockEvent(Latch lockInfo)
73     {
74         if (SanityManager.DEBUG)
75         {
76             if (!(lockInfo.getQualifier() instanceof ShExQual))
77                 SanityManager.THROWASSERT("qualifier is a " + lockInfo.getQualifier().getClass().getName() +
78                 "instead of a ShExQual.");
79         }
80     }
81
82     /** @see Lockable#unlockEvent */
83     public void unlockEvent(Latch lockInfo)
84     {
85         if (SanityManager.DEBUG)
86         {
87             if (!(lockInfo.getQualifier() instanceof ShExQual))
88                 SanityManager.THROWASSERT("qualifier is a " + lockInfo.getQualifier().getClass().getName() +
89                 "instead of a ShExQual.");
90         }
91     }
92
93     /**
94      * This lockable want to participate in the Virtual LockTable
95      * when we want to print LATCH information.
96      * Any lockable object which DOES NOT want to participate should
97      * override this function.
98      */

99     public boolean lockAttributes(int flag, Hashtable JavaDoc attributes)
100     {
101         if((flag & VirtualLockTable.SHEXLOCK) == 0)
102             return false;
103         // No containerId, but need something in there so it can print
104
attributes.put(VirtualLockTable.CONTAINERID, new Long JavaDoc(-1) );
105
106         attributes.put(VirtualLockTable.LOCKNAME, this.toString() );
107
108         attributes.put(VirtualLockTable.LOCKTYPE, "ShExLockable");
109
110         return true;
111     }
112
113 }
114
Popular Tags