Search in sources :

Example 11 with Closeable

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

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, long 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 = Maps.newConcurrentMap();
            jars.put(jarName, jar);
            addFunctions(jar, newJar.getValue());
        }
        this.version = version;
    }
}
Also used : Closeable(org.apache.drill.common.AutoCloseables.Closeable) List(java.util.List) Map(java.util.Map) Queue(java.util.Queue)

Example 12 with Closeable

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

the class CustomHandlerRegistry method handle.

public Response handle(CustomMessage message, DrillBuf dBody) throws RpcException {
    final ParsingHandler<?, ?> handler;
    try (@SuppressWarnings("unused") Closeable lock = read.open()) {
        handler = handlers.get(message.getType());
    }
    if (handler == null) {
        throw new UserRpcException(endpoint, "Unable to handle message.", new IllegalStateException(String.format("Unable to handle message. The message type provided [%d] did not have a registered handler.", message.getType())));
    }
    final CustomResponse<?> customResponse = handler.onMessage(message.getMessage(), dBody);
    @SuppressWarnings("unchecked") final CustomMessage responseMessage = CustomMessage.newBuilder().setMessage(ByteString.copyFrom(((Controller.CustomSerDe<Object>) handler.getResponseSerDe()).serializeToSend(customResponse.getMessage()))).setType(message.getType()).build();
    // make sure we don't pass in a null array.
    final ByteBuf[] dBodies = customResponse.getBodies() == null ? new DrillBuf[0] : customResponse.getBodies();
    return new Response(RpcType.RESP_CUSTOM, responseMessage, dBodies);
}
Also used : Response(org.apache.drill.exec.rpc.Response) CustomResponse(org.apache.drill.exec.rpc.control.Controller.CustomResponse) UserRpcException(org.apache.drill.exec.rpc.UserRpcException) Closeable(org.apache.drill.common.AutoCloseables.Closeable) CustomMessage(org.apache.drill.exec.proto.BitControl.CustomMessage) ByteBuf(io.netty.buffer.ByteBuf)

Example 13 with Closeable

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

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

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

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

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

the class VersionedDelegatingStore method close.

@Override
public void close() throws Exception {
    try (@SuppressWarnings("unused") Closeable lock = writeLock.open()) {
        store.close();
        version = -1;
    }
}
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