Search in sources :

Example 1 with ConnectionDelegate

use of com.ctrip.platform.dal.dao.datasource.cluster.ConnectionDelegate in project dal by ctripcorp.

the class MajorityHostValidator method validate.

@Override
public boolean validate(HostConnection connection) throws SQLException {
    try {
        HostSpec currentHost = connection.getHost();
        if (connection.isWrapperFor(ConnectionDelegate.class)) {
            ConnectionDelegate connectionDelegate = connection.unwrap(ConnectionDelegate.class);
            if (connectionDelegate.getDelegated() == null) {
                LOGGER.warn(CREATE_CONNECTION_FAILED + currentHost.toString());
                LOGGER.logEvent(CAT_LOG_TYPE, CREATE_CONNECTION_FAILED, currentHost.toString());
                asyncValidate(orderHosts);
                return false;
            }
        }
        ValidateResult validateResult = validateAndUpdate(connection, currentHost, configuredHosts.size());
        LOGGER.info(VALIDATE_RESULT + currentHost.toString() + ":" + validateResult.validateResult);
        LOGGER.logEvent(CAT_LOG_TYPE, currentHost.toString() + ":" + validateResult.validateResult, validateResult.toString());
        if (!validateResult.validateResult) {
            asyncValidate(orderHosts);
        }
        return validateResult.validateResult;
    } catch (SQLException e) {
        asyncValidate(orderHosts);
        throw e;
    }
}
Also used : ConnectionDelegate(com.ctrip.platform.dal.dao.datasource.cluster.ConnectionDelegate) SQLException(java.sql.SQLException) HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec)

Aggregations

HostSpec (com.ctrip.framework.dal.cluster.client.base.HostSpec)1 ConnectionDelegate (com.ctrip.platform.dal.dao.datasource.cluster.ConnectionDelegate)1 SQLException (java.sql.SQLException)1