本文整理了Java中java.nio.channels.SocketChannel.keyFor()
方法的一些代码示例,展示了SocketChannel.keyFor()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SocketChannel.keyFor()
方法的具体详情如下:
包路径:java.nio.channels.SocketChannel
类名称:SocketChannel
方法名:keyFor
暂无
代码示例来源:origin: apache/rocketmq
private void closeMaster() {
if (null != this.socketChannel) {
try {
SelectionKey sk = this.socketChannel.keyFor(this.selector);
if (sk != null) {
sk.cancel();
}
this.socketChannel.close();
this.socketChannel = null;
} catch (IOException e) {
log.warn("closeMaster exception. ", e);
}
this.lastWriteTimestamp = 0;
this.dispatchPostion = 0;
this.byteBufferBackup.position(0);
this.byteBufferBackup.limit(READ_MAX_BUFFER_SIZE);
this.byteBufferRead.position(0);
this.byteBufferRead.limit(READ_MAX_BUFFER_SIZE);
}
}
代码示例来源:origin: apache/incubator-gobblin
private void connect() throws IOException {
if (this.proxy.isOpen()) {
if (this.proxy.finishConnect()) {
this.proxy.register(this.selector, SelectionKey.OP_WRITE, this);
SelectionKey clientKey = this.client.keyFor(this.selector);
if (clientKey != null) {
clientKey.cancel();
}
this.state = HandlerState.WRITING;
} else if (this.connectStartTime + Config.PROXY_CONNECT_TIMEOUT_MS < System.currentTimeMillis()) {
LOG.warn("Proxy connect timed out for client {}", this.client);
closeChannels();
}
}
}
代码示例来源:origin: apache/hbase
/**
* Take the list of the connections that want to write, and register them in the selector.
*/
private void registerWrites() {
Iterator<SimpleServerRpcConnection> it = writingCons.iterator();
while (it.hasNext()) {
SimpleServerRpcConnection c = it.next();
it.remove();
SelectionKey sk = c.channel.keyFor(writeSelector);
try {
if (sk == null) {
try {
c.channel.register(writeSelector, SelectionKey.OP_WRITE, c);
} catch (ClosedChannelException e) {
// ignore: the client went away.
if (SimpleRpcServer.LOG.isTraceEnabled()) SimpleRpcServer.LOG.trace("ignored", e);
}
} else {
sk.interestOps(SelectionKey.OP_WRITE);
}
} catch (CancelledKeyException e) {
// ignore: the client went away.
if (SimpleRpcServer.LOG.isTraceEnabled()) SimpleRpcServer.LOG.trace("ignored", e);
}
}
}
代码示例来源:origin: apache/incubator-gobblin
private void read()
throws IOException {
SelectionKey proxyKey = this.proxy.keyFor(this.selector);
SelectionKey clientKey = this.client.keyFor(this.selector);
代码示例来源:origin: voldemort/voldemort
protected void closeInternal() {
if(logger.isDebugEnabled())
logger.debug("Closing remote connection from " + socketChannel.socket());
try {
socketChannel.socket().close();
} catch(IOException e) {
if(logger.isEnabledFor(Level.WARN))
logger.warn(e.getMessage(), e);
}
try {
socketChannel.close();
} catch(IOException e) {
if(logger.isEnabledFor(Level.WARN))
logger.warn(e.getMessage(), e);
}
SelectionKey selectionKey = socketChannel.keyFor(selector);
if(selectionKey != null) {
try {
selectionKey.attach(null);
selectionKey.cancel();
} catch(Exception e) {
if(logger.isEnabledFor(Level.WARN))
logger.warn(e.getMessage(), e);
}
}
// close the streams, so we account for comm buffer frees
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(outputStream);
}
代码示例来源:origin: ltsopensource/light-task-scheduler
public Futures.WriteFuture writeAndFlush(NioChannel channel, Object msg) {
SelectionKey key = channel.socketChannel().keyFor(selectorLoop.selector());
if(key != null && key.isValid()){
key.interestOps(SelectionKey.OP_WRITE);
}
return write(channel, msg, true);
}
代码示例来源:origin: ltsopensource/light-task-scheduler
public Futures.WriteFuture writeAndFlush(NioChannel channel, Object msg) {
SelectionKey key = channel.socketChannel().keyFor(selectorLoop.selector());
if(key != null && key.isValid()){
key.interestOps(SelectionKey.OP_WRITE);
}
return write(channel, msg, true);
}
代码示例来源:origin: apache/incubator-gobblin
private void write()
throws IOException {
SelectionKey proxyKey = this.proxy.keyFor(this.selector);
SelectionKey clientKey = this.client.keyFor(this.selector);
代码示例来源:origin: voldemort/voldemort
SelectionKey selectionKey = socketChannel.keyFor(selector);
代码示例来源:origin: mpetazzoni/ttorrent
continue;
SelectionKey key = socketChannel.keyFor(selector);
if (key == null) {
logger.warn("unable to find key for channel {}", socketChannel);
代码示例来源:origin: voldemort/voldemort
public void run() {
try {
SelectionKey selectionKey = socketChannel.keyFor(selector);
代码示例来源:origin: apache/rocketmq
SelectionKey sk = this.socketChannel.keyFor(this.selector);
if (sk != null) {
sk.cancel();
代码示例来源:origin: apache/rocketmq
SelectionKey sk = this.socketChannel.keyFor(this.selector);
if (sk != null) {
sk.cancel();
代码示例来源:origin: ltsopensource/light-task-scheduler
SelectionKey key = channel.socketChannel().keyFor(selectorLoop.selector());
if(key != null && key.isValid()){
key.interestOps(SelectionKey.OP_READ);
代码示例来源:origin: ltsopensource/light-task-scheduler
SelectionKey key = channel.socketChannel().keyFor(selectorLoop.selector());
if(key != null && key.isValid()){
key.interestOps(SelectionKey.OP_READ);
代码示例来源:origin: didi/DDMQ
private void closeMaster() {
if (null != this.socketChannel) {
try {
SelectionKey sk = this.socketChannel.keyFor(this.selector);
if (sk != null) {
sk.cancel();
}
this.socketChannel.close();
this.socketChannel = null;
} catch (IOException e) {
log.warn("closeMaster exception. ", e);
}
this.lastWriteTimestamp = 0;
this.dispatchPostion = 0;
this.byteBufferBackup.position(0);
this.byteBufferBackup.limit(READ_MAX_BUFFER_SIZE);
this.byteBufferRead.position(0);
this.byteBufferRead.limit(READ_MAX_BUFFER_SIZE);
}
}
代码示例来源:origin: didi/DDMQ
SelectionKey sk = this.socketChannel.keyFor(this.selector);
if (sk != null) {
sk.cancel();
代码示例来源:origin: camunda/camunda-bpm-platform
if (sc == null)
continue;
SelectionKey sk = sc.keyFor(selector);
代码示例来源:origin: com.sun.mail/javax.mail
if (sc == null)
continue;
SelectionKey sk = sc.keyFor(selector);
代码示例来源:origin: didi/DDMQ
SelectionKey sk = this.socketChannel.keyFor(this.selector);
if (sk != null) {
sk.cancel();
内容来源于网络,如有侵权,请联系作者删除!