Package javax.servlet

Examples of javax.servlet.AsyncContext


        httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        return;
      }

      if (checkLimit && limits.isOverLimit(httpRequest, username)) {
        final AsyncContext asyncContext = httpRequest.startAsync(httpRequest, httpResponse);

        asyncExecutor.schedule(LoginService.OVER_LIMIT_DELAY, new Runnable() {
          @Override
          public void run() {
            try {
              processRequest(httpRequest, httpResponse, request, false);
              asyncContext.complete();
            } catch (Exception e) {
              log.error("Unexpected error caught in async task", e);
            }
          }
        });
View Full Code Here


                if (logger.isLoggable(Level.FINE)) {
                    logger.fine("Resuming" + res);
                }

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

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

                Action nextAction = resumed(req, res);
                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()) {
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.isLoggable(Level.FINE)) {
                logger.fine("Already resumed or cancelled " + actionEvent);
            }
View Full Code Here

        }

        @Override
        protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            // step 1 - start async
            AsyncContext actx = req.startAsync();
            actx.setTimeout(Long.MAX_VALUE);
            actx.addListener(new AsyncListener() {

                @Override
                public void onTimeout(AsyncEvent event) throws IOException {
                    log.info("onTimeout");
View Full Code Here

        public volatile TestReadListener rlistener;

        @Override
        protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            // step 1 - start async
            AsyncContext actx = req.startAsync();
            actx.setTimeout(Long.MAX_VALUE);
            actx.addListener(new AsyncListener() {

                @Override
                public void onTimeout(AsyncEvent event) throws IOException {
                    log.info("onTimeout");
View Full Code Here

        public volatile TestReadWriteListener rwlistener;

        @Override
        protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            // step 1 - start async
            AsyncContext actx = req.startAsync();
            actx.setTimeout(Long.MAX_VALUE);

            // step 2 - notify on read
            ServletInputStream in = req.getInputStream();
            rwlistener = new TestReadWriteListener(actx);
            in.setReadListener(rwlistener);
View Full Code Here

     */
    public void event(Request request, Response response, HttpEvent event)
        throws IOException, ServletException {
       
        // Async processing
        AsyncContext asyncContext = request.getAsyncContext();
        if (asyncContext != null) {
            async(request, response, event);
            return;
        }
       
View Full Code Here

    queue.heartBeat();

    final OutputStreamWriteAdapter writer;

    if (isSSERequest(request)) {
      final AsyncContext asyncContext = request.startAsync();
      asyncContext.setTimeout(getSSETimeout());
      queue.setTimeout(getSSETimeout() + 5000);
     
      final HttpServletResponse asynResponse = (HttpServletResponse) asyncContext.getResponse();
      prepareSSE(asynResponse);
      prepareSSEContinue(asynResponse);
      asynResponse.getOutputStream().flush();
      writer = new OutputStreamWriteAdapter(asynResponse.getOutputStream());

      asyncContext.addListener(new AsyncListener() {
        @Override
        public void onComplete(final AsyncEvent event) throws IOException {
          synchronized (queue.getActivationLock()) {
            queue.setActivationCallback(null);
            asyncContext.complete();
          }
        }

        @Override
        public void onTimeout(final AsyncEvent event) throws IOException {
          onComplete(event);
        }

        @Override
        public void onError(final AsyncEvent event) throws IOException {
          queue.setActivationCallback(null);
        }

        @Override
        public void onStartAsync(final AsyncEvent event) throws IOException {
        }
      });

      synchronized (queue.getActivationLock()) {
        if (queue.messagesWaiting()) {
          queue.poll(writer);
          writer.write(SSE_TERMINATION_BYTES);
          writer.flush();
          return;
        }

        queue.setActivationCallback(new QueueActivationCallback() {
          @Override
          public void activate(final MessageQueue queue) {
            try {
              queue.poll(writer);

              writer.write(SSE_TERMINATION_BYTES);

              queue.heartBeat();
              writer.flush();

              prepareSSEContinue(asynResponse);
            }
            catch (IOException e) {
              log.debug("Closing queue with id: " + queue.getSession().getSessionId() + " due to IOException", e);
              queue.stopQueue();
            }
            catch (final Throwable t) {
              try {
                writeExceptionToOutputStream((HttpServletResponse) asyncContext.getResponse(), t);
              }
              catch (Throwable t2) {
                log.debug("Failed to write exception to dead client", t2);
              }
            }
          }
        });
      }
    }

    else {
      final AsyncContext asyncContext = request.startAsync();
      asyncContext.setTimeout(60000);
      queue.setTimeout(65000);
      writer = new OutputStreamWriteAdapter(asyncContext.getResponse().getOutputStream());

      asyncContext.addListener(new AsyncListener() {
          @Override
          public void onComplete(final AsyncEvent event) throws IOException {
            synchronized (queue.getActivationLock()) {
              queue.setActivationCallback(null);
              asyncContext.complete();
            }
          }

          @Override
          public void onTimeout(final AsyncEvent event) throws IOException {
            onComplete(event);
          }

          @Override
          public void onError(final AsyncEvent event) throws IOException {
            queue.setActivationCallback(null);
          }

          @Override
          public void onStartAsync(final AsyncEvent event) throws IOException {
          }
        });

      synchronized (queue.getActivationLock()) {
        if (queue.messagesWaiting()) {
          queue.poll(writer);
          asyncContext.complete();
          return;
        }

        queue.setActivationCallback(new QueueActivationCallback() {
          @Override
          public void activate(final MessageQueue queue) {
            try {
              queue.poll(writer);
              queue.setActivationCallback(null);

              queue.heartBeat();
              writer.flush();
            }
            catch (IOException e) {
              log.debug("Closing queue with id: " + queue.getSession().getSessionId() + " due to IOException", e);
             
            }
            catch (final Throwable t) {
              try {
                writeExceptionToOutputStream((HttpServletResponse) asyncContext.getResponse(), t);
              }
              catch (Throwable t2) {
                log.debug("Failed to write exception to dead client", t2);
              }
            }
            finally {
              asyncContext.complete();
            }
          }
        });
        writer.flush();
      }
View Full Code Here

     */
    public void event(Request request, Response response, HttpEvent event)
        throws IOException, ServletException {
       
        // Async processing
        AsyncContext asyncContext = request.getAsyncContext();
        if (asyncContext != null) {
            async(request, response, event);
            return;
        }
       
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.