Package org.atmosphere.cpr

Examples of org.atmosphere.cpr.AtmosphereResource


                config.getInitParameter(ApplicationConfig.SUPPORT_LOCATION_HEADER)) ||
                ctx.getActionAnnotation(Resume.class) != null) {
            useResumeAnnotation = true;
        }
       
        AtmosphereResource resource = (AtmosphereResource) req
                .getAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE);
        //TODO debugging
        logger.info("resource: " + resource);
       
        //TODO get current status
View Full Code Here


            long delay, int waitFor,
            Class<? extends BroadcastFilter>[] filters,
            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();
            }
View Full Code Here

    }
   
    @SuppressWarnings("unchecked")
    private View doPublish(Object entity, HttpServletRequest req, AtmosphereConfig config, String topic) {
       
        AtmosphereResource resource = (AtmosphereResource) req.getAttribute(SUSPENDED_RESOURCE);

        Class<Broadcaster> broadCasterClass = null;
        try {
            broadCasterClass =
                    (Class<Broadcaster>) Class.forName(
                            (String) req.getAttribute(ApplicationConfig.BROADCASTER_CLASS));
        } catch (Throwable e) {
            throw new IllegalStateException(e.getMessage());
        }
        resource.setBroadcaster(config.getBroadcasterFactory().lookup(broadCasterClass, topic, true));
       
        return doBroadcast(entity, req, config, new ArrayList<ClusterBroadcastFilter>(), -1, -1, null, true, topic, false);
    }
View Full Code Here

public class AtmospherePushConnectionTest {
    @Test
    public void testSerialization() throws Exception {

        UI ui = EasyMock.createNiceMock(UI.class);
        AtmosphereResource resource = EasyMock
                .createNiceMock(AtmosphereResource.class);

        AtmospherePushConnection connection = new AtmospherePushConnection(ui);
        connection.connect(resource);
View Full Code Here

   * @param event
   * @param resourceUuid
   */
  public void post(Object event, String resourceUuid)
  {
    AtmosphereResource resource = AtmosphereResourceFactory.getDefault().find(resourceUuid);
    if (resource != null)
    {
      post(event, resource);
    }
  }
View Full Code Here

   * @param event
   * @param resourceUuid
   */
  public void post(Object event, String resourceUuid)
  {
    AtmosphereResource resource = AtmosphereResourceFactory.getDefault().find(resourceUuid);
    if (resource != null)
    {
      post(event, resource);
    }
  }
View Full Code Here

   * @param event
   * @param resourceUuid
   */
  public void post(Object event, String resourceUuid)
  {
    AtmosphereResource resource = AtmosphereResourceFactory.getDefault().find(resourceUuid);
    if (resource != null)
    {
      post(event, resource);
    }
  }
View Full Code Here

  @Override
  public void onRequest()
  {
    TesterBroadcaster broadcaster = (TesterBroadcaster) eventBus.getBroadcaster();

    AtmosphereResource atmosphereResource = new AtmosphereResourceImpl();
    AtmosphereRequest atmosphereRequest = AtmosphereRequest.wrap(wicketTester.getRequest());
    AtmosphereResponse atmosphereResponse = AtmosphereResponse.wrap(wicketTester.getResponse());
    TesterAsyncSupport asyncSupport = new TesterAsyncSupport();
    atmosphereResource.initialize(broadcaster.getApplicationConfig(), broadcaster, atmosphereRequest, atmosphereResponse,
        asyncSupport, new AtmosphereHandlerAdapter());

    atmosphereResource.setBroadcaster(broadcaster);
    broadcaster.addAtmosphereResource(atmosphereResource);

    String uuid = atmosphereResource.uuid();
    Page page = getComponent().getPage();

    page.setMetaData(ATMOSPHERE_UUID, uuid);
    eventBus.registerPage(uuid, page);
  }
View Full Code Here

   * @param event
   * @param resourceUuid
   */
  public void post(Object event, String resourceUuid)
  {
    AtmosphereResource resource = AtmosphereResourceFactory.getDefault().find(resourceUuid);
    if (resource != null)
    {
      post(event, resource);
    }
  }
View Full Code Here

    @Override
    public void onStateChange(AtmosphereResourceEvent event) throws IOException {


      AtmosphereResponse response = event.getResource().getResponse();
      AtmosphereResource resource = event.getResource();

      if (event.isSuspended()) {

        // Set content type before do response.getWriter()
        // http://docs.oracle.com/javaee/5/api/javax/servlet/ServletResponse.html#setContentType(java.lang.String)
        response.setContentType("text/plain; charset=UTF-8");
        response.setCharacterEncoding("UTF-8");


        if (event.getMessage().getClass().isArray()) {

          LOG.fine("SEND MESSAGE ARRAY " + event.getMessage().toString());

          List<Object> list = Arrays.asList(event.getMessage());

          response.getOutputStream().write(MSG_SEPARATOR.getBytes(MSG_CHARSET));
          for (Object object : list) {
            String message = (String) object;
            message += MSG_SEPARATOR;
            response.getOutputStream().write(message.getBytes(MSG_CHARSET));
          }

        } else if (event.getMessage() instanceof List) {

          LOG.fine("SEND MESSAGE LIST " + event.getMessage().toString());

          @SuppressWarnings("unchecked")
          List<Object> list = List.class.cast(event.getMessage());

          response.getOutputStream().write(MSG_SEPARATOR.getBytes(MSG_CHARSET));
          for (Object object : list) {
            String message = (String) object;
            message += MSG_SEPARATOR;
            response.getOutputStream().write(message.getBytes(MSG_CHARSET));
          }

        } else if (event.getMessage() instanceof String) {

          LOG.fine("SEND MESSAGE " + event.getMessage().toString());

          String message = (String) event.getMessage();
          response.getOutputStream().write(message.getBytes(MSG_CHARSET));
        }



        try {

          response.flushBuffer();

          switch (resource.transport()) {
            case JSONP:
            case LONG_POLLING:
              event.getResource().resume();
              break;
            case WEBSOCKET:
View Full Code Here

TOP

Related Classes of org.atmosphere.cpr.AtmosphereResource

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.