| 226 | } |
| 227 | |
| 228 | Lock lock(LockLevel lockLevel, List<String> path, boolean reuseCurrentLock) { |
| 229 | if (myLock != null && !reuseCurrentLock) { |
| 230 | // I'm already locked. no need to go any further |
| 231 | return null; |
| 232 | } |
| 233 | if (lockLevel == level) { |
| 234 | // lock is supposed to be acquired at this level |
| 235 | if (myLock != null && reuseCurrentLock) { |
| 236 | // I am already locked, and I want to be re-used |
| 237 | refCount++; |
| 238 | return myLock; |
| 239 | } |
| 240 | // If I am locked or any of my children or grandchildren are locked |
| 241 | // it is not possible to acquire a lock |
| 242 | if (isLocked()) return null; |
| 243 | refCount++; |
| 244 | return myLock = new LockImpl(this); |
| 245 | } else { |
| 246 | String childName = path.get(level.getHeight()); |
| 247 | Node child = children.get(childName); |
| 248 | if (child == null) |
| 249 | children.put(childName, child = new Node(childName, level.getChild(), this)); |
| 250 | return child.lock(lockLevel, path, false); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | boolean validateSubpath(int lockLevel, List<String> path) { |
| 255 | return level.getHeight() <= lockLevel |