Package java.nio.channels

Examples of java.nio.channels.SelectableChannel


          log.fine("select loop");
         
          for (SelectionKey key : selector.keys()) {
            if (key.isValid()) {
             
              SelectableChannel ch = key.channel();
              int interst = key.interestOps();
              if (log.isLoggable(Level.FINE)) log.fine(Integer.toBinaryString(interst) + ":"  + ch);
             
            }
          }
View Full Code Here


   * @param remove
   * @param cancellations
   */
  private void process_clear_interest_request(Interest interest) {

    SelectableChannel ch = interest.ch;
    SelectionKey key = ch.keyFor(selector);
    NIOHandler handler = interest.handler;

    if (key == null || !key.isValid()) {
     
      // TODO: maybe this should be considered an error?
View Full Code Here

  /**
   * @param remove
   * @param active2
   */
  private void process_add_interest_request(Interest interest) {
    SelectableChannel ch = interest.ch;
    SelectionKey key = ch.keyFor(selector);
    NIOChannelInfo info = null;
   
    if (key != null && !key.isValid()) {
      try {
        selector.selectNow();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      key = null;
    }
    if (key == null || !key.isValid()) {
      try {
        key = ch.register(selector, interest.ops,
            info = new NIOChannelInfo(interest));
      } catch (ClosedChannelException e) {
        interest.handler.exception(ch, e);
      }
    } else {
View Full Code Here

   * @param ioRequest
   */
  public void clear_interest(Interest req) {
    NIOHandler handler = req.handler;
    boolean releaseNotify = req.releaseNotify;
    SelectableChannel ch = req.ch;

    Interest old = interest.get(handler);
    if (old == null) {
      if (releaseNotify && handler != null) {
        handler.released(ch);
View Full Code Here

   * there is something ready with this channel...
   *
   * @param key
   */
  public void ready(SelectionKey key) {
    final SelectableChannel ch = key.channel();
    int readyOps;
   
    try {
      readyOps = key.readyOps();
    } catch (CancelledKeyException e) {
View Full Code Here

  protected void stop(EObject reason) throws Pausable {
    super.stop(reason);
    tcp_close_check();
    InetSocket ff = fd;
    if (ff != null) {
      SelectableChannel ch = ff.channel();
      if (ch != null) {
      sock_close(ch);
      }
    }
  }
View Full Code Here

        interestOps = key.interestOps();
    } catch (CancelledKeyException e) {
        throw new ClosedAsynchronousChannelException();
    }

                SelectableChannel channel = asyncKey.channel();
               
                // These precondition checks don't belong here; they
                // should be refactored to AsyncSocketChannelImpl.
                // However, they need to occur inside the asyncKey
                // lock after we know the interest ops won't change,
View Full Code Here

        return new IoSessionIterator(selector.selectedKeys());
    }

    @Override
    protected void init(NioSession session) throws Exception {
        SelectableChannel ch = (SelectableChannel) session.getChannel();
        ch.configureBlocking(false);
        session.setSelectionKey(ch.register(selector, SelectionKey.OP_READ, session));
    }
View Full Code Here

            {
                if (_interestOps>0)
                {
                    if (_key==null || !_key.isValid())
                    {
                        SelectableChannel sc = (SelectableChannel)getChannel();
                        if (sc.isRegistered())
                        {
                            updateKey();  
                        }
                        else
                        {
View Full Code Here

            }
        }
    }

    private boolean isConnected(SelectionKeyImpl key) {
        SelectableChannel channel = key.channel();
        if (channel instanceof SocketChannel) {
            return ((SocketChannel) channel).isConnected();
        }
        return true;
    }
View Full Code Here

TOP

Related Classes of java.nio.channels.SelectableChannel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.