Package javax.servlet

Examples of javax.servlet.AsyncListener


            throw new IllegalStateException(sm.getString("coyoteRequest.cannotStartAsync"));
        }
        LinkedHashMap<AsyncListener, AsyncListenerRegistration> localAsyncListeners = asyncListeners;
        asyncListeners = new LinkedHashMap<AsyncListener, AsyncListenerRegistration>();
        for (AsyncListenerRegistration registration : localAsyncListeners.values()) {
            AsyncListener asyncListener = registration.getListener();
            AsyncEvent asyncEvent = new AsyncEvent(asyncContext, registration.getRequest(), registration.getResponse());
            try {
                asyncListener.onStartAsync(asyncEvent);
            } catch (IOException e) {
                throw new IllegalStateException(sm.getString("coyoteRequest.onStartAsyncError",
                        asyncListener.getClass().getName()), e);
            }
        }
        canStartAsync = false;
        if (asyncContext == null) {
            asyncContext = new AsyncContextImpl();
View Full Code Here


      final AsyncContext asyncContext = request.startAsync();
      asyncContext.setTimeout(getSSETimeout());
      queue.setTimeout(getSSETimeout() + 5000);

      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);
        }

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

              writer.write(SSE_TERMINATION_BYTES);

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

              prepareSSEContinue(response);
            }
            catch (final Throwable t) {
              try {
                writeExceptionToOutputStream((HttpServletResponse) asyncContext.getResponse(), t);
              }
              catch (IOException e) {
                throw new RuntimeException("Failed to write exception to output stream", e);
              }
            }
          }
        });

        writer.flush();
      }
    }

    else {
      final AsyncContext asyncContext = request.startAsync();
      asyncContext.setTimeout(60000);
      queue.setTimeout(65000);

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

  public Object suspend(final CometServletResponseImpl response, CometSessionImpl session, HttpServletRequest request) throws IOException {
    assert Thread.holdsLock(response);
    assert session == null || !Thread.holdsLock(session);
    response.flush();
    AsyncContext asyncContext = request.startAsync();
    asyncContext.addListener(new AsyncListener() {
     
      @Override
      public void onStartAsync(AsyncEvent e) throws IOException {
      }
     
View Full Code Here

        System.out.println("====filter servlet 1  before");

        final AsyncContext asyncContext = req.startAsync();
        asyncContext.setTimeout(10L * 1000);
        asyncContext.addListener(new AsyncListener() {
            @Override
            public void onComplete(final AsyncEvent event) throws IOException {
                System.out.println("=====async complete");
            }

View Full Code Here

        System.out.println("====filter servlet 2  before");

        final AsyncContext asyncContext = req.startAsync();
        asyncContext.setTimeout(10L * 1000);
        asyncContext.addListener(new AsyncListener() {
            @Override
            public void onComplete(final AsyncEvent event) throws IOException {
                System.out.println("=====async complete");
            }

View Full Code Here

    @Override
    protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
        final AsyncContext asyncContext = req.startAsync();
        asyncContext.setTimeout(10 * 1000);
        asyncContext.addListener(new AsyncListener() {
            @Override
            public void onComplete(final AsyncEvent event) throws IOException {
                System.out.println("=====async complete");
            }

View Full Code Here

            usernameToAsyncContextMap.put(username, queue);
        }

        queue.add(asyncContext);

        asyncContext.addListener(new AsyncListener() {
            @Override
            public void onComplete(final AsyncEvent event) throws IOException {
                Queue<AsyncContext> queue = usernameToAsyncContextMap.get(username);
                if(queue != null) {
                    queue.remove(event.getAsyncContext());
View Full Code Here

    @Override
    protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
        final AsyncContext asyncContext = req.startAsync();
        asyncContext.setTimeout(2 * 1000);
        asyncContext.addListener(new AsyncListener() {
            @Override
            public void onComplete(final AsyncEvent event) throws IOException {
                System.out.println("=====async complete");
            }

View Full Code Here

    @Override
    protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
        final AsyncContext asyncContext = req.startAsync();
        asyncContext.setTimeout(10 * 1000);

        asyncContext.addListener(new AsyncListener() {
            @Override
            public void onComplete(final AsyncEvent event) throws IOException {
                System.out.println("=====async complete");
            }

View Full Code Here

        System.out.println("===before start async:" + req.isAsyncStarted());
        final AsyncContext asyncContext = req.startAsync();
        System.out.println("===after start async:" + req.isAsyncStarted());

        asyncContext.setTimeout(10L * 1000);
        asyncContext.addListener(new AsyncListener() {
            @Override
            public void onComplete(final AsyncEvent event) throws IOException {
                System.out.println("=====async complete");
            }

View Full Code Here

TOP

Related Classes of javax.servlet.AsyncListener

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.