Examples of Broadcaster


Examples of org.atmosphere.cpr.Broadcaster

        res.addHeader("Pragma", "no-cache");

        if (req.getMethod().equalsIgnoreCase("GET")) {
            event.suspend();

            Broadcaster bc = event.getBroadcaster();
            bc.getBroadcasterConfig().addFilter(new XSSHtmlFilter());
            bc.broadcast(event.getAtmosphereConfig().getWebServerName()
                    + "**has suspended a connection from "
                    + req.getRemoteAddr());
        } else if (req.getMethod().equalsIgnoreCase("POST")) {
            res.setCharacterEncoding("UTF-8");
            String action = req.getParameterValues("action")[0];
View Full Code Here

Examples of org.atmosphere.cpr.Broadcaster

     */
    @Override
    public void init() {
        logger.info("Starting Atmosphere Redis Clustering support");

        final Broadcaster broadcaster = bc;
        listener.submit(new Runnable() {
            public void run() {
                jedisSubscriber.subscribe(new JedisPubSub() {
                    public void onMessage(String channel, String message) {
                        receivedMessages.offer(message);
                        broadcaster.broadcast(message);
                    }

                    public void onSubscribe(String channel, int subscribedChannels) {
                        logger.debug("onSubscribe(): channel: {}", channel);
                    }
View Full Code Here

Examples of org.atmosphere.cpr.Broadcaster

            public void onRequest(AtmosphereResource<HttpServletRequest, HttpServletResponse> event) throws IOException {
                currentTime = System.currentTimeMillis();
                event.suspend(5000, false);
                try {
                Broadcaster b = BroadcasterFactory.getDefault().lookup(DefaultBroadcaster.class, "ExternalBroadcaster", true);
                b.addAtmosphereResource(event);
                b.broadcast("Outer broadcast").get();


                    event.getBroadcaster().broadcast("Inner broadcast").get();
                } catch (InterruptedException e) {
                    e.printStackTrace();
View Full Code Here

Examples of org.atmosphere.cpr.Broadcaster

                        if (r instanceof AtmosphereEventLifecycle) {
                            ((AtmosphereEventLifecycle) r).addEventListener(el);
                        }
                    }

                    Broadcaster bc = s.broadcaster();
                    if (bc == null){
                        bc = (Broadcaster) servletReq.getAttribute(INJECTED_BROADCASTER);
                    }

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

                    break;
                case SUSPEND:
                case SUSPEND_RESUME:
                    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) {
                            throw new WebApplicationException(
                                    new IllegalStateException("Invalid AtmosphereResourceEventListener " + listener, t));
                        }
                    }
                    suspend(sessionSupported, resumeOnBroadcast, outputJunk, suspendTimeout, request, response, (
                            Broadcaster) servletReq.getAttribute(INJECTED_BROADCASTER), r);
                    break;
                case RESUME:
                    if (response.getEntity() != null) {
                        try {
                            response.write();
                        } catch (IOException ex) {
                            throw new WebApplicationException(ex);
                        }
                    }

                    if (sessionSupported) {
                        r = (AtmosphereResource) servletReq.getSession().getAttribute(SUSPENDED_RESOURCE);
                    } else {
                        String path = response.getContainerRequest().getPath();
                        r = resumeCandidates.remove(path.substring(path.lastIndexOf("/") + 1));
                    }

                    if (r != null) {
                        resume(r);
                    } else {
                        throw new WebApplicationException(
                                new IllegalStateException("Unable to retrieve suspended Response. " +
                                        "Either session-support is not enabled in atmosphere.xml or the" +
                                        "path used to resume is invalid."));

                    }
                    break;
                case BROADCAST:
                case RESUME_ON_BROADCAST:
                    AtmosphereResource ar = (AtmosphereResource) servletReq.getAttribute(SUSPENDED_RESOURCE);
                    if (ar != null) {
                        r = ar;
                    }
                    broadcast(response, r, suspendTimeout);
                    break;
                case SCHEDULE:
                case SCHEDULE_RESUME:
                    Object o = response.getEntity();
                    Broadcaster b = r.getBroadcaster();
                    if (response.getEntity() instanceof Broadcastable) {
                        b = ((Broadcastable) response.getEntity()).getBroadcaster();
                        o = ((Broadcastable) response.getEntity()).getMessage();
                        response.setEntity(((Broadcastable) response.getEntity()).getResponseMessage());
                    }

                    if (response.getEntity() != null) {
                        try {
                            response.write();
                        } catch (IOException ex) {
                            throw new WebApplicationException(ex);
                        }
                    }

                    if (action == Action.SCHEDULE_RESUME) {
                        configureResumeOnBroadcast(b);
                    }

                    b.scheduleFixedBroadcast(o, waitFor, suspendTimeout, TimeUnit.SECONDS);
                    break;
            }

            return response;
        }
View Full Code Here

Examples of org.atmosphere.cpr.Broadcaster

        }

        void broadcast(ContainerResponse r, AtmosphereResource ar, long delay) {
            Object o = r.getEntity();

            Broadcaster b = ar.getBroadcaster();
            Object msg = o;
            String returnMsg = null;
            // Something went wrong if null.
            if (o instanceof Broadcastable) {
                b = ((Broadcastable) o).getBroadcaster();
                msg = ((Broadcastable) o).getMessage();
                returnMsg = ((Broadcastable) o).getResponseMessage().toString();
            }

            if (action == Action.RESUME_ON_BROADCAST) {
                configureResumeOnBroadcast(b);
            }

            if (o != null) {
                addFilter(b);
                try {
                    r.setEntity(msg);
                    if (msg == null) return;

                    if (delay == -1) {
                        Future<Object> f = b.broadcast(msg);
                        if (f == null) return;
                        Object t = f.get();
                        if (o instanceof Broadcastable) {
                            r.setEntity(returnMsg);
                        }
                    } else if (delay == 0) {
                        b.delayBroadcast(msg);
                    } else {
                        b.delayBroadcast(msg, delay, TimeUnit.SECONDS);
                    }
                } catch (InterruptedException ex) {
                    logger.error("broadcast interrupted", ex);
                } catch (ExecutionException ex) {
                    logger.error("execution exception during broadcast", ex);
View Full Code Here

Examples of org.atmosphere.cpr.Broadcaster

                    throw new IllegalStateException("Invalid AtmosphereResourceEventListener " + listener, t);
                }
            }
        }

        Broadcaster broadcaster = (Broadcaster) req.getAttribute(INJECTED_BROADCASTER);
        if (subscribe) {
            Class<Broadcaster> c = null;
            try {
                c = (Class<Broadcaster>) Class.forName((String) req.getAttribute(ApplicationConfig.BROADCASTER_CLASS));
            } catch (Throwable e) {
View Full Code Here

Examples of org.atmosphere.cpr.Broadcaster

        if (s.getEntity() == null) {
            //https://github.com/Atmosphere/atmosphere/issues/423
            view = new EmptyView();
        }

        Broadcaster bc = s.broadcaster();
        if (bc == null && s.scope() != Suspend.SCOPE.REQUEST) {
            /*
             * TODO how does INJECTED_BROADCASTER get set?
             */
            bc = (Broadcaster) req.getAttribute(INJECTED_BROADCASTER);
View Full Code Here

Examples of org.atmosphere.cpr.Broadcaster

            boolean writeEntity, String topic, boolean resume) {
       
        View view = null;
        AtmosphereResource resource = (AtmosphereResource) req.getAttribute(SUSPENDED_RESOURCE);
       
        Broadcaster broadcaster = resource.getBroadcaster();
        Object msg = entity;
        if (entity instanceof Broadcastable) {
            if (((Broadcastable) entity).getBroadcaster() != null) {
                broadcaster = ((Broadcastable) entity).getBroadcaster();
            }
            msg = ((Broadcastable) entity).getMessage();
        }

        if (resume) {
            configureResumeOnBroadcast(broadcaster);
        }

        addFilter(broadcaster, filters, clusterBroadcastFilters);
        if (msg == null) return view;

        if (delay == -1) {
            broadcaster.broadcast(msg);
        } else if (delay == 0) {
            broadcaster.delayBroadcast(msg);
        } else {
            broadcaster.delayBroadcast(msg, delay, TimeUnit.SECONDS);
        }
       
        if (!writeEntity) {
            view = new EmptyView();
        }
View Full Code Here

Examples of org.atmosphere.cpr.Broadcaster

    private void doSchedule(int timeout, int waitFor, Object entity, View marshalledEntity,
            AtmosphereResource resource, HttpServletRequest req, HttpServletResponse resp,
            boolean resume) {
       
        Object message = entity;
        Broadcaster broadcaster = resource.getBroadcaster();
        if (entity instanceof Broadcastable) {
            broadcaster = ((Broadcastable) entity).getBroadcaster();
            message = ((Broadcastable) entity).getMessage();
            entity = ((Broadcastable) entity).getResponseMessage();
        }

        if (entity != null) {
            //TODO see com.sun.jersey.spi.container.ContainerResponse.write()
            /*
             * in the case of the Mojave framework, the entity here will never be null: it
             * will always be at least a View--unless it is a Broadcastable and the
             * getResponseMessage() returns null
             *
             * 3 possibilities for entity here:
             *
             * 1. it is a View (that was marshalled to itself in the action invoker)
             * 2. it is a non-Broadcastable entity
             * 3. it was a Broadcastable and is now the Broadcastable response message
             *    
             * NOTE: committed means: write status and headers and flush the outputstream
             *
             * if the entity is other than a SuspendResponse, as it is in this case,
             * then a @Returns annotation must be present on the method to indicate the
             * return content-type--the action invoker will marshall any embedded entity
             */
            //write entity to response outputstream
            /*
             * NOTE:
             * we can work with the marshalledEntity and we don't need to write out the
             * entity itself, as it would have been marshalled even if it were embedded,
             * as in the case of Broadcastable.getResponseMessage()
             */
            write(marshalledEntity, req, resp);
        }

        if (resume) {
            configureResumeOnBroadcast(broadcaster);
        }
       
        broadcaster.scheduleFixedBroadcast(message, waitFor, timeout, TimeUnit.SECONDS);
    }
View Full Code Here

Examples of org.atmosphere.cpr.Broadcaster

      }  
    }
   
    @Override
    public Broadcaster addAtmosphereResource(AtmosphereResource resource) {
      Broadcaster result = super.addAtmosphereResource(resource);
      addMessageListener();
      return result;
    }
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.