Search in sources :

Example 1 with CarbonConnectException

use of com.peterphi.carbon.exception.CarbonConnectException in project stdlib by petergeneric.

the class CarbonClientImpl method createSocket.

private Socket createSocket() {
    int attempt = 0;
    Timeout sleep = reconnectSleep;
    while (attempt++ < MAX_CONNECT_ATTEMPTS) try {
        return new Socket(host, port);
    } catch (Exception e) {
        if (attempt < MAX_CONNECT_ATTEMPTS) {
            // back off
            sleep.sleep();
            // Sleep longer next time
            sleep = sleep.multiply(reconnectSleepMultiplier);
        } else {
            throw new CarbonConnectException("Could not connect to Carbon API in " + MAX_CONNECT_ATTEMPTS + " attempts", e);
        }
    }
    throw new CarbonConnectException("Could not conect to Carbon API socket!");
}
Also used : Timeout(com.peterphi.std.threading.Timeout) CarbonConnectException(com.peterphi.carbon.exception.CarbonConnectException) Socket(java.net.Socket) CarbonException(com.peterphi.carbon.exception.CarbonException) CarbonConnectException(com.peterphi.carbon.exception.CarbonConnectException) JDOMException(org.jdom2.JDOMException) IOException(java.io.IOException)

Aggregations

CarbonConnectException (com.peterphi.carbon.exception.CarbonConnectException)1 CarbonException (com.peterphi.carbon.exception.CarbonException)1 Timeout (com.peterphi.std.threading.Timeout)1 IOException (java.io.IOException)1 Socket (java.net.Socket)1 JDOMException (org.jdom2.JDOMException)1