Package javax.servlet

Examples of javax.servlet.AsyncListener


        this.traceRequests = metricRegistry.timer(name(prefix, "trace-requests"));
        this.connectRequests = metricRegistry.timer(name(prefix, "connect-requests"));
        this.moveRequests = metricRegistry.timer(name(prefix, "move-requests"));
        this.otherRequests = metricRegistry.timer(name(prefix, "other-requests"));

        this.listener = new AsyncListener() {
            private long startTime;

            @Override
            public void onTimeout(AsyncEvent event) throws IOException {
                asyncTimeouts.mark();
View Full Code Here


        this.traceRequests = metricRegistry.timer(name(prefix, "trace-requests"));
        this.connectRequests = metricRegistry.timer(name(prefix, "connect-requests"));
        this.moveRequests = metricRegistry.timer(name(prefix, "move-requests"));
        this.otherRequests = metricRegistry.timer(name(prefix, "other-requests"));

        this.listener = new AsyncListener() {
            private long startTime;

            @Override
            public void onTimeout(AsyncEvent event) throws IOException {
                asyncTimeouts.mark();
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

        @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

                boolean error = (event.getType() == EventType.ERROR) ? true : false;
                Iterator<AsyncListenerRegistration> asyncListenerRegistrations =
                    asyncContext.getAsyncListeners().values().iterator();
                while (asyncListenerRegistrations.hasNext()) {
                    AsyncListenerRegistration asyncListenerRegistration = asyncListenerRegistrations.next();
                    AsyncListener asyncListener = asyncListenerRegistration.getListener();
                    try {
                        if (timeout) {
                            AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
                                    asyncListenerRegistration.getRequest(), asyncListenerRegistration.getResponse());
                            asyncListener.onTimeout(asyncEvent);
                        } else if (error) {
                            Throwable t = (Throwable) request.getAttribute(Globals.EXCEPTION_ATTR);
                            AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
                                    asyncListenerRegistration.getRequest(), asyncListenerRegistration.getResponse(), t);
                            asyncListener.onError(asyncEvent);
                        } else {
                            AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
                                    asyncListenerRegistration.getRequest(), asyncListenerRegistration.getResponse());
                            asyncListener.onComplete(asyncEvent);
                        }
                    } catch (Throwable e) {
                        container.getLogger().error(sm.getString("standardWrapper.async.listenerError",
                                getContainer().getName()), e);
                        exception(request, response, e);
View Full Code Here

      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();
View Full Code Here

                } else if (request.getAsyncContext() != null) {
                    // The AC was closed right away, so call onComplete as no event callback
                    // will occur in that case
                    Request.AsyncContextImpl asyncContext = (Request.AsyncContextImpl) request.getAsyncContext();
                    for (AsyncListenerRegistration asyncListenerRegistration : asyncContext.getAsyncListeners().values()) {
                        AsyncListener asyncListener = asyncListenerRegistration.getListener();
                        AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
                                asyncListenerRegistration.getRequest(), asyncListenerRegistration.getResponse());
                        try {
                            asyncListener.onComplete(asyncEvent);
                        } catch (Throwable t) {
                            log.error(sm.getString("coyoteAdapter.complete", asyncListener.getClass()), t);
                        }
                    }
                }

            }
View Full Code Here

            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

                } else if (request.getAsyncContext() != null) {
                    // The AC was closed right away, so call onComplete as no event callback
                    // will occur in that case
                    Request.AsyncContextImpl asyncContext = (Request.AsyncContextImpl) request.getAsyncContext();
                    for (AsyncListenerRegistration asyncListenerRegistration : asyncContext.getAsyncListeners().values()) {
                        AsyncListener asyncListener = asyncListenerRegistration.getListener();
                        AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
                                asyncListenerRegistration.getRequest(), asyncListenerRegistration.getResponse());
                        try {
                            asyncListener.onComplete(asyncEvent);
                        } catch (Throwable t) {
                            log.error(sm.getString("coyoteAdapter.complete", asyncListener.getClass()), t);
                        }
                    }
                }

            }
View Full Code Here

                boolean error = (event.getType() == EventType.ERROR) ? true : false;
                Iterator<AsyncListenerRegistration> asyncListenerRegistrations =
                    asyncContext.getAsyncListeners().values().iterator();
                while (asyncListenerRegistrations.hasNext()) {
                    AsyncListenerRegistration asyncListenerRegistration = asyncListenerRegistrations.next();
                    AsyncListener asyncListener = asyncListenerRegistration.getListener();
                    try {
                        if (timeout) {
                            AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
                                    asyncListenerRegistration.getRequest(), asyncListenerRegistration.getResponse());
                            asyncListener.onTimeout(asyncEvent);
                        } else if (error) {
                            Throwable t = (Throwable) request.getAttribute(Globals.EXCEPTION_ATTR);
                            AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
                                    asyncListenerRegistration.getRequest(), asyncListenerRegistration.getResponse(), t);
                            asyncListener.onError(asyncEvent);
                        } else {
                            AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
                                    asyncListenerRegistration.getRequest(), asyncListenerRegistration.getResponse());
                            asyncListener.onComplete(asyncEvent);
                        }
                    } catch (Throwable e) {
                        container.getLogger().error(sm.getString("standardWrapper.async.listenerError",
                                getContainer().getName()), e);
                        exception(request, response, e);
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.