Search in sources :

Example 1 with NetworkChannel

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

the class PostgreSQLBackendConnectionFactory method make.

@SuppressWarnings({ "unchecked", "rawtypes" })
public PostgreSQLBackendConnection make(PostgreSQLDataSource pool, ResponseHandler handler, final String schema) throws IOException {
    final DBHostConfig dsc = pool.getConfig();
    NetworkChannel channel = this.openSocketChannel(MycatServer.getInstance().isAIO());
    final PostgreSQLBackendConnection c = new PostgreSQLBackendConnection(channel, pool.isReadNode());
    MycatServer.getInstance().getConfig().setSocketParams(c, false);
    // 设置NIOHandler
    c.setHandler(new PostgreSQLBackendConnectionHandler(c));
    c.setHost(dsc.getIp());
    c.setPort(dsc.getPort());
    c.setUser(dsc.getUser());
    c.setPassword(dsc.getPassword());
    c.setSchema(schema);
    c.setPool(pool);
    c.setResponseHandler(handler);
    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 2 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 3 with NetworkChannel

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

the class MycatConfig method setSocketParams.

public void setSocketParams(AbstractConnection con, boolean isFrontChannel) throws IOException {
    int sorcvbuf = 0;
    int sosndbuf = 0;
    int soNoDelay = 0;
    if (isFrontChannel) {
        sorcvbuf = system.getFrontsocketsorcvbuf();
        sosndbuf = system.getFrontsocketsosndbuf();
        soNoDelay = system.getFrontSocketNoDelay();
    } else {
        sorcvbuf = system.getBacksocketsorcvbuf();
        sosndbuf = system.getBacksocketsosndbuf();
        soNoDelay = system.getBackSocketNoDelay();
    }
    NetworkChannel channel = con.getChannel();
    channel.setOption(StandardSocketOptions.SO_RCVBUF, sorcvbuf);
    channel.setOption(StandardSocketOptions.SO_SNDBUF, sosndbuf);
    channel.setOption(StandardSocketOptions.TCP_NODELAY, soNoDelay == 1);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
    con.setMaxPacketSize(system.getMaxPacketSize());
    con.setPacketHeaderSize(system.getPacketHeaderSize());
    con.setIdleTimeout(system.getIdleTimeout());
    con.setCharset(system.getCharset());
}
Also used : NetworkChannel(java.nio.channels.NetworkChannel)

Example 4 with NetworkChannel

use of java.nio.channels.NetworkChannel in project Mycat_plus by coderczp.

the class MycatConfig method setSocketParams.

public void setSocketParams(AbstractConnection con, boolean isFrontChannel) throws IOException {
    int sorcvbuf = 0;
    int sosndbuf = 0;
    int soNoDelay = 0;
    if (isFrontChannel) {
        sorcvbuf = system.getFrontsocketsorcvbuf();
        sosndbuf = system.getFrontsocketsosndbuf();
        soNoDelay = system.getFrontSocketNoDelay();
    } else {
        sorcvbuf = system.getBacksocketsorcvbuf();
        sosndbuf = system.getBacksocketsosndbuf();
        soNoDelay = system.getBackSocketNoDelay();
    }
    NetworkChannel channel = con.getChannel();
    channel.setOption(StandardSocketOptions.SO_RCVBUF, sorcvbuf);
    channel.setOption(StandardSocketOptions.SO_SNDBUF, sosndbuf);
    channel.setOption(StandardSocketOptions.TCP_NODELAY, soNoDelay == 1);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
    con.setMaxPacketSize(system.getMaxPacketSize());
    con.setPacketHeaderSize(system.getPacketHeaderSize());
    con.setIdleTimeout(system.getIdleTimeout());
    con.setCharset(system.getCharset());
}
Also used : NetworkChannel(java.nio.channels.NetworkChannel)

Example 5 with NetworkChannel

use of java.nio.channels.NetworkChannel in project Mycat_plus by coderczp.

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)

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