Package java.nio.channels

Examples of java.nio.channels.SelectionKey.readyOps()


        for (Iterator<SelectionKey> iter = keys.iterator(); iter.hasNext();) {
          SelectionKey selectionKey = iter.next();
          iter.remove();
          Connection fromConnection = (Connection)selectionKey.attachment();
          try {
            int ops = selectionKey.readyOps();

            if (fromConnection != null) { // Must be a TCP read or write operation.
              if (udp != null && fromConnection.udpRemoteAddress == null) {
                fromConnection.close();
                continue;
View Full Code Here


        if (key.isValid() && key.isAcceptable()) {
          controller.onAccept(key);
          continue;
        }
        if (key.isValid()
            && (key.readyOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) {
          // Remove write interest
          key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE);
          controller.onWrite(key);
          if (!controller.isHandleReadWriteConcurrently()) {
            skipOpRead = true;
View Full Code Here

            skipOpRead = true;
          }
        }
        if (!skipOpRead
            && key.isValid()
            && (key.readyOps() & SelectionKey.OP_READ) == SelectionKey.OP_READ) {
          key.interestOps(key.interestOps() & ~SelectionKey.OP_READ);
          if (!controller.getStatistics().isReceiveOverFlow()) {
            // Remove read interest
            controller.onRead(key);
          } else {
View Full Code Here

            key.interestOps(key.interestOps()
                | SelectionKey.OP_READ);
          }

        }
        if ((key.readyOps() & SelectionKey.OP_CONNECT) == SelectionKey.OP_CONNECT) {
          controller.onConnect(key);
        }

      } catch (CancelledKeyException e) {
        // ignore
View Full Code Here

            Iterator<SelectionKey> it = selector.selectedKeys().iterator();
            while (it.hasNext()) {
                SelectionKey sk = it.next();
                it.remove();
                try {
                    int readyOps = sk.readyOps();
                    sk.interestOps(sk.interestOps() & ~readyOps);
                    if (sender.process(sk, false)) {
                        total = total.add(bytes);
                        sender.reset();
                        seq++;
View Full Code Here

       
        Iterator it = selector.selectedKeys().iterator();
        while (it.hasNext()) {
            SelectionKey sk = (SelectionKey) it.next();
            it.remove();
            int readyOps = sk.readyOps();
            sk.interestOps(sk.interestOps() & ~readyOps);
            NioSender sender = (NioSender) sk.attachment();
            try {
                if (sender.process(sk,waitForAck)) {
                    completed++;
View Full Code Here

            synchronized (asyncKey) {
                if (!key.isValid()) {
                    continue;
                }
                try {
                    readyOps = key.readyOps();
                    key.interestOps(key.interestOps() & (~readyOps));
                } catch (CancelledKeyException e) {
                    // swallow exception
                    continue;
                }
View Full Code Here

        SelectionKey key = client.register(selector,SelectionKey.OP_READ);

        // assert it is not selected
        assertTrue(key.isValid());
        assertFalse(key.isReadable());
        assertEquals(0,key.readyOps());

        // try selecting and assert nothing selected
        int selected = selector.selectNow();
        assertEquals(0,selected);
        assertEquals(0,selector.selectedKeys().size());
View Full Code Here

        int selected = selector.selectNow();
        assertEquals(0,selected);
        assertEquals(0,selector.selectedKeys().size());
        assertTrue(key.isValid());
        assertFalse(key.isReadable());
        assertEquals(0,key.readyOps());

        // Write a byte from server to client
        server.getOutputStream().write(42);
        server.getOutputStream().flush();
View Full Code Here

        selected = selector.select(1000);
        assertEquals(1,selected);
        assertEquals(1,selector.selectedKeys().size());
        assertTrue(key.isValid());
        assertTrue(key.isReadable());
        assertEquals(1,key.readyOps());

        // select again and see that it is not reselect, but stays selected
        selected = selector.select(100);
        assertEquals(0,selected);
        assertEquals(1,selector.selectedKeys().size());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.