Package org.atmosphere.cpr

Examples of org.atmosphere.cpr.Action


    @Override
    public Action cancelled(AtmosphereRequest req, AtmosphereResponse res)
            throws IOException, ServletException {

        Action action = super.cancelled(req, res);
        if (req.getAttribute(MAX_INACTIVE) != null && Long.class.cast(req.getAttribute(MAX_INACTIVE)) == -1) {
            endAsyncContext(req);
        }
        return action;
    }
View Full Code Here


    @Override
    public Action service(AtmosphereRequest req, AtmosphereResponse res)
            throws IOException, ServletException {

        CometContext ctx = CometEngine.getEngine().getCometContext(atmosphereCtx);
        Action action = suspended(req, res);
        if (action.type() == Action.TYPE.SUSPEND) {
            suspend(ctx, action, req, res);
        } else if (action.type() == Action.TYPE.RESUME) {
            resume(req, ctx);
        }
        return action;
    }
View Full Code Here

    @Override
    public Action cancelled(AtmosphereRequest req, AtmosphereResponse res)
            throws IOException, ServletException {

        Action action = super.cancelled(req, res);
        if (req.getAttribute(MAX_INACTIVE) != null && Long.class.cast(req.getAttribute(MAX_INACTIVE)) == -1) {
            resume(req, CometEngine.getEngine().getCometContext(atmosphereCtx));
        }
        return action;
    }
View Full Code Here

    @Override
    public Action service(AtmosphereRequest req, AtmosphereResponse res)
            throws IOException, ServletException {

        Action action;
        action = suspended(req, res);
        if (action.type() == Action.TYPE.SUSPEND) {
            req.setAttribute(SUSPEND, action);
        } else if (action.type() == Action.TYPE.RESUME) {
            req.setAttribute(SUSPEND, action);

            // If resume occurs during a suspend operation, stop processing.
            Boolean resumeOnBroadcast = (Boolean) req.getAttribute(ApplicationConfig.RESUME_ON_BROADCAST);
            if (resumeOnBroadcast != null && resumeOnBroadcast) {
                return action;
            }

            Action nextAction = resumed(req, res);
            if (nextAction.type() == Action.TYPE.SUSPEND) {
                req.setAttribute(SUSPEND, action);
            }
        }

        return action;
View Full Code Here

        super(config);
    }

    @Override
    public Action service(final AtmosphereRequest req, final AtmosphereResponse res) throws IOException, ServletException {
        Action action = null;

        Continuation c = (Continuation) req.getAttribute(Continuation.class.getName());

        if (c == null || c.isInitial()) {
            action = suspended(req, res);
            if (action.type() == Action.TYPE.SUSPEND && req.getAttribute(FrameworkConfig.CANCEL_SUSPEND_OPERATION) == null) {
                c = getContinuation(req);
                req.setAttribute(Continuation.class.getName(), c);

                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.setAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE, req.getAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE));
                c.addContinuationListener(new ContinuationListener() {

                    @Override
                    public void onComplete(Continuation continuation) {
                        AtmosphereResourceImpl r = (AtmosphereResourceImpl) req.getAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE);
                        if (r != null) {
                            try {
                                r.cancel();
                            } catch (IOException e) {
                            }
                        }
                    }

                    @Override
                    public void onTimeout(Continuation continuation) {
                        AtmosphereResourceImpl r = (AtmosphereResourceImpl) req.getAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE);
                        if (r != null) {
                            try {
                                timedout(r.getRequest(), r.getResponse());
                            } catch (Throwable t) {
                                logger.error("", t);
                            }
                        } else {
                            logger.trace("AtmosphereResource was null");
                        }
                        try {
                            continuation.complete();
                        } catch (Throwable t) {
                        }
                    }
                });

                if (req.getAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE) != null) {
                    c.suspend(res);
                }
            } else if (action.type() == Action.TYPE.RESUME) {
                // If resume occurs during a suspend operation, stop processing.
                Boolean resumeOnBroadcast = (Boolean) req.getAttribute(ApplicationConfig.RESUME_ON_BROADCAST);
                if (resumeOnBroadcast != null && resumeOnBroadcast) {
                    return action;
                }
View Full Code Here

        boolean skipClose = false;
        final PlayAsyncIOWriter w = PlayAsyncIOWriter.class.cast(response.getAsyncIOWriter());

        try {

            Action a = framework.doCometSupport(request, response);
            final AtmosphereResourceImpl impl = (AtmosphereResourceImpl) request.getAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE);

            String transport = (String) request.getAttribute(FrameworkConfig.TRANSPORT_IN_USE);
            if (transport == null) {
                transport = request.getHeader(X_ATMOSPHERE_TRANSPORT);
            }

            if (a.type() == Action.TYPE.SUSPEND) {
                if (transport.equalsIgnoreCase(HeaderConfig.LONG_POLLING_TRANSPORT) || transport.equalsIgnoreCase(HeaderConfig.JSONP_TRANSPORT)) {
                    resumeOnBroadcast = true;
                }
            } else {
                keptOpen = false;
            }

            logger.debug("Transport {} resumeOnBroadcast {}", transport, resumeOnBroadcast);

            final Action action = (Action) request.getAttribute(NettyCometSupport.SUSPEND);
            if (action != null && action.type() == Action.TYPE.SUSPEND && action.timeout() != -1) {
                final AtomicReference<Future<?>> f = new AtomicReference<Future<?>>();
                f.set(suspendTimer.scheduleAtFixedRate(new Runnable() {
                    @Override
                    public void run() {
                        if (!w.isClosed() && (System.currentTimeMillis() - w.lastTick()) > action.timeout()) {
                            asynchronousProcessor.endRequest(impl, false);
                            f.get().cancel(true);
                        }
                    }
                }, action.timeout(), action.timeout(), TimeUnit.MILLISECONDS));
            } else if (action != null && action.type() == Action.TYPE.RESUME) {
                resumeOnBroadcast = false;
            }
            w.resumeOnBroadcast(resumeOnBroadcast);
        } catch (Throwable e) {
            logger.error("Unable to process request", e);
View Full Code Here

TOP

Related Classes of org.atmosphere.cpr.Action

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.