Example usage for java.nio.channels.spi AbstractSelectableChannel register

List of usage examples for java.nio.channels.spi AbstractSelectableChannel register

Introduction

In this page you can find the example usage for java.nio.channels.spi AbstractSelectableChannel register.

Prototype

public final SelectionKey register(Selector sel, int ops, Object att) throws ClosedChannelException 

Source Link

Document

Registers this channel with the given selector, returning a selection key.

Usage

From source file:net.timewalker.ffmq4.transport.tcp.nio.NIOTcpMultiplexer.java

protected void addInterest(AbstractSelectableChannel channel, int interest, Object attachment,
        Selector selector) {/*from w w w. j  av  a 2  s .  co  m*/
    try {
        SelectionKey sk = channel.keyFor(selector);
        if (sk != null) {
            if (!sk.isValid())
                return;

            int actualInterests = sk.interestOps();
            if ((actualInterests & interest) != interest)
                sk.interestOps(actualInterests | interest);
            if (attachment != null)
                sk.attach(attachment);
        } else
            channel.register(selector, interest, attachment);
    } catch (ClosedChannelException e) {
        log.warn("Cannot add interest to selector channel : channel is closed");
    }
}