Search in sources :

Example 1 with NIOConnector

use of com.actiontech.dble.net.NIOConnector in project dble by actiontech.

the class MySQLConnectionFactory method make.

@SuppressWarnings({ "unchecked", "rawtypes" })
public MySQLConnection make(MySQLDataSource pool, ResponseHandler handler, String schema) throws IOException {
    DBHostConfig dsc = pool.getConfig();
    NetworkChannel channel = openSocketChannel(DbleServer.getInstance().isAIO());
    MySQLConnection c = new MySQLConnection(channel, pool.isReadNode());
    c.setSocketParams(false);
    c.setHost(dsc.getIp());
    c.setPort(dsc.getPort());
    c.setUser(dsc.getUser());
    c.setPassword(dsc.getPassword());
    c.setSchema(schema);
    c.setHandler(new MySQLConnectionAuthenticator(c, handler));
    c.setPool(pool);
    c.setIdleTimeout(pool.getConfig().getIdleTimeout());
    if (channel instanceof AsynchronousSocketChannel) {
        ((AsynchronousSocketChannel) channel).connect(new InetSocketAddress(dsc.getIp(), dsc.getPort()), c, (CompletionHandler) DbleServer.getInstance().getConnector());
    } else {
        ((NIOConnector) DbleServer.getInstance().getConnector()).postConnect(c);
    }
    return c;
}
Also used : DBHostConfig(com.actiontech.dble.config.model.DBHostConfig) NetworkChannel(java.nio.channels.NetworkChannel) AsynchronousSocketChannel(java.nio.channels.AsynchronousSocketChannel) NIOConnector(com.actiontech.dble.net.NIOConnector) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

DBHostConfig (com.actiontech.dble.config.model.DBHostConfig)1 NIOConnector (com.actiontech.dble.net.NIOConnector)1 InetSocketAddress (java.net.InetSocketAddress)1 AsynchronousSocketChannel (java.nio.channels.AsynchronousSocketChannel)1 NetworkChannel (java.nio.channels.NetworkChannel)1