Search in sources :

Example 1 with GetConnectionHandler

use of com.actiontech.dble.backend.mysql.nio.handler.GetConnectionHandler in project dble by actiontech.

the class PhysicalDBPool method initSource.

private boolean initSource(int index, PhysicalDatasource ds) {
    int initSize = ds.getConfig().getMinCon();
    LOGGER.info("init backend mysql source ,create connections total " + initSize + " for " + ds.getName() + " index :" + index);
    CopyOnWriteArrayList<BackendConnection> list = new CopyOnWriteArrayList<>();
    GetConnectionHandler getConHandler = new GetConnectionHandler(list, initSize);
    for (int i = 0; i < initSize; i++) {
        try {
            ds.initMinConnection(this.schemas[i % schemas.length], true, getConHandler, null);
        } catch (Exception e) {
            LOGGER.info(getMessage(index, " init connection error."), e);
        }
    }
    long timeOut = System.currentTimeMillis() + 60 * 1000;
    // waiting for finish
    while (!getConHandler.finished() && (System.currentTimeMillis() < timeOut)) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            /**
             * hardly triggered no error is needed
             */
            LOGGER.info("initError", e);
        }
    }
    LOGGER.info("init result :" + getConHandler.getStatusInfo());
    return !list.isEmpty();
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) GetConnectionHandler(com.actiontech.dble.backend.mysql.nio.handler.GetConnectionHandler) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

BackendConnection (com.actiontech.dble.backend.BackendConnection)1 GetConnectionHandler (com.actiontech.dble.backend.mysql.nio.handler.GetConnectionHandler)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1