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