Search in sources :

Example 61 with Closeable

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);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) MountedDeploymentOverlay(org.jboss.as.server.deployment.MountedDeploymentOverlay) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) MountHandle(org.jboss.as.server.deployment.module.MountHandle) ModuleSpecification(org.jboss.as.server.deployment.module.ModuleSpecification) Closeable(java.io.Closeable) IOException(java.io.IOException) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 62 with Closeable

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);
}
Also used : Closeable(java.io.Closeable) Test(org.junit.Test)

Example 63 with Closeable

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);
    }
}
Also used : SelectionKey(java.nio.channels.SelectionKey) Closeable(java.io.Closeable) VoldemortException(voldemort.VoldemortException) ClosedSelectorException(java.nio.channels.ClosedSelectorException) IOException(java.io.IOException)

Example 64 with Closeable

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;
        }
    });
}
Also used : CloseableIterator(org.apache.cassandra.utils.CloseableIterator) Closeable(java.io.Closeable) IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) SSTableScanner(org.apache.cassandra.io.sstable.SSTableScanner) MergeIterator(org.apache.cassandra.utils.MergeIterator)

Example 65 with Closeable

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<>();
}
Also used : IdentityHashMap(java.util.IdentityHashMap) Closeable(java.io.Closeable) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

Closeable (java.io.Closeable)283 Test (org.junit.Test)100 IOException (java.io.IOException)99 ArrayList (java.util.ArrayList)33 File (java.io.File)32 URL (java.net.URL)18 HttpResponse (org.apache.http.HttpResponse)17 HttpClient (org.apache.http.client.HttpClient)17 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)16 Greeter (org.apache.cxf.greeter_control.Greeter)16 HashMap (java.util.HashMap)13 BasicGreeterService (org.apache.cxf.greeter_control.BasicGreeterService)13 VirtualFile (org.jboss.vfs.VirtualFile)12 InputStream (java.io.InputStream)11 PingMeFault (org.apache.cxf.greeter_control.PingMeFault)11 Path (java.nio.file.Path)10 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)9 HttpOptions (org.apache.http.client.methods.HttpOptions)9 Map (java.util.Map)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8