@Override public void shutdown() { latch.countDown(); this.acceptor.shutdown(); this.reactor.shutdown(); }
@Override public void startup() { this.acceptor.startup(); this.reactor.startup(); try { log.info("{} started successfully complete !", this); latch.await(); } catch (InterruptedException e) { throw new RuntimeException(e.getMessage(), e); } }
public ServerBootstrap(int reactors, int port) throws IOException { reactor = new Reactor(reactors, new DefaultSessionFactory()); acceptor = new Acceptor("goudai-rpc-accpector-trhead", new InetSocketAddress(port), this.reactor); this.port = port; }
@Override public void run() { while (started.get()) { this.doSelect(); if (this.selector.isOpen()) { Set<SelectionKey> selectionKeys = selector.selectedKeys(); try { selectionKeys.forEach(this::accept); } finally { selectionKeys.clear(); } } else { log.error("{} selector is closed ,selector = [{}]", this.getName(), this.selector); return; } } }
@Override public void shutdown() { log.info("accept {} shutdowning", this.getName()); try { this.selector.close(); this.serverSocketChannel.close(); } catch (IOException e) { throw new RuntimeException(e); } }
public Acceptor(String name, InetSocketAddress bindSocketAddress, Reactor reactor) throws IOException { super(name); this.setDaemon(true); this.selector = Selector.open(); this.reactor = reactor; this.serverSocketChannel = (ServerSocketChannel) ServerSocketChannel.open().bind(bindSocketAddress).configureBlocking(false); serverSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true); serverSocketChannel.setOption(StandardSocketOptions.SO_RCVBUF, 1024 * 16 * 2); this.serverSocketChannel.register(this.selector, SelectionKey.OP_ACCEPT); log.info("start server,bind socket address -->[{}],port -->[{}]", bindSocketAddress.getHostName(), bindSocketAddress.getPort()); }
public ClusterServerBootstrap(int reactors) throws IOException { reactor = new Reactor(reactors, new DefaultSessionFactory()); acceptor = new Acceptor("goudai-rpc-accpector-trhead", new InetSocketAddress(ClusterConfig.port), this.reactor); }
@Override public void startup() { this.acceptor.startup(); this.reactor.startup(); try { log.info("{} started successfully complete !", this); latch.await(); } catch (InterruptedException e) { throw new RuntimeException(e.getMessage(), e); } }
@Override public void shutdown() { latch.countDown(); this.acceptor.shutdown(); this.reactor.shutdown(); }