Example #1
0
    @Override
    public void run() {
      try {
        for (; ; ) {
          long startMillis = System.currentTimeMillis();

          try {
            Map<String, BotUpdateEvent> lastBotUpdateEvents;

            synchronized (LAST_BOT_UPDATE_EVENTS) {
              lastBotUpdateEvents = new HashMap<>(LAST_BOT_UPDATE_EVENTS);
            }

            session.pulse(lastBotUpdateEvents.values());
          } catch (SessionEndedException e) {
            break;
          } catch (Exception e) {
            System.err.println("Exception occured for session " + session);
            e.printStackTrace();
          }

          long duration = System.currentTimeMillis() - startMillis;

          if (duration > 20) {
            // System.out.println(">>> Slow Pulse (" + duration + " ms) for " + session + " -- " +
            // session.getMe());
          }
          Thread.sleep(10);
        }
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }

      synchronized (sessions) {
        sessions.remove(session.getPort());
      }

      System.err.println("EQ Session ended, pulse thread exiting: " + session);
    }