Package javax.servlet

Examples of javax.servlet.AsyncContext


  public void index(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    if (req.isAsyncStarted()) {
      req.getAsyncContext().complete();
    } else if (req.isAsyncSupported()) {
      AsyncContext actx = req.startAsync();
      actx.addListener(this);
      resp.setContentType("text/plain");
      actx.setTimeout(3000);
      clients.add(actx);
      if (clientcount.incrementAndGet() == 1) {
        ticker.addTickListener(this);
      }
    } else {
View Full Code Here


  @Override
  public void tick(Stock stock) {
    ticks.add((Stock) stock.clone());
    Iterator<AsyncContext> it = clients.iterator();
    while (it.hasNext()) {
      AsyncContext actx = it.next();
      writeStock(actx, stock);
    }
  }
View Full Code Here

      log.info("After complete called started:" + req.isAsyncStarted());
      out.write("Async dispatch worked:+" + System.currentTimeMillis() + "\n");
      req.getAsyncContext().complete();
    } else {
      resp.setContentType("text/plain");
      final AsyncContext actx = req.startAsync();
      actx.setTimeout(Long.MAX_VALUE);
      Runnable run = new Runnable() {
        @Override
        public void run() {
          try {
            req.setAttribute("dispatch", Boolean.TRUE);
            Thread.currentThread().setName("Async0-Thread");
            log.info("Putting AsyncThread to sleep");
            //Thread.sleep(2 * 1000);
            Thread.sleep(100);
            log.info("Dispatching");
            actx.dispatch();
          } catch (InterruptedException x) {
            log.error("Async1", x);
          } catch (IllegalStateException x) {
            log.error("Async1", x);
          }
View Full Code Here

public class Async2 {

  private static final Log log = LogFactory.getLog(Async2.class);

  public void index(final HttpServletRequest req) {
    final AsyncContext actx = req.startAsync();
    actx.setTimeout(30 * 1000);
    Runnable run = new Runnable() {
      @Override
      public void run() {
        try {
          Thread.currentThread().setName("Async2-Thread");
          log.info("Putting AsyncThread to sleep");
          //Thread.sleep(2*1000);
          Thread.sleep(100);
          log.info("Writing data.");
          actx.getResponse().getWriter().write(
              "Output from background thread. Time:" + System.currentTimeMillis() + "\n");
          actx.complete();
        } catch (InterruptedException x) {
          log.error("Async2", x);
        } catch (IllegalStateException x) {
          log.error("Async2", x);
        } catch (IOException x) {
View Full Code Here

public class Async1 {

  private static final Log log = LogFactory.getLog(Async1.class);

  public void index(final HttpServletRequest req) {
    final AsyncContext actx = req.startAsync();
    actx.setTimeout(30 * 1000);
    Runnable run = new Runnable() {
      @Override
      public void run() {
        try {
          String path = "/jsp/async/async1.jsp";
          Thread.currentThread().setName("Async1-Thread");
          log.info("Putting AsyncThread to sleep");
          //Thread.sleep(2 * 1000);
          Thread.sleep(100);
          log.info("Dispatching to " + path);
          actx.dispatch(path);
        } catch (InterruptedException x) {
          log.error("Async1", x);
        } catch (IllegalStateException x) {
          log.error("Async1", x);
        }
View Full Code Here

@douyu.mvc.Controller
public class Async3 {

    public void index(final HttpServletRequest req) {
        final AsyncContext actx = req.startAsync();
        actx.setTimeout(30*1000);
        actx.dispatch("/jsp/async/async3.jsp");
    }
View Full Code Here

   @Override
   public AsynchronousResponse createAsynchronousResponse(long l)
   {
      suspended = true;
      final AsyncContext context = request.startAsync(request, response);
      asynchronousResponse = new AbstractAsynchronousResponse()
      {
         public void setResponse(Response response)
         {
            try
            {
               setupResponse((ServerResponse) response);
               dispatcher.asynchronousDelivery(Servlet3AsyncHttpRequest.this, httpResponse, response);
            }
            finally
            {
               context.complete();
            }
         }
      };
      return asynchronousResponse;
   }
View Full Code Here

            }
            else if (action.type == Action.TYPE.RESUME) {
                logger.debug("Resuming response: {}", response);

                if (supportSession()) {
                    AsyncContext asyncContext =
                            (AsyncContext) request.getSession().getAttribute("org.atmosphere.container.asyncContext");

                    if (asyncContext != null) {
                        asyncContext.complete();
                    }
                }

                Action nextAction = resumed(request, response);
                if (nextAction.type == Action.TYPE.SUSPEND) {
View Full Code Here

     */
    private void suspend(Action action, HttpServletRequest req, HttpServletResponse res)
            throws IOException, ServletException {

        if (!req.isAsyncStarted()) {
            AsyncContext asyncContext = req.startAsync();
            asyncContext.addListener(new CometListener());
            // Do nothing except setting the times out
            if (action.timeout != -1) {
                asyncContext.setTimeout(action.timeout);
            } else {
                // Jetty 8 does something really weird if you set it to
                // Long.MAX_VALUE, which is to resume automatically.
                asyncContext.setTimeout(Integer.MAX_VALUE);
            }
            req.setAttribute("org.atmosphere.container.asyncContext", asyncContext);

            if (supportSession()) {
                // Store as well in the session in case the resume operation
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public void action(AtmosphereResourceImpl actionEvent) {
        if (actionEvent.action().type == Action.TYPE.RESUME && actionEvent.isInScope()) {
            AsyncContext asyncContext =
                    (AsyncContext) actionEvent.getRequest().getAttribute("org.atmosphere.container.asyncContext");

            // Try to find using the Session
            if (asyncContext == null && supportSession()) {
                asyncContext = (AsyncContext) actionEvent.getRequest().getSession()
                        .getAttribute("org.atmosphere.container.asyncContext");
            }

            if (asyncContext != null && (config.getInitParameter(AtmosphereServlet.RESUME_AND_KEEPALIVE) == null
                    || config.getInitParameter(AtmosphereServlet.RESUME_AND_KEEPALIVE).equalsIgnoreCase("false"))) {
                asyncContext.complete();
            }
        }
        else {
            if (!actionEvent.isInScope()) {
                logger.debug("Already resumed or cancelled: event: {}", actionEvent);
View Full Code Here

TOP

Related Classes of javax.servlet.AsyncContext

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.