Example #1
0
  @OnMessage
  public void startSession(String message, TwitterRemote tr) {
    if (message.equals("register")) {
      this.initThread();
    } else {
      try {
        tr.getSession().close(new CloseReason(CloseReason.Code.NORMAL_CLOSURE, "User logged off"));
      } catch (IOException ioe) {
      }

      if (myContext.getConversations().size() == 0 && this.updateThread != null) {
        this.updateThread.halt();
        this.updateThread = null;
      }
    }
  }
Example #2
0
  public void broadcast() {
    for (Session session : myContext.getConversations()) {

      try {
        HttpSession httpSession = session.getHttpSession();
        ApplicationPreferences preferences =
            (ApplicationPreferences)
                httpSession.getAttribute(ApplicationPreferences.APP_PREFERENCES);
        if (preferences != null) {
          ((TwitterRemote) session.getRemote())
              .sendSearchResults(this.doSearch(preferences.getTickers()));
        } else {
          System.out.println("Failed to get preferences in broadcasting twitter update");
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }