Package org.atmosphere.cpr

Examples of org.atmosphere.cpr.BroadcasterFactory


                Broadcaster broadcaster;
                try {
                    AtmosphereResource r =
                            (AtmosphereResource)
                                    req.getAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE);
                    BroadcasterFactory bp = r.getAtmosphereConfig().getBroadcasterFactory();

                    Class<? extends Broadcaster> c;
                    try {
                        c = (Class<Broadcaster>) Class.forName((String) req.getAttribute(ApplicationConfig.BROADCASTER_CLASS));
                    } catch (Throwable e) {
                        throw new IllegalStateException(e.getMessage());
                    }
                    broadcaster = bp.lookup(c, topic, true);
                } catch (Throwable ex) {
                    throw new WebApplicationException(ex);
                }
                logger.trace("Injected Broadcaster {}", broadcaster);
                req.setAttribute(AtmosphereFilter.INJECTED_BROADCASTER, broadcaster);
View Full Code Here


            // Force the status code to 200 events independently of the value of the entity (null or not)
            if (response.getStatus() == 204) {
                response.setStatus(200);
            }

            BroadcasterFactory broadcasterFactory = r.getAtmosphereConfig().getBroadcasterFactory();

            boolean sessionSupported = (Boolean) servletReq.getAttribute(FrameworkConfig.SUPPORT_SESSION);
            URI location = null;
            // Do not add location header if already there.
            if (useResumeAnnotation && !sessionSupported && !resumeOnBroadcast && response.getHttpHeaders().getFirst("Location") == null) {
                String uuid = UUID.randomUUID().toString();

                location = uriInfo.getAbsolutePathBuilder().path(uuid).build("");

                resumeCandidates.put(uuid, r);
                servletReq.setAttribute(RESUME_UUID, uuid);
                servletReq.setAttribute(RESUME_CANDIDATES, resumeCandidates);
            }

            if (bc == null && localScope != Suspend.SCOPE.REQUEST) {
                bc = r.getBroadcaster();
            }

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

            if (response.getEntity() instanceof Broadcastable) {
                Broadcastable b = (Broadcastable) response.getEntity();
                bc = b.getBroadcaster();
                response.setEntity(b.getResponseMessage());
            }

            if ((localScope == Suspend.SCOPE.REQUEST) && bc == null) {
                if (bc == null) {
                    try {
                        String id = servletReq.getHeader(X_ATMOSPHERE_TRACKING_ID);
                        if (id == null) {
                            id = UUID.randomUUID().toString();
                        }

                        bc = broadcasterFactory.get(id);
                        bc.setScope(Broadcaster.SCOPE.REQUEST);
                    } catch (Exception ex) {
                        logger.error("failed to instantiate broadcaster with factory: " + broadcasterFactory, ex);
                    }
                } else {
View Full Code Here

*/
public class AtmosphereBroadcaster implements WebSocketsBroadcaster {

  @Override
  public void broadcast(String data) {
    BroadcasterFactory broadcasterFactory = BroadcasterFactory.getDefault();
    if (broadcasterFactory == null) {
      return;
    }

    Broadcaster b = broadcasterFactory.lookup("changes", true);
    if (b != null) {
      b.broadcast(data);
    }
  }
View Full Code Here

    this(application, lookupDefaultBroadcaster());
  }

  private static Broadcaster lookupDefaultBroadcaster()
  {
    BroadcasterFactory factory = BroadcasterFactory.getDefault();
    if (factory == null)
    {
      throw new WicketRuntimeException(
        "There is no Atmosphere BroadcasterFactory configured. Did you include the "
          + "atmosphere.xml configuration file and configured AtmosphereServlet?");
    }
    Collection<Broadcaster> allBroadcasters = factory.lookupAll();
    if (allBroadcasters.isEmpty())
    {
      throw new WicketRuntimeException(
        "The Atmosphere BroadcasterFactory has no Broadcasters, "
          + "something is wrong with your Atmosphere configuration.");
View Full Code Here

TOP

Related Classes of org.atmosphere.cpr.BroadcasterFactory

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.