Package java.nio.channels

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


        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
        ByteBuffer buf = ByteBuffer.allocate(1024);
        int len=client.read(buf);
        assertEquals(1,len);
View Full Code Here


        buf.clear();

        // But this does not change the key
        assertTrue(key.isValid());
        assertTrue(key.isReadable());
        assertEquals(1,key.readyOps());

        // Even if we select again ?
        selected = selector.select(100);
        assertEquals(0,selected);
        assertEquals(1,selector.selectedKeys().size());
View Full Code Here

        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
        // and then it is still flagged as isReadable()
        selector.selectedKeys().clear();
        assertEquals(0,selector.selectedKeys().size());
View Full Code Here

        // 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!!!
        selected = selector.select(100);
        assertEquals(0,selected);
        assertEquals(0,selector.selectedKeys().size());
View Full Code Here

        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.
        key.interestOps(SelectionKey.OP_READ|SelectionKey.OP_WRITE);
        selected = selector.select(1000);
        assertEquals(1,selected);
View Full Code Here

        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

        }
        for (Iterator<SelectionKey> i = selectedKeys.iterator(); i.hasNext();) {
            SelectionKey k = i.next();
            i.remove();
            try {
                int readyOps = k.readyOps();
                if ((readyOps & SelectionKey.OP_READ) != 0 || readyOps == 0) {
                    if (!read(k)) {
                        // Connection already closed - no need to handle write.
                        continue;
                    }
View Full Code Here

      SelectionKey selectionKey = (SelectionKey) iter.next();
      Key key = (Key) selectionKey.attachment();

      int readyMask = 0;
      try {
          readyMask = selectionKey.readyOps();
          assert readyMask != 0;
          assert (key.interestMask & readyMask) == readyMask;

          /*
           * Remove interest in I/O events detected to be
View Full Code Here

                        SelectionKey sk = iterator.next();
                        KeyAttachment attachment = (KeyAttachment)sk.attachment();
                        try {
                            attachment.access();
                            iterator.remove();
                            sk.interestOps(sk.interestOps() & (~sk.readyOps()));
                            if ( sk.isReadable() ) {
                                countDown(attachment.getReadLatch());
                            }
                            if (sk.isWritable()) {
                                countDown(attachment.getWriteLatch());
View Full Code Here

        }
        for (Iterator<SelectionKey> i = selectedKeys.iterator(); i.hasNext();) {
            SelectionKey k = i.next();
            i.remove();
            try {
                int readyOps = k.readyOps();
                if ((readyOps & SelectionKey.OP_READ) != 0 || readyOps == 0) {
                    if (!read(k)) {
                        // Connection already closed - no need to handle write.
                        continue;
                    }
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.