Package java.nio.channels

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


                    }

                    processRegisterTaskQueue();

                    if (selectedKeyCount > 0) {
                        processSelectedKeys(selector.selectedKeys());
                    }

                    // Handle connection timeout every 0.5 seconds approximately.
                    long currentTimeNanos = System.nanoTime();
                    if (currentTimeNanos - lastConnectTimeoutCheckTimeNanos >= 500 * 1000000L) {
View Full Code Here


                }

                cancelledKeys = 0;
                processRegisterTaskQueue();
                processWriteTaskQueue();
                processSelectedKeys(selector.selectedKeys());

                // Exit the loop when there's nothing to handle.
                // The shutdown flag is used to delay the shutdown of this
                // loop to avoid excessive Selector creation when
                // connections are registered in a one-by-one manner instead of
View Full Code Here

                }

                cancelledKeys = 0;
                processRegisterTaskQueue();
                processWriteTaskQueue();
                processSelectedKeys(selector.selectedKeys());

                // Exit the loop when there's nothing to handle (the registered
                // key set is empty.
                // The shutdown flag is used to delay the shutdown of this
                // loop to avoid excessive Selector creation when
View Full Code Here

                        // Reduce the time remaining by the elapsed time and
                        timeRemaining = timeRemaining.subtract(elapsed);
                        startTime = now;
                    }
                } else if (keys == 1) {
                    Set selectedKeys = selector.selectedKeys();
                    if (selectedKeys.contains(key)) {
                        connected = true;
                    } else {
                        throw new IllegalStateException(
                                "Expected selected keys to contain " + key +
View Full Code Here

    private void addStatus (StringBuilder sb) {
  sb.append ("Status of selector at: ");
  sb.append (new Date ());
  sb.append ("<p>\n");
  Selector sel = con.getSelector ();
  appendKeys (sb, sel.selectedKeys (), "Selected key");
  appendKeys (sb, sel.keys (), "registered key");
    }

    private void appendKeys (StringBuilder sb,
           Set<SelectionKey> sks, String header) {
View Full Code Here

            if (selector.keys().isEmpty()) {
                throw new IOException("Connection failed for " + hostString +
                        ": " + exceptions);
            }
            selector.select()// you can add a timeout parameter in millseconds
            Set<SelectionKey> keys = selector.selectedKeys();
            if (keys.isEmpty()) {
                throw new IOException("Selection keys unexpectedly empty for " +
                        hostString + "[exceptions: " + exceptions + "]");
            }
            for (SelectionKey key : keys) {
View Full Code Here

          client.connected_.keyFor(selector).interestOps(SelectionKey.OP_WRITE);
        }
      }

      // handle selectable I/O
      for (Iterator<SelectionKey> i = selector.selectedKeys().iterator();
           i.hasNext();) {
        SelectionKey key = i.next();
        SocketChannel channel = (SocketChannel) key.channel();
        i.remove();
View Full Code Here

      {

        // Waiting for events
        selector.select();
        // Get keys
        Set keys = selector.selectedKeys();

        Iterator iter = keys.iterator();

        // For each keys...
        while (iter.hasNext())
View Full Code Here

                    int nKeys = selector.select();

                    registerNew();

                    if (nKeys > 0) {
                        processReadySessions(selector.selectedKeys());
                    }

                    flushSessions();
                    cancelKeys();
View Full Code Here

                    int nKeys = selector.select(1000);

                    registerNew();

                    if (nKeys > 0) {
                        processSessions(selector.selectedKeys());
                    }

                    processTimedOutSessions(selector.keys());

                    if (selector.keys().isEmpty()) {
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.