1 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 ; 31 32 public class ShExLockable implements Lockable 33 { 34 35 public ShExLockable() 36 { 37 } 38 39 40 public boolean lockerAlwaysCompatible() 41 { 42 return true; 43 } 44 45 46 public boolean requestCompatible(Object requestedQualifier, 47 Object 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 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 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 99 public boolean lockAttributes(int flag, Hashtable attributes) 100 { 101 if((flag & VirtualLockTable.SHEXLOCK) == 0) 102 return false; 103 attributes.put(VirtualLockTable.CONTAINERID, new Long (-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 |