Example usage for java.nio.channels SelectableChannel isOpen

List of usage examples for java.nio.channels SelectableChannel isOpen

Introduction

In this page you can find the example usage for java.nio.channels SelectableChannel isOpen.

Prototype

public final boolean isOpen() 

Source Link

Usage

From source file:com.alibaba.napoli.gecko.core.nio.impl.Reactor.java

private void registerChannelNow(final SelectableChannel channel, final int ops, final Object attachment,
        final Selector selector) {
    this.gate.lock();
    try {//  ww  w .j a v  a 2 s .c  om
        if (channel.isOpen()) {
            channel.register(selector, ops, attachment);
        }
    } catch (final ClosedChannelException e) {
        log.error("Register channel error", e);
        this.controller.notifyException(e);
    } finally {
        this.gate.unlock();
    }
}

From source file:com.alibaba.napoli.gecko.core.nio.impl.Reactor.java

final void unregisterChannel(final SelectableChannel channel) {
    try {//from  w w  w.  ja  va 2  s .c  o m
        final Selector selector = this.selector;
        if (selector != null) {
            if (channel != null) {
                final SelectionKey key = channel.keyFor(selector);
                if (key != null) {
                    key.cancel();
                    this.cancelledKeys++;
                }
            }
        }
        if (channel != null && channel.isOpen()) {
            channel.close();
        }
    } catch (final Throwable t) {
        // ignore
    }
    this.wakeup();
}

From source file:net.ymate.platform.serv.nio.support.NioEventProcessor.java

protected void __doRegisterEvent() {
    Object[] _event;//from w w w.ja  v  a  2  s .c  om
    while ((_event = __eventQueues.poll()) != null) {
        try {
            SelectableChannel _channel = (SelectableChannel) _event[0];
            if (!_channel.isOpen()) {
                continue;
            }
            INioSession _session = (INioSession) _event[2];
            SelectionKey _key = _channel.register(__selector, (Integer) _event[1], _session);
            if (_session != null) {
                _session.selectionKey(_key);
                _session.status(ISession.Status.CONNECTED);
                //
                __eventGroup.listener().onSessionRegisted(_session);
            }
        } catch (Exception e) {
            _LOG.error(e.getMessage(), RuntimeUtils.unwrapThrow(e));
        }
    }
}