Example usage for io.netty.channel.socket SocketChannel isOpen

List of usage examples for io.netty.channel.socket SocketChannel isOpen

Introduction

In this page you can find the example usage for io.netty.channel.socket SocketChannel isOpen.

Prototype

boolean isOpen();

Source Link

Document

Returns true if the Channel is open and may get active later

Usage

From source file:blazingcache.network.netty.NettyChannel.java

License:Apache License

@Override
public void sendOneWayMessage(Message message, SendResultCallback callback) {
    if (message.getMessageId() == null) {
        message.setMessageId(UUID.randomUUID().toString());
    }//from   w  w  w  .j  a v  a 2s  . c o  m
    SocketChannel _socket = this.socket;
    if (_socket == null || !_socket.isOpen()) {
        callback.messageSent(message, new Exception(this + " connection is closed"));
        return;
    }
    _socket.writeAndFlush(message).addListener(new GenericFutureListener() {

        @Override
        public void operationComplete(Future future) throws Exception {
            if (future.isSuccess()) {
                callback.messageSent(message, null);
            } else {
                LOGGER.log(Level.SEVERE, this + ": error " + future.cause(), future.cause());
                callback.messageSent(message, future.cause());
                close();
            }
        }

    });
}

From source file:blazingcache.network.netty.NettyChannel.java

License:Apache License

@Override
public boolean isValid() {
    SocketChannel _socket = socket;
    return _socket != null && _socket.isOpen() && !ioErrors;
}

From source file:com.datastax.driver.core.utils.SocketChannelMonitor.java

License:Apache License

/**
 * @param addresses The addresses to include.
 * @return Open channels matching the given socket addresses.
 *///from  ww w  .j a  va 2s.c  o  m
public Collection<SocketChannel> openChannels(final Collection<InetSocketAddress> addresses) {
    List<SocketChannel> channels = Lists.newArrayList(matchingChannels(new Predicate<SocketChannel>() {
        @Override
        public boolean apply(SocketChannel input) {
            return input.isOpen() && input.remoteAddress() != null && addresses.contains(input.remoteAddress());
        }
    }));
    Collections.sort(channels, BY_REMOTE_ADDRESS);
    return channels;
}