Package javax.servlet

Examples of javax.servlet.AsyncContext


      /*
      if (_request == null)
        return;
        */
     
      AsyncContext oldContext = _context;
     
      if (_request.isConnectionClosed() || _request.isClosed())
        return;
     
      _context = _request.startAsync();
View Full Code Here


   
    @Override
    public boolean wake()
    {
      if (! _isWake.getAndSet(true)) {
        AsyncContext context = _context;
       
        if (context != null) {
          try {
            context.dispatch();
          } catch (Exception e) {
            log.log(Level.FINER, e.toString(), e);
           
            return false;
          }
View Full Code Here

    }

    @Override
    public void close()
    {
      AsyncContext context = _context;
      _context = null;
     
      if (context != null) {
        context.complete();
      }
    }
View Full Code Here

            context.addListener(this);
        }

        void startAsyncAgain() {
           
            AsyncContext old = context;
            try {
                context = req.startAsync();
                context.addListener(this);
                isComplete = false;
            } catch (IllegalStateException ex) {
View Full Code Here

            } else {
                req.getCookies(); // We have to do this so Tomcat will actually parse the cookies from the request
            }

            req.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", Boolean.TRUE);
            AsyncContext asyncContext = req.startAsync();
            asyncContext.setTimeout(5000);

            bug55772Latch1.countDown();

            PrintWriter writer = asyncContext.getResponse().getWriter();
            writer.print('\n');
            writer.flush();

            bug55772Latch2.countDown();
        }
View Full Code Here

  private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseQueryServlet.class);

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType(MEDIATYPE_APPLICATION_JSON);
    AsyncContext asyncContext = req.startAsync();
    int randId = ThreadLocalRandom.current().nextInt(WORLD_LEAST_VALUE, WORLD_BOUND_VALUE+1);
    ListenableFuture<?> future = dao.read(randId);
    addResponseCallback(asyncContext, future, executorService);
  }
View Full Code Here

  private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseQueriesServlet.class);

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType(MEDIATYPE_APPLICATION_JSON);
    final AsyncContext asyncContext = req.startAsync();
    ListenableFuture<?> future = dao.read(generateRandomNumbers(getQueries(req.getParameter("queries")),
      WORLD_LEAST_VALUE, WORLD_BOUND_VALUE+1));
    addResponseCallback(asyncContext, future, executorService);
  }
View Full Code Here

            private static final long serialVersionUID = 1L;

            @Override
            protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
            {
                final AsyncContext asyncContext = req.startAsync(req, resp);
                asyncContext.setTimeout(2000);
                asyncContext.start(new Runnable()
                {
                    public void run()
                    {
                        try
                        {
                            // Simulate a long running process...
                            Thread.sleep(1000);

                            HttpServletResponse response = (HttpServletResponse) asyncContext.getResponse();
                            response.setStatus(SC_OK);
                            response.getWriter().printf("Hello Async world!");

                            asyncContext.complete();
                        }
                        catch (InterruptedException e)
                        {
                            Thread.currentThread().interrupt();
                        }
View Full Code Here

            protected void doGet(final HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
            {
                DispatcherType dispatcherType = req.getDispatcherType();
                if (DispatcherType.REQUEST == dispatcherType)
                {
                    final AsyncContext asyncContext = req.startAsync(req, resp);
                    asyncContext.start(new Runnable()
                    {
                        public void run()
                        {
                            try
                            {
                                // Simulate a long running process...
                                Thread.sleep(1000);

                                asyncContext.getRequest().setAttribute("msg", "Hello Async world!");
                                asyncContext.dispatch();
                            }
                            catch (InterruptedException e)
                            {
                                Thread.currentThread().interrupt();
                            }
View Full Code Here

    private LongRunningService longRunningService;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
        // Here the request is put in asynchronous mode
        AsyncContext asyncContext = req.startAsync();

        // This method will return immediately when invoked,
        // the actual execution will run in a separate thread.
        longRunningService.readData(asyncContext);
    }
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.