类java.nio.channels.NetworkChannel源码实例Demo

下面列出了怎么用java.nio.channels.NetworkChannel的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: dble   文件: MySQLConnection.java
public MySQLConnection(NetworkChannel channel, boolean fromSlaveDB, boolean autocommitSynced, boolean isolationSynced) {
    super(channel);
    this.lastTime = TimeUtil.currentTimeMillis();
    this.autocommitSynced = autocommitSynced;
    boolean sysAutocommit = DbleServer.getInstance().getConfig().getSystem().getAutocommit() == 1;
    this.autocommit = sysAutocommit == autocommitSynced; // T + T-> T, T + F-> F, F +T ->F, F + F->T
    this.fromSlaveDB = fromSlaveDB;
    this.isolationSynced = isolationSynced;
    if (isolationSynced) {
        this.txIsolation = DbleServer.getInstance().getConfig().getSystem().getTxIsolation();
    } else {
        /* if the txIsolation in server.xml is different from the isolation level in MySQL node,
         * it need to sync the status firstly for new idle connection*/
        this.txIsolation = -1;
    }
    this.complexQuery = false;
    this.usrVariables = new LinkedHashMap<>();
    this.sysVariables = new LinkedHashMap<>();
}
 
源代码2 项目: dble   文件: MySQLConnectionFactory.java
@SuppressWarnings({"unchecked", "rawtypes"})
public MySQLConnection make(MySQLDataSource pool, ResponseHandler handler,
                            String schema) throws IOException {

    DataSourceConfig dsc = pool.getConfig();
    NetworkChannel channel = openSocketChannel(DbleServer.getInstance().isAIO());

    MySQLConnection c = new MySQLConnection(channel, pool.isReadNode(), pool.isAutocommitSynced(), pool.isIsolationSynced());
    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;
}
 
源代码3 项目: Mycat-NIO   文件: NetSystem.java
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());

}
 
@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;
}
 
源代码5 项目: Mycat2   文件: ManagerConnectionFactory.java
@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;
}
 
源代码6 项目: Mycat2   文件: ServerConnection.java
public ServerConnection(NetworkChannel channel)
		throws IOException {
	super(channel);
	this.txInterrupted = false;
	this.autocommit = true;
	this.preAcStates = true;
	this.txReadonly = false;
}
 
源代码7 项目: Mycat2   文件: ServerConnectionFactory.java
@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());
    c.setQueryHandler(new ServerQueryHandler(c));
    c.setLoadDataInfileHandler(new ServerLoadDataInfileHandler(c));
    c.setPrepareHandler(new ServerPrepareHandler(c,sys.getMaxPreparedStmtCount()));
    c.setTxIsolation(sys.getTxIsolation());
    c.setSession2(new NonBlockingSession(c));
    return c;
}
 
源代码8 项目: Mycat2   文件: 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());

}
 
源代码9 项目: Mycat2   文件: BackendConnectionFactory.java
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;
	}

}
 
源代码10 项目: Mycat2   文件: FrontendConnectionFactory.java
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;
}
 
源代码11 项目: Mycat2   文件: AbstractConnection.java
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;
}
 
源代码12 项目: Mycat2   文件: AIOAcceptor.java
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);
	}
}
 
源代码13 项目: Mycat2   文件: AIOAcceptor.java
private static void closeChannel(NetworkChannel channel) {
	if (channel == null) {
		return;
	}
	try {
		channel.close();
	} catch (IOException e) {
        LOGGER.error("AioAcceptorError", e);
	}
}
 
@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;
}
 
源代码15 项目: Mycat2   文件: MySQLConnection.java
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();
	this.txReadonly = false;
}
 
源代码16 项目: Mycat2   文件: 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;
}
 
源代码17 项目: dble   文件: ManagerConnectionFactory.java
@Override
protected FrontendConnection getConnection(NetworkChannel channel) throws IOException {
    ManagerConnection c = new ManagerConnection(channel);
    c.setSocketParams(true);
    c.setPrivileges(ManagerPrivileges.instance());
    c.setHandler(new ManagerAuthenticator(c));
    c.setQueryHandler(new ManagerQueryHandler(c));
    return c;
}
 
源代码18 项目: dble   文件: ServerConnection.java
public ServerConnection(NetworkChannel channel)
        throws IOException {
    super(channel);
    this.txInterrupted = false;
    this.autocommit = DbleServer.getInstance().getConfig().getSystem().getAutocommit() == 1;
    this.txID = new AtomicLong(1);
    this.sptprepare = new ServerSptPrepare(this);
    this.usrVariables = new LinkedHashMap<>();
    this.sysVariables = new LinkedHashMap<>();
}
 
源代码19 项目: dble   文件: ServerConnectionFactory.java
@Override
protected FrontendConnection getConnection(NetworkChannel channel) throws IOException {
    ServerConnection c = new ServerConnection(channel);
    c.setSocketParams(true);
    c.setPrivileges(ServerPrivileges.instance());
    c.setQueryHandler(new ServerQueryHandler(c));
    c.setLoadDataInfileHandler(new ServerLoadDataInfileHandler(c));
    c.setPrepareHandler(new ServerPrepareHandler(c));
    SystemConfig sys = DbleServer.getInstance().getConfig().getSystem();
    c.setTxIsolation(sys.getTxIsolation());
    c.setSession2(new NonBlockingSession(c));
    return c;
}
 
源代码20 项目: dble   文件: BackendConnectionFactory.java
protected NetworkChannel openSocketChannel(boolean isAIO)
        throws IOException {
    if (isAIO) {
        return AsynchronousSocketChannel.open(DbleServer.getInstance().getNextAsyncChannelGroup());
    } else {
        SocketChannel channel = null;
        channel = SocketChannel.open();
        channel.configureBlocking(false);
        return channel;
    }

}
 
源代码21 项目: dble   文件: FrontendConnectionFactory.java
public FrontendConnection make(NetworkChannel channel) throws IOException {
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);

    FrontendConnection c = getConnection(channel);
    c.setSocketParams(true);
    return c;
}
 
源代码22 项目: dble   文件: AbstractConnection.java
public AbstractConnection(NetworkChannel channel) {
    this.channel = channel;
    boolean isAIO = (channel instanceof AsynchronousChannel);
    if (isAIO) {
        socketWR = new AIOSocketWR(this);
    } else {
        socketWR = new NIOSocketWR(this);
    }
    this.startupTime = TimeUtil.currentTimeMillis();
    this.lastReadTime = startupTime;
    this.lastWriteTime = startupTime;
}
 
源代码23 项目: Tomcat8-Source-Read   文件: Nio2Endpoint.java
@Override
protected NetworkChannel getServerSocket() {
    return serverSock;
}
 
源代码24 项目: Tomcat8-Source-Read   文件: NioEndpoint.java
@Override
protected NetworkChannel getServerSocket() {
    return serverSock;
}
 
源代码25 项目: trufflesqueak   文件: SqueakTCPSocket.java
@Override
protected NetworkChannel asNetworkChannel() {
    return listening ? serverChannel : clientChannel;
}
 
源代码26 项目: trufflesqueak   文件: SqueakUDPSocket.java
@Override
protected NetworkChannel asNetworkChannel() {
    return channel;
}
 
源代码27 项目: Mycat2   文件: ManagerConnection.java
public ManagerConnection(NetworkChannel channel) throws IOException {
	super(channel);
}
 
源代码28 项目: Mycat2   文件: FrontendConnectionFactory.java
protected abstract FrontendConnection getConnection(NetworkChannel channel)
throws IOException;
 
源代码29 项目: Mycat2   文件: AbstractConnection.java
public NetworkChannel getChannel() {
	return channel;
}
 
源代码30 项目: Mycat2   文件: BackendAIOConnection.java
public BackendAIOConnection(NetworkChannel channel) {
	super(channel);
}
 
 类所在包
 类方法
 同包方法