@Override
  public void onStateChange(AtmosphereResourceEvent event) throws IOException {
    AtmosphereResource r = event.getResource();
    AtmosphereResponse res = r.getResponse();

    if (event.isSuspended()) {
      String body = event.getMessage().toString();

      ChatData data = new Gson().fromJson(body, ChatData.class);

      res.getWriter().write(new ChatData(data.getAuthor(), data.getText()).toString());
      switch (r.transport()) {
        case JSONP:
        case AJAX:
        case LONG_POLLING:
          event.getResource().resume();
          break;
        default:
          res.getWriter().flush();
          break;
      }
    } else if (!event.isResuming()) {
      event.broadcaster().broadcast(new ChatData("Someone", "say bye bye!").toString());
    }
  }
Esempio n. 2
0
  public void onThrowable(AtmosphereResourceEvent event) {
    // called when a push connection is broken

    try {
      JSONObject dim = (JSONObject) event.getMessage();
      internalNotifySchedule.pushNotAtendedNotification(dim);
      logger.info("Sending again the Notification: " + dim);

    } catch (Exception e) {
      logger.debug("Not correct message!");
    }

    event.broadcaster().destroy();
    internalNotifySchedule.removeBroadcaster(event.broadcaster());

    if (logger.isDebugEnabled()) {
      logger.error("Atmosphere connection broken: " + event);
    } else {
      logger.warn("Atmosphere connection broken: " + event.getMessage());
    }
  }
Esempio n. 3
0
 public void onDisconnect(AtmosphereResourceEvent event) {
   event.broadcaster().destroy();
   internalNotifySchedule.removeBroadcaster(event.broadcaster());
   logger.info("onDisconnect: " + event);
 }