Example usage for java.nio.channels SocketChannel validOps

List of usage examples for java.nio.channels SocketChannel validOps

Introduction

In this page you can find the example usage for java.nio.channels SocketChannel validOps.

Prototype

public final int validOps() 

Source Link

Document

Returns an operation set identifying this channel's supported operations.

Usage

From source file:org.openhab.binding.irtrans.handler.EthernetBridgeHandler.java

protected void onAcceptable() {
    lock.lock();//  w  w w  . j  av a  2 s  . c  om
    try {
        try {
            selector.selectNow();
        } catch (IOException e) {
            logger.debug("An exception occurred while selecting: {}", e.getMessage());
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
        }

        Iterator<SelectionKey> it = selector.selectedKeys().iterator();
        while (it.hasNext()) {
            SelectionKey selKey = it.next();
            it.remove();
            if (selKey.isValid()) {
                if (selKey.isAcceptable() && selKey == listenerKey) {
                    try {
                        SocketChannel newChannel = listenerChannel.accept();
                        newChannel.configureBlocking(false);
                        logger.trace("Received a connection request from '{}'", newChannel.getRemoteAddress());

                        synchronized (selector) {
                            selector.wakeup();
                            newChannel.register(selector, newChannel.validOps());
                        }
                    } catch (IOException e) {
                        logger.debug("An exception occurred while accepting a connection on channel '{}': {}",
                                listenerChannel, e.getMessage());
                        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
                                e.getMessage());
                    }
                }
            }
        }
    } finally {
        lock.unlock();
    }
}