java.nio.channels.NetworkChannel

Here are the examples of the java api class java.nio.channels.NetworkChannel taken from open source projects.

1. MycatConfig#setSocketParams()

Project: Mycat-Server
File: MycatConfig.java
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());
}

2. PostgreSQLBackendConnectionFactory#make()

Project: Mycat-Server
File: PostgreSQLBackendConnectionFactory.java
@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;
}

3. MySQLConnectionFactory#make()

Project: Mycat-Server
File: MySQLConnectionFactory.java
@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;
}