Examples of AsyncListener


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

Examples of javax.servlet.AsyncListener

      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

Examples of javax.servlet.AsyncListener

  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

Examples of javax.servlet.AsyncListener

        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

Examples of javax.servlet.AsyncListener

        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

Examples of javax.servlet.AsyncListener

    @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

Examples of javax.servlet.AsyncListener

            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

Examples of javax.servlet.AsyncListener

    @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

Examples of javax.servlet.AsyncListener

    @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

Examples of javax.servlet.AsyncListener

        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
Copyright © 2018 www.massapi.com. 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.