本文整理了Java中org.apache.flink.util.IOUtils.closeQuietly()
方法的一些代码示例,展示了IOUtils.closeQuietly()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.closeQuietly()
方法的具体详情如下:
包路径:org.apache.flink.util.IOUtils
类名称:IOUtils
方法名:closeQuietly
[英]Closes the given AutoCloseable.
Important: This method is expected to never throw an exception.
[中]关闭给定的自动关闭。
重要提示:此方法预计永远不会引发异常。
代码示例来源:origin: apache/flink
@Override
public void close() {
IOUtils.closeQuietly(currentOut);
}
}
代码示例来源:origin: apache/flink
void dispose() {
// we can suppress exceptions here, because we do not rely on close() to
// flush or persist any data
IOUtils.closeQuietly(currentPartStream);
}
代码示例来源:origin: apache/flink
public void closeStream() {
if (!closed) {
IOUtils.closeQuietly(stream);
closed = true;
}
}
代码示例来源:origin: apache/flink
/**
* Closes all elements in the iterable with closeQuietly().
*/
public static void closeAllQuietly(Iterable<? extends AutoCloseable> closeables) {
if (null != closeables) {
for (AutoCloseable closeable : closeables) {
closeQuietly(closeable);
}
}
}
代码示例来源:origin: apache/flink
@Override
public void close() {
IOUtils.closeQuietly(iterator);
}
}
代码示例来源:origin: apache/flink
private static void closeFromRegistry(Closeable closeable, CloseableRegistry registry) {
if (registry.unregisterCloseable(closeable)) {
IOUtils.closeQuietly(closeable);
}
}
代码示例来源:origin: apache/flink
/**
* Closes the safety net for a thread. This closes all remaining unclosed streams that were opened
* by safety-net-guarded file systems. After this method was called, no streams can be opened any more
* from any FileSystem instance that was obtained while the thread was guarded by the safety net.
*
* <p>This method should be called at the very end of a guarded thread.
*/
@Internal
public static void closeSafetyNetAndGuardedResourcesForThread() {
SafetyNetCloseableRegistry registry = REGISTRIES.get();
if (null != registry) {
REGISTRIES.remove();
IOUtils.closeQuietly(registry);
}
}
代码示例来源:origin: apache/flink
IOUtils.closeQuietly(writeBatchWrapper);
IOUtils.closeQuietly(defaultColumnFamily);
IOUtils.closeQuietly(columnMetaData.f0);
IOUtils.closeQuietly(db);
IOUtils.closeQuietly(columnOptions);
IOUtils.closeQuietly(dbOptions);
IOUtils.closeQuietly(writeOptions);
kvStateInformation.clear();
代码示例来源:origin: apache/flink
@Override
public void close() {
IOUtils.closeQuietly(currentSubIterator);
currentSubIterator = null;
IOUtils.closeAllQuietly(heap);
heap.clear();
}
}
代码示例来源:origin: apache/flink
@Override
public void close() throws RocksDBException {
if (batch.count() != 0) {
flush();
}
IOUtils.closeQuietly(batch);
}
}
代码示例来源:origin: apache/flink
private PriorityQueue<RocksSingleStateIterator> buildIteratorHeap(
List<Tuple2<RocksIteratorWrapper, Integer>> kvStateIterators) {
Comparator<RocksSingleStateIterator> iteratorComparator = COMPARATORS.get(keyGroupPrefixByteCount - 1);
PriorityQueue<RocksSingleStateIterator> iteratorPriorityQueue =
new PriorityQueue<>(kvStateIterators.size(), iteratorComparator);
for (Tuple2<RocksIteratorWrapper, Integer> rocksIteratorWithKVStateId : kvStateIterators) {
final RocksIteratorWrapper rocksIterator = rocksIteratorWithKVStateId.f0;
rocksIterator.seekToFirst();
if (rocksIterator.isValid()) {
iteratorPriorityQueue.offer(
new RocksSingleStateIterator(rocksIterator, rocksIteratorWithKVStateId.f1));
} else {
IOUtils.closeQuietly(rocksIterator);
}
}
return iteratorPriorityQueue;
}
代码示例来源:origin: apache/flink
/**
* Registers a {@link Closeable} with the registry. In case the registry is already closed, this method throws an
* {@link IllegalStateException} and closes the passed {@link Closeable}.
*
* @param closeable Closeable tor register
* @throws IOException exception when the registry was closed before
*/
public final void registerCloseable(C closeable) throws IOException {
if (null == closeable) {
return;
}
synchronized (getSynchronizationLock()) {
if (!closed) {
doRegister(closeable, closeableToRef);
return;
}
}
IOUtils.closeQuietly(closeable);
throw new IOException("Cannot register Closeable, registry is already closed. Closing argument.");
}
代码示例来源:origin: apache/flink
public static void readAllResultLines(
List<String> target,
String resultPath,
String[] excludePrefixes,
boolean inOrderOfFiles) throws IOException {
checkArgument(resultPath != null, "resultPath cannot be be null");
final BufferedReader[] readers = getResultReader(resultPath, excludePrefixes, inOrderOfFiles);
try {
for (BufferedReader reader : readers) {
String s;
while ((s = reader.readLine()) != null) {
target.add(s);
}
}
}
finally {
for (BufferedReader reader : readers) {
org.apache.flink.util.IOUtils.closeQuietly(reader);
}
}
}
代码示例来源:origin: apache/flink
@Override
public TransportClient createClient(Map<String, String> clientConfig) {
Settings settings = Settings.builder().put(clientConfig)
.put(NetworkModule.HTTP_TYPE_KEY, Netty3Plugin.NETTY_HTTP_TRANSPORT_NAME)
.put(NetworkModule.TRANSPORT_TYPE_KEY, Netty3Plugin.NETTY_TRANSPORT_NAME)
.build();
TransportClient transportClient = new PreBuiltTransportClient(settings);
for (TransportAddress transport : ElasticsearchUtils.convertInetSocketAddresses(transportAddresses)) {
transportClient.addTransportAddress(transport);
}
// verify that we actually are connected to a cluster
if (transportClient.connectedNodes().isEmpty()) {
// close the transportClient here
IOUtils.closeQuietly(transportClient);
throw new RuntimeException("Elasticsearch client is not connected to any Elasticsearch nodes!");
}
if (LOG.isInfoEnabled()) {
LOG.info("Created Elasticsearch TransportClient with connected nodes {}", transportClient.connectedNodes());
}
return transportClient;
}
代码示例来源:origin: apache/flink
@Override
public TransportClient createClient(Map<String, String> clientConfig) {
Settings settings = Settings.settingsBuilder().put(clientConfig).build();
TransportClient transportClient = TransportClient.builder().settings(settings).build();
for (TransportAddress address : ElasticsearchUtils.convertInetSocketAddresses(transportAddresses)) {
transportClient.addTransportAddress(address);
}
// verify that we actually are connected to a cluster
if (transportClient.connectedNodes().isEmpty()) {
// close the transportClient here
IOUtils.closeQuietly(transportClient);
throw new RuntimeException("Elasticsearch client is not connected to any Elasticsearch nodes!");
}
if (LOG.isInfoEnabled()) {
LOG.info("Created Elasticsearch TransportClient with connected nodes {}", transportClient.connectedNodes());
}
return transportClient;
}
代码示例来源:origin: apache/flink
@Override
public void close() throws FlinkKafkaException {
final FlinkKafkaProducer.KafkaTransactionState currentTransaction = currentTransaction();
if (currentTransaction != null) {
// to avoid exceptions on aborting transactions with some pending records
flush(currentTransaction);
// normal abort for AT_LEAST_ONCE and NONE do not clean up resources because of producer reusing, thus
// we need to close it manually
switch (semantic) {
case EXACTLY_ONCE:
break;
case AT_LEAST_ONCE:
case NONE:
currentTransaction.producer.close();
break;
}
}
try {
super.close();
}
catch (Exception e) {
asyncException = ExceptionUtils.firstOrSuppressed(e, asyncException);
}
// make sure we propagate pending errors
checkErroneous();
pendingTransactions().forEach(transaction ->
IOUtils.closeQuietly(transaction.getValue().producer)
);
}
代码示例来源:origin: apache/flink
@Override
public void close() throws FlinkKafka011Exception {
final KafkaTransactionState currentTransaction = currentTransaction();
if (currentTransaction != null) {
// to avoid exceptions on aborting transactions with some pending records
flush(currentTransaction);
// normal abort for AT_LEAST_ONCE and NONE do not clean up resources because of producer reusing, thus
// we need to close it manually
switch (semantic) {
case EXACTLY_ONCE:
break;
case AT_LEAST_ONCE:
case NONE:
currentTransaction.producer.close();
break;
}
}
try {
super.close();
}
catch (Exception e) {
asyncException = ExceptionUtils.firstOrSuppressed(e, asyncException);
}
// make sure we propagate pending errors
checkErroneous();
pendingTransactions().forEach(transaction ->
IOUtils.closeQuietly(transaction.getValue().producer)
);
}
代码示例来源:origin: apache/flink
/**
* Advances the iterator. Should only be called if {@link #isValid()} returned true.
* Valid flag can only change after calling {@link #next()}.
*/
public void next() {
newKeyGroup = false;
newKVState = false;
final RocksIteratorWrapper rocksIterator = currentSubIterator.getIterator();
rocksIterator.next();
byte[] oldKey = currentSubIterator.getCurrentKey();
if (rocksIterator.isValid()) {
currentSubIterator.setCurrentKey(rocksIterator.key());
if (isDifferentKeyGroup(oldKey, currentSubIterator.getCurrentKey())) {
heap.offer(currentSubIterator);
currentSubIterator = heap.remove();
newKVState = currentSubIterator.getIterator() != rocksIterator;
detectNewKeyGroup(oldKey);
}
} else {
IOUtils.closeQuietly(rocksIterator);
if (heap.isEmpty()) {
currentSubIterator = null;
valid = false;
} else {
currentSubIterator = heap.remove();
newKVState = true;
detectNewKeyGroup(oldKey);
}
}
}
代码示例来源:origin: apache/flink
/**
* Restore one key groups state handle.
*/
private void restoreKeyGroupsInStateHandle()
throws IOException, StateMigrationException, RocksDBException {
try {
currentStateHandleInStream = currentKeyGroupsStateHandle.openInputStream();
rocksDBKeyedStateBackend.cancelStreamRegistry.registerCloseable(currentStateHandleInStream);
currentStateHandleInView = new DataInputViewStreamWrapper(currentStateHandleInStream);
restoreKVStateMetaData();
restoreKVStateData();
} finally {
if (rocksDBKeyedStateBackend.cancelStreamRegistry.unregisterCloseable(currentStateHandleInStream)) {
IOUtils.closeQuietly(currentStateHandleInStream);
}
}
}
代码示例来源:origin: apache/flink
HadoopRecoverableFsDataOutputStream(
FileSystem fs,
HadoopFsRecoverable recoverable) throws IOException {
ensureTruncateInitialized();
this.fs = checkNotNull(fs);
this.targetFile = checkNotNull(recoverable.targetFile());
this.tempFile = checkNotNull(recoverable.tempFile());
// truncate back and append
try {
truncate(fs, tempFile, recoverable.offset());
} catch (Exception e) {
throw new IOException("Missing data in tmp file: " + tempFile, e);
}
waitUntilLeaseIsRevoked(tempFile);
out = fs.append(tempFile);
// sanity check
long pos = out.getPos();
if (pos != recoverable.offset()) {
IOUtils.closeQuietly(out);
throw new IOException("Truncate failed: " + tempFile +
" (requested=" + recoverable.offset() + " ,size=" + pos + ')');
}
}
内容来源于网络,如有侵权,请联系作者删除!