Search in sources :

Example 1 with ErrorMessages

use of org.wso2.carbon.identity.cors.mgt.core.constant.ErrorMessages in project siddhi by wso2.

the class MultiClientDistributedSink method connect.

/**
 * Will be called to connect to the backend before events are published
 *
 * @throws ConnectionUnavailableException if it cannot connect to the backend
 */
@Override
public void connect() throws ConnectionUnavailableException {
    StringBuilder errorMessages = null;
    int errorCount = 0;
    for (int i = 0; i < transports.size(); i++) {
        try {
            Sink transport = transports.get(i);
            if (!transport.isConnected()) {
                transport.connect();
                transport.setConnected(true);
                strategy.destinationAvailable(i);
                log.info("Connected to destination Id " + i);
            }
        } catch (ConnectionUnavailableException e) {
            errorCount++;
            if (errorMessages == null) {
                errorMessages = new StringBuilder();
            }
            errorMessages.append("[Destination").append(i).append("]:").append(e.getMessage());
            log.warn(ExceptionUtil.getMessageWithContext(e, siddhiAppContext) + " Failed to Connect to destination ID " + i);
        }
    }
    if (errorCount > 0) {
        throw new ConnectionUnavailableException("Error on '" + siddhiAppContext.getName() + "'. " + errorCount + "/" + transports.size() + " connections failed while trying to connect with following error " + "messages:" + errorMessages.toString());
    }
}
Also used : Sink(org.wso2.siddhi.core.stream.output.sink.Sink) ConnectionUnavailableException(org.wso2.siddhi.core.exception.ConnectionUnavailableException)

Aggregations

ConnectionUnavailableException (org.wso2.siddhi.core.exception.ConnectionUnavailableException)1 Sink (org.wso2.siddhi.core.stream.output.sink.Sink)1