Search in sources :

Example 11 with MultiException

use of org.eclipse.jetty.util.MultiException in project hbase by apache.

the class HttpServer method stop.

/**
   * stop the server
   */
public void stop() throws Exception {
    MultiException exception = null;
    for (ListenerInfo li : listeners) {
        if (!li.isManaged) {
            continue;
        }
        try {
            li.listener.close();
        } catch (Exception e) {
            LOG.error("Error while stopping listener for webapp" + webAppContext.getDisplayName(), e);
            exception = addMultiException(exception, e);
        }
    }
    try {
        // clear & stop webAppContext attributes to avoid memory leaks.
        webAppContext.clearAttributes();
        webAppContext.stop();
    } catch (Exception e) {
        LOG.error("Error while stopping web app context for webapp " + webAppContext.getDisplayName(), e);
        exception = addMultiException(exception, e);
    }
    try {
        webServer.stop();
    } catch (Exception e) {
        LOG.error("Error while stopping web server for webapp " + webAppContext.getDisplayName(), e);
        exception = addMultiException(exception, e);
    }
    if (exception != null) {
        exception.ifExceptionThrow();
    }
}
Also used : MultiException(org.eclipse.jetty.util.MultiException) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) MultiException(org.eclipse.jetty.util.MultiException) FileNotFoundException(java.io.FileNotFoundException) BindException(java.net.BindException) InterruptedIOException(java.io.InterruptedIOException) HadoopIllegalArgumentException(org.apache.hadoop.HadoopIllegalArgumentException) IOException(java.io.IOException)

Example 12 with MultiException

use of org.eclipse.jetty.util.MultiException in project jetty.project by eclipse.

the class AnnotationConfiguration method scanForAnnotations.

/**
     * Perform scanning of classes for annotations
     * 
     * @param context the context for the scan
     * @throws Exception if unable to scan
     */
protected void scanForAnnotations(WebAppContext context) throws Exception {
    AnnotationParser parser = createAnnotationParser();
    _parserTasks = new ArrayList<ParserTask>();
    long start = 0;
    if (LOG.isDebugEnabled())
        LOG.debug("Annotation scanning commencing: webxml={}, metadatacomplete={}, configurationDiscovered={}, multiThreaded={}, maxScanWait={}", context.getServletContext().getEffectiveMajorVersion(), context.getMetaData().isMetaDataComplete(), context.isConfigurationDiscovered(), isUseMultiThreading(context), getMaxScanWait(context));
    parseContainerPath(context, parser);
    //email from Rajiv Mordani jsrs 315 7 April 2010
    //    If there is a <others/> then the ordering should be
    //          WEB-INF/classes the order of the declared elements + others.
    //    In case there is no others then it is
    //          WEB-INF/classes + order of the elements.
    parseWebInfClasses(context, parser);
    parseWebInfLib(context, parser);
    start = System.nanoTime();
    //execute scan, either effectively synchronously (1 thread only), or asynchronously (limited by number of processors available) 
    final Semaphore task_limit = (isUseMultiThreading(context) ? new Semaphore(Runtime.getRuntime().availableProcessors()) : new Semaphore(1));
    final CountDownLatch latch = new CountDownLatch(_parserTasks.size());
    final MultiException me = new MultiException();
    for (final ParserTask p : _parserTasks) {
        task_limit.acquire();
        context.getServer().getThreadPool().execute(new Runnable() {

            @Override
            public void run() {
                try {
                    p.call();
                } catch (Exception e) {
                    me.add(e);
                } finally {
                    task_limit.release();
                    latch.countDown();
                }
            }
        });
    }
    boolean timeout = !latch.await(getMaxScanWait(context), TimeUnit.SECONDS);
    long elapsedMs = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
    LOG.info("Scanning elapsed time={}ms", elapsedMs);
    if (LOG.isDebugEnabled()) {
        for (ParserTask p : _parserTasks) LOG.debug("Scanned {} in {}ms", p.getResource(), TimeUnit.MILLISECONDS.convert(p.getStatistic().getElapsed(), TimeUnit.NANOSECONDS));
        LOG.debug("Scanned {} container path jars, {} WEB-INF/lib jars, {} WEB-INF/classes dirs in {}ms for context {}", _containerPathStats.getTotal(), _webInfLibStats.getTotal(), _webInfClassesStats.getTotal(), elapsedMs, context);
    }
    if (timeout)
        me.add(new Exception("Timeout scanning annotations"));
    me.ifExceptionThrow();
}
Also used : Semaphore(java.util.concurrent.Semaphore) CountDownLatch(java.util.concurrent.CountDownLatch) MultiException(org.eclipse.jetty.util.MultiException) MultiException(org.eclipse.jetty.util.MultiException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 13 with MultiException

use of org.eclipse.jetty.util.MultiException in project jetty.project by eclipse.

the class AnnotationParser method parse.

/**
     * Parse the given classes
     * 
     * @param handlers the set of handlers to look for class in 
     * @param classNames the class names
     * @throws Exception if unable to parse
     */
public void parse(Set<? extends Handler> handlers, List<String> classNames) throws Exception {
    MultiException me = new MultiException();
    for (String s : classNames) {
        try {
            if (!isParsed(s)) {
                s = s.replace('.', '/') + ".class";
                URL resource = Loader.getResource(s);
                if (resource != null) {
                    Resource r = Resource.newResource(resource);
                    try (InputStream is = r.getInputStream()) {
                        scanClass(handlers, null, is);
                    }
                }
            }
        } catch (Exception e) {
            me.add(new RuntimeException("Error scanning class " + s, e));
        }
    }
    me.ifExceptionThrow();
}
Also used : JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) Resource(org.eclipse.jetty.util.resource.Resource) MultiException(org.eclipse.jetty.util.MultiException) URL(java.net.URL) MultiException(org.eclipse.jetty.util.MultiException) IOException(java.io.IOException)

Example 14 with MultiException

use of org.eclipse.jetty.util.MultiException in project jetty.project by eclipse.

the class AnnotationParser method parseJar.

/**
     * Parse a resource that is a jar file.
     * 
     * @param handlers the handlers to look for classes in  
     * @param jarResource the jar resource to parse
     * @throws Exception if unable to parse
     */
protected void parseJar(Set<? extends Handler> handlers, Resource jarResource) throws Exception {
    if (jarResource == null)
        return;
    if (jarResource.toString().endsWith(".jar")) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Scanning jar {}", jarResource);
        }
        ;
        //treat it as a jar that we need to open and scan all entries from  
        InputStream in = jarResource.getInputStream();
        if (in == null)
            return;
        MultiException me = new MultiException();
        JarInputStream jar_in = new JarInputStream(in);
        try {
            JarEntry entry = jar_in.getNextJarEntry();
            while (entry != null) {
                try {
                    parseJarEntry(handlers, jarResource, entry);
                } catch (Exception e) {
                    me.add(new RuntimeException("Error scanning entry " + entry.getName() + " from jar " + jarResource, e));
                }
                entry = jar_in.getNextJarEntry();
            }
        } catch (Exception e) {
            me.add(new RuntimeException("Error scanning jar " + jarResource, e));
        } finally {
            jar_in.close();
        }
        me.ifExceptionThrow();
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) JarEntry(java.util.jar.JarEntry) MultiException(org.eclipse.jetty.util.MultiException) MultiException(org.eclipse.jetty.util.MultiException) IOException(java.io.IOException)

Example 15 with MultiException

use of org.eclipse.jetty.util.MultiException in project jetty.project by eclipse.

the class WebAppContext method destroy.

/* ------------------------------------------------------------ */
@Override
public void destroy() {
    // Prepare for configuration
    MultiException mx = new MultiException();
    if (_configurations != null) {
        for (int i = _configurations.size(); i-- > 0; ) {
            try {
                _configurations.get(i).destroy(this);
            } catch (Exception e) {
                mx.add(e);
            }
        }
    }
    _configurations.clear();
    super.destroy();
    mx.ifExceptionThrowRuntime();
}
Also used : MultiException(org.eclipse.jetty.util.MultiException) MultiException(org.eclipse.jetty.util.MultiException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

MultiException (org.eclipse.jetty.util.MultiException)18 IOException (java.io.IOException)14 ServletException (javax.servlet.ServletException)7 FileNotFoundException (java.io.FileNotFoundException)4 InterruptedIOException (java.io.InterruptedIOException)4 BindException (java.net.BindException)4 HadoopIllegalArgumentException (org.apache.hadoop.HadoopIllegalArgumentException)4 InputStream (java.io.InputStream)3 MalformedURLException (java.net.MalformedURLException)3 JarInputStream (java.util.jar.JarInputStream)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 JarEntry (java.util.jar.JarEntry)2 UnavailableException (javax.servlet.UnavailableException)2 Handler (org.eclipse.jetty.server.Handler)2 ErrorHandler (org.eclipse.jetty.server.handler.ErrorHandler)2 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ServletHandler (org.eclipse.jetty.servlet.ServletHandler)2 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)2