Package java.nio.channels

Examples of java.nio.channels.SocketChannel.socket()


                    Collections.shuffle(selectedList);
                    for (SelectionKey k : selectedList) {
                        if ((k.readyOps() & SelectionKey.OP_ACCEPT) != 0) {
                            SocketChannel sc = ((ServerSocketChannel) k
                                    .channel()).accept();    
                            InetAddress ia = sc.socket().getInetAddress();
                            int cnxncount = getClientCnxnCount(ia);
                            if (maxClientCnxns > 0 && cnxncount >= maxClientCnxns){                                 
                                LOG.warn("Too many connections from " + ia
                                         + " - max is " + maxClientCnxns );
                                sc.close();                
View Full Code Here


        if ((senderWorkerMap.get(sid) == null)) {
            SocketChannel channel;
            try {
                channel = SocketChannel
                        .open(self.quorumPeers.get(sid).electionAddr);
                channel.socket().setTcpNoDelay(true);
                initiateConnection(channel, sid);
            } catch (IOException e) {
                LOG.warn("Cannot open channel to " + sid, e);
            }
        }
View Full Code Here

                ss.socket().setReuseAddress(true);
                ss.socket().bind(new InetSocketAddress(port));

                while (!shutdown) {
                    SocketChannel client = ss.accept();
                    Socket sock = client.socket();
                    sock.setTcpNoDelay(true);
                   
                    LOG.info("Connection request "
                            + sock.getRemoteSocketAddress());
                    //synchronized(senderWorkerMap){
View Full Code Here

                nextAddrToTry = 0;
            }
            SocketChannel sock;
            sock = SocketChannel.open();
            sock.configureBlocking(false);
            sock.socket().setSoLinger(false, -1);
            sock.socket().setTcpNoDelay(true);
            LOG.info("Attempting connection to server " + addr);
            sockKey = sock.register(selector, SelectionKey.OP_CONNECT);
            if (sock.connect(addr)) {
                primeConnection(sockKey);
View Full Code Here

            }
            SocketChannel sock;
            sock = SocketChannel.open();
            sock.configureBlocking(false);
            sock.socket().setSoLinger(false, -1);
            sock.socket().setTcpNoDelay(true);
            LOG.info("Attempting connection to server " + addr);
            sockKey = sock.register(selector, SelectionKey.OP_CONNECT);
            if (sock.connect(addr)) {
                primeConnection(sockKey);
            }
View Full Code Here

        private void cleanup() {
            if (sockKey != null) {
                SocketChannel sock = (SocketChannel) sockKey.channel();
                sockKey.cancel();
                try {
                    sock.socket().shutdownInput();
                } catch (IOException e) {
                    LOG.warn("Ignoring exception during shutdown input", e);
                }
                try {
                    sock.socket().shutdownOutput();
View Full Code Here

                    sock.socket().shutdownInput();
                } catch (IOException e) {
                    LOG.warn("Ignoring exception during shutdown input", e);
                }
                try {
                    sock.socket().shutdownOutput();
                } catch (IOException e) {
                    LOG.warn("Ignoring exception during shutdown output", e);
                }
                try {
                    sock.socket().close();
View Full Code Here

                    sock.socket().shutdownOutput();
                } catch (IOException e) {
                    LOG.warn("Ignoring exception during shutdown output", e);
                }
                try {
                    sock.socket().close();
                } catch (IOException e) {
                    LOG.warn("Ignoring exception during socket close", e);
                }
                try {
                    sock.close();
View Full Code Here

            s = new Socket(proxy);
            s.connect(addr);
        } else {
            log.error(addr);
            SocketChannel sc = SocketChannel.open(addr);
            s = sc.socket();
        }
        s.setTcpNoDelay(true);
        return s;
    }
View Full Code Here

      for (int i=0; i<10; i++) {
        SocketChannel channel = server.accept();
        if (channel==null) return;

        channel.configureBlocking(false);
        channel.socket().setTcpNoDelay(tcpNoDelay);
        SelectionKey readKey = channel.register(selector, SelectionKey.OP_READ);
        c = new Connection(readKey, channel, System.currentTimeMillis());
        readKey.attach(c);
        synchronized (connectionList) {
          connectionList.add(numConnections, c);
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.