use of org.apache.drill.common.AutoCloseables.Closeable in project drill by apache.
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;
}
}
use of org.apache.drill.common.AutoCloseables.Closeable in project drill by apache.
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;
}
}
use of org.apache.drill.common.AutoCloseables.Closeable in project drill by apache.
the class FunctionRegistryHolder method getAllJarsWithFunctionHolders.
/**
* Retrieves all functions (holders) associated with all the jars
* This is read operation, so several users can perform this operation at the same time.
* @return list of all functions, mapped by their sources
*/
public Map<String, List<FunctionHolder>> getAllJarsWithFunctionHolders() {
Map<String, List<FunctionHolder>> allFunctionHoldersByJar = new HashMap<>();
try (@SuppressWarnings("unused") Closeable lock = readLock.open()) {
for (String jarName : jars.keySet()) {
// Capture functionHolders here
List<FunctionHolder> drillFuncHolderList = new LinkedList<>();
Map<String, Queue<String>> functionsInJar = jars.get(jarName);
for (Map.Entry<String, Queue<String>> functionEntry : functionsInJar.entrySet()) {
String fnName = functionEntry.getKey();
Queue<String> fnSignatureList = functionEntry.getValue();
// Get all FunctionHolders (irrespective of source)
Map<String, DrillFuncHolder> functionHolders = functions.get(fnName);
// Iterate for matching entries and populate new Map
for (Map.Entry<String, DrillFuncHolder> entry : functionHolders.entrySet()) {
if (fnSignatureList.contains(entry.getKey())) {
drillFuncHolderList.add(new FunctionHolder(fnName, entry.getKey(), entry.getValue()));
}
}
}
allFunctionHoldersByJar.put(jarName, drillFuncHolderList);
}
}
return allFunctionHoldersByJar;
}
use of org.apache.drill.common.AutoCloseables.Closeable in project drill by apache.
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);
}
Aggregations