Package org.atmosphere.cpr

Examples of org.atmosphere.cpr.BroadcasterFactory


                Broadcaster broadcaster = null;
                try {
                    AtmosphereResource<HttpServletRequest, HttpServletResponse> r =
                            (AtmosphereResource<HttpServletRequest, HttpServletResponse>)
                                    req.getAttribute(AtmosphereServlet.ATMOSPHERE_RESOURCE);
                    BroadcasterFactory bp = (BroadcasterFactory)
                            req.getAttribute(AtmosphereServlet.BROADCASTER_FACTORY);

                    broadcaster = bp.lookup(r.getBroadcaster().getClass(), topic, true);
                } catch (Throwable ex) {
                    throw new WebApplicationException(ex);
                }
                req.setAttribute(AtmosphereFilter.INJECTED_BROADCASTER, broadcaster);
                return 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 = (BroadcasterFactory) servletReq
                    .getAttribute(AtmosphereServlet.BROADCASTER_FACTORY);

            // Do not add location header if already there.
            if (!sessionSupported && !resumeOnBroadcast && response.getHttpHeaders().getFirst("Location") == null) {
                String uuid = UUID.randomUUID().toString();

                response.getHttpHeaders().putSingle(
                        HttpHeaders.LOCATION,
                        uriInfo.getAbsolutePathBuilder().path(uuid).build(""));

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

            if (bc == null) {
                bc = r.getBroadcaster();
            }

            if (sessionSupported && servletReq.getSession().getAttribute(SUSPENDED_RESOURCE) != null) {
                AtmosphereResource<HttpServletRequest, HttpServletResponse> cached =
                        (AtmosphereResource) servletReq.getSession().getAttribute(SUSPENDED_RESOURCE);
                bc = cached.getBroadcaster();
                // Just in case something went wrong.
                bc.removeAtmosphereResource(cached);
            }

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

                if ((scope == Suspend.SCOPE.REQUEST) && (bc.getScope() != Broadcaster.SCOPE.REQUEST)) {
                    bc.setScope(Broadcaster.SCOPE.REQUEST);
                }
            } else if ((scope == Suspend.SCOPE.REQUEST) && (bc.getScope() != Broadcaster.SCOPE.REQUEST)) {
                try {
                    String id = bc.getID();
                    bc.setID(bc.getClass().getSimpleName() + "-" + UUID.randomUUID());

                    // Re-generate a new one with proper scope.
                    bc = broadcasterFactory.get();
                    bc.setScope(Broadcaster.SCOPE.REQUEST);
                    bc.setID(id);
                }
                catch (Exception ex) {
                    logger.error("failed to instantiate broadcaster with factory: " + broadcasterFactory, ex);
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

       //HttpServletResponse response = ctx.getResponse();
       //if (response.getStatus() == 204) {
       //    response.setStatus(200);
       //}
   
       BroadcasterFactory broadcasterFactory =
               (BroadcasterFactory) req.getAttribute(ApplicationConfig.BROADCASTER_FACTORY);
   
       boolean sessionSupported = (Boolean) req.getAttribute(FrameworkConfig.SUPPORT_SESSION);
       URI location = null;
       // Do not add location header if already there.
       if (useResumeAnnotation && !sessionSupported && !resumeOnBroadcast && !res.containsHeader("Location")) {
           String uuid = UUID.randomUUID().toString();
   
           //TODO uriInfo is a JAX-RS object
           //location = uriInfo.getAbsolutePathBuilder().path(uuid).build("");
   
           //TODO resumeCandidates may be an application global map
           //resumeCandidates.put(uuid, r);
          
           //TODO where are RESUME_UUID and RESUME_CANDIDATES read?
           //req.setAttribute(RESUME_UUID, uuid);
           //req.setAttribute(RESUME_CANDIDATES, resumeCandidates);
       }
   
       if (bc == null && localScope != Suspend.SCOPE.REQUEST) {
           bc = r.getBroadcaster();
       }
   
       if (entity instanceof Broadcastable) {
           Broadcastable b = (Broadcastable) entity;
           bc = b.getBroadcaster();
           //response.setEntity(b.getResponseMessage());
       }
   
       if ((localScope == Suspend.SCOPE.REQUEST) && bc == null) {
           if (bc == null) {
               try {
                   String id = req.getHeader(HeaderConfig.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

    this(application, null);
  }

  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

    this(application, null);
  }

  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

    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

    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

    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

    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.