本文整理了Java中java.nio.channels.SocketChannel.isBlocking()
方法的一些代码示例,展示了SocketChannel.isBlocking()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SocketChannel.isBlocking()
方法的具体详情如下:
包路径:java.nio.channels.SocketChannel
类名称:SocketChannel
方法名:isBlocking
暂无
代码示例来源:origin: TooTallNate/Java-WebSocket
@Override
public boolean isBlocking() {
return socketChannel.isBlocking();
}
代码示例来源:origin: TooTallNate/Java-WebSocket
@Override
public boolean isBlocking() {
return socketChannel.isBlocking();
}
代码示例来源:origin: TooTallNate/Java-WebSocket
@Override
public boolean isBlocking() {
if( channel instanceof SocketChannel )
return ( (SocketChannel) channel ).isBlocking();
else if( channel instanceof WrappedByteChannel )
return ( (WrappedByteChannel) channel ).isBlocking();
return false;
}
代码示例来源:origin: apache/ignite
/**
* Safely write buffer fully to blocking socket channel.
* Will throw assert if non blocking channel passed.
*
* @param sockCh WritableByteChannel.
* @param buf Buffer.
* @throws IOException IOException.
*/
public static void writeFully(SocketChannel sockCh, ByteBuffer buf) throws IOException {
int totalWritten = 0;
assert sockCh.isBlocking() : "SocketChannel should be in blocking mode " + sockCh;
while (buf.hasRemaining()) {
int written = sockCh.write(buf);
if (written < 0)
throw new IOException("Error writing buffer to channel " +
"[written = " + written + ", buf " + buf + ", totalWritten = " + totalWritten + "]");
totalWritten += written;
}
}
代码示例来源:origin: robovm/robovm
@Override
public void write(int oneByte) throws IOException {
if (!channel.isBlocking()) {
throw new IllegalBlockingModeException();
}
ByteBuffer buffer = ByteBuffer.allocate(1);
buffer.put(0, (byte) (oneByte & 0xFF));
channel.write(buffer);
}
}
代码示例来源:origin: robovm/robovm
@Override
public int read() throws IOException {
if (!channel.isBlocking()) {
throw new IllegalBlockingModeException();
}
ByteBuffer buf = ByteBuffer.allocate(1);
int result = channel.read(buf);
return (result == -1) ? result : (buf.get(0) & 0xff);
}
代码示例来源:origin: robovm/robovm
@Override
public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount);
if (!channel.isBlocking()) {
throw new IllegalBlockingModeException();
}
ByteBuffer buf = ByteBuffer.wrap(buffer, byteOffset, byteCount);
return channel.read(buf);
}
}
代码示例来源:origin: robovm/robovm
@Override
public void write(byte[] buffer, int offset, int byteCount) throws IOException {
Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
ByteBuffer buf = ByteBuffer.wrap(buffer, offset, byteCount);
if (!channel.isBlocking()) {
throw new IllegalBlockingModeException();
}
channel.write(buf);
}
代码示例来源:origin: apache/nifi
@Override
public int read(final byte[] b, final int off, final int len) throws IOException {
if (bufferedByte != null) {
final byte retVal = bufferedByte;
bufferedByte = null;
b[off] = retVal;
return 1;
}
final ByteBuffer buffer = ByteBuffer.wrap(b, off, len);
final boolean blocking = channel.isBlocking();
try {
channel.configureBlocking(true);
final long maxTime = System.currentTimeMillis() + timeoutMillis;
int bytesRead;
do {
bytesRead = channel.read(buffer);
if (bytesRead == 0) {
if (System.currentTimeMillis() > maxTime) {
throw new SocketTimeoutException("Timed out reading from socket");
}
}
} while (bytesRead == 0);
return bytesRead;
} finally {
if (!blocking) {
channel.configureBlocking(false);
}
}
}
代码示例来源:origin: apache/nifi
final boolean blocking = channel.isBlocking();
代码示例来源:origin: h2oai/h2o-2
public SocketChannel getTCPSocket() throws IOException {
// Under lock, claim an existing open socket if possible
synchronized(this) {
// Limit myself to the number of open sockets from node-to-node
while( _socksAvail == 0 )
try { wait(); } catch( InterruptedException ie ) { }
// Claim an open socket
SocketChannel sock = _socks[--_socksAvail];
if( sock != null ) {
if( sock.isOpen() ) return sock; // Return existing socket!
// Else its an already-closed socket, lower open TCP count
assert TCPS.get() > 0;
TCPS.decrementAndGet();
}
}
// Must make a fresh socket
SocketChannel sock2 = SocketChannel.open();
sock2.socket().setReuseAddress(true);
sock2.socket().setSendBufferSize(AutoBuffer.BBSIZE);
boolean res = sock2.connect( _key );
assert res && !sock2.isConnectionPending() && sock2.isBlocking() && sock2.isConnected() && sock2.isOpen();
TCPS.incrementAndGet(); // Cluster-wide counting
return sock2;
}
public synchronized void freeTCPSocket( SocketChannel sock ) {
代码示例来源:origin: org.mongodb/mongo-java-driver
/**
* Initializes a new instance of this class.
*
* @param channelGroup group to associate new new channel to
* @param tlsChannel existing TLS channel to be used asynchronously
* @param socketChannel underlying socket
* @throws ClosedChannelException if any of the underlying channels are closed.
* @throws IllegalArgumentException is the socket is in blocking mode
*/
public AsynchronousTlsChannel(
final AsynchronousTlsChannelGroup channelGroup,
final TlsChannel tlsChannel,
final SocketChannel socketChannel) throws ClosedChannelException, IllegalArgumentException {
if (!socketChannel.isOpen()) {
throw new ClosedChannelException();
}
if (!tlsChannel.isOpen()) {
throw new ClosedChannelException();
}
if (socketChannel.isBlocking()) {
throw new IllegalArgumentException("socket channel must be in non-blocking mode");
}
this.group = channelGroup;
this.tlsChannel = tlsChannel;
this.registeredSocket = channelGroup.registerSocket(tlsChannel, socketChannel);
}
代码示例来源:origin: apache/geode
boolean blocking = socketChannel.isBlocking();
if (blocking) {
socketChannel.configureBlocking(false);
代码示例来源:origin: org.apache.hadoop/hadoop-common
SocketAddress endpoint, int timeout) throws IOException {
boolean blockingOn = channel.isBlocking();
if (blockingOn) {
channel.configureBlocking(false);
代码示例来源:origin: MobiVM/robovm
@Override
public void write(int oneByte) throws IOException {
if (!channel.isBlocking()) {
throw new IllegalBlockingModeException();
}
ByteBuffer buffer = ByteBuffer.allocate(1);
buffer.put(0, (byte) (oneByte & 0xFF));
channel.write(buffer);
}
}
代码示例来源:origin: ibinti/bugvm
@Override
public int read() throws IOException {
if (!channel.isBlocking()) {
throw new IllegalBlockingModeException();
}
ByteBuffer buf = ByteBuffer.allocate(1);
int result = channel.read(buf);
return (result == -1) ? result : (buf.get(0) & 0xff);
}
代码示例来源:origin: MobiVM/robovm
@Override
public int read() throws IOException {
if (!channel.isBlocking()) {
throw new IllegalBlockingModeException();
}
ByteBuffer buf = ByteBuffer.allocate(1);
int result = channel.read(buf);
return (result == -1) ? result : (buf.get(0) & 0xff);
}
代码示例来源:origin: ibinti/bugvm
@Override
public void write(byte[] buffer, int offset, int byteCount) throws IOException {
Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
ByteBuffer buf = ByteBuffer.wrap(buffer, offset, byteCount);
if (!channel.isBlocking()) {
throw new IllegalBlockingModeException();
}
channel.write(buf);
}
代码示例来源:origin: MobiVM/robovm
@Override
public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount);
if (!channel.isBlocking()) {
throw new IllegalBlockingModeException();
}
ByteBuffer buf = ByteBuffer.wrap(buffer, byteOffset, byteCount);
return channel.read(buf);
}
}
代码示例来源:origin: triplea-game/triplea
/**
* Add this channel.
* The channel will either be unquarantined, or an error will be reported
*/
public void add(final SocketChannel channel, final QuarantineConversation conversation) {
if (channel.isBlocking()) {
throw new IllegalArgumentException("Channel is blocking");
}
// add the decoder first, so it can quarantine the messages!
decoder.add(channel, conversation);
reader.add(channel);
}
内容来源于网络,如有侵权,请联系作者删除!