Search in sources :

Example 81 with Closeable

use of java.io.Closeable in project sling by apache.

the class JcrResourceProvider method unregisterListeners.

/**
     * Unregister all observation listeners.
     */
private void unregisterListeners() {
    logger.debug("Unregistering resource listeners...");
    for (final Closeable c : this.listeners.values()) {
        try {
            logger.debug("Removing listener for {}", ((JcrResourceListener) c).getConfig().getPaths());
            c.close();
        } catch (final IOException e) {
        // ignore this as the method above does not throw it
        }
    }
    this.listeners.clear();
    if (this.listenerConfig != null) {
        try {
            this.listenerConfig.close();
        } catch (final IOException e) {
        // ignore this as the method above does not throw it
        }
        this.listenerConfig = null;
    }
    logger.debug("Unregistered resource listeners");
}
Also used : Closeable(java.io.Closeable) JcrResourceListener(org.apache.sling.jcr.resource.internal.JcrResourceListener) IOException(java.io.IOException)

Example 82 with Closeable

use of java.io.Closeable in project wildfly by wildfly.

the class ScannerTest method testZippedJar.

@Test
public void testZippedJar() throws Exception {
    File defaultPar = buildDefaultPar();
    addPackageToClasspath(defaultPar);
    final VirtualFile virtualFile = VFS.getChild(defaultPar.getAbsolutePath());
    Closeable closeable = VFS.mountZip(virtualFile, virtualFile, tempFileProvider);
    try {
        ArchiveDescriptor archiveDescriptor = VirtualFileSystemArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(virtualFile.toURL());
        AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector(new StandardScanOptions());
        archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(new PersistenceUnitDescriptorAdapter(), true, resultCollector));
        validateResults(resultCollector, ApplicationServer.class, Version.class);
    } finally {
        closeable.close();
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) AbstractScannerImpl(org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl) Closeable(java.io.Closeable) ArchiveDescriptor(org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File) StandardScanOptions(org.hibernate.jpa.boot.scan.internal.StandardScanOptions) Test(org.junit.Test)

Example 83 with Closeable

use of java.io.Closeable in project wildfly by wildfly.

the class ScannerTest method testNestedJarProtocol.

@Test
public void testNestedJarProtocol() throws Exception {
    File defaultPar = buildDefaultPar();
    File nestedEar = buildNestedEar(defaultPar);
    addPackageToClasspath(nestedEar);
    final VirtualFile nestedEarVirtualFile = VFS.getChild(nestedEar.getAbsolutePath());
    Closeable closeable = VFS.mountZip(nestedEarVirtualFile, nestedEarVirtualFile, tempFileProvider);
    try {
        VirtualFile parVirtualFile = nestedEarVirtualFile.getChild("defaultpar.par");
        Closeable closeable2 = VFS.mountZip(parVirtualFile, parVirtualFile, tempFileProvider);
        try {
            ArchiveDescriptor archiveDescriptor = VirtualFileSystemArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(parVirtualFile.toURL());
            AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector(new StandardScanOptions());
            archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(new PersistenceUnitDescriptorAdapter(), true, resultCollector));
            validateResults(resultCollector, ApplicationServer.class, Version.class);
        } finally {
            closeable2.close();
        }
    } finally {
        closeable.close();
    }
    File nestedEarDir = buildNestedEarDir(defaultPar);
    final VirtualFile nestedEarDirVirtualFile = VFS.getChild(nestedEarDir.getAbsolutePath());
    try {
        VirtualFile parVirtualFile = nestedEarDirVirtualFile.getChild("defaultpar.par");
        closeable = VFS.mountZip(parVirtualFile, parVirtualFile, tempFileProvider);
        try {
            ArchiveDescriptor archiveDescriptor = VirtualFileSystemArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(parVirtualFile.toURL());
            AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector(new StandardScanOptions());
            archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(new PersistenceUnitDescriptorAdapter(), true, resultCollector));
            validateResults(resultCollector, ApplicationServer.class, Version.class);
        } finally {
            closeable.close();
        }
    } finally {
        closeable.close();
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) AbstractScannerImpl(org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl) Closeable(java.io.Closeable) ArchiveDescriptor(org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File) StandardScanOptions(org.hibernate.jpa.boot.scan.internal.StandardScanOptions) Test(org.junit.Test)

Example 84 with Closeable

use of java.io.Closeable in project wildfly by wildfly.

the class WarStructureDeploymentProcessor method createResourceRoots.

/**
     * Create the resource roots for a .war deployment
     *
     *
     * @param deploymentRoot the deployment root
     * @return the resource roots
     * @throws java.io.IOException for any error
     */
private List<ResourceRoot> createResourceRoots(final VirtualFile deploymentRoot, final DeploymentUnit deploymentUnit) throws IOException, DeploymentUnitProcessingException {
    final List<ResourceRoot> entries = new ArrayList<ResourceRoot>();
    // WEB-INF classes
    final VirtualFile webinfClasses = deploymentRoot.getChild(WEB_INF_CLASSES);
    if (webinfClasses.exists()) {
        final ResourceRoot webInfClassesRoot = new ResourceRoot(webinfClasses.getName(), webinfClasses, null);
        ModuleRootMarker.mark(webInfClassesRoot);
        entries.add(webInfClassesRoot);
    }
    // WEB-INF lib
    Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);
    final VirtualFile webinfLib = deploymentRoot.getChild(WEB_INF_LIB);
    if (webinfLib.exists()) {
        final List<VirtualFile> archives = webinfLib.getChildren(DEFAULT_WEB_INF_LIB_FILTER);
        for (final VirtualFile archive : archives) {
            try {
                String relativeName = archive.getPathNameRelativeTo(deploymentRoot);
                MountedDeploymentOverlay overlay = overlays.get(relativeName);
                Closeable closable = null;
                if (overlay != null) {
                    overlay.remountAsZip(false);
                } else if (archive.isFile()) {
                    closable = VFS.mountZip(archive, archive, TempFileProviderService.provider());
                } else {
                    closable = null;
                }
                final ResourceRoot webInfArchiveRoot = new ResourceRoot(archive.getName(), archive, new MountHandle(closable));
                ModuleRootMarker.mark(webInfArchiveRoot);
                entries.add(webInfArchiveRoot);
            } catch (IOException e) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToProcessWebInfLib(archive), e);
            }
        }
    }
    return entries;
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) MountedDeploymentOverlay(org.jboss.as.server.deployment.MountedDeploymentOverlay) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) MountHandle(org.jboss.as.server.deployment.module.MountHandle) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 85 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)

Aggregations

Closeable (java.io.Closeable)216 IOException (java.io.IOException)88 Test (org.junit.Test)56 ArrayList (java.util.ArrayList)29 File (java.io.File)26 HashMap (java.util.HashMap)12 VirtualFile (org.jboss.vfs.VirtualFile)12 URL (java.net.URL)9 Path (java.nio.file.Path)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 Map (java.util.Map)7 ISE (io.druid.java.util.common.ISE)6 InputStream (java.io.InputStream)6 MountHandle (org.jboss.as.server.deployment.module.MountHandle)6 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)6 ProgramController (co.cask.cdap.app.runtime.ProgramController)5 ProgramType (co.cask.cdap.proto.ProgramType)4 ProgramId (co.cask.cdap.proto.id.ProgramId)4 Pair (io.druid.java.util.common.Pair)4 FileOutputStream (java.io.FileOutputStream)4