Fixing last access for communication channels.

This commit is contained in:
marcins78
2013-01-08 18:07:06 +00:00
parent 41fbb652d7
commit 68240b70b8
6 changed files with 28 additions and 13 deletions

View File

@@ -13,7 +13,7 @@ import static com.gempukku.lotro.game.state.GameEvent.Type.*;
public class GatheringParticipantCommunicationChannel implements GameStateListener {
private List<GameEvent> _events = new LinkedList<GameEvent>();
private String _self;
private Date _lastConsumed = new Date();
private long _lastConsumed = System.currentTimeMillis();
private int _channelNumber;
public GatheringParticipantCommunicationChannel(String self, int channelNumber) {
@@ -164,17 +164,22 @@ public class GatheringParticipantCommunicationChannel implements GameStateListen
}
public List<GameEvent> consumeGameEvents() {
updateLastAccess();
List<GameEvent> result = _events;
_events = new LinkedList<GameEvent>();
_lastConsumed = new Date();
return result;
}
public boolean hasGameEvents() {
updateLastAccess();
return _events.size()>0;
}
public Date getLastConsumed() {
private void updateLastAccess() {
_lastConsumed = System.currentTimeMillis();
}
public long getLastAccessed() {
return _lastConsumed;
}
}

View File

@@ -101,7 +101,7 @@ public class ChatRoomMediator {
for (Map.Entry<String, GatheringChatRoomListener> playerListener : copy.entrySet()) {
String playerId = playerListener.getKey();
GatheringChatRoomListener listener = playerListener.getValue();
if (currentTime > listener.getLastConsumed().getTime() + _channelInactivityTimeoutPeriod) {
if (currentTime > listener.getLastAccessed() + _channelInactivityTimeoutPeriod) {
_chatRoom.partChatRoom(playerId);
_listeners.remove(playerId);
}

View File

@@ -3,13 +3,12 @@ package com.gempukku.lotro.game;
import com.gempukku.lotro.chat.ChatMessage;
import com.gempukku.lotro.chat.ChatRoomListener;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
public class GatheringChatRoomListener implements ChatRoomListener {
private List<ChatMessage> _messages = new LinkedList<ChatMessage>();
private Date _lastConsumed = new Date();
private long _lastConsumed = System.currentTimeMillis();
@Override
public synchronized void messageReceived(ChatMessage message) {
@@ -17,17 +16,22 @@ public class GatheringChatRoomListener implements ChatRoomListener {
}
public synchronized List<ChatMessage> consumeMessages() {
updateLastAccess();
List<ChatMessage> messages = _messages;
_messages = new LinkedList<ChatMessage>();
_lastConsumed = new Date();
return messages;
}
public synchronized boolean hasMessages() {
updateLastAccess();
return _messages.size()>0;
}
public synchronized Date getLastConsumed() {
private void updateLastAccess() {
_lastConsumed = System.currentTimeMillis();
}
public synchronized long getLastAccessed() {
return _lastConsumed;
}
}

View File

@@ -236,7 +236,7 @@ public class LotroGameMediator {
// Channel is stale (user no longer connected to game, to save memory, we remove the channel
// User can always reconnect and establish a new channel
GatheringParticipantCommunicationChannel channel = playerChannels.getValue();
if (currentTime > channel.getLastConsumed().getTime() + _playerDecisionTimeoutPeriod) {
if (currentTime > channel.getLastAccessed() + _playerDecisionTimeoutPeriod) {
_lotroGame.removeGameStateListener(channel);
_communicationChannels.remove(playerId);
}

View File

@@ -25,11 +25,17 @@ public class HallCommunicationChannel {
return _channelNumber;
}
public long getLastConsumed() {
private void updateLastAccess() {
_lastConsumed = System.currentTimeMillis();
}
public long getLastAccessed() {
return _lastConsumed;
}
public synchronized boolean hasChangesInCommunicationChannel(HallServer hallServer, Player player) {
updateLastAccess();
final MutableObject newMotd = new MutableObject();
final Map<String, Map<String, String>> tournamentQueuesOnServer = new LinkedHashMap<String, Map<String, String>>();
@@ -137,6 +143,8 @@ public class HallCommunicationChannel {
}
public synchronized void processCommunicationChannel(HallServer hallServer, Player player, final HallChannelVisitor hallChannelVisitor) {
updateLastAccess();
hallChannelVisitor.channelNumber(_channelNumber);
final MutableObject newMotd = new MutableObject();
@@ -228,8 +236,6 @@ public class HallCommunicationChannel {
if (newMotd.getValue() != null && !newMotd.equals(_lastMotd))
hallChannelVisitor.motdChanged((String) newMotd.getValue());
_lastConsumed = System.currentTimeMillis();
}
private void notifyAboutTables(HallChannelVisitor hallChannelVisitor, Map<String, Map<String, String>> tablesOnServer) {

View File

@@ -566,7 +566,7 @@ public class HallServer extends AbstractServer {
long currentTime = System.currentTimeMillis();
Map<Player, HallCommunicationChannel> visitCopy = new LinkedHashMap<Player, HallCommunicationChannel>(_playerChannelCommunication);
for (Map.Entry<Player, HallCommunicationChannel> lastVisitedPlayer : visitCopy.entrySet()) {
if (currentTime > lastVisitedPlayer.getValue().getLastConsumed() + _playerInactivityPeriod) {
if (currentTime > lastVisitedPlayer.getValue().getLastAccessed() + _playerInactivityPeriod) {
Player player = lastVisitedPlayer.getKey();
_playerChannelCommunication.remove(player);
leaveAwaitingTables(player);