All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.joshworks.stream.client.ConnectionMonitor Maven / Gradle / Ivy

There is a newer version: 0.3.1
Show newest version
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