Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  //  ========================================================================
  //  Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
  //  ------------------------------------------------------------------------
  //  All rights reserved. This program and the accompanying materials
  //  are made available under the terms of the Eclipse Public License v1.0
  //  and Apache License v2.0 which accompanies this distribution.
  //
  //      The Eclipse Public License is available at
 //      http://www.eclipse.org/legal/epl-v10.html
 //
 //      The Apache License v2.0 is available at
 //      http://www.opensource.org/licenses/apache2.0.php
 //
 //  You may elect to redistribute this code under either of these licenses.
 //  ========================================================================
 //
 
 package org.eclipse.jetty.server.handler;
 
 
 
 
 /* ------------------------------------------------------------ */
A collection of handlers.

The default implementations calls all handlers in list order, regardless of the response status or exceptions. Derived implementation may alter the order or the conditions of calling the contained handlers.

Org.apache.xbean.XBean:
 
 {
     private final boolean _mutableWhenRunning;
     private volatile Handler[] _handlers;
     private boolean _parallelStart=false
 
     /* ------------------------------------------------------------ */
     public HandlerCollection()
     {
         =false;
     }
     
     /* ------------------------------------------------------------ */
     public HandlerCollection(boolean mutableWhenRunning)
     {
         =mutableWhenRunning;
     }
 
     /* ------------------------------------------------------------ */
    

Returns:
Returns the handlers.
 
     public Handler[] getHandlers()
     {
         return ;
     }
     
     /* ------------------------------------------------------------ */
    

Parameters:
handlers The handlers to set.
 
     public void setHandlers(Handler[] handlers)
     {
         if (! && isStarted())
             throw new IllegalStateException();
         
         Handler [] old_handlers = ==null?null:.clone();
          = handlers;
         
         Server server = getServer();
         MultiException mex = new MultiException();
         for (int i=0;handlers!=null && i<handlers.length;i++)
         {
             if (handlers[i].getServer()!=server)
                 handlers[i].setServer(server);
         }
 
         if (getServer()!=null)
             getServer().getContainer().update(thisold_handlershandlers"handler");
         
         // stop old handlers
         for (int i=0;old_handlers!=null && i<old_handlers.length;i++)
         {
             if (old_handlers[i]!=null)
            {
                try
                {
                    if (old_handlers[i].isStarted())
                        old_handlers[i].stop();
                }
                catch (Throwable e)
                {
                    mex.add(e);
                }
            }
        }
                
        mex.ifExceptionThrowRuntime();
    }
    
    
    /* ------------------------------------------------------------ */
    
Get the parrallelStart.

Returns:
true if the contained handlers are started in parallel.
    public boolean isParallelStart()
    {
        return ;
    }
    /* ------------------------------------------------------------ */
    
Set the parallelStart.

Parameters:
parallelStart If true, contained handlers are started in parallel.
    public void setParallelStart(boolean parallelStart)
    {
        this. = parallelStart;
    }
    /* ------------------------------------------------------------ */
    
    public void handle(String targetRequest baseRequestHttpServletRequest requestHttpServletResponse response
        throws IOExceptionServletException
    {
        if (!=null && isStarted())
        {
            MultiException mex=null;
            
            for (int i=0;i<.;i++)
            {
                try
                {
                    [i].handle(target,baseRequestrequestresponse);
                }
                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);
            }
            
        }    
    }
    /* ------------------------------------------------------------ */
    /* 
     * @see org.eclipse.jetty.server.server.handler.AbstractHandler#doStart()
     */
    @Override
    protected void doStart() throws Exception
    {
        final MultiException mex=new MultiException();
        if (!=null)
        {
            if ()
            {
                final CountDownLatch latch = new CountDownLatch(.);
                final ClassLoader loader = Thread.currentThread().getContextClassLoader();
                for (int i=0;i<.;i++)
                {
                    final int h=i;
                    getServer().getThreadPool().dispatch(
                            new Runnable()
                            {
                                public void run()
                                {
                                    ClassLoader orig = Thread.currentThread().getContextClassLoader();
                                    try
                                    {
                                        Thread.currentThread().setContextClassLoader(loader);
                                        [h].start();
                                    }
                                    catch(Throwable e)
                                    {
                                        mex.add(e);
                                    }
                                    finally
                                    {
                                        Thread.currentThread().setContextClassLoader(orig);
                                        latch.countDown();
                                    }
                                }
                            }
                    );
                }
                latch.await();
            }
            else
            {
                for (int i=0;i<.;i++)
                {
                    try{[i].start();}
                    catch(Throwable e){mex.add(e);}
                }
            }
        }
        super.doStart();
        mex.ifExceptionThrow();
    }
    /* ------------------------------------------------------------ */
    /* 
     * @see org.eclipse.jetty.server.server.handler.AbstractHandler#doStop()
     */
    @Override
    protected void doStop() throws Exception
    {
        MultiException mex=new MultiException();
        try { super.doStop(); } catch(Throwable e){mex.add(e);}
        if (!=null)
        {
            for (int i=.;i-->0;)
                try{[i].stop();}catch(Throwable e){mex.add(e);}
        }
        mex.ifExceptionThrow();
    }
    
    /* ------------------------------------------------------------ */
    @Override
    public void setServer(Server server)
    {
        if (isStarted())
            throw new IllegalStateException();
        
        Server old_server=getServer();
        
        super.setServer(server);
        Handler[] h=getHandlers();
        for (int i=0;h!=null && i<h.length;i++)
            h[i].setServer(server);
        
        if (server!=null && server!=old_server)
            server.getContainer().update(thisnull,"handler");
        
    }
    /* ------------------------------------------------------------ */
    /* Add a handler.
     * This implementation adds the passed handler to the end of the existing collection of handlers. 
     * @see org.eclipse.jetty.server.server.HandlerContainer#addHandler(org.eclipse.jetty.server.server.Handler)
     */
    public void addHandler(Handler handler)
    {
        setHandlers((Handler[])LazyList.addToArray(getHandlers(), handlerHandler.class));
    }
    
    /* ------------------------------------------------------------ */
    public void removeHandler(Handler handler)
    {
        Handler[] handlers = getHandlers();
        
        if (handlers!=null && handlers.length>0 )
            setHandlers((Handler[])LazyList.removeFromArray(handlershandler));
    }
    /* ------------------------------------------------------------ */
    @Override
    protected Object expandChildren(Object listClass byClass)
    {
        Handler[] handlers = getHandlers();
        for (int i=0;handlers!=null && i<handlers.length;i++)
            list=expandHandler(handlers[i], listbyClass);
        return list;
    }
    /* ------------------------------------------------------------ */
    @Override
    public void destroy()
    {
        if (!isStopped())
            throw new IllegalStateException("!STOPPED");
        Handler[] children=getChildHandlers();
        setHandlers(null);
        for (Handler childchildren)
            child.destroy();
        super.destroy();
    }
New to GrepCode? Check out our FAQ X