Esempio n. 1
0
  @Override
  public List<String> getPendingMessage(String room) throws OKMException {
    updateSessionManager();
    String user = getThreadLocalRequest().getRemoteUser();
    List<String> pendingMessages = new ArrayList<String>();

    try {
      if (user != null) {
        int countCycle = 0;

        // Persistence connection = DELAY * CYCLES
        do {
          pendingMessages = manager.getPendingMessage(user, room);
          countCycle++;

          try {
            Thread.sleep(DELAY);
          } catch (InterruptedException e) {
            // Ignore
          }
        } while (pendingMessages.isEmpty()
            && (countCycle < CYCLES)
            && manager.getLoggedUsers().contains(user));
      }
    } catch (PrincipalAdapterException e) {
      log.error(e.getMessage(), e);
      throw new OKMException(
          ErrorCode.get(ErrorCode.ORIGIN_OKMChatService, ErrorCode.CAUSE_PrincipalAdapter),
          e.getMessage());
    }

    return pendingMessages;
  }