Search in sources :

Example 1 with GetConnectionHandler

use of io.mycat.backend.mysql.nio.handler.GetConnectionHandler in project Mycat-Server by MyCATApache.

the class PhysicalDBPool method initSource.

private boolean initSource(int index, PhysicalDatasource ds) {
    int initSize = ds.getConfig().getMinCon();
    LOGGER.info("init backend myqsl source ,create connections total " + initSize + " for " + ds.getName() + " index :" + index);
    CopyOnWriteArrayList<BackendConnection> list = new CopyOnWriteArrayList<BackendConnection>();
    GetConnectionHandler getConHandler = new GetConnectionHandler(list, initSize);
    for (int i = 0; i < initSize; i++) {
        try {
            ds.getConnection(this.schemas[i % schemas.length], true, getConHandler, null);
        } catch (Exception e) {
            LOGGER.warn(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) {
            LOGGER.error("initError", e);
        }
    }
    LOGGER.info("init result :" + getConHandler.getStatusInfo());
    //		}
    return !list.isEmpty();
}
Also used : BackendConnection(io.mycat.backend.BackendConnection) GetConnectionHandler(io.mycat.backend.mysql.nio.handler.GetConnectionHandler) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

BackendConnection (io.mycat.backend.BackendConnection)1 GetConnectionHandler (io.mycat.backend.mysql.nio.handler.GetConnectionHandler)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1