Search in sources :

Example 6 with NetworkChannel

use of java.nio.channels.NetworkChannel in project Mycat-Server by MyCATApache.

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(MycatServer.getInstance().isAIO());
    MySQLConnection c = new MySQLConnection(channel, pool.isReadNode());
    MycatServer.getInstance().getConfig().setSocketParams(c, 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) MycatServer.getInstance().getConnector());
    } else {
        ((NIOConnector) MycatServer.getInstance().getConnector()).postConnect(c);
    }
    return c;
}
Also used : DBHostConfig(io.mycat.config.model.DBHostConfig) NetworkChannel(java.nio.channels.NetworkChannel) AsynchronousSocketChannel(java.nio.channels.AsynchronousSocketChannel) NIOConnector(io.mycat.net.NIOConnector) InetSocketAddress(java.net.InetSocketAddress)

Example 7 with NetworkChannel

use of java.nio.channels.NetworkChannel 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)

Example 8 with NetworkChannel

use of java.nio.channels.NetworkChannel in project tomcat by apache.

the class AbstractJsseEndpoint method getLocalAddress.

@Override
protected final InetSocketAddress getLocalAddress() throws IOException {
    NetworkChannel serverSock = getServerSocket();
    if (serverSock == null) {
        return null;
    }
    SocketAddress sa = serverSock.getLocalAddress();
    if (sa instanceof InetSocketAddress) {
        return (InetSocketAddress) sa;
    }
    return null;
}
Also used : NetworkChannel(java.nio.channels.NetworkChannel) InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

NetworkChannel (java.nio.channels.NetworkChannel)8 InetSocketAddress (java.net.InetSocketAddress)5 AsynchronousSocketChannel (java.nio.channels.AsynchronousSocketChannel)4 DBHostConfig (io.mycat.config.model.DBHostConfig)3 NIOConnector (io.mycat.net.NIOConnector)3 DBHostConfig (com.actiontech.dble.config.model.DBHostConfig)1 NIOConnector (com.actiontech.dble.net.NIOConnector)1 SocketAddress (java.net.SocketAddress)1 Test (org.junit.jupiter.api.Test)1