use of org.apache.drill.common.AutoCloseables.Closeable in project drill by axbaretto.
the class CustomHandlerRegistry method registerCustomHandler.
public <REQUEST, RESPONSE> void registerCustomHandler(int messageTypeId, CustomMessageHandler<REQUEST, RESPONSE> handler, Controller.CustomSerDe<REQUEST> requestSerde, Controller.CustomSerDe<RESPONSE> responseSerde) {
Preconditions.checkNotNull(handler);
Preconditions.checkNotNull(requestSerde);
Preconditions.checkNotNull(responseSerde);
try (@SuppressWarnings("unused") Closeable lock = write.open()) {
ParsingHandler<?, ?> parsingHandler = handlers.get(messageTypeId);
if (parsingHandler != null) {
throw new IllegalStateException(String.format("Only one handler can be registered for a given custom message type. You tried to register a handler for " + "the %d message type but one had already been registered.", messageTypeId));
}
parsingHandler = new ParsingHandler<REQUEST, RESPONSE>(handler, requestSerde, responseSerde);
handlers.put(messageTypeId, parsingHandler);
}
}
use of org.apache.drill.common.AutoCloseables.Closeable in project drill by axbaretto.
the class VersionedDelegatingStore method contains.
@Override
public boolean contains(final String key, final DataChangeVersion dataChangeVersion) {
try (@SuppressWarnings("unused") Closeable lock = readLock.open()) {
boolean contains = store.contains(key);
dataChangeVersion.setVersion(version);
return contains;
}
}
use of org.apache.drill.common.AutoCloseables.Closeable in project drill by axbaretto.
the class VersionedDelegatingStore method delete.
@Override
public void delete(final String key) {
try (@SuppressWarnings("unused") Closeable lock = writeLock.open()) {
store.delete(key);
version++;
}
}
use of org.apache.drill.common.AutoCloseables.Closeable in project drill by axbaretto.
the class AllocationManager method associate.
private BufferLedger associate(final BaseAllocator allocator, final boolean retain) {
allocator.assertOpen();
if (root != allocator.root) {
throw new IllegalStateException("A buffer can only be associated between two allocators that share the same root.");
}
try (@SuppressWarnings("unused") Closeable read = readLock.open()) {
final BufferLedger ledger = map.get(allocator);
if (ledger != null) {
if (retain) {
ledger.inc();
}
return ledger;
}
}
try (@SuppressWarnings("unused") Closeable write = writeLock.open()) {
// we have to recheck existing ledger since a second reader => writer could be competing with us.
final BufferLedger existingLedger = map.get(allocator);
if (existingLedger != null) {
if (retain) {
existingLedger.inc();
}
return existingLedger;
}
final BufferLedger ledger = new BufferLedger(allocator, new ReleaseListener(allocator));
if (retain) {
ledger.inc();
}
BufferLedger oldLedger = map.put(allocator, ledger);
Preconditions.checkArgument(oldLedger == null);
allocator.associateLedger(ledger);
return ledger;
}
}
use of org.apache.drill.common.AutoCloseables.Closeable in project drill by apache.
the class VersionedDelegatingStore method delete.
@Override
public void delete(final String key) {
try (@SuppressWarnings("unused") Closeable lock = writeLock.open()) {
store.delete(key);
version++;
}
}
Aggregations