Package java.nio.channels

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


    SelectionKey tmpKey = null;
    try {
      if (this.selectableChannel.isOpen()) {
        tmpKey = this.selectableChannel.register(readSelector, 0);
        tmpKey.interestOps(tmpKey.interestOps() | SelectionKey.OP_READ);
        int code = readSelector.select(500);
        tmpKey.interestOps(tmpKey.interestOps() & ~SelectionKey.OP_READ);
        if (code > 0) {
          do {
            n = ((ReadableByteChannel) this.selectableChannel)
                .read(this.readBuffer.buf());
View Full Code Here


                start = System.currentTimeMillis();
            }
            sender.setMessage(buf);
            int selectedKeys = 0;
            try {
                selectedKeys = selector.select(0);
            } catch (Exception e) {
                e.printStackTrace();
                continue;
            }
View Full Code Here

                    ch.register(selector, SelectionKey.OP_CONNECT);
                    ch.connect(addr);
                }
            }

            int select = selector.select(1000 * 10); // 10s
            if (select > 0) {
                System.out.println("select return: " + select
                        + " events ; current connection per ip: " + currentConnectionPerIP);
                Set<SelectionKey> selectedKeys = selector.selectedKeys();
                Iterator<SelectionKey> it = selectedKeys.iterator();
View Full Code Here

        }

        start = System.currentTimeMillis();

        while (true) {
            int select = selector.select();
            D("selec return " + select);
            if (select > 0) {
                Set<SelectionKey> selectedKeys = selector.selectedKeys();
                Iterator<SelectionKey> it = selectedKeys.iterator();
                while (it.hasNext()) {
View Full Code Here

        // register the ServerSocketChannel with the Selector
        serverChannel.register (selector, SelectionKey.OP_ACCEPT);
        while (doListen) {
            // this may block for a long time, upon return the
            // selected set contains keys of the ready channels
            int n = selector.select();
            if (n == 0) {
                continue// nothing to do
            }
            // get an iterator over the set of selected keys
            Iterator it = selector.selectedKeys().iterator();
View Full Code Here

                try {
                    selector = SelectorFactory.openWithRetryFrom(recv.getRuntime(), SelectorProvider.provider());
                    nim.channel.configureBlocking(false);
                    SelectionKey key = nim.channel.register(selector, SelectionKey.OP_READ);
                    int n = selector.select(timeout);

                    if(n > 0) {
                        IRubyObject readItems = io.read(new IRubyObject[]{recv.getRuntime().newFixnum(1024*16)});
                        return buf.concat(readItems);
                    } else {
View Full Code Here

                        break;
                    }
                    if (_scheduler.numRunnables() > 0) {
                        n = sel.selectNow();
                    } else {
                        n = sel.select();
                    }
                } catch (IOException ignore) {
                    n = 0;
                    ignore.printStackTrace();
                }
View Full Code Here

                            }
                            key = getIOChannel().register(selector, hsStatus);
                        } else {
                            key.interestOps(hsStatus); // null warning supressed
                        }
                        int keyCount = selector.select(timeout);
                        if (keyCount == 0 && ((System.currentTimeMillis()-now) >= timeout)) {
                            throw new SocketTimeoutException(sm.getString("channel.nio.ssl.timeoutDuringHandshake"));
                        }
                        isReadable = key.isReadable();
                        isWriteable = key.isWritable();
View Full Code Here

            (selector, SelectionKey.OP_READ, null);

          int state = 0;
          ByteBuffer inBuffer = ByteBuffer.allocate(Message.length);
          loop: while (true) {
            selector.select();

            switch (state) {
            case 0: {
              if (outKey.isWritable()) {
                if (send) {
View Full Code Here

        // Write a byte from server to client
        server.getOutputStream().write(42);
        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());
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.