001: /*
002:
003: Derby - Class org.apache.derby.iapi.services.locks.ShExLockable
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.iapi.services.locks;
023:
024: import org.apache.derby.iapi.services.locks.Lockable;
025: import org.apache.derby.iapi.services.locks.Latch;
026: import org.apache.derby.iapi.services.locks.VirtualLockTable;
027:
028: import org.apache.derby.iapi.services.sanity.SanityManager;
029:
030: import java.util.Hashtable;
031:
032: public class ShExLockable implements Lockable {
033:
034: public ShExLockable() {
035: }
036:
037: /** @see Lockable#lockerAlwaysCompatible */
038: public boolean lockerAlwaysCompatible() {
039: return true;
040: }
041:
042: /** @see Lockable#requestCompatible */
043: public boolean requestCompatible(Object requestedQualifier,
044: Object grantedQualifier) {
045: if (SanityManager.DEBUG) {
046: if (!(requestedQualifier instanceof ShExQual))
047: SanityManager.THROWASSERT("requestedQualifier is a "
048: + requestedQualifier.getClass().getName()
049: + "instead of a ShExQual.");
050:
051: if (!(grantedQualifier instanceof ShExQual))
052: SanityManager.THROWASSERT("grantedQualifier is a "
053: + grantedQualifier.getClass().getName()
054: + "instead of a ShExQual.");
055: }
056:
057: ShExQual requested = (ShExQual) requestedQualifier;
058: ShExQual granted = (ShExQual) grantedQualifier;
059:
060: return (requested.getLockState() == ShExQual.SHARED)
061: && (granted.getLockState() == ShExQual.SHARED);
062: }
063:
064: /** @see Lockable#lockEvent */
065: public void lockEvent(Latch lockInfo) {
066: if (SanityManager.DEBUG) {
067: if (!(lockInfo.getQualifier() instanceof ShExQual))
068: SanityManager.THROWASSERT("qualifier is a "
069: + lockInfo.getQualifier().getClass().getName()
070: + "instead of a ShExQual.");
071: }
072: }
073:
074: /** @see Lockable#unlockEvent */
075: public void unlockEvent(Latch lockInfo) {
076: if (SanityManager.DEBUG) {
077: if (!(lockInfo.getQualifier() instanceof ShExQual))
078: SanityManager.THROWASSERT("qualifier is a "
079: + lockInfo.getQualifier().getClass().getName()
080: + "instead of a ShExQual.");
081: }
082: }
083:
084: /**
085: * This lockable want to participate in the Virtual LockTable
086: * when we want to print LATCH information.
087: * Any lockable object which DOES NOT want to participate should
088: * override this function.
089: */
090: public boolean lockAttributes(int flag, Hashtable attributes) {
091: if ((flag & VirtualLockTable.SHEXLOCK) == 0)
092: return false;
093: // No containerId, but need something in there so it can print
094: attributes.put(VirtualLockTable.CONTAINERID, new Long(-1));
095:
096: attributes.put(VirtualLockTable.LOCKNAME, this .toString());
097:
098: attributes.put(VirtualLockTable.LOCKTYPE, "ShExLockable");
099:
100: return true;
101: }
102:
103: }
|