Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User: use a stably-ordered queue for long-polling #234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/main/java/net/socialgamer/cah/data/ConnectedUsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ public void broadcastToAll(final MessageType type,
* @param broadcastTo
* List of users to broadcast the message to.
* @param type
* Type of message to broadcast. This determines the order the messages are returned by
* priority.
* Type of message to broadcast.
* @param masterData
* Message data to broadcast.
*/
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/socialgamer/cah/data/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,7 @@ private void returnCardsToHand() {
* Broadcast a message to all players in this game.
*
* @param type
* Type of message to broadcast. This determines the order the messages are returned by
* priority.
* Type of message to broadcast.
* @param masterData
* Message data to broadcast.
*/
Expand Down
18 changes: 2 additions & 16 deletions src/main/java/net/socialgamer/cah/data/QueuedMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*
* @author Andy Janata ([email protected])
*/
public class QueuedMessage implements Comparable<QueuedMessage> {
public class QueuedMessage {

private final MessageType messageType;
private final Map<ReturnableData, Object> data;
Expand All @@ -42,8 +42,7 @@ public class QueuedMessage implements Comparable<QueuedMessage> {
* Create a new queued message.
*
* @param messageType
* Type of message to be queued. The type influences the priority in returning messages
* to the client.
* Type of message to be queued.
* @param data
* The data of the message to be queued.
*/
Expand All @@ -66,15 +65,6 @@ public Map<ReturnableData, Object> getData() {
return data;
}

/**
* This is not guaranteed to be consistent with .equals() since we do not care about the data for
* ordering.
*/
@Override
public int compareTo(final QueuedMessage qm) {
return this.messageType.getWeight() - qm.messageType.getWeight();
}

@Override
public String toString() {
return messageType.toString() + "_" + data.toString();
Expand All @@ -92,9 +82,5 @@ public enum MessageType {
MessageType(final int weight) {
this.weight = weight;
}

public int getWeight() {
return weight;
}
}
}
7 changes: 4 additions & 3 deletions src/main/java/net/socialgamer/cah/data/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -54,7 +55,7 @@ public class User {

private final String idCode;

private final PriorityBlockingQueue<QueuedMessage> queuedMessages;
private final BlockingQueue<QueuedMessage> queuedMessages;

private final Object queuedMessageSynchronization = new Object();

Expand Down Expand Up @@ -121,7 +122,7 @@ public User(@Assisted("nickname") final String nickname,
this.sessionId = sessionId;
this.clientLanguage = clientLanguage == null ? "" : clientLanguage;
agent = UADetectorServiceFactory.getResourceModuleParser().parse(clientAgent);
queuedMessages = new PriorityBlockingQueue<QueuedMessage>();
queuedMessages = new LinkedBlockingQueue<QueuedMessage>();
}

public interface Factory {
Expand Down