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;
}
}
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);
}
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++;
}
}
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;
}
}
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;
}
}
Aggregations