Giving direct access to GatheringChatRoomListener.

This commit is contained in:
marcins78
2013-01-18 14:14:02 +00:00
parent 753d2aa079
commit 69563e6c0d
3 changed files with 5 additions and 17 deletions

View File

@@ -89,7 +89,7 @@ public class ChatRequestHandler extends LotroServerRequestHandler implements Uri
@Override
public boolean isChanged() {
try {
return _chatRoom.hasPendingMessages(_playerId);
return _chatRoom.getChatRoomListener(_playerId).hasMessages();
} catch (SubscriptionExpiredException e) {
return true;
}
@@ -98,7 +98,7 @@ public class ChatRequestHandler extends LotroServerRequestHandler implements Uri
@Override
public void process() {
try {
List<ChatMessage> chatMessages = _chatRoom.getPendingMessages(_playerId);
List<ChatMessage> chatMessages = _chatRoom.getChatRoomListener(_playerId).consumeMessages();
Collection<String> usersInRoom = _chatRoom.getUsersInRoom();

View File

@@ -46,25 +46,13 @@ public class ChatRoomMediator {
}
}
public boolean hasPendingMessages(String playerId) throws SubscriptionExpiredException {
public GatheringChatRoomListener getChatRoomListener(String playerId) throws SubscriptionExpiredException {
_lock.readLock().lock();
try {
GatheringChatRoomListener gatheringChatRoomListener = _listeners.get(playerId);
if (gatheringChatRoomListener == null)
throw new SubscriptionExpiredException();
return gatheringChatRoomListener.hasMessages();
} finally {
_lock.readLock().unlock();
}
}
public List<ChatMessage> getPendingMessages(String playerId) throws SubscriptionExpiredException {
_lock.readLock().lock();
try {
GatheringChatRoomListener gatheringChatRoomListener = _listeners.get(playerId);
if (gatheringChatRoomListener == null)
throw new SubscriptionExpiredException();
return gatheringChatRoomListener.consumeMessages();
return gatheringChatRoomListener;
} finally {
_lock.readLock().unlock();
}

View File

@@ -27,7 +27,7 @@ public class GatheringChatRoomListener implements ChatRoomListener {
return _messages.size()>0;
}
private void updateLastAccess() {
private synchronized void updateLastAccess() {
_lastConsumed = System.currentTimeMillis();
}