Search in sources :

Example 1 with CGateConnectException

use of com.daveoxley.cbus.CGateConnectException in project openhab-addons by openhab.

the class CBusCGateHandler method connect.

private void connect() {
    CGateSession cGateSession = this.cGateSession;
    if (cGateSession == null) {
        cGateSession = CGateInterface.connect(this.ipAddress, 20023, 20024, 20025, new CBusThreadPool());
        cGateSession.registerEventCallback(new EventMonitor());
        cGateSession.registerStatusChangeCallback(new StatusChangeMonitor());
        this.cGateSession = cGateSession;
    }
    if (cGateSession.isConnected()) {
        logger.debug("CGate session reports online");
        updateStatus(ThingStatus.ONLINE);
    } else {
        try {
            cGateSession.connect();
            updateStatus();
        } catch (CGateConnectException e) {
            updateStatus();
            logger.debug("Failed to connect to CGate:", e);
            try {
                cGateSession.close();
            } catch (CGateException ignore) {
            // We dont really care if an exception is thrown when clossing the connection after a failure
            // connecting.
            }
        }
    }
}
Also used : CGateConnectException(com.daveoxley.cbus.CGateConnectException) CGateSession(com.daveoxley.cbus.CGateSession) CBusThreadPool(org.openhab.binding.cbus.internal.CBusThreadPool) CGateException(com.daveoxley.cbus.CGateException)

Aggregations

CGateConnectException (com.daveoxley.cbus.CGateConnectException)1 CGateException (com.daveoxley.cbus.CGateException)1 CGateSession (com.daveoxley.cbus.CGateSession)1 CBusThreadPool (org.openhab.binding.cbus.internal.CBusThreadPool)1