Package java.nio.channels

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


            Time startTime = clock.getCurrentTime();

            boolean connected = false;
            while (!connected) {
                long timeout = timeRemaining.inMillisTreatIndefinitelyAsZero();
                int keys = selector.select(timeout);
                if (keys == 0) {
                    // Selector woken up, check to see whether it has timed out.
                    Time now = clock.getCurrentTime();
                    Period elapsed = now.getPeriodSince(startTime);
                    if (Comparator.GE.compare(
View Full Code Here


                    selector = SelectorFactory.getSelector();

                    if (selector != null) {
                        selectionKey = this.selectableChannel.register(
                                selector, SelectionKey.OP_READ);
                        selector.select(IoUtils.TIMEOUT_MS);
                    }
                } finally {
                    NioUtils.release(selector, selectionKey);
                }
View Full Code Here

                selector = SelectorFactory.getSelector();

                while (selected == 0) {
                    selectionKey = selectableChannel.register(selector,
                            operations);
                    selected = selector.select(IoUtils.TIMEOUT_MS);
                }
            } finally {
                NioUtils.release(selector, selectionKey);
            }
        }
View Full Code Here

        while (true) {
            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 + "]");
            }
View Full Code Here

      // select until the next client is ready
      if (set.size() > 0) {
        client = set.first();
        long delay = Math.max(0, client.next_ - System.currentTimeMillis());
        if (delay > 0) {
          selector.select(delay);
        }
      } else {
        selector.select(10);
      }
    }
View Full Code Here

        long delay = Math.max(0, client.next_ - System.currentTimeMillis());
        if (delay > 0) {
          selector.select(delay);
        }
      } else {
        selector.select(10);
      }
    }

    outputResults();
  }
View Full Code Here

   
                // Do the select.
                if (wait > 10) // TODO tune or configure this
                {
                    long before=now;
                    int selected=selector.select(wait);
                    now = System.currentTimeMillis();
                    _idleTimeout.setNow(now);
                    _retryTimeout.setNow(now);

                    // Look for JVM bugs
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

      // Infinite server loop
      for (;;)
      {

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

        Iterator iter = keys.iterator();
View Full Code Here

                            }
                            key = getIOChannel().register(selector, hsStatus);
                        } else {
                            key.interestOps(hsStatus);
                        }
                        int keyCount = selector.select(timeout);
                        if (keyCount == 0 && ((System.currentTimeMillis()-now) >= timeout)) {
                            throw new SocketTimeoutException("Handshake operation timed out.");
                        }
                        isReadable = key.isReadable();
                        isWriteable = key.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.