@Override public boolean tryLock() { if (entry == -1) { entry = qlock.addEntry(new ParsedLock(this.lockType(), this.userData).getLockData()); log.info("Added lock entry {} userData {} lockTpye {}", entry, new String(this.userData, UTF_8), lockType()); } SortedMap<Long,byte[]> entries = qlock.getEarlierEntries(entry); for (Entry<Long,byte[]> entry : entries.entrySet()) { ParsedLock parsed = new ParsedLock(entry.getValue()); if (entry.getKey().equals(this.entry)) return true; if (parsed.type == LockType.WRITE) return false; } throw new IllegalStateException("Did not find our own lock in the queue: " + this.entry + " userData " + new String(this.userData, UTF_8) + " lockType " + lockType()); }
@Override public void unlock() { if (entry == -1) return; log.debug("Removing lock entry {} userData {} lockType {}", entry, new String(this.userData, UTF_8), lockType()); qlock.removeEntry(entry); entry = -1; }
@Override public boolean tryLock() { if (entry == -1) { entry = qlock.addEntry(new ParsedLock(this.lockType(), this.userData).getLockData()); log.info("Added lock entry " + entry + " userData " + new String(this.userData, UTF_8) + " lockType " + lockType()); } SortedMap<Long,byte[]> entries = qlock.getEarlierEntries(entry); for (Entry<Long,byte[]> entry : entries.entrySet()) { ParsedLock parsed = new ParsedLock(entry.getValue()); if (entry.getKey().equals(this.entry)) return true; if (parsed.type == LockType.WRITE) return false; } throw new IllegalStateException("Did not find our own lock in the queue: " + this.entry + " userData " + new String(this.userData, UTF_8) + " lockType " + lockType()); }
@Override public boolean tryLock() { if (entry == -1) { entry = qlock.addEntry(new ParsedLock(this.lockType(), this.userData).getLockData()); log.info("Added lock entry " + entry + " userData " + new String(this.userData, UTF_8) + " lockType " + lockType()); } SortedMap<Long,byte[]> entries = qlock.getEarlierEntries(entry); Iterator<Entry<Long,byte[]>> iterator = entries.entrySet().iterator(); if (!iterator.hasNext()) throw new IllegalStateException("Did not find our own lock in the queue: " + this.entry + " userData " + new String(this.userData, UTF_8) + " lockType " + lockType()); if (iterator.next().getKey().equals(entry)) return true; return false; } }
static public Lock recoverLock(QueueLock qlock, byte[] data) { SortedMap<Long,byte[]> entries = qlock.getEarlierEntries(Long.MAX_VALUE); for (Entry<Long,byte[]> entry : entries.entrySet()) { ParsedLock parsed = new ParsedLock(entry.getValue()); if (Arrays.equals(data, parsed.getUserData())) { switch (parsed.getType()) { case READ: return new ReadLock(qlock, parsed.getUserData(), entry.getKey()); case WRITE: return new WriteLock(qlock, parsed.getUserData(), entry.getKey()); } } } return null; }
@Override public void unlock() { if (entry == -1) return; log.debug("Removing lock entry " + entry + " userData " + new String(this.userData, UTF_8) + " lockType " + lockType()); qlock.removeEntry(entry); entry = -1; }
@Override public boolean tryLock() { if (entry == -1) { entry = qlock.addEntry(new ParsedLock(this.lockType(), this.userData).getLockData()); log.info("Added lock entry {} userData {} lockType {}", entry, new String(this.userData, UTF_8), lockType()); } SortedMap<Long,byte[]> entries = qlock.getEarlierEntries(entry); Iterator<Entry<Long,byte[]>> iterator = entries.entrySet().iterator(); if (!iterator.hasNext()) throw new IllegalStateException("Did not find our own lock in the queue: " + this.entry + " userData " + new String(this.userData, UTF_8) + " lockType " + lockType()); return iterator.next().getKey().equals(entry); } }
public static Lock recoverLock(QueueLock qlock, byte[] data) { SortedMap<Long,byte[]> entries = qlock.getEarlierEntries(Long.MAX_VALUE); for (Entry<Long,byte[]> entry : entries.entrySet()) { ParsedLock parsed = new ParsedLock(entry.getValue()); if (Arrays.equals(data, parsed.getUserData())) { switch (parsed.getType()) { case READ: return new ReadLock(qlock, parsed.getUserData(), entry.getKey()); case WRITE: return new WriteLock(qlock, parsed.getUserData(), entry.getKey()); } } } return null; }