Search in sources :

Example 6 with Closeable

use of org.apache.drill.common.AutoCloseables.Closeable in project drill by apache.

the class VersionedDelegatingStore method get.

@Override
public V get(final String key, final DataChangeVersion dataChangeVersion) {
    try (@SuppressWarnings("unused") Closeable lock = readLock.open()) {
        V value = store.get(key);
        dataChangeVersion.setVersion(version);
        return value;
    }
}
Also used : Closeable(org.apache.drill.common.AutoCloseables.Closeable)

Example 7 with Closeable

use of org.apache.drill.common.AutoCloseables.Closeable in project drill by apache.

the class VersionedDelegatingStore method close.

@Override
public void close() throws Exception {
    try (@SuppressWarnings("unused") Closeable lock = writeLock.open()) {
        store.close();
        version = DataChangeVersion.NOT_AVAILABLE;
    }
}
Also used : Closeable(org.apache.drill.common.AutoCloseables.Closeable)

Example 8 with Closeable

use of org.apache.drill.common.AutoCloseables.Closeable in project drill by apache.

the class VersionedDelegatingStore method put.

@Override
public void put(final String key, final V value, final DataChangeVersion dataChangeVersion) {
    try (@SuppressWarnings("unused") Closeable lock = writeLock.open()) {
        if (dataChangeVersion.getVersion() != version) {
            throw new VersionMismatchException("Version mismatch detected", dataChangeVersion.getVersion());
        }
        store.put(key, value);
        version++;
    }
}
Also used : Closeable(org.apache.drill.common.AutoCloseables.Closeable) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException)

Example 9 with Closeable

use of org.apache.drill.common.AutoCloseables.Closeable in project drill by apache.

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 10 with Closeable

use of org.apache.drill.common.AutoCloseables.Closeable in project drill by apache.

the class FunctionRegistryHolder method addJars.

/**
 * Adds jars to the function registry.
 * If jar with the same name already exists, it and its functions will be removed.
 * Then jar will be added to {@link #jars}
 * and each function will be added using {@link #addFunctions(Map, List)}.
 * Registry version is updated with passed version if all jars were added successfully.
 * This is write operation, so one user at a time can call perform such action,
 * others will wait till first user completes his action.
 *
 * @param newJars jars and list of their function holders, each contains function name, signature and holder
 */
public void addJars(Map<String, List<FunctionHolder>> newJars, int version) {
    try (@SuppressWarnings("unused") Closeable lock = writeLock.open()) {
        for (Map.Entry<String, List<FunctionHolder>> newJar : newJars.entrySet()) {
            String jarName = newJar.getKey();
            removeAllByJar(jarName);
            Map<String, Queue<String>> jar = new ConcurrentHashMap<>();
            jars.put(jarName, jar);
            addFunctions(jar, newJar.getValue());
        }
        this.version = version;
    }
}
Also used : Closeable(org.apache.drill.common.AutoCloseables.Closeable) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) Queue(java.util.Queue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

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