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

com.openfin.desktop.net.WebSocketClientFactory Maven / Gradle / Ivy

There is a newer version: 11.0.2
Show newest version
package com.openfin.desktop.net;

import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Make singleton of WebSocketClient
 *
 * Created by wche on 9/22/2016.
 */
class WebSocketClientFactory {
    private static Logger logger = LoggerFactory.getLogger(WebSocketClientFactory.class.getName());
    private static WebSocketClient client;

    static synchronized WebSocketClient getWebSocketClient() {
        if (client == null) {
            logger.debug("Creating WebSocketClient");
            client = new WebSocketClient();
            try {
                logger.debug("Starting WebSocketClient");
                client.start();
            } catch (Exception e) {
                logger.error("Error creating WebSocketClient", e);
            }
        }
        return client;
    }

    static synchronized void stopWebSocketClient() {
        if (client != null) {
            try {
                client.stop();
                client = null;
            } catch (Exception e) {
                logger.error("Error stopping WebSocketClient", e);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy