本文整理了Java中java.nio.channels.SocketChannel.close()
方法的一些代码示例,展示了SocketChannel.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SocketChannel.close()
方法的具体详情如下:
包路径:java.nio.channels.SocketChannel
类名称:SocketChannel
方法名:close
暂无
代码示例来源:origin: apache/nifi
/**
* Closes the underlying socket channel.
*
* @throws java.io.IOException for issues closing underlying stream
*/
@Override
public void close() throws IOException {
channel.close();
}
}
代码示例来源:origin: apache/kafka
@Override
public void close() throws IOException {
socketChannel.socket().close();
socketChannel.close();
}
代码示例来源:origin: square/okhttp
@Override public void close() throws IOException {
getChannel().close();
}
}
代码示例来源:origin: square/okhttp
@Override public void close() throws IOException {
getChannel().close();
}
}
代码示例来源:origin: apache/kafka
private KafkaChannel buildAndAttachKafkaChannel(SocketChannel socketChannel, String id, SelectionKey key) throws IOException {
try {
KafkaChannel channel = channelBuilder.buildChannel(id, key, maxReceiveSize, memoryPool);
key.attach(channel);
return channel;
} catch (Exception e) {
try {
socketChannel.close();
} finally {
key.cancel();
}
throw new IOException("Channel could not be created for socket " + socketChannel, e);
}
}
代码示例来源:origin: apache/rocketmq
public void close() {
if (this.socketChannel != null) {
try {
this.socketChannel.close();
} catch (IOException e) {
HAConnection.log.error("", e);
}
}
}
代码示例来源:origin: rapidoid/rapidoid
private void clearKey(SelectionKey key) throws IOException {
if (key.isValid()) {
SocketChannel socketChannel = (SocketChannel) key.channel();
socketChannel.close();
key.attach(null);
key.cancel();
}
}
代码示例来源:origin: rapidoid/rapidoid
private void clearKey(SelectionKey key) throws IOException {
if (key.isValid()) {
SocketChannel socketChannel = (SocketChannel) key.channel();
socketChannel.close();
key.attach(null);
key.cancel();
}
}
代码示例来源:origin: apache/kafka
public void closeSocketChannels() throws IOException {
for (SocketChannel channel : socketChannels) {
channel.close();
}
socketChannels.clear();
}
代码示例来源:origin: netty/netty
@Override
protected void doClose() throws Exception {
super.doClose();
javaChannel().close();
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
protected void cancel( SelectionKey key, SocketChannel c ) throws IOException
{
NioEndpoint p = (NioEndpoint)key.attachment();
log.log( Level.FINE, "Closing channel endpoint:{0}.", p );
Object o = endpointKeys.remove(p);
log.log( Level.FINE, "Endpoint keys size:{0}", endpointKeys.size() );
key.cancel();
c.close();
removeEndpoint( p, c );
}
代码示例来源:origin: redisson/redisson
@Override
protected void doClose() throws Exception {
super.doClose();
javaChannel().close();
}
代码示例来源: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: TooTallNate/Java-WebSocket
public void close() throws IOException {
sslEngine.closeOutbound();
sslEngine.getSession().invalidate();
if( socketChannel.isOpen() )
socketChannel.write( wrap( emptybuffer ) );// FIXME what if not all bytes can be written
socketChannel.close();
}
代码示例来源:origin: apache/zookeeper
@Override
void connect(InetSocketAddress addr) throws IOException {
SocketChannel sock = createSock();
try {
registerAndConnect(sock, addr);
} catch (IOException e) {
LOG.error("Unable to open socket to " + addr);
sock.close();
throw e;
}
initialized = false;
/*
* Reset incomingBuffer
*/
lenBuffer.clear();
incomingBuffer = lenBuffer;
}
代码示例来源:origin: wildfly/wildfly
@Override
protected void doClose() throws Exception {
super.doClose();
javaChannel().close();
}
代码示例来源:origin: TooTallNate/Java-WebSocket
/**
* This method should be called when this peer wants to explicitly close the connection
* or when a close message has arrived from the other peer, in order to provide an orderly shutdown.
* <p/>
* It first calls {@link SSLEngine#closeOutbound()} which prepares this peer to send its own close message and
* sets {@link SSLEngine} to the <code>NEED_WRAP</code> state. Then, it delegates the exchange of close messages
* to the handshake method and finally, it closes socket channel.
*
* @throws IOException if an I/O error occurs to the socket channel.
*/
private void closeConnection() throws IOException {
engine.closeOutbound();
try {
doHandshake();
} catch ( IOException e ) {
//Just ignore this exception since we are closing the connection already
}
socketChannel.close();
}
代码示例来源:origin: netty/netty
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
SocketChannel ch = SocketUtils.accept(javaChannel());
try {
if (ch != null) {
buf.add(new NioSocketChannel(this, ch));
return 1;
}
} catch (Throwable t) {
logger.warn("Failed to create a new channel from an accepted socket.", t);
try {
ch.close();
} catch (Throwable t2) {
logger.warn("Failed to close a socket.", t2);
}
}
return 0;
}
代码示例来源:origin: wildfly/wildfly
protected void closeAction() throws IOException {
try {
conduit.cancelKey(false);
conduit.getSocketChannel().close();
} catch (ClosedChannelException ignored) {
} finally {
final ChannelClosed closedHandle = this.closedHandle;
if (closedHandle!= null) closedHandle.channelClosed();
}
}
代码示例来源:origin: redisson/redisson
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
SocketChannel ch = SocketUtils.accept(javaChannel());
try {
if (ch != null) {
buf.add(new NioSocketChannel(this, ch));
return 1;
}
} catch (Throwable t) {
logger.warn("Failed to create a new channel from an accepted socket.", t);
try {
ch.close();
} catch (Throwable t2) {
logger.warn("Failed to close a socket.", t2);
}
}
return 0;
}
内容来源于网络,如有侵权,请联系作者删除!