1 8 9 package com.sleepycat.je.txn; 10 11 16 public class LockType { 17 18 22 public static final LockType READ 23 = new LockType(0, false, "READ"); 24 public static final LockType WRITE 25 = new LockType(1, true, "WRITE"); 26 public static final LockType RANGE_READ 27 = new LockType(2, false, "RANGE_READ"); 28 public static final LockType RANGE_WRITE 29 = new LockType(3, true, "RANGE_WRITE"); 30 public static final LockType RANGE_INSERT 31 = new LockType(4, false, "RANGE_INSERT"); 32 33 37 public static final LockType NONE 38 = new LockType(5, false, "NONE"); 39 40 44 public static final LockType RESTART 45 = new LockType(6, false, "RESTART"); 46 47 53 static { 54 RANGE_READ.setCausesRestart(); 55 RANGE_WRITE.setCausesRestart(); 56 } 57 58 62 private static LockConflict[][] conflictMatrix = { 63 { LockConflict.ALLOW, LockConflict.BLOCK, LockConflict.ALLOW, LockConflict.BLOCK, LockConflict.ALLOW, }, 70 { LockConflict.BLOCK, LockConflict.BLOCK, LockConflict.BLOCK, LockConflict.BLOCK, LockConflict.ALLOW, }, 77 { LockConflict.ALLOW, LockConflict.BLOCK, LockConflict.ALLOW, LockConflict.BLOCK, LockConflict.BLOCK, }, 84 { LockConflict.BLOCK, LockConflict.BLOCK, LockConflict.BLOCK, LockConflict.BLOCK, LockConflict.BLOCK, }, 91 { LockConflict.ALLOW, LockConflict.ALLOW, LockConflict.RESTART, LockConflict.RESTART, LockConflict.ALLOW, }, 98 }; 99 100 104 private static LockUpgrade[][] upgradeMatrix = { 105 { LockUpgrade.EXISTING, LockUpgrade.WRITE_PROMOTE, LockUpgrade.RANGE_READ_IMMED, LockUpgrade.RANGE_WRITE_PROMOTE, LockUpgrade.ILLEGAL, }, 112 { LockUpgrade.EXISTING, LockUpgrade.EXISTING, LockUpgrade.RANGE_WRITE_IMMED, LockUpgrade.RANGE_WRITE_IMMED, LockUpgrade.ILLEGAL, }, 119 { LockUpgrade.EXISTING, LockUpgrade.RANGE_WRITE_PROMOTE, LockUpgrade.EXISTING, LockUpgrade.RANGE_WRITE_PROMOTE, LockUpgrade.ILLEGAL, }, 126 { LockUpgrade.EXISTING, LockUpgrade.EXISTING, LockUpgrade.EXISTING, LockUpgrade.EXISTING, LockUpgrade.ILLEGAL, }, 133 { LockUpgrade.ILLEGAL, LockUpgrade.ILLEGAL, LockUpgrade.ILLEGAL, LockUpgrade.ILLEGAL, LockUpgrade.EXISTING, }, 140 }; 141 142 private int index; 143 private boolean write; 144 private String name; 145 private boolean causesRestart; 146 147 150 private LockType(int index, boolean write, String name) { 151 this.index = index; 152 this.write = write; 153 this.name = name; 154 } 155 156 161 public final boolean isWriteLock() { 162 return write; 163 } 164 165 169 private void setCausesRestart() { 170 causesRestart = true; 171 } 172 173 177 final boolean getCausesRestart() { 178 return causesRestart; 179 } 180 181 185 LockConflict getConflict(LockType requestedType) { 186 return conflictMatrix[index][requestedType.index]; 187 } 188 189 196 LockUpgrade getUpgrade(LockType requestedType) { 197 LockUpgrade upgrade = upgradeMatrix[index][requestedType.index]; 198 assert !upgrade.getIllegal() : toString() + " to " + requestedType; 199 return upgrade; 200 } 201 202 public String toString() { 203 return name; 204 } 205 } 206 | Popular Tags |