Package org.eclipse.jetty.util

Examples of org.eclipse.jetty.util.MultiException


     * Called automatically from start if autoInitializeServlet is true.
     */
    public void initialize()
        throws Exception
    {
        MultiException mx = new MultiException();

        //start filter holders now
        if (_filters != null)
        {
            for (FilterHolder f: _filters)
            {
                try
                {
                    f.start();
                    f.initialize();
                }
                catch (Exception e)
                {
                    mx.add(e);
                }
            }
        }
       
        // Sort and Initialize servlets
        if (_servlets!=null)
        {
            ServletHolder[] servlets = _servlets.clone();
            Arrays.sort(servlets);
            for (ServletHolder servlet : servlets)
            {
                try
                {
                    if (servlet.getClassName() == null && servlet.getForcedPath() != null)
                    {
                        ServletHolder forced_holder = _servletPathMap.match(servlet.getForcedPath());
                        if (forced_holder == null || forced_holder.getClassName() == null)
                        {
                            mx.add(new IllegalStateException("No forced path servlet for " + servlet.getForcedPath()));
                            continue;
                        }
                        servlet.setClassName(forced_holder.getClassName());
                    }
                   
                    servlet.start();
                    servlet.initialize();
                }
                catch (Throwable e)
                {
                    LOG.debug(Log.EXCEPTION, e);
                    mx.add(e);
                }
            }
        }

        //any other beans
        for (Holder<?> h: getBeans(Holder.class))
        {
            try
            {
                if (!h.isStarted())
                {
                    h.start();
                    h.initialize();
                }
            }
            catch (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();

        LOG.info(String.format("Started @%dms",ManagementFactory.getRuntimeMXBean().getUptime()));
    }
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

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.