Skip to content

Commit

Permalink
try different queue impl
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollovati committed Sep 1, 2023
1 parent 1dd0172 commit b767591
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
Expand All @@ -48,7 +48,7 @@ public class HillaPushClient extends Endpoint implements MessageHandler.Whole<St
private static final Logger LOGGER = LoggerFactory.getLogger(HillaPushClient.class);
private static final AtomicInteger CLIENT_ID_GEN = new AtomicInteger();

final LinkedBlockingDeque<String> messages = new LinkedBlockingDeque<>();
final ArrayBlockingQueue<String> messages = new ArrayBlockingQueue<>(1000);

final String id;
private final String endpointName;
Expand All @@ -69,29 +69,29 @@ public HillaPushClient(String endpointName, String methodName, Object... paramet
public void onOpen(Session session, EndpointConfig config) {
LOGGER.trace("Client {} connected", id);
this.session = session;
messages.add("CONNECT");
messages.offer("CONNECT");
session.addMessageHandler(this);
session.getAsyncRemote().sendText(createSubscribeMessage());
}

@Override
public void onClose(Session session, CloseReason closeReason) {
LOGGER.trace("Session closed for client {} with reason {}", id, closeReason);
messages.add("CLOSED: " + closeReason.toString());
messages.offer("CLOSED: " + closeReason.toString());
session.removeMessageHandler(this);
this.session = null;
}

@Override
public void onError(Session session, Throwable throwable) {
LOGGER.trace("Got error for client {}", id, throwable);
messages.add("ERROR: " + throwable.getMessage());
messages.offer("ERROR: " + throwable.getMessage());
}

public void onMessage(String msg) {
if (msg != null && !msg.isBlank()) {
LOGGER.trace("Message received for client {} :: {}", id, msg);
messages.add(msg);
messages.offer(msg);
} else {
LOGGER.trace("Ignored empty message for client {} :: {}", id, msg);
}
Expand Down

0 comments on commit b767591

Please sign in to comment.