Package org.eclipse.jetty.continuation

Examples of org.eclipse.jetty.continuation.Continuation


     * {@inheritDoc}
     */
    public Action service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
        Action action = null;

        Continuation c = ContinuationSupport.getContinuation(req);

        if (c.isInitial()) {
            action = suspended(req, res);
            if (action.type == Action.TYPE.SUSPEND) {
                logger.debug("Suspending {}", res);

                // Do nothing except setting the times out
                if (action.timeout != -1) {
                    c.setTimeout(action.timeout);
                }
                else {
                    // Jetty 7 does something really weird if you set it to
                    // Long.MAX_VALUE, which is to resume automatically.
                    c.setTimeout(Integer.MAX_VALUE);
                }
                c.suspend();
            }
            else if (action.type == Action.TYPE.RESUME) {
                logger.debug("Resume {}", res);

                if (!resumed.remove(c)) {
                    try {
                        c.complete();
                    }
                    catch (IllegalStateException ex) {
                        logger.debug("Continuation.complete()", ex);
                    }
                    finally {
                        resumed(req, res);
                    }
                }
            }
        }
        else if (!c.isInitial() && c.isExpired()) {
            timedout(req, res);
        }
        return action;
    }
View Full Code Here


    public void action(AtmosphereResourceImpl actionEvent) {
        super.action(actionEvent);
        if (actionEvent.isInScope() && actionEvent.action().type == Action.TYPE.RESUME &&
                (config.getInitParameter(AtmosphereServlet.RESUME_AND_KEEPALIVE) == null ||
                        config.getInitParameter(AtmosphereServlet.RESUME_AND_KEEPALIVE).equalsIgnoreCase("false"))) {
            Continuation c = ContinuationSupport.getContinuation(actionEvent.getRequest());
            try {
                c.complete();
            }
            catch (IllegalStateException ex) {
                logger.debug("Continuation.complete() failed", ex);
            }
            finally {
View Full Code Here

                                            long timeout = session.calculateTimeout(getTimeout());

                                            // Support old clients that do not send advice:{timeout:0} on the first connect
                                            if (timeout > 0 && wasConnected && session.isConnected()) {
                                                // Suspend and wait for messages
                                                Continuation continuation = ContinuationSupport.getContinuation(request);
                                                continuation.setTimeout(timeout);
                                                continuation.suspend(response);
                                                scheduler = new LongPollScheduler(session, continuation, reply, browserId);
                                                session.setScheduler(scheduler);
                                                request.setAttribute(LongPollScheduler.ATTRIBUTE, scheduler);
                                                reply = null;
                                                metaConnectSuspended(request, session, timeout);
View Full Code Here

    public boolean supportWebSocket() {
        return true;
    }

    protected Continuation getContinuation(AtmosphereRequest req) {
        Continuation falseContinuation = (Continuation) req.getAttribute(Continuation.ATTRIBUTE);
        req.setAttribute(Continuation.ATTRIBUTE, null);
        Continuation c = ContinuationSupport.getContinuation(req);
        req.setAttribute(Continuation.ATTRIBUTE, falseContinuation);
        return c;
    }
View Full Code Here

    public void action(AtmosphereResourceImpl actionEvent) {
        super.action(actionEvent);
        if (actionEvent.isInScope() && actionEvent.action().type == Action.TYPE.RESUME
                && (config.getInitParameter(AtmosphereServlet.RESUME_AND_KEEPALIVE) == null
                || config.getInitParameter(AtmosphereServlet.RESUME_AND_KEEPALIVE).equalsIgnoreCase("false"))) {
            Continuation c = ContinuationSupport.getContinuation(actionEvent.getRequest());
            try {
                c.complete();
            } catch (java.lang.IllegalStateException ex) {
                if (logger.isLoggable(Level.FINE)) {
                    logger.fine("Continuation.complete() " + ex);
                }
            } finally {
View Full Code Here

     */
    public Action service(HttpServletRequest req, HttpServletResponse res)
            throws IOException, ServletException {
        Action action = null;

        Continuation c = ContinuationSupport.getContinuation(req);

        if (c.isInitial()) {
            action = suspended(req, res);
            if (action.type == Action.TYPE.SUSPEND) {
                if (logger.isLoggable(Level.FINE)) {
                    logger.fine("Suspending " + res);
                }
                // Do nothing except setting the times out
                if (action.timeout != -1) {
                    c.setTimeout(action.timeout);
                } else {
                    // Jetty 7 does something really weird if you set it to
                    // Long.MAX_VALUE, which is to resume automatically.
                    c.setTimeout(Integer.MAX_VALUE);
                }
                c.suspend();
            } else if (action.type == Action.TYPE.RESUME) {
                if (logger.isLoggable(Level.FINE)) {
                    logger.fine("Resume " + res);
                }

                if (!resumed.remove(c)) {
                    try {
                        c.complete();
                    } catch (java.lang.IllegalStateException ex) {
                        if (logger.isLoggable(Level.FINE)) {
                            logger.fine("Continuation.complete() " + ex);
                        }
                    } finally {
                        resumed(req, res);
                    }
                }
            }
        } else if (!c.isInitial() && c.isExpired()) {
            timedout(req, res);
        }
        return action;
    }
View Full Code Here

                }
                update.offer(data.roomsToString());
            }
        } else {
            //save the continuation to get the servlet response
            Continuation continuation = ContinuationSupport.getContinuation(req);
            // optionally set a timeout to avoid suspending requests for too long
            continuation.setTimeout(0);
            continuation.suspend();
            continuations.offer(continuation);
        }
    }
View Full Code Here

        }
       
        final Exchange result = (Exchange) request.getAttribute(EXCHANGE_ATTRIBUTE_NAME);
        if (result == null) {
            // no asynchronous result so leverage continuation
            final Continuation continuation = ContinuationSupport.getContinuation(request);
            if (continuation.isInitial() && continuationTimeout != null) {
                // set timeout on initial
                continuation.setTimeout(continuationTimeout);
            }

            // are we suspended and a request is dispatched initially?
            if (consumer.isSuspended() && continuation.isInitial()) {
                response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
                return;
            }

            if (continuation.isExpired()) {
                String id = (String) continuation.getAttribute(EXCHANGE_ATTRIBUTE_ID);
                // remember this id as expired
                expiredExchanges.put(id, id);
                log.warn("Continuation expired of exchangeId: {}", id);
                response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
                return;
            }

            // a new request so create an exchange
            final Exchange exchange = new DefaultExchange(consumer.getEndpoint(), ExchangePattern.InOut);

            if (consumer.getEndpoint().isBridgeEndpoint()) {
                exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
            }
            if (consumer.getEndpoint().isDisableStreamCache()) {
                exchange.setProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, Boolean.TRUE);
            }
           
            HttpHelper.setCharsetFromContentType(request.getContentType(), exchange);
           
            exchange.setIn(new HttpMessage(exchange, request, response));
            // set context path as header
            String contextPath = consumer.getEndpoint().getPath();
            exchange.getIn().setHeader("CamelServletContextPath", contextPath);
           
            String httpPath = (String)exchange.getIn().getHeader(Exchange.HTTP_PATH);
            // here we just remove the CamelServletContextPath part from the HTTP_PATH
            if (contextPath != null
                && httpPath.startsWith(contextPath)) {
                exchange.getIn().setHeader(Exchange.HTTP_PATH,
                        httpPath.substring(contextPath.length()));
            }

            if (log.isTraceEnabled()) {
                log.trace("Suspending continuation of exchangeId: {}", exchange.getExchangeId());
            }
            continuation.setAttribute(EXCHANGE_ATTRIBUTE_ID, exchange.getExchangeId());

            // we want to handle the UoW
            try {
                consumer.createUoW(exchange);
            } catch (Exception e) {
                log.error("Error processing request", e);
                throw new ServletException(e);
            }

            // must suspend before we process the exchange
            continuation.suspend();

            ClassLoader oldTccl = overrideTccl(exchange);

            if (log.isTraceEnabled()) {
                log.trace("Processing request for exchangeId: {}", exchange.getExchangeId());
            }
            // use the asynchronous API to process the exchange
           
            consumer.getAsyncProcessor().process(exchange, new AsyncCallback() {
                public void done(boolean doneSync) {
                    // check if the exchange id is already expired
                    boolean expired = expiredExchanges.remove(exchange.getExchangeId()) != null;
                    if (!expired) {
                        if (log.isTraceEnabled()) {
                            log.trace("Resuming continuation of exchangeId: {}", exchange.getExchangeId());
                        }
                        // resume processing after both, sync and async callbacks
                        continuation.setAttribute(EXCHANGE_ATTRIBUTE_NAME, exchange);
                        continuation.resume();
                    } else {
                        log.warn("Cannot resume expired continuation of exchangeId: {}", exchange.getExchangeId());
                    }
                }
            });
View Full Code Here

            if (sentResponses.size() > maximumSentResponses || (!isClientAcknowledgements() && sentResponses.size() > requests)) {
                sentResponses.remove(sentResponses.firstKey());
            }
        }
       
        Continuation continuation = ContinuationSupport.getContinuation(req.getHttpServletRequest());
        continuation.setAttribute("response", boshResponse);
        continuation.resume();
        latestWriteTimestamp = System.currentTimeMillis();
    }
View Full Code Here

        body = boshHandler.addAttribute(body, "condition", condition);
        BoshResponse boshResponse = getBoshResponse(body, null);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("BOSH writing response: {}", new String(boshResponse.getContent()));
        }
        Continuation continuation = ContinuationSupport.getContinuation(req.getHttpServletRequest());
        continuation.setAttribute("response", boshResponse);
        continuation.resume();
        close();
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.continuation.Continuation

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.