use of java.io.Closeable in project wildfly by wildfly.
the class RaStructureProcessor method deploy.
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ResourceRoot resourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
if (resourceRoot == null) {
return;
}
final VirtualFile deploymentRoot = resourceRoot.getRoot();
if (deploymentRoot == null || !deploymentRoot.exists()) {
return;
}
final String deploymentRootName = deploymentRoot.getName().toLowerCase(Locale.ENGLISH);
if (!deploymentRootName.endsWith(RAR_EXTENSION)) {
return;
}
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
moduleSpecification.setPublicModule(true);
//this violates the spec, but everyone expects it to work
ModuleRootMarker.mark(resourceRoot, true);
Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);
try {
final List<VirtualFile> childArchives = deploymentRoot.getChildren(CHILD_ARCHIVE_FILTER);
for (final VirtualFile child : childArchives) {
String relativeName = child.getPathNameRelativeTo(deploymentRoot);
MountedDeploymentOverlay overlay = overlays.get(relativeName);
Closeable closable = NO_OP_CLOSEABLE;
if (overlay != null) {
overlay.remountAsZip(false);
} else if (child.isFile()) {
closable = VFS.mountZip(child, child, TempFileProviderService.provider());
}
final MountHandle mountHandle = new MountHandle(closable);
final ResourceRoot childResource = new ResourceRoot(child, mountHandle);
ModuleRootMarker.mark(childResource);
deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);
resourceRoot.addToAttachmentList(Attachments.INDEX_IGNORE_PATHS, child.getPathNameRelativeTo(deploymentRoot));
}
} catch (IOException e) {
throw ConnectorLogger.ROOT_LOGGER.failedToProcessRaChild(e, deploymentRoot);
}
}
use of java.io.Closeable in project heron by twitter.
the class SysUtilsTest method testCloseIgnoringException.
@Test
public void testCloseIgnoringException() throws Exception {
Closeable closeable = new Closeable() {
@Override
public void close() throws IOException {
throw new RuntimeException("Deliberate exception to be ignored.");
}
};
// This invocation should not throw any exceptions
// Otherwise, the test will automatically fail
SysUtils.closeIgnoringExceptions(closeable);
Assert.assertTrue(true);
}
use of java.io.Closeable in project voldemort by voldemort.
the class AbstractSelectorManager method close.
public void close() {
// the punch...
if (!isClosed.compareAndSet(false, true))
return;
try {
for (SelectionKey sk : selector.keys()) {
try {
if (logger.isTraceEnabled())
logger.trace("Closing SelectionKey's channel");
sk.channel().close();
Object attachment = sk.attachment();
if (attachment instanceof Closeable) {
IOUtils.closeQuietly((Closeable) attachment);
}
} catch (Exception e) {
if (logger.isEnabledFor(Level.WARN))
logger.warn(e.getMessage(), e);
}
try {
if (logger.isTraceEnabled())
logger.trace("Cancelling SelectionKey");
sk.cancel();
} catch (Exception e) {
if (logger.isEnabledFor(Level.WARN))
logger.warn(e.getMessage(), e);
}
}
} catch (Exception e) {
if (logger.isEnabledFor(Level.WARN))
logger.warn(e.getMessage(), e);
}
try {
selector.close();
} catch (Exception e) {
if (logger.isEnabledFor(Level.WARN))
logger.warn(e.getMessage(), e);
}
}
use of java.io.Closeable in project eiger by wlloyd.
the class RowIteratorFactory method getIterator.
/**
* Get a row iterator over the provided memtables and sstables, between the provided keys
* and filtered by the queryfilter.
* @param memtables Memtables pending flush.
* @param sstables SStables to scan through.
* @param startWith Start at this key
* @param stopAt Stop and this key
* @param filter Used to decide which columns to pull out
* @param cfs
* @return A row iterator following all the given restrictions
*/
public static CloseableIterator<Row> getIterator(final Iterable<Memtable> memtables, final Collection<SSTableReader> sstables, final RowPosition startWith, final RowPosition stopAt, final QueryFilter filter, final ColumnFamilyStore cfs) {
// fetch data from current memtable, historical memtables, and SSTables in the correct order.
final List<CloseableIterator<IColumnIterator>> iterators = new ArrayList<CloseableIterator<IColumnIterator>>();
// memtables
for (Memtable memtable : memtables) {
iterators.add(new ConvertToColumnIterator(filter, memtable.getEntryIterator(startWith, stopAt)));
}
for (SSTableReader sstable : sstables) {
final SSTableScanner scanner = sstable.getScanner(filter);
scanner.seekTo(startWith);
// otherwise we leak FDs
assert scanner instanceof Closeable;
iterators.add(scanner);
}
// reduce rows from all sources into a single row
return MergeIterator.get(iterators, COMPARE_BY_KEY, new MergeIterator.Reducer<IColumnIterator, Row>() {
private final int gcBefore = (int) (System.currentTimeMillis() / 1000) - cfs.metadata.getGcGraceSeconds();
private final List<IColumnIterator> colIters = new ArrayList<IColumnIterator>();
private DecoratedKey key;
private ColumnFamily returnCF;
@Override
protected void onKeyChange() {
this.returnCF = ColumnFamily.create(cfs.metadata);
}
public void reduce(IColumnIterator current) {
this.colIters.add(current);
this.key = current.getKey();
this.returnCF.delete(current.getColumnFamily());
}
protected Row getReduced() {
// First check if this row is in the rowCache. If it is we can skip the rest
ColumnFamily cached = cfs.getRawCachedRow(key);
if (cached == null)
// not cached: collate
filter.collateColumns(returnCF, colIters, gcBefore);
else {
QueryFilter keyFilter = new QueryFilter(key, filter.path, filter.filter);
returnCF = cfs.filterColumnFamily(cached, keyFilter, gcBefore);
}
Row rv = new Row(key, returnCF);
colIters.clear();
key = null;
return rv;
}
});
}
use of java.io.Closeable in project lucene-solr by apache.
the class MockDirectoryWrapper method crash.
/** Simulates a crash of OS or machine by overwriting
* unsynced files. */
public synchronized void crash() throws IOException {
openFiles = new HashMap<>();
openFilesForWrite = new HashSet<>();
openFilesDeleted = new HashSet<>();
// first force-close all files, so we can corrupt on windows etc.
// clone the file map, as these guys want to remove themselves on close.
Map<Closeable, Exception> m = new IdentityHashMap<>(openFileHandles);
for (Closeable f : m.keySet()) {
try {
f.close();
} catch (Exception ignored) {
}
}
corruptFiles(unSyncedFiles);
crashed = true;
unSyncedFiles = new HashSet<>();
}
Aggregations