private AutoCloseableLock sharedLock(byte[] key) { Preconditions.checkNotNull(key); final int hash = Arrays.hashCode(key); AutoCloseableLock lock = sharedLocks[Math.abs(hash % parallel)]; lock.open(); return lock; }
private AutoCloseableLock exclusiveLock(byte[] key) { Preconditions.checkNotNull(key); final int hash = Arrays.hashCode(key); AutoCloseableLock lock = exclusiveLocks[Math.abs(hash % parallel)]; lock.open(); return lock; }
@SuppressWarnings("resource") public AutoCloseableLock readLock() { return new AutoCloseableLock(readLock).open(); }
@Override public void close() throws Exception { try (AutoCloseableLock lock = exclusiveCloseLock.open()) { closed = true; AutoCloseables.close(Iterables.concat( collectorMap.values(), Collections.singleton(allocator) )); } }
@SuppressWarnings("resource") AutoCloseableLock writeLock() { return new AutoCloseableLock(writeLock).open(); }
@SuppressWarnings("resource") public AutoCloseableLock writeLock() { return new AutoCloseableLock(writeLock).open(); }
@SuppressWarnings("resource") AutoCloseableLock readLock() { return new AutoCloseableLock(readLock).open(); }
public void completionArrived(final FragmentStreamComplete completion) { try (AutoCloseableLock lock = sharedIncomingBatchLock.open()) { if (closed) { return; } final DataCollector collector = collector(completion.getSendingMajorFragmentId()); synchronized (collector) { collector.streamCompleted(completion.getSendingMinorFragmentId()); } } }
public void batchArrived(final IncomingDataBatch incomingBatch) throws FragmentSetupException, IOException { if(!incomingBatch.checkAcceptance(allocator.getHeadroom())){ deferredException.addException(UserException.memoryError() .message("Out of memory while receiving incoming message. Message size: %d, Current thread allocation: %d, thread limit: %d.", incomingBatch.size(), allocator.getAllocatedMemory(), allocator.getLimit()) .build(logger)); return; } // we want to make sure that we only generate local record batch reference in the case that we're not closed. // Otherwise we would leak memory. try (AutoCloseableLock lock = sharedIncomingBatchLock.open()) { if (closed) { return; } final DataCollector collector = collector(incomingBatch.getHeader().getSendingMajorFragmentId()); synchronized (collector) { try(final RawFragmentBatch newRawFragmentBatch = incomingBatch.newRawFragmentBatch(allocator)){ collector.batchArrived(incomingBatch.getHeader().getSendingMinorFragmentId(), newRawFragmentBatch); } } } }