public NIOAcceptor(String name, int port, FrontendConnectionFactory factory) throws IOException { super.setName(name); this.port = port; this.selector = Selector.open(); this.serverChannel = ServerSocketChannel.open(); this.serverChannel.socket().bind(new InetSocketAddress(port)); this.serverChannel.configureBlocking(false); this.serverChannel.register(selector, SelectionKey.OP_ACCEPT); this.factory = factory; }
private static ServerSocketChannel newSocket() { try { ServerSocketChannel ch = ServerSocketChannel.open(); ch.configureBlocking(false); return ch; } catch (IOException e) { throw new NioException("Open a server socket error:" + e.getMessage(), e); } }
public ServerSocket createServerSocket(String type, InetSocketAddress inetSocketAddress) throws IOException { ServerSocketChannel serverSocketChannel = null; ServerSocket serverSocket = null; if (orb.getORBData().acceptorSocketType().equals(ORBConstants.SOCKETCHANNEL)) { serverSocketChannel = ServerSocketChannel.open(); serverSocket = serverSocketChannel.socket(); } else { serverSocket = new ServerSocket(); } serverSocket.bind(inetSocketAddress); return serverSocket; }
public void start(String ... options) throws Exception { options(options); if(server) { // simple single threaded server, can only handle a single connection at a time srv_channel=ServerSocketChannel.open(); srv_channel.bind(new InetSocketAddress(host, port), 50); System.out.println("server started (ctrl-c to kill)"); for(;;) { client_channel=srv_channel.accept(); // client_channel.socket().setTcpNoDelay(true); // we're concerned about latency receiver_thread=new Receiver(); receiver_thread.start(); } } else { client_channel=SocketChannel.open(); //client_channel.socket().setTcpNoDelay(true); client_channel.connect(new InetSocketAddress(host, port)); receiver_thread=new Receiver(); receiver_thread.start(); } }
protected void start(boolean direct) throws Exception { selector=Selector.open(); ch=ServerSocketChannel.open(); ch.bind(new InetSocketAddress("0.0.0.0", 7500)); ch.configureBlocking(false); ch.register(selector, SelectionKey.OP_ACCEPT, null); System.out.println("-- server ready");
conf.getInt("hbase.ipc.server.read.connection-queue.size", 100); acceptChannel = ServerSocketChannel.open(); acceptChannel.configureBlocking(false); bind(acceptChannel.socket(), bindAddress, backlogLength); port = acceptChannel.socket().getLocalPort(); //Could be an ephemeral port address = (InetSocketAddress)acceptChannel.socket().getLocalSocketAddress();
/** * Create a non-secure TcpPeerServer. * * @param socketWriteTimeout The Socket write timeout in ms. * @param bindAddr The address to bind to. * @param backlogLength The length of the tcp accept backlog * @throws IOException */ public TcpPeerServer(int socketWriteTimeout, InetSocketAddress bindAddr, int backlogLength) throws IOException { this.serverSocket = (socketWriteTimeout > 0) ? ServerSocketChannel.open().socket() : new ServerSocket(); Server.bind(serverSocket, bindAddr, backlogLength); }
/** * Starts listening to slave connections. * * @throws Exception If fails. */ public void beginAccept() throws Exception { this.serverSocketChannel = ServerSocketChannel.open(); this.selector = RemotingUtil.openSelector(); this.serverSocketChannel.socket().setReuseAddress(true); this.serverSocketChannel.socket().bind(this.socketAddressListen); this.serverSocketChannel.configureBlocking(false); this.serverSocketChannel.register(this.selector, SelectionKey.OP_ACCEPT); }
public NioSocketService(RequestHandlerFactory requestHandlerFactory, int port, int socketBufferSize, boolean socketKeepAlive, int selectors, String serviceName, boolean enableJmx, int acceptorBacklog, long selectorMaxHeartBeatTimeMs) { super(ServiceType.SOCKET, port, serviceName, enableJmx); this.requestHandlerFactory = requestHandlerFactory; this.socketBufferSize = socketBufferSize; this.socketKeepAlive=socketKeepAlive; this.acceptorBacklog = acceptorBacklog; this.selectorMaxHeartBeatTimeMs = selectorMaxHeartBeatTimeMs; try { this.serverSocketChannel = ServerSocketChannel.open(); } catch(IOException e) { throw new VoldemortException(e); } this.endpoint = new InetSocketAddress(port); this.selectorManagers = new NioSelectorManager[selectors]; String threadFactoryPrefix = "voldemort-" + serviceName; this.selectorManagerThreadPool = Executors.newFixedThreadPool(selectorManagers.length, new DaemonThreadFactory(threadFactoryPrefix)); this.statusManager = new StatusManager((ThreadPoolExecutor) this.selectorManagerThreadPool); this.acceptorThread = new Thread(new Acceptor(), threadFactoryPrefix + ".Acceptor"); }
@Override public void start() throws IOException { serverSocketChannel = ServerSocketChannel.open(); serverSocketChannel.configureBlocking(true); serverSocketChannel.bind(new InetSocketAddress(port));
NioServerSocketChannel( ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink, Boss boss, WorkerPool<NioWorker> workerPool) { super(factory, pipeline, sink); this.boss = boss; this.workerPool = workerPool; try { socket = ServerSocketChannel.open(); } catch (IOException e) { throw new ChannelException( "Failed to open a server socket.", e); } try { socket.configureBlocking(false); } catch (IOException e) { try { socket.close(); } catch (IOException e2) { if (logger.isWarnEnabled()) { logger.warn( "Failed to close a partially initialized socket.", e2); } } throw new ChannelException("Failed to enter non-blocking mode.", e); } config = new DefaultServerSocketChannelConfig(socket.socket()); fireChannelOpen(this); }
private static ServerSocketChannel newSocket() { try { ServerSocketChannel ch = ServerSocketChannel.open(); ch.configureBlocking(false); return ch; } catch (IOException e) { throw new NioException("Open a server socket error:" + e.getMessage(), e); } }
@Override public ServerSocket createServerSocket(int port) throws IOException { ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); serverSocketChannel.socket().bind(new InetSocketAddress(port)); return serverSocketChannel.socket(); }
@Test public void testInboundConnectionsCountInConnectionCreationMetric() throws Exception { int conns = 5; try (ServerSocketChannel ss = ServerSocketChannel.open()) { ss.bind(new InetSocketAddress(0)); InetSocketAddress serverAddress = (InetSocketAddress) ss.getLocalAddress(); for (int i = 0; i < conns; i++) { Thread sender = createSender(serverAddress, randomPayload(1)); sender.start(); SocketChannel channel = ss.accept(); channel.configureBlocking(false); selector.register(Integer.toString(i), channel); } } assertEquals((double) conns, getMetric("connection-creation-total").metricValue()); assertEquals((double) conns, getMetric("connection-count").metricValue()); }
/** * Adds a server socket channel for listening to connections. * * @param nicIPAddress - if null binds to wildcard address * @param port - port to bind to * @param receiveBufferSize - size of OS receive buffer to request. If less * than 0 then will not be set and OS default will win. * @throws IOException if unable to add socket */ public void addServerSocket(final InetAddress nicIPAddress, final int port, final int receiveBufferSize) throws IOException { final ServerSocketChannel ssChannel = ServerSocketChannel.open(); ssChannel.configureBlocking(false); if (receiveBufferSize > 0) { ssChannel.setOption(StandardSocketOptions.SO_RCVBUF, receiveBufferSize); final int actualReceiveBufSize = ssChannel.getOption(StandardSocketOptions.SO_RCVBUF); if (actualReceiveBufSize < receiveBufferSize) { LOGGER.warn(this + " attempted to set TCP Receive Buffer Size to " + receiveBufferSize + " bytes but could only set to " + actualReceiveBufSize + "bytes. You may want to consider changing the Operating System's " + "maximum receive buffer"); } } ssChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true); ssChannel.bind(new InetSocketAddress(nicIPAddress, port)); ssChannel.register(serverSocketSelector, SelectionKey.OP_ACCEPT); }
try { boolean ok = false; final ServerSocketChannel serverChannel = ServerSocketChannel.open(); try { serverChannel.configureBlocking(false); if (optionMap.contains(Options.RECEIVE_BUFFER)) { serverChannel.socket().setReceiveBufferSize(optionMap.get(Options.RECEIVE_BUFFER, -1)); serverChannel.socket().setReuseAddress(optionMap.get(Options.REUSE_ADDRESSES, true)); serverChannel.bind(destination); if (bindListener != null) ChannelListeners.invokeChannelListener(new BoundChannel() {
private Tunnel open() throws IOException { try { this.server = ServerSocketChannel.open().bind(null); this.server.configureBlocking(false); Selector selector = Selector.open(); startTunnelThread(selector); return this; } catch (IOException ioe) { LOG.error("Failed to open the tunnel", ioe); throw ioe; } }
@Override public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException { ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); serverSocketChannel.socket().bind(new InetSocketAddress(ifAddress, port), backlog); return serverSocketChannel.socket(); } };