use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project druid by druid-io.
the class CuratorInventoryManager method stop.
@LifecycleStop
public void stop() throws IOException {
synchronized (lock) {
if (childrenCache == null) {
return;
}
// This close() call actually calls shutdownNow() on the executor registered with the Cache object...
childrenCache.close();
childrenCache = null;
}
Closer closer = Closer.create();
for (ContainerHolder containerHolder : containers.values()) {
closer.register(containerHolder.getCache());
}
try {
closer.close();
} finally {
pathChildrenCacheExecutor.shutdown();
}
}
use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project alluxio by Alluxio.
the class CommandLineJob method run.
@Override
public boolean run() {
try {
String outputPath = getJobConf().getOutputFilePath();
LOG.info("Exec {} output to {}", mCommand, outputPath);
Process p = java.lang.Runtime.getRuntime().exec(mCommand);
String line;
Closer closer = Closer.create();
try {
BufferedReader bri = closer.register(new BufferedReader(new InputStreamReader(p.getInputStream())));
BufferedReader bre = closer.register(new BufferedReader(new InputStreamReader(p.getErrorStream())));
File file = new File(outputPath);
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = closer.register(new BufferedWriter(fw));
while ((line = bri.readLine()) != null) {
bw.write(line + "\n");
}
while ((line = bre.readLine()) != null) {
bw.write(line + "\n");
}
bw.flush();
} finally {
closer.close();
}
p.waitFor();
LOG.info("Exec {} output to {} done.", mCommand, outputPath);
} catch (IOException | InterruptedException e) {
LOG.error(e.getMessage());
return false;
}
return true;
}
use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project alluxio by Alluxio.
the class UnderFileSystemBlockInStream method create.
/**
* Creates an instance of {@link UnderFileSystemBlockInStream}.
* This method keeps polling the block worker until the block is cached to Alluxio or
* it successfully acquires a UFS read token with a timeout.
* (1) If the block is cached to Alluxio after polling, it returns {@link BufferedBlockInStream}
* to read the block from Alluxio storage.
* (2) If a UFS read token is acquired after polling, it returns
* {@link UnderFileSystemBlockInStream} to read the block from an Alluxio worker that reads
* the block from UFS.
* (3) If the polling times out, an {@link IOException} with cause
* {@link alluxio.exception.UfsBlockAccessTokenUnavailableException} is thrown.
*
* @param context the file system context
* @param ufsPath the UFS path
* @param blockId the block ID
* @param blockSize the block size
* @param blockStart the start position of the block in the UFS file
* @param workerNetAddress the worker network address
* @param options the in stream options
* @return the {@link UnderFileSystemBlockInStream} instance or the {@link BufferedBlockOutStream}
* that reads from Alluxio directly
* @throws IOException if it fails to create {@link UnderFileSystemBlockInStream}
*/
public static BufferedBlockInStream create(FileSystemContext context, String ufsPath, long blockId, long blockSize, long blockStart, WorkerNetAddress workerNetAddress, InStreamOptions options) throws IOException {
Closer closer = Closer.create();
try {
BlockWorkerClient blockWorkerClient = closer.register(context.createBlockWorkerClient(workerNetAddress));
LockBlockOptions lockBlockOptions = LockBlockOptions.defaults().setUfsPath(ufsPath).setOffset(blockStart).setBlockSize(blockSize).setMaxUfsReadConcurrency(options.getMaxUfsReadConcurrency());
LockBlockResult result = closer.register(blockWorkerClient.lockUfsBlock(blockId, lockBlockOptions)).getResult();
if (result.getLockBlockStatus().blockInAlluxio()) {
boolean local = blockWorkerClient.getDataServerAddress().getHostName().equals(NetworkAddressUtils.getLocalHostName());
if (local) {
LocalFileBlockReader reader = closer.register(new LocalFileBlockReader(result.getBlockPath()));
return LocalBlockInStream.createWithLockedBlock(blockWorkerClient, blockId, blockSize, reader, closer, options);
} else {
return RemoteBlockInStream.createWithLockedBlock(context, blockWorkerClient, blockId, blockSize, result.getLockId(), closer, options);
}
}
Preconditions.checkState(result.getLockBlockStatus().ufsTokenAcquired());
return new UnderFileSystemBlockInStream(context, blockId, blockSize, blockWorkerClient, closer, options);
} catch (AlluxioException | IOException e) {
CommonUtils.closeQuitely(closer);
throw CommonUtils.castToIOException(e);
}
}
use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project alluxio by Alluxio.
the class BlockOutStream method createRemoteBlockOutStream.
/**
* Creates a new remote block output stream.
*
* @param blockId the block id
* @param blockSize the block size
* @param workerNetAddress the worker network address
* @param context the file system context
* @param options the options
* @throws IOException if an I/O error occurs
* @return the {@link BlockOutStream} instance created
*/
public static BlockOutStream createRemoteBlockOutStream(long blockId, long blockSize, WorkerNetAddress workerNetAddress, FileSystemContext context, OutStreamOptions options) throws IOException {
Closer closer = Closer.create();
try {
BlockWorkerClient client = closer.register(context.createBlockWorkerClient(workerNetAddress));
PacketOutStream outStream = PacketOutStream.createNettyPacketOutStream(context, client.getDataServerAddress(), client.getSessionId(), blockId, blockSize, options.getWriteTier(), Protocol.RequestType.ALLUXIO_BLOCK);
closer.register(outStream);
return new BlockOutStream(outStream, blockId, blockSize, client, options);
} catch (IOException e) {
closer.close();
throw e;
}
}
use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project alluxio by Alluxio.
the class CpCommandTest method equals.
private boolean equals(AlluxioURI file1, AlluxioURI file2) throws Exception {
try (Closer closer = Closer.create()) {
OpenFileOptions openFileOptions = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE);
FileInStream is1 = closer.register(mFileSystem.openFile(file1, openFileOptions));
FileInStream is2 = closer.register(mFileSystem.openFile(file2, openFileOptions));
return IOUtils.contentEquals(is1, is2);
}
}
Aggregations