Making all the CommunicationChannels being LongPollableResources.
This commit is contained in:
@@ -5,16 +5,19 @@ import com.gempukku.lotro.communication.GameStateListener;
|
||||
import com.gempukku.lotro.game.PhysicalCard;
|
||||
import com.gempukku.lotro.logic.decisions.AwaitingDecision;
|
||||
import com.gempukku.lotro.logic.timing.GameStats;
|
||||
import com.gempukku.polling.LongPollableResource;
|
||||
import com.gempukku.polling.LongPollingResource;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.gempukku.lotro.game.state.GameEvent.Type.*;
|
||||
|
||||
public class GameCommunicationChannel implements GameStateListener {
|
||||
public class GameCommunicationChannel implements GameStateListener, LongPollableResource {
|
||||
private List<GameEvent> _events = new LinkedList<GameEvent>();
|
||||
private String _self;
|
||||
private long _lastConsumed = System.currentTimeMillis();
|
||||
private int _channelNumber;
|
||||
private LongPollingResource _longPollingResource;
|
||||
|
||||
public GameCommunicationChannel(String self, int channelNumber) {
|
||||
_self = self;
|
||||
@@ -33,9 +36,20 @@ public class GameCommunicationChannel implements GameStateListener {
|
||||
appendEvent(new GameEvent(P).participantId(_self).allParticipantIds(participantIds));
|
||||
}
|
||||
|
||||
private void appendEvent(GameEvent event) {
|
||||
_events.add(event);
|
||||
@Override
|
||||
public synchronized void deregisterResource(LongPollingResource longPollingResource) {
|
||||
_longPollingResource = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void registerForChanges(LongPollingResource longPollingResource) {
|
||||
_longPollingResource = longPollingResource;
|
||||
}
|
||||
|
||||
private synchronized void appendEvent(GameEvent event) {
|
||||
_events.add(event);
|
||||
if (_longPollingResource != null)
|
||||
_longPollingResource.processIfNotProcessed();
|
||||
}
|
||||
|
||||
private int[] getCardIds(Collection<PhysicalCard> cards) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.gempukku.lotro.tournament.TournamentCallback;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
// TODO - it has to be thread safe
|
||||
public class DefaultDraft implements Draft {
|
||||
// 35 seconds
|
||||
public static final int PICK_TIME = 35 * 1000;
|
||||
@@ -63,6 +64,8 @@ public class DefaultDraft implements Draft {
|
||||
}
|
||||
} else {
|
||||
presentNewCardChoices();
|
||||
for (DraftCommunicationChannel draftCommunicationChannel : _playerDraftCommunications.values())
|
||||
draftCommunicationChannel.draftChanged();
|
||||
}
|
||||
} else {
|
||||
if (choiceTimePassed()) {
|
||||
@@ -128,6 +131,7 @@ public class DefaultDraft implements Draft {
|
||||
if (cardChoice.removeItem(cardId, 1)) {
|
||||
_collectionsManager.addItemsToPlayerCollection(false, "Pick in draft", playerName, _collectionType, Arrays.asList(CardCollection.Item.createItem(cardId, 1)));
|
||||
_cardChoice.remove(playerName);
|
||||
_playerDraftCommunications.get(playerName).draftChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package com.gempukku.lotro.draft;
|
||||
|
||||
import com.gempukku.lotro.game.CardCollection;
|
||||
import com.gempukku.polling.LongPollableResource;
|
||||
import com.gempukku.polling.LongPollingResource;
|
||||
|
||||
public class DraftCommunicationChannel {
|
||||
public class DraftCommunicationChannel implements LongPollableResource {
|
||||
private int _channelNumber;
|
||||
private long _lastAccessed;
|
||||
|
||||
private String _cardChoiceOnClient;
|
||||
private LongPollingResource _longPollingResource;
|
||||
|
||||
public DraftCommunicationChannel(int channelNumber) {
|
||||
_channelNumber = channelNumber;
|
||||
@@ -24,6 +27,21 @@ public class DraftCommunicationChannel {
|
||||
_lastAccessed = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregisterResource(LongPollingResource longPollingResource) {
|
||||
_longPollingResource = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerForChanges(LongPollingResource longPollingResource) {
|
||||
_longPollingResource = longPollingResource;
|
||||
}
|
||||
|
||||
public synchronized void draftChanged() {
|
||||
if (_longPollingResource != null)
|
||||
_longPollingResource.processIfNotProcessed();
|
||||
}
|
||||
|
||||
public boolean hasChangesInCommunicationChannel(DraftCardChoice draftCardChoice) {
|
||||
updateLastAccess();
|
||||
|
||||
|
||||
@@ -2,17 +2,32 @@ package com.gempukku.lotro.game;
|
||||
|
||||
import com.gempukku.lotro.chat.ChatMessage;
|
||||
import com.gempukku.lotro.chat.ChatRoomListener;
|
||||
import com.gempukku.polling.LongPollableResource;
|
||||
import com.gempukku.polling.LongPollingResource;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChatCommunicationChannel implements ChatRoomListener {
|
||||
public class ChatCommunicationChannel implements ChatRoomListener, LongPollableResource {
|
||||
private List<ChatMessage> _messages = new LinkedList<ChatMessage>();
|
||||
private long _lastConsumed = System.currentTimeMillis();
|
||||
private LongPollingResource _longPollingResource;
|
||||
|
||||
@Override
|
||||
public synchronized void deregisterResource(LongPollingResource longPollingResource) {
|
||||
_longPollingResource = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void registerForChanges(LongPollingResource longPollingResource) {
|
||||
_longPollingResource = longPollingResource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void messageReceived(ChatMessage message) {
|
||||
_messages.add(message);
|
||||
if (_longPollingResource != null)
|
||||
_longPollingResource.processIfNotProcessed();
|
||||
}
|
||||
|
||||
public synchronized List<ChatMessage> consumeMessages() {
|
||||
@@ -24,7 +39,7 @@ public class ChatCommunicationChannel implements ChatRoomListener {
|
||||
|
||||
public synchronized boolean hasMessages() {
|
||||
updateLastAccess();
|
||||
return _messages.size()>0;
|
||||
return _messages.size() > 0;
|
||||
}
|
||||
|
||||
private synchronized void updateLastAccess() {
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package com.gempukku.lotro.hall;
|
||||
|
||||
import com.gempukku.lotro.game.Player;
|
||||
import com.gempukku.polling.LongPollableResource;
|
||||
import com.gempukku.polling.LongPollingResource;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.mutable.MutableObject;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class HallCommunicationChannel {
|
||||
public class HallCommunicationChannel implements LongPollableResource {
|
||||
private int _channelNumber;
|
||||
private long _lastConsumed;
|
||||
private String _lastMotd;
|
||||
@@ -15,13 +17,26 @@ public class HallCommunicationChannel {
|
||||
private Map<String, Map<String, String>> _tablePropsOnClient = new LinkedHashMap<String, Map<String, String>>();
|
||||
private Set<String> _playedGames = new HashSet<String>();
|
||||
private boolean _changed;
|
||||
private LongPollingResource _longPollingResource;
|
||||
|
||||
public HallCommunicationChannel(int channelNumber) {
|
||||
_channelNumber = channelNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void deregisterResource(LongPollingResource longPollingResource) {
|
||||
_longPollingResource = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void registerForChanges(LongPollingResource longPollingResource) {
|
||||
_longPollingResource = longPollingResource;
|
||||
}
|
||||
|
||||
public synchronized void hallChanged() {
|
||||
_changed = true;
|
||||
if (_longPollingResource != null)
|
||||
_longPollingResource.processIfNotProcessed();
|
||||
}
|
||||
|
||||
public int getChannelNumber() {
|
||||
|
||||
Reference in New Issue
Block a user