Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  //  ========================================================================
  //  Copyright (c) 1995-2013 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.continuation;
 
 
 
 
 
 /* ------------------------------------------------------------ */

ContinuationFilter must be applied to servlet paths that make use of the asynchronous features provided by Continuation APIs, but that are deployed in servlet containers that are neither Jetty (>= 7) nor a compliant Servlet 3.0 container.

The following init parameters may be used to configure the filter (these are mostly for testing):

debug
Boolean controlling debug output
jetty6
Boolean to force use of Jetty 6 continuations
faux
Boolean to force use of faux continuations

If the servlet container is not Jetty (either 6 or 7) nor a Servlet 3 container, then "faux" continuations will be used.

Faux continuations will just put the thread that called Continuation.suspend() in wait, and will notify that thread when Continuation.resume() or Continuation.complete() is called.

Faux continuations are not threadless continuations (they are "faux" - fake - for this reason) and as such they will scale less than proper continuations.

 
 public class ContinuationFilter implements Filter
 {
     static boolean _initialized;
     static boolean __debug// shared debug status
     private boolean _faux;
     private boolean _jetty6;
     private boolean _filtered;
     private boolean _debug;
 
     public void init(FilterConfig filterConfigthrows ServletException
     {
         boolean jetty_7_or_greater="org.eclipse.jetty.servlet".equals(filterConfig.getClass().getPackage().getName());
          = filterConfig.getServletContext();
 
         String param=filterConfig.getInitParameter("debug");
         =param!=null&&Boolean.parseBoolean(param);
         if ()
             =true;
 
         param=filterConfig.getInitParameter("jetty6");
         if (param==null)
             param=filterConfig.getInitParameter("partial");
         if (param!=null)
             =Boolean.parseBoolean(param);
         else
             =. && !jetty_7_or_greater;
 
         param=filterConfig.getInitParameter("faux");
         if (param!=null)
             =Boolean.parseBoolean(param);
         else
             =!(jetty_7_or_greater ||  || .getMajorVersion()>=3);
 
         =||;
         if ()
             .log("ContinuationFilter "+
                     " jetty="+jetty_7_or_greater+
                     " jetty6="++
                     " faux="++
                     " filtered="++
                     " servlet3="+.);
         =true;
     }
 
     public void doFilter(ServletRequest requestServletResponse responseFilterChain chainthrows IOExceptionServletException
     {
        if ()
        {
            Continuation c = (Continuationrequest.getAttribute(.);
            FilteredContinuation fc;
            if ( && (c==null || !(c instanceof FauxContinuation)))
            {
                fc = new FauxContinuation(request);
                request.setAttribute(.,fc);
            }
            else
                fc=(FilteredContinuation)c;
            boolean complete=false;
            while (!complete)
            {
                try
                {
                    if (fc==null || (fc).enter(response))
                        chain.doFilter(request,response);
                }
                catch (ContinuationThrowable e)
                {
                    debug("faux",e);
                }
                finally
                {
                    if (fc==null)
                        fc = (FilteredContinuationrequest.getAttribute(.);
                    complete=fc==null || (fc).exit();
                }
            }
        }
        else
        {
            try
            {
                chain.doFilter(request,response);
            }
            catch (ContinuationThrowable e)
            {
                debug("caught",e);
            }
        }
    }
    private void debug(String string)
    {
        if ()
        {
            .log(string);
        }
    }
    private void debug(String stringThrowable th)
    {
        if ()
        {
            if (th instanceof ContinuationThrowable)
                .log(string+":"+th);
            else
                .log(string,th);
        }
    }
    public void destroy()
    {
    }
    public interface FilteredContinuation extends Continuation
    {
        boolean enter(ServletResponse response);
        boolean exit();
    }
New to GrepCode? Check out our FAQ X