Package org.atmosphere.cpr

Examples of org.atmosphere.cpr.AtmosphereResourceEventListener


            final Meteor m = Meteor.build(req);
            req.getSession().setAttribute("meteor", m);
            m.suspend(5000, false);
           
            m.broadcast("resume");
            m.addListener(new AtmosphereResourceEventListener(){

                @Override
                public void onSuspend(final AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event){
                }
View Full Code Here


           
            m.suspend(5000, false);
            broadcasterId.set(m.getBroadcaster().getID());

            res.getOutputStream().write("resume".getBytes());
            m.addListener(new AtmosphereResourceEventListener(){

                @Override
                public void onSuspend(final AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event){
                     event.getResource().getRequest().setAttribute(AtmosphereServlet.RESUME_ON_BROADCAST, "true");
                }
View Full Code Here

                    outputJunk = outputJunk(request,outputComments);
                    resumeOnBroadcast = resumeOnBroadcast(request,(action == Action.SUSPEND_RESUME));

                    for (Class<? extends AtmosphereResourceEventListener> listener : listeners) {
                        try {
                            AtmosphereResourceEventListener el = listener.newInstance();
                            InjectorProvider.getInjector().inject(el);
                            if (r instanceof AtmosphereEventLifecycle) {
                                ((AtmosphereEventLifecycle) r).addEventListener(el);
                            }
                        } catch (Throwable t) {
View Full Code Here

        boolean resumeOnBroadcast = resumeOnBroadcast(resume, req);

        if (listeners != null) {
            for (Class<? extends AtmosphereResourceEventListener> listener : listeners) {
                try {
                    AtmosphereResourceEventListener el = listener.newInstance();
                    InjectorProvider.getInjector().inject(el);
                    r.addEventListener(el);
                } catch (Throwable t) {
                    throw new IllegalStateException("Invalid AtmosphereResourceEventListener " + listener, t);
                }
View Full Code Here

                        final boolean resumeOnBroadcast = transport.equals(JSONP_TRANSPORT) || transport.equals(LONG_POLLING_TRANSPORT);

                        if (listeners != null) {
                            for (Class<? extends AtmosphereResourceEventListener> listener : listeners) {
                                try {
                                    AtmosphereResourceEventListener el = atmosphereFramework.newClassInstance(AtmosphereResourceEventListener.class, listener);
                                    r.addEventListener(el);
                                } catch (Throwable t) {
                                    throw new WebApplicationException(
                                            new IllegalStateException("Invalid AtmosphereResourceEventListener " + listener));
                                }
                            }
                        }
                        final Object entity = response.getEntity();

                        r.addEventListener(new OnSuspend() {
                            @Override
                            public void onSuspend(AtmosphereResourceEvent event) {
                                try {
                                    if (entity != null) {
                                        if (waitForResource) {
                                            bcaster.awaitAndBroadcast(entity, 30, TimeUnit.SECONDS);
                                        } else {
                                            bcaster.broadcastOnResume(entity);
                                            event.getResource().resume();
                                        }
                                    }
                                } finally {
                                    event.getResource().removeEventListener(this);
                                }
                            }
                        });

                        if (resumeOnBroadcast) {
                            servletReq.setAttribute(RESUME_ON_BROADCAST, new Boolean(true));
                        }

                        r.setBroadcaster(bcaster);
                        executeSuspend(r, timeout, resumeOnBroadcast, null, request, response, writeEntity);
                    } else {
                        Object entity = response.getEntity();
                        if (waitForResource) {
                            bcaster.awaitAndBroadcast(entity, 30, TimeUnit.SECONDS);
                        } else {
                            bcaster.broadcast(entity);
                        }

                        if (subProtocol == null && writeEntity) {
                            try {
                                if (Callable.class.isAssignableFrom(entity.getClass())) {
                                    entity = Callable.class.cast(entity).call();
                                }
                                synchronized (response) {
                                    response.setEntity(entity);
                                    response.write();
                                }
                            } catch (Throwable t) {
                                logger.debug("Error running Callable", t);
                                response.setEntity(null);
                            }
                        } else {
                            response.setEntity(null);
                        }
                    }
                    break;
                case SUSPEND_RESPONSE:
                    SuspendResponse<?> s = SuspendResponse.class.cast(JResponseAsResponse.class.cast(response.getResponse()).getJResponse());
                    boolean resumeOnBroadcast = resumeOnBroadcast(s.resumeOnBroadcast());

                    for (AtmosphereResourceEventListener el : s.listeners()) {
                        r.addEventListener(el);
                    }

                    if (s.getEntity() == null) {
                        //https://github.com/Atmosphere/atmosphere/issues/423
                        response.setEntity("");
                    }

                    Broadcaster bc = s.broadcaster();
                    if (bc == null && s.scope() != Suspend.SCOPE.REQUEST) {
                        bc = (Broadcaster) servletReq.getAttribute(INJECTED_BROADCASTER);
                    }

                    suspend(resumeOnBroadcast,
                            translateTimeUnit(s.period().value(), s.period().timeUnit()), request, response, bc, r, s.scope(), s.writeEntity());

                    break;
                case SUBSCRIBE:
                case SUSPEND:
                case SUSPEND_RESUME:
                    resumeOnBroadcast = resumeOnBroadcast((action == Action.SUSPEND_RESUME));

                    if (listeners != null) {
                        for (Class<? extends AtmosphereResourceEventListener> listener : listeners) {
                            try {
                                AtmosphereResourceEventListener el = atmosphereFramework.newClassInstance(AtmosphereResourceEventListener.class, listener);
                                r.addEventListener(el);
                            } catch (Throwable t) {
                                throw new WebApplicationException(
                                        new IllegalStateException("Invalid AtmosphereResourceEventListener " + listener, t));
                            }
View Full Code Here

TOP

Related Classes of org.atmosphere.cpr.AtmosphereResourceEventListener

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.