当前位置: 首页>>代码示例>>Java>>正文


Java NetworkChannel类代码示例

本文整理汇总了Java中java.nio.channels.NetworkChannel的典型用法代码示例。如果您正苦于以下问题:Java NetworkChannel类的具体用法?Java NetworkChannel怎么用?Java NetworkChannel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NetworkChannel类属于java.nio.channels包,在下文中一共展示了NetworkChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getConnection

import java.nio.channels.NetworkChannel; //导入依赖的package包/类
@Override
protected FrontendConnection getConnection(NetworkChannel channel) throws IOException {
    SystemConfig sys = MycatServer.getInstance().getConfig().getSystem();
    ServerConnection c = new ServerConnection(channel);
    MycatServer.getInstance().getConfig().setSocketParams(c, true);
    c.setPrivileges(MycatPrivileges.instance());
    // 每个新的ServerConnection都会绑定
    // 一个新的ServerQueryHandler负责处理sql指令
    c.setQueryHandler(new ServerQueryHandler(c));
    // 一个ServerLoadDataInfileHandler负责处理文件载入命令
    c.setLoadDataInfileHandler(new ServerLoadDataInfileHandler(c));
    c.setPrepareHandler(new ServerPrepareHandler(c));
    c.setTxIsolation(sys.getTxIsolation());
    // 一个session负责处理事务
    c.setSession2(new NonBlockingSession(c));
    return c;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:18,代码来源:ServerConnectionFactory.java

示例2: setSocketParams

import java.nio.channels.NetworkChannel; //导入依赖的package包/类
public void setSocketParams(Connection con, boolean isFrontChannel) throws IOException {
	int sorcvbuf = 0;
	int sosndbuf = 0;
	int soNoDelay = 0;
	if (isFrontChannel) {
		sorcvbuf = netConfig.getFrontsocketsorcvbuf();
		sosndbuf = netConfig.getFrontsocketsosndbuf();
		soNoDelay = netConfig.getFrontSocketNoDelay();
	} else {
		sorcvbuf = netConfig.getBacksocketsorcvbuf();
		sosndbuf = netConfig.getBacksocketsosndbuf();
		soNoDelay = netConfig.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);
}
 
开发者ID:variflight,项目名称:feeyo-redisproxy,代码行数:21,代码来源:NetSystem.java

示例3: make

import java.nio.channels.NetworkChannel; //导入依赖的package包/类
@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;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:27,代码来源:MySQLConnectionFactory.java

示例4: setSocketParams

import java.nio.channels.NetworkChannel; //导入依赖的package包/类
public void setSocketParams(Connection con, boolean isFrontChannel) throws IOException {
	int sorcvbuf = 0;
	int sosndbuf = 0;
	int soNoDelay = 0;
	if (isFrontChannel) {
		sorcvbuf = netConfig.getFrontsocketsorcvbuf();
		sosndbuf = netConfig.getFrontsocketsosndbuf();
		soNoDelay = netConfig.getFrontSocketNoDelay();
	} else {
		sorcvbuf = netConfig.getBacksocketsorcvbuf();
		sosndbuf = netConfig.getBacksocketsosndbuf();
		soNoDelay = netConfig.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(netConfig.getMaxPacketSize());
	con.setPacketHeaderSize(netConfig.getPacketHeaderSize());

}
 
开发者ID:MyCATApache,项目名称:Mycat-NIO,代码行数:25,代码来源:NetSystem.java

示例5: bind

import java.nio.channels.NetworkChannel; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public NetworkChannel bind(final SocketAddress local, final int backlog) throws IOException {
	if (!(local instanceof GroupSocketAddress)) {
		throw new IllegalArgumentException("GroupChannel can only bind to a GroupSocketAddress");
	}
	final GroupSocketAddress group = (GroupSocketAddress) local;
	if (group.size() != channels.length) {
		throw new IllegalArgumentException("local.size() != channels.length");
	}
	final int k = channels.length;
	for (int i = 0; i < k; i++) {
		channels[i].bind(group.get(i), backlog);
	}
	return this;
}
 
开发者ID:ricardopadilha,项目名称:dsys-snio,代码行数:19,代码来源:GroupChannel.java

示例6: getConnection

import java.nio.channels.NetworkChannel; //导入依赖的package包/类
@Override
protected FrontendConnection getConnection(NetworkChannel channel) throws IOException {
    ManagerConnection c = new ManagerConnection(channel);
    MycatServer.getInstance().getConfig().setSocketParams(c, true);
    c.setPrivileges(MycatPrivileges.instance());
    c.setQueryHandler(new ManagerQueryHandler(c));
    return c;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:9,代码来源:ManagerConnectionFactory.java

示例7: setSocketParams

import java.nio.channels.NetworkChannel; //导入依赖的package包/类
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());

}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:30,代码来源:MycatConfig.java

示例8: openSocketChannel

import java.nio.channels.NetworkChannel; //导入依赖的package包/类
protected NetworkChannel openSocketChannel(boolean isAIO)
		throws IOException {
	if (isAIO) {
		return AsynchronousSocketChannel
               .open(MycatServer.getInstance().getNextAsyncChannelGroup());
	} else {
		SocketChannel channel = null;
		channel = SocketChannel.open();
		channel.configureBlocking(false);
		return channel;
	}

}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:14,代码来源:BackendConnectionFactory.java

示例9: make

import java.nio.channels.NetworkChannel; //导入依赖的package包/类
public FrontendConnection make(NetworkChannel channel) throws IOException {
	channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
	channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);

	FrontendConnection c = getConnection(channel);
	MycatServer.getInstance().getConfig().setSocketParams(c, true);
	return c;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:9,代码来源:FrontendConnectionFactory.java

示例10: AbstractConnection

import java.nio.channels.NetworkChannel; //导入依赖的package包/类
public AbstractConnection(NetworkChannel channel) {
	this.channel = channel;
	boolean isAIO = (channel instanceof AsynchronousChannel);
	if (isAIO) {
		socketWR = new AIOSocketWR(this);
	} else {
		socketWR = new NIOSocketWR(this);
	}
	this.isClosed = new AtomicBoolean(false);
	this.startupTime = TimeUtil.currentTimeMillis();
	this.lastReadTime = startupTime;
	this.lastWriteTime = startupTime;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:14,代码来源:AbstractConnection.java

示例11: accept

import java.nio.channels.NetworkChannel; //导入依赖的package包/类
private void accept(NetworkChannel channel, Long id) {
	try {
		FrontendConnection c = factory.make(channel);
		c.setAccepted(true);
		c.setId(id);
		NIOProcessor processor = MycatServer.getInstance().nextProcessor();
		c.setProcessor(processor);
		c.register();
	} catch (Exception e) {
	    LOGGER.error("AioAcceptorError", e);
		closeChannel(channel);
	}
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:14,代码来源:AIOAcceptor.java

示例12: closeChannel

import java.nio.channels.NetworkChannel; //导入依赖的package包/类
private static void closeChannel(NetworkChannel channel) {
	if (channel == null) {
		return;
	}
	try {
		channel.close();
	} catch (IOException e) {
        LOGGER.error("AioAcceptorError", e);
	}
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:11,代码来源:AIOAcceptor.java

示例13: make

import java.nio.channels.NetworkChannel; //导入依赖的package包/类
@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;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:34,代码来源:PostgreSQLBackendConnectionFactory.java

示例14: MySQLConnection

import java.nio.channels.NetworkChannel; //导入依赖的package包/类
public MySQLConnection(NetworkChannel channel, boolean fromSlaveDB) {
	super(channel);
	this.clientFlags = CLIENT_FLAGS;
	this.lastTime = TimeUtil.currentTimeMillis();
	this.isQuit = new AtomicBoolean(false);
	this.autocommit = true;
	this.fromSlaveDB = fromSlaveDB;
	// 设为默认值,免得每个初始化好的连接都要去同步一下
	this.txIsolation = MycatServer.getInstance().getConfig().getSystem().getTxIsolation();
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:11,代码来源:MySQLConnection.java

示例15: make

import java.nio.channels.NetworkChannel; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
// 这里传入的ResponseHandler为DelegateResponseHandler,在连接建立验证之后,会调用
public MySQLConnection make(MySQLDataSource pool, ResponseHandler handler,
		String schema) throws IOException {
	// DBHost配置
	DBHostConfig dsc = pool.getConfig();
	// 根据是否为NIO返回SocketChannel或者AIO的AsynchronousSocketChannel
	NetworkChannel channel = openSocketChannel(MycatServer.getInstance()
			.isAIO());
	// 新建MySQLConnection
	MySQLConnection c = new MySQLConnection(channel, pool.isReadNode());
	// 根据配置初始化MySQLConnection
	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);
	// 目前实际连接还未建立,handler为MySQL连接认证MySQLConnectionAuthenticatorHandler
	c.setHandler(new MySQLConnectionAuthenticatorHandler(c, handler));
	c.setPool(pool);
	c.setIdleTimeout(pool.getConfig().getIdleTimeout());
	// AIO和NIO连接方式建立实际的MySQL连接
	if (channel instanceof AsynchronousSocketChannel) {
		((AsynchronousSocketChannel) channel).connect(
				new InetSocketAddress(dsc.getIp(), dsc.getPort()), c,
				(CompletionHandler) MycatServer.getInstance()
						.getConnector());
	} else {
		// 通过NIOConnector建立连接
		// 通过NIOConnector建立实际连接的过程与前端连接的建立相似,
		// 也是先放在队列中,之后由NIOConnector去建立连接
		((NIOConnector) MycatServer.getInstance().getConnector())
				.postConnect(c);

	}
	return c;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:39,代码来源:MySQLConnectionFactory.java


注:本文中的java.nio.channels.NetworkChannel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。