Package org.eclipse.jetty.util

Examples of org.eclipse.jetty.util.MultiException


        }
  }
 
  public void initializeSip() throws Exception
  {
    MultiException mx = new MultiException();

    if (_sipServlets != null)
    {
          // Sort and Initialize servlets
          SipServletHolder[] servlets = (SipServletHolder[]) _sipServlets.clone();
          Arrays.sort(servlets);
          for (int i=0; i<servlets.length; i++)
          {
              try
              {
                  servlets[i].start();
              }
              catch(Exception e)
              {

                Log.debug(Log.EXCEPTION, e);
                  mx.add(e);
              }
          }
          mx.ifExceptionThrow()
    }
  }
View Full Code Here


        ShutdownMonitor.getInstance().start(); // initialize

        LOG.info("jetty-" + getVersion());
        HttpGenerator.setJettyVersion(HttpConfiguration.SERVER_VERSION);
        MultiException mex=new MultiException();

        // check size of thread pool
        SizedThreadPool pool = getBean(SizedThreadPool.class);
        int max=pool==null?-1:pool.getMaxThreads();
        int needed=1;
        if (mex.size()==0)
        {
            for (Connector connector : _connectors)
            {
                if (connector instanceof AbstractConnector)
                    needed+=((AbstractConnector)connector).getAcceptors();
                if (connector instanceof ServerConnector)
                    needed+=((ServerConnector)connector).getSelectorManager().getSelectorCount();
            }
        }

        if (max>0 && needed>max)
            throw new IllegalStateException("Insufficient max threads in ThreadPool: max="+max+" < needed="+needed);
       
        try
        {
            super.doStart();
        }
        catch(Throwable e)
        {
            mex.add(e);
        }

        // start connectors last
        for (Connector connector : _connectors)
        {
            try
            {  
                connector.start();
            }
            catch(Throwable e)
            {
                mex.add(e);
            }
        }
       
        if (isDumpAfterStart())
            dumpStdErr();

        mex.ifExceptionThrow();
    }
View Full Code Here

    protected void doStop() throws Exception
    {
        if (isDumpBeforeStop())
            dumpStdErr();

        MultiException mex=new MultiException();

        // list if graceful futures
        List<Future<Void>> futures = new ArrayList<>();

        // First close the network connectors to stop accepting new connections
        for (Connector connector : _connectors)
            futures.add(connector.shutdown());

        // Then tell the contexts that we are shutting down
       
        Handler[] gracefuls = getChildHandlersByClass(Graceful.class);
        for (Handler graceful : gracefuls)
            futures.add(((Graceful)graceful).shutdown());

        // Shall we gracefully wait for zero connections?
        long stopTimeout = getStopTimeout();
        if (stopTimeout>0)
        {
            long stop_by=System.currentTimeMillis()+stopTimeout;
            LOG.debug("Graceful shutdown {} by ",this,new Date(stop_by));

            // Wait for shutdowns
            for (Future<Void> future: futures)
            {
                try
                {
                    if (!future.isDone())
                        future.get(Math.max(1L,stop_by-System.currentTimeMillis()),TimeUnit.MILLISECONDS);
                }
                catch (Exception e)
                {
                    mex.add(e.getCause());
                }
            }
        }

        // Cancel any shutdowns not done
        for (Future<Void> future: futures)
            if (!future.isDone())
                future.cancel(true);

        // Now stop the connectors (this will close existing connections)
        for (Connector connector : _connectors)
        {
            try
            {
                connector.stop();
            }
            catch (Throwable e)
            {
                mex.add(e);
            }
        }

        // And finally stop everything else
        try
        {
            super.doStop();
        }
        catch (Throwable e)
        {
            mex.add(e);
        }

        if (getStopAtShutdown())
            ShutdownThread.deregister(this);

        mex.ifExceptionThrow();

    }
View Full Code Here

        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);
         
        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(),
                    (TimeUnit.MILLISECONDS.convert(System.nanoTime()-start, TimeUnit.NANOSECONDS)),
                    context);
        }

        if (timeout)
            me.add(new Exception("Timeout scanning annotations"));
        me.ifExceptionThrow();  
    }
View Full Code Here

     * @throws Exception
     */
    public void parse (Set<? extends Handler> handlers, List<String> classNames, ClassNameResolver resolver)
    throws Exception
    {
        MultiException me = new MultiException();
       
        for (String s:classNames)
        {
            try
            {
                if ((resolver == null) || (!resolver.isExcluded(s) &&  (!isParsed(s) || resolver.shouldOverride(s))))
                {
                    s = s.replace('.', '/')+".class";
                    URL resource = Loader.getResource(this.getClass(), s);
                    if (resource!= null)
                    {
                        Resource r = Resource.newResource(resource);
                        scanClass(handlers, null, r.getInputStream());
                    }
                }
            }
            catch (Exception e)
            {
                me.add(new RuntimeException("Error scanning class "+s, e));
            }
        }
        me.ifExceptionThrow();
    }
View Full Code Here

        if (!dir.isDirectory() || !dir.exists() || dir.getName().startsWith("."))
            return;

        if (LOG.isDebugEnabled()) {LOG.debug("Scanning dir {}", dir);};

        MultiException me = new MultiException();
       
        String[] files=dir.list();
        for (int f=0;files!=null && f<files.length;f++)
        {
            Resource res = dir.addPath(files[f]);
            if (res.isDirectory())
                parseDir(handlers, res, resolver);
            else
            {
                //we've already verified the directories, so just verify the class file name
                File file = res.getFile();
                if (isValidClassFileName((file==null?null:file.getName())))
                {
                    try
                    {
                        String name = res.getName();
                        if ((resolver == null)|| (!resolver.isExcluded(name) && (!isParsed(name) || resolver.shouldOverride(name))))
                        {
                            Resource r = Resource.newResource(res.getURL());
                            if (LOG.isDebugEnabled()) {LOG.debug("Scanning class {}", r);};
                            scanClass(handlers, dir, r.getInputStream());
                        }
                    }                 
                    catch (Exception ex)
                    {
                        if (LOG.isDebugEnabled()) LOG.debug("Error scanning file "+files[f], ex);
                        me.add(new RuntimeException("Error scanning file "+files[f],ex));
                    }
                }
                else
                {
                   if (LOG.isDebugEnabled()) LOG.debug("Skipping scan on invalid file {}", res);
                }
            }
        }

        me.ifExceptionThrow();
    }
View Full Code Here

            return;

        if (!(loader instanceof URLClassLoader))
            return; //can't extract classes?

        final MultiException me = new MultiException();
       
        JarScanner scanner = new JarScanner()
        {
            @Override
            public void processEntry(URI jarUri, JarEntry entry)
            {
                try
                {
                    parseJarEntry(handlers, Resource.newResource(jarUri), entry, resolver);
                }
                catch (Exception e)
                {
                    me.add(new RuntimeException("Error parsing entry "+entry.getName()+" from jar "+ jarUri, e));
                }
            }

        };

        scanner.scan(null, loader, nullInclusive, visitParents);
        me.ifExceptionThrow();
    }
View Full Code Here

    throws Exception
    {
        if (uris==null)
            return;

        MultiException me = new MultiException();
       
        for (URI uri:uris)
        {
            try
            {
                parse(handlers, uri, resolver);
            }
            catch (Exception e)
            {
                me.add(new RuntimeException("Problem parsing classes from "+ uri, e));
            }
        }
        me.ifExceptionThrow();
    }
View Full Code Here

           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, resolver);                       
                    }
                    catch (Exception e)
                    {
                        me.add(new RuntimeException("Error scanning entry "+entry.getName()+" from jar "+jarResource, e));
                    }
                    entry = jar_in.getNextJarEntry();
                }
            }
            finally
            {
                jar_in.close();
            }
            me.ifExceptionThrow();
        }       
    }
View Full Code Here

    public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        if (_handlers!=null && isStarted())
        {
            MultiException mex=null;

            for (int i=0;i<_handlers.length;i++)
            {
                try
                {
                    _handlers[i].handle(target,baseRequest, request, response);
                }
                catch(IOException e)
                {
                    throw e;
                }
                catch(RuntimeException e)
                {
                    throw e;
                }
                catch(Exception e)
                {
                    if (mex==null)
                        mex=new MultiException();
                    mex.add(e);
                }
            }
            if (mex!=null)
            {
                if (mex.size()==1)
                    throw new ServletException(mex.getThrowable(0));
                else
                    throw new ServletException(mex);
            }

        }
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.util.MultiException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.