Package java.nio.channels

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


    private class Worker implements Runnable {
        public void run() {
            Selector selector = DatagramConnectorDelegate.this.selector;
            for (;;) {
                try {
                    int nKeys = selector.select();

                    registerNew();
                    doUpdateTrafficMask();

                    if (nKeys > 0) {
View Full Code Here


            // this may block for a long time, upon return the
            // selected set contains keys of the ready channels
            try {
                events();
                socketTimeouts();
                int n = selector.select(getSelectorTimeout());
                if (n == 0) {
                    //there is a good chance that we got here
                    //because the TcpReplicationThread called
                    //selector wakeup().
                    //if that happens, we must ensure that that
View Full Code Here

                            selector = Selector.open();
                            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

                            }
                            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("Handshake operation timed out.");
                        }
                        isReadable = key.isReadable();
                        isWriteable = key.isWritable();
View Full Code Here

                    return 0;
                }
                count=1;
                tmpKey=socketChannel.register(readSelector,SelectionKey.OP_READ);
                tmpKey.interestOps(tmpKey.interestOps()|SelectionKey.OP_READ);
                int code=readSelector.select(readTimeout);
                tmpKey.interestOps(tmpKey.interestOps()&(~SelectionKey.OP_READ));
                while (count>0)
                {
                    count=socketChannel.read(dst);
                    if (count>0)
View Full Code Here

                        key = socketChannel.register(writeSelector,
                             SelectionKey.OP_WRITE);
                    }

                    long startTime = System.currentTimeMillis();
                    if (writeSelector.select(writeTimeout) == 0) {
                        elapsedTime += (System.currentTimeMillis() - startTime);
                        if (attempts > 2 && ( writeTimeout > 0 && elapsedTime >= writeTimeout ) )
                            throw new IOException("Client is busy or timed out");
                    }
                }
View Full Code Here

                    key = socketChannel.register(writeSelector,
                                                 SelectionKey.OP_WRITE);

                    long startTime = System.currentTimeMillis();
                    if (writeSelector.select(writeTimeout) == 0) {
                        elapsedTime += (System.currentTimeMillis() - startTime);
                        if (attempts > 2 && ( writeTimeout > 0 && elapsedTime >= writeTimeout ) )
                            throw new IOException("Client is busy or timed out");
                    }
                }
View Full Code Here

                           .register(readSelector,SelectionKey.OP_READ);              
                tmpKey.interestOps(tmpKey.interestOps() | SelectionKey.OP_READ);
               
                int code = 0;
                if (timeout > 0) {
                    code = readSelector.select(timeout);
                } else {
                    code = readSelector.selectNow();
                }
                tmpKey.interestOps(
                    tmpKey.interestOps() & (~SelectionKey.OP_READ));
View Full Code Here

            return;
          }
          tmpKey = selectableChannel.register(writeSelector,
              SelectionKey.OP_WRITE);
        }
        if (writeSelector.select(1000) == 0) {
          attempts++;
          if (attempts > 2) {
            return;
          }
        } else {
View Full Code Here

              continue;
            }
            tmpKey = channel.register(writeSelector,
                SelectionKey.OP_WRITE);
          }
          if (writeSelector.select(1000) == 0) {
            if (attempts > 2) {
              throw new IOException("Client disconnected");
            }
          }
        }
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.