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;
}
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;
}
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());
}
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());
}
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;
}
Aggregations