io.joshworks.stream.client.ConnectionMonitor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stream-client Show documentation
Show all versions of stream-client Show documentation
Resilient client for Server sent events and WebSockets
package io.joshworks.stream.client;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Created by Josh Gontijo on 6/9/17.
*/
public class ConnectionMonitor {
private static final Logger logger = LoggerFactory.getLogger(ConnectionMonitor.class);
private static final Map connections = new ConcurrentHashMap<>();
public void add(String uuid, Runnable close) {
connections.put(uuid, close);
}
public void remove(String uuid) {
connections.remove(uuid);
}
void closeAll() {
for (Map.Entry entry : connections.entrySet()) {
try {
logger.info("Shutting down client connection with uuid: {}", entry.getKey());
entry.getValue().run();
} catch (Exception ignore) {
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy