Package java.nio.channels

Examples of java.nio.channels.Selector.selectedKeys()


        assertEquals(0,key.readyOps());

        // try selecting and assert nothing selected
        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
View Full Code Here


        server.getOutputStream().flush();

        // select again and assert selection found for read
        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
View Full Code Here

        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());
        assertTrue(key.isValid());
        assertTrue(key.isReadable());
        assertEquals(1,key.readyOps());

        // read the byte
View Full Code Here

        assertEquals(1,key.readyOps());

        // Even if we select again ?
        selected = selector.select(100);
        assertEquals(0,selected);
        assertEquals(1,selector.selectedKeys().size());
        assertTrue(key.isValid());
        assertTrue(key.isReadable());
        assertEquals(1,key.readyOps());

        // Unless we remove the key from the select set
View Full Code Here

        assertTrue(key.isReadable());
        assertEquals(1,key.readyOps());

        // Unless we remove the key from the select set
        // and then it is still flagged as isReadable()
        selector.selectedKeys().clear();
        assertEquals(0,selector.selectedKeys().size());
        assertTrue(key.isValid());
        assertTrue(key.isReadable());
        assertEquals(1,key.readyOps());
View Full Code Here

        assertEquals(1,key.readyOps());

        // Unless we remove the key from the select set
        // and then it is still flagged as isReadable()
        selector.selectedKeys().clear();
        assertEquals(0,selector.selectedKeys().size());
        assertTrue(key.isValid());
        assertTrue(key.isReadable());
        assertEquals(1,key.readyOps());

        // Now if we select again - it is still flagged as readable!!!
View Full Code Here

        assertEquals(1,key.readyOps());

        // Now if we select again - it is still flagged as readable!!!
        selected = selector.select(100);
        assertEquals(0,selected);
        assertEquals(0,selector.selectedKeys().size());
        assertTrue(key.isValid());
        assertTrue(key.isReadable());
        assertEquals(1,key.readyOps());

        // Only when it is selected for something else does that state change.
View Full Code Here

        {
            Selector selector = _selector;
            return String.format("%s keys=%d selected=%d",
                    super.toString(),
                    selector != null && selector.isOpen() ? selector.keys().size() : -1,
                    selector != null && selector.isOpen() ? selector.selectedKeys().size() : -1);
        }

        private class DumpKeys implements Runnable
        {
            private final CountDownLatch latch = new CountDownLatch(1);
View Full Code Here

        // Only when it is selected for something else does that state change.
        key.interestOps(SelectionKey.OP_READ|SelectionKey.OP_WRITE);
        selected = selector.select(1000);
        assertEquals(1,selected);
        assertEquals(1,selector.selectedKeys().size());
        assertTrue(key.isValid());
        assertTrue(key.isWritable());
        assertFalse(key.isReadable());
        assertEquals(SelectionKey.OP_WRITE,key.readyOps());
    }
View Full Code Here

      log.info("readyCount={}", readyCount);

      final long timeDiff = timeFinish - timeStart;
      log.info("timeDiff={}", timeDiff);

      final Set<SelectionKey> selectedKeySet = selector.selectedKeys();
      logSet(selectedKeySet);

      for (final SelectionKey key : selectedKeySet) {
        if (key.isWritable()) {
          log.info("isWritable");
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.