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;
  }
Esempio n. 2
0
 @Override
 public void addUserToChatRoom(String room, String user) throws OKMException {
   updateSessionManager();
   try {
     manager.addUserToChatRoom(user, room);
   } catch (PrincipalAdapterException e) {
     log.error(e.getMessage(), e);
     throw new OKMException(
         ErrorCode.get(ErrorCode.ORIGIN_OKMChatService, ErrorCode.CAUSE_PrincipalAdapter),
         e.getMessage());
   }
 }
Esempio n. 3
0
 @Override
 public String createNewChatRoom(String user) throws OKMException {
   updateSessionManager();
   try {
     String actualUser = getThreadLocalRequest().getRemoteUser();
     return manager.createNewChatRoom(actualUser, user);
   } catch (PrincipalAdapterException e) {
     log.error(e.getMessage(), e);
     throw new OKMException(
         ErrorCode.get(ErrorCode.ORIGIN_OKMChatService, ErrorCode.CAUSE_PrincipalAdapter),
         e.getMessage());
   }
 }
Esempio n. 4
0
  @Override
  public List<String> getUsersInRoom(String room) throws OKMException {
    updateSessionManager();

    try {
      return manager.getUsersInRoom(room);
    } catch (PrincipalAdapterException e) {
      log.error(e.getMessage(), e);
      throw new OKMException(
          ErrorCode.get(ErrorCode.ORIGIN_OKMChatService, ErrorCode.CAUSE_PrincipalAdapter),
          e.getMessage());
    }
  }
Esempio n. 5
0
  @Override
  public void closeRoom(String room) throws OKMException {
    updateSessionManager();
    String user = getThreadLocalRequest().getRemoteUser();

    try {
      if (user != null) {
        manager.closeRoom(user, room);
      }
    } catch (PrincipalAdapterException e) {
      log.error(e.getMessage(), e);
      throw new OKMException(
          ErrorCode.get(ErrorCode.ORIGIN_OKMChatService, ErrorCode.CAUSE_PrincipalAdapter),
          e.getMessage());
    }
  }
Esempio n. 6
0
 @Override
 public List<GWTUser> getLoggedUsers() throws OKMException {
   List<GWTUser> users = new ArrayList<GWTUser>();
   updateSessionManager();
   try {
     for (String userId : manager.getLoggedUsers()) {
       GWTUser user = new GWTUser();
       user.setId(userId);
       user.setUsername(OKMAuth.getInstance().getName(null, userId));
       users.add(user);
     }
   } catch (PrincipalAdapterException e) {
     log.error(e.getMessage(), e);
     throw new OKMException(
         ErrorCode.get(ErrorCode.ORIGIN_OKMChatService, ErrorCode.CAUSE_PrincipalAdapter),
         e.getMessage());
   }
   return users;
 }