本文整理了Java中java.nio.channels.SocketChannel.validOps()
方法的一些代码示例,展示了SocketChannel.validOps()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SocketChannel.validOps()
方法的具体详情如下:
包路径:java.nio.channels.SocketChannel
类名称:SocketChannel
方法名:validOps
[英]Gets the valid operations of this channel. Socket channels support connect, read and write operation, so this method returns SelectionKey.OP_CONNECT | SelectionKey.OP_READ | SelectionKey.OP_WRITE.
[中]获取此通道的有效操作。套接字通道支持连接、读写操作,因此此方法返回SelectionKey。OP|u CONNECT |选择键。操作读取|选择键。OP_写作。
代码示例来源:origin: org.apache.thrift/libthrift
/**
* Writes to the underlying output stream if not null.
*/
public void write(byte[] buf, int off, int len) throws TTransportException {
if ((socketChannel_.validOps() & SelectionKey.OP_WRITE) != SelectionKey.OP_WRITE) {
throw new TTransportException(TTransportException.NOT_OPEN,
"Cannot write to write-only socket channel");
}
try {
socketChannel_.write(ByteBuffer.wrap(buf, off, len));
} catch (IOException iox) {
throw new TTransportException(TTransportException.UNKNOWN, iox);
}
}
代码示例来源:origin: org.apache.thrift/libthrift
/**
* Reads from the underlying input stream if not null.
*/
public int read(byte[] buf, int off, int len) throws TTransportException {
if ((socketChannel_.validOps() & SelectionKey.OP_READ) != SelectionKey.OP_READ) {
throw new TTransportException(TTransportException.NOT_OPEN,
"Cannot read from write-only socket channel");
}
try {
return socketChannel_.read(ByteBuffer.wrap(buf, off, len));
} catch (IOException iox) {
throw new TTransportException(TTransportException.UNKNOWN, iox);
}
}
代码示例来源:origin: org.apache.thrift/libthrift
key = s.register(selector, s.validOps());
代码示例来源:origin: annmuor/jnode
private void init(SocketChannel socket) throws IOException {
socket.configureBlocking(false);
selector = Selector.open();
socket.register(selector, socket.validOps());
}
代码示例来源:origin: stackoverflow.com
SocketChannel SC = SocketChannel.open()
SC.configureBlocking( false )
SC.connect(new INetSocketAddress( A-machine, A-port )
SC.register( selector, SC.validOps())
代码示例来源:origin: org.apache.cassandra.deps/libthrift
/**
* Reads from the underlying input stream if not null.
*/
public int read(byte[] buf, int off, int len) throws TTransportException {
if ((socketChannel_.validOps() & SelectionKey.OP_READ) != SelectionKey.OP_READ) {
throw new TTransportException(TTransportException.NOT_OPEN,
"Cannot read from write-only socket channel");
}
try {
return socketChannel_.read(ByteBuffer.wrap(buf, off, len));
} catch (IOException iox) {
throw new TTransportException(TTransportException.UNKNOWN, iox);
}
}
代码示例来源:origin: XiaoMi/galaxy-sdk-java
/**
* Writes to the underlying output stream if not null.
*/
public void write(byte[] buf, int off, int len) throws TTransportException {
if ((socketChannel_.validOps() & SelectionKey.OP_WRITE) != SelectionKey.OP_WRITE) {
throw new TTransportException(TTransportException.NOT_OPEN,
"Cannot write to write-only socket channel");
}
try {
socketChannel_.write(ByteBuffer.wrap(buf, off, len));
} catch (IOException iox) {
throw new TTransportException(TTransportException.UNKNOWN, iox);
}
}
代码示例来源:origin: com.xiaomi.infra.galaxy/galaxy-thrift-api
/**
* Writes to the underlying output stream if not null.
*/
public void write(byte[] buf, int off, int len) throws TTransportException {
if ((socketChannel_.validOps() & SelectionKey.OP_WRITE) != SelectionKey.OP_WRITE) {
throw new TTransportException(TTransportException.NOT_OPEN,
"Cannot write to write-only socket channel");
}
try {
socketChannel_.write(ByteBuffer.wrap(buf, off, len));
} catch (IOException iox) {
throw new TTransportException(TTransportException.UNKNOWN, iox);
}
}
代码示例来源:origin: org.apache.cassandra.deps/libthrift
/**
* Writes to the underlying output stream if not null.
*/
public void write(byte[] buf, int off, int len) throws TTransportException {
if ((socketChannel_.validOps() & SelectionKey.OP_WRITE) != SelectionKey.OP_WRITE) {
throw new TTransportException(TTransportException.NOT_OPEN,
"Cannot write to write-only socket channel");
}
try {
socketChannel_.write(ByteBuffer.wrap(buf, off, len));
} catch (IOException iox) {
throw new TTransportException(TTransportException.UNKNOWN, iox);
}
}
代码示例来源:origin: com.google.code.maven-play-plugin.org.apache.thrift/thrift
/**
* Writes to the underlying output stream if not null.
*/
public void write(byte[] buf, int off, int len) throws TTransportException {
if ((socketChannel.validOps() & SelectionKey.OP_WRITE) != SelectionKey.OP_WRITE) {
throw new TTransportException(TTransportException.NOT_OPEN,
"Cannot write to write-only socket channel");
}
try {
socketChannel.write(ByteBuffer.wrap(buf, off, len));
} catch (IOException iox) {
throw new TTransportException(TTransportException.UNKNOWN, iox);
}
}
代码示例来源:origin: XiaoMi/galaxy-sdk-java
/**
* Reads from the underlying input stream if not null.
*/
public int read(byte[] buf, int off, int len) throws TTransportException {
if ((socketChannel_.validOps() & SelectionKey.OP_READ) != SelectionKey.OP_READ) {
throw new TTransportException(TTransportException.NOT_OPEN,
"Cannot read from write-only socket channel");
}
try {
return socketChannel_.read(ByteBuffer.wrap(buf, off, len));
} catch (IOException iox) {
throw new TTransportException(TTransportException.UNKNOWN, iox);
}
}
代码示例来源:origin: com.twitter/libthrift
/**
* Reads from the underlying input stream if not null.
*/
public int read(byte[] buf, int off, int len) throws TTransportException {
if ((socketChannel_.validOps() & SelectionKey.OP_READ) != SelectionKey.OP_READ) {
throw new TTransportException(TTransportException.NOT_OPEN,
"Cannot read from write-only socket channel");
}
try {
return socketChannel_.read(ByteBuffer.wrap(buf, off, len));
} catch (IOException iox) {
throw new TTransportException(TTransportException.UNKNOWN, iox);
}
}
代码示例来源:origin: com.twitter/libthrift
/**
* Writes to the underlying output stream if not null.
*/
public void write(byte[] buf, int off, int len) throws TTransportException {
if ((socketChannel_.validOps() & SelectionKey.OP_WRITE) != SelectionKey.OP_WRITE) {
throw new TTransportException(TTransportException.NOT_OPEN,
"Cannot write to write-only socket channel");
}
try {
socketChannel_.write(ByteBuffer.wrap(buf, off, len));
} catch (IOException iox) {
throw new TTransportException(TTransportException.UNKNOWN, iox);
}
}
代码示例来源:origin: com.xiaomi.infra.galaxy/galaxy-thrift-api
/**
* Reads from the underlying input stream if not null.
*/
public int read(byte[] buf, int off, int len) throws TTransportException {
if ((socketChannel_.validOps() & SelectionKey.OP_READ) != SelectionKey.OP_READ) {
throw new TTransportException(TTransportException.NOT_OPEN,
"Cannot read from write-only socket channel");
}
try {
return socketChannel_.read(ByteBuffer.wrap(buf, off, len));
} catch (IOException iox) {
throw new TTransportException(TTransportException.UNKNOWN, iox);
}
}
代码示例来源:origin: com.google.code.maven-play-plugin.org.apache.thrift/thrift
/**
* Reads from the underlying input stream if not null.
*/
public int read(byte[] buf, int off, int len) throws TTransportException {
if ((socketChannel.validOps() & SelectionKey.OP_READ) != SelectionKey.OP_READ) {
throw new TTransportException(TTransportException.NOT_OPEN,
"Cannot read from write-only socket channel");
}
try {
return socketChannel.read(ByteBuffer.wrap(buf, off, len));
} catch (IOException iox) {
throw new TTransportException(TTransportException.UNKNOWN, iox);
}
}
代码示例来源:origin: stackoverflow.com
int validOps = socketChannel.validOps();
代码示例来源:origin: org.ow2.joram/a3-rt
/**
* The session is well initialized, we can start the server thread that
* "listen" the connected socket. If the maximum number of connections
* is reached, one connection from the pool is closed.
*/
private void startEnd() throws IOException {
server.active = true;
server.retry = 0;
// mos = new MessageOutputStream();
nbwrite = 0;
// bufin = ByteBuffer.allocateDirect(SO_BUFSIZE);
bufin.clear();
// mis = new MessageInputStream();
// The returned channel is in blocking mode.
channel.configureBlocking(false);
// Register channels with selector
channel.register(selector, channel.validOps(), this);
if (logmon.isLoggable(BasicLevel.DEBUG))
logmon.log(BasicLevel.DEBUG,
getName() + ", connection started");
sendlist.reset();
}
代码示例来源:origin: org.objectweb.joram/a3-rt
/**
* The session is well initialized, we can start the server thread that
* "listen" the connected socket. If the maximum number of connections
* is reached, one connection from the pool is closed.
*/
private void startEnd() throws IOException {
server.active = true;
server.retry = 0;
// mos = new MessageOutputStream();
nbwrite = 0;
// bufin = ByteBuffer.allocateDirect(SO_BUFSIZE);
bufin.clear();
// mis = new MessageInputStream();
// The returned channel is in blocking mode.
channel.configureBlocking(false);
// Register channels with selector
channel.register(selector, channel.validOps(), this);
if (logmon.isLoggable(BasicLevel.DEBUG))
logmon.log(BasicLevel.DEBUG,
getName() + ", connection started");
sendlist.reset();
}
代码示例来源:origin: org.ow2.joram/a3-rt
synchronized void send(Message msg) throws IOException {
if (logmon.isLoggable(BasicLevel.DEBUG))
logmon.log(BasicLevel.DEBUG,
getName() + ", send message: " + msg);
// Adds it to the list of message to be sent, it will be removed
// after its ack receipt.
sendlist.addMessage(msg);
if ((channel != null) && (bufout == null)) {
// As no message are actually sending the channel is only subscribe
// for reading, subscribe this channel for write operation will permit
// to transmit the new added message.
// Be careful, as this change is only take in account for the next
// select operation, we have to use wakeup on selector
SelectionKey key = channel.keyFor(selector);
if (logmon.isLoggable(BasicLevel.DEBUG))
logmon.log(BasicLevel.DEBUG,
getName() + ", send message, key=" + key);
if (key != null)
key.interestOps(channel.validOps());
}
// In all case a selector.wakeup() will solve the problem !!
if (selector == null) {
logmon.log(BasicLevel.WARN,
getName() + ", network not started.");
} else {
selector.wakeup();
}
}
代码示例来源:origin: org.objectweb.joram/a3-rt
synchronized void send(Message msg) throws IOException {
if (logmon.isLoggable(BasicLevel.DEBUG))
logmon.log(BasicLevel.DEBUG,
getName() + ", send message: " + msg);
// Adds it to the list of message to be sent, it will be removed
// after its ack receipt.
sendlist.addMessage(msg);
if ((channel != null) && (bufout == null)) {
// As no message are actually sending the channel is only subscribe
// for reading, subscribe this channel for write operation will permit
// to transmit the new added message.
// Be careful, as this change is only take in account for the next
// select operation, we have to use wakeup on selector
SelectionKey key = channel.keyFor(selector);
if (logmon.isLoggable(BasicLevel.DEBUG))
logmon.log(BasicLevel.DEBUG,
getName() + ", send message, key=" + key);
if (key != null)
key.interestOps(channel.validOps());
}
// In all case a selector.wakeup() will solve the problem !!
if (selector == null) {
logmon.log(BasicLevel.WARN,
getName() + ", network not started.");
} else {
selector.wakeup();
}
}
内容来源于网络,如有侵权,请联系作者删除!