Search in sources :

Example 1 with Closeable

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);
    }
}
Also used : Closeable(org.apache.drill.common.AutoCloseables.Closeable)

Example 2 with Closeable

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;
    }
}
Also used : Closeable(org.apache.drill.common.AutoCloseables.Closeable)

Example 3 with Closeable

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++;
    }
}
Also used : Closeable(org.apache.drill.common.AutoCloseables.Closeable)

Example 4 with Closeable

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;
    }
}
Also used : Closeable(org.apache.drill.common.AutoCloseables.Closeable)

Example 5 with Closeable

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++;
    }
}
Also used : Closeable(org.apache.drill.common.AutoCloseables.Closeable)

Aggregations

Closeable (org.apache.drill.common.AutoCloseables.Closeable)19 List (java.util.List)3 Map (java.util.Map)3 Queue (java.util.Queue)3 ByteBuf (io.netty.buffer.ByteBuf)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 VersionMismatchException (org.apache.drill.exec.exception.VersionMismatchException)2 CustomMessage (org.apache.drill.exec.proto.BitControl.CustomMessage)2 Response (org.apache.drill.exec.rpc.Response)2 UserRpcException (org.apache.drill.exec.rpc.UserRpcException)2 CustomResponse (org.apache.drill.exec.rpc.control.Controller.CustomResponse)2 DrillFuncHolder (org.apache.drill.exec.expr.fn.DrillFuncHolder)1