Search in sources :

Example 1 with NewConnectionRespHandler

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

the class PhysicalDatasource method getConnection.

public BackendConnection getConnection(String schema, boolean autocommit) throws IOException {
    BackendConnection con = this.conMap.tryTakeCon(schema, autocommit);
    if (con == null) {
        // the max active
        int activeCons = this.getActiveCount();
        if (activeCons + 1 > size) {
            LOGGER.warn(AlarmCode.CORE_PERFORMANCE_WARN + "the max activeConnnections size can not be max than maxconnections");
            throw new IOException("the max activeConnnections size can not be max than maxconnections");
        } else {
            // create connection
            LOGGER.info("no ilde connection in pool,create new connection for " + this.name + " of schema " + schema);
            NewConnectionRespHandler simpleHandler = new NewConnectionRespHandler();
            this.createNewConnection(simpleHandler, schema);
            con = simpleHandler.getBackConn();
        }
    }
    return takeCon(con, schema);
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) NewConnectionRespHandler(com.actiontech.dble.backend.mysql.nio.handler.NewConnectionRespHandler) IOException(java.io.IOException)

Example 2 with NewConnectionRespHandler

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

the class PhysicalDatasource method createByIdleLittle.

private void createByIdleLittle(int idleCons, int createCount) {
    LOGGER.info("create connections ,because idle connection not enough ,cur is " + idleCons + ", minCon is " + hostConfig.getMinCon() + " for " + name);
    final String[] schemas = dbPool.getSchemas();
    for (int i = 0; i < createCount; i++) {
        if (this.getActiveCount() + this.getIdleCount() >= size) {
            break;
        }
        NewConnectionRespHandler simpleHandler = new NewConnectionRespHandler();
        try {
            // creat new connection
            this.createNewConnection(simpleHandler, null, schemas[i % schemas.length]);
            simpleHandler.getBackConn().release();
        } catch (IOException e) {
            LOGGER.info("create connection err " + e);
        }
    }
}
Also used : NewConnectionRespHandler(com.actiontech.dble.backend.mysql.nio.handler.NewConnectionRespHandler) IOException(java.io.IOException)

Aggregations

NewConnectionRespHandler (com.actiontech.dble.backend.mysql.nio.handler.NewConnectionRespHandler)2 IOException (java.io.IOException)2 BackendConnection (com.actiontech.dble.backend.BackendConnection)1