/** * Lifecycle operation. Called after create(). When this method is called, the managed attributes * have already been set.<br> * Brings the Router into a fully functional state. */ @ManagedOperation(description="Lifecycle operation. Called after create(). When this method is called, " + "the managed attributes have already been set. Brings the Router into a fully functional state.") public void start() throws Exception { if(!running.compareAndSet(false, true)) return; if(jmx) JmxConfigurator.register(this, Util.getMBeanServer(), "jgroups:name=GossipRouter"); InetAddress tmp=bind_addr != null? InetAddress.getByName(bind_addr) : null; server=use_nio? new NioServer(thread_factory, socket_factory, tmp, port, port, null, 0) : new TcpServer(thread_factory, socket_factory, tmp, port, port, null, 0); server.receiver(this); server.start(); server.addConnectionListener(this); Runtime.getRuntime().addShutdownHook(new Thread(GossipRouter.this::stop)); }
protected void start(InetAddress bind_addr, int port, boolean nio) throws Exception { server=nio? new NioServer(bind_addr, port) : new TcpServer(bind_addr, port); server.receiver(this); server.start(); JmxConfigurator.register(server, Util.getMBeanServer(), "pub:name=pub-server"); int local_port=server.localAddress() instanceof IpAddress? ((IpAddress)server.localAddress()).getPort(): 0; System.out.printf("\nPubServer listening at %s:%s\n", bind_addr != null? bind_addr : "0.0.0.0", local_port); }
public void start(String ... options) throws Exception { options(options); if(server) { srv=nio? new NioServer(host, port) : new TcpServer(host, port); srv.connExpireTimeout(0); srv.tcpNodelay(false); srv.receiver(this); srv.start(); System.out.printf("server started on %s (ctrl-c to terminate)\n", srv.localAddress()); } else { srv=nio? new NioClient(null, 0, host, port) : new TcpClient(null, 0, host, port); srv.tcpNodelay(false); srv.receiver(this); srv.start(); } }
public void start() throws Exception { server=new TcpServer(getThreadFactory(), getSocketFactory(), bind_addr, bind_port, bind_port+port_range, external_addr, external_port); server.receiver(this) .timeService(time_service) .receiveBufferSize(recv_buf_size) .sendBufferSize(send_buf_size) .socketConnectionTimeout(sock_conn_timeout) .tcpNodelay(tcp_nodelay).linger(linger) .clientBindAddress(client_bind_addr).clientBindPort(client_bind_port).deferClientBinding(defer_client_bind_addr) .log(this.log); server.setBufferedInputStreamSize(buffered_input_stream_size).setBufferedOutputStreamSize(buffered_output_stream_size) .peerAddressReadTimeout(peer_addr_read_timeout) .usePeerConnections(true) .socketFactory(getSocketFactory()); if(reaper_interval > 0 || conn_expire_time > 0) { if(reaper_interval == 0) { reaper_interval=5000; log.warn("reaper_interval was 0, set it to %d", reaper_interval); } if(conn_expire_time == 0) { conn_expire_time=(long) 1000 * 60 * 5; log.warn("conn_expire_time was 0, set it to %d", conn_expire_time); } server.connExpireTimeout(conn_expire_time).reaperInterval(reaper_interval); } // we first start threads in TP (http://jira.jboss.com/jira/browse/JGRP-626) super.start(); }
public static class TcpServerStarter implements Runnable { public void run(){ new TcpServer(8500).run(); } }
public static class TcpServerStarter extends Thread { @Override public void run() { new TcpServer(8500).run(); } } public static class UdpServerStarter extends Thread { @Override public void run() { new UdpServer(1000).run(); } }
new Thread(new UdpServer(9094)).start(); new Thread(new TcpServer(9093)).start();
ServerSocket ss = new ServerSocket(20000); Socket s = new Socket("127.0.0.1", 20000); new Thread(new TcpServer(ss)).start(); new Thread(new TcpClient(s)).start();
public class ServerStarter { public static void main(String[] args) { System.out.print("Reach 1"); Thread tcp = new Thread(new TcpServerStarter()); tcp.start(); System.out.print("Reach 2"); Thread udp = new Thread(new UdpServerStarter()); System.out.print("Reach 3"); //HibernateUtil.buildSessionFactory(); System.out.print("Reach 4"); } public static class TcpServerStarter extends Thread{ public TcpServerStarter(){ new TcpServer(8500).run(); } } public static class UdpServerStarter extends Thread{ public UdpServerStarter(){ new UdpServer(1000).run(); } }
/** * Lifecycle operation. Called after create(). When this method is called, the managed attributes * have already been set.<br> * Brings the Router into a fully functional state. */ @ManagedOperation(description="Lifecycle operation. Called after create(). When this method is called, " + "the managed attributes have already been set. Brings the Router into a fully functional state.") public void start() throws Exception { if(!running.compareAndSet(false, true)) return; if(jmx) JmxConfigurator.register(this, Util.getMBeanServer(), "jgroups:name=GossipRouter"); InetAddress tmp=bind_addr != null? InetAddress.getByName(bind_addr) : null; server=use_nio? new NioServer(thread_factory, socket_factory, tmp, port, port, null, 0) : new TcpServer(thread_factory, socket_factory, tmp, port, port, null, 0); server.receiver(this); server.start(); server.addConnectionListener(this); Runtime.getRuntime().addShutdownHook(new Thread(GossipRouter.this::stop)); }
protected void start(InetAddress bind_addr, int port, boolean nio) throws Exception { server=nio? new NioServer(bind_addr, port) : new TcpServer(bind_addr, port); server.receiver(this); server.start(); JmxConfigurator.register(server, Util.getMBeanServer(), "pub:name=pub-server"); int local_port=server.localAddress() instanceof IpAddress? ((IpAddress)server.localAddress()).getPort(): 0; System.out.printf("\nPubServer listening at %s:%s\n", bind_addr != null? bind_addr : "0.0.0.0", local_port); }
public void start(String ... options) throws Exception { options(options); if(server) { srv=nio? new NioServer(host, port) : new TcpServer(host, port); srv.connExpireTimeout(0); srv.tcpNodelay(false); srv.receiver(this); srv.start(); System.out.printf("server started on %s (ctrl-c to terminate)\n", srv.localAddress()); } else { srv=nio? new NioClient(null, 0, host, port) : new TcpClient(null, 0, host, port); srv.tcpNodelay(false); srv.receiver(this); srv.start(); } }
public void start() throws Exception { server=new TcpServer(getThreadFactory(), getSocketFactory(), bind_addr, bind_port, bind_port+port_range, external_addr, external_port); server.receiver(this) .timeService(time_service) .receiveBufferSize(recv_buf_size) .sendBufferSize(send_buf_size) .socketConnectionTimeout(sock_conn_timeout) .tcpNodelay(tcp_nodelay).linger(linger) .clientBindAddress(client_bind_addr).clientBindPort(client_bind_port).deferClientBinding(defer_client_bind_addr) .log(this.log); server.setBufferedInputStreamSize(buffered_input_stream_size).setBufferedOutputStreamSize(buffered_output_stream_size) .peerAddressReadTimeout(peer_addr_read_timeout) .usePeerConnections(true) .socketFactory(getSocketFactory()); if(reaper_interval > 0 || conn_expire_time > 0) { if(reaper_interval == 0) { reaper_interval=5000; log.warn("reaper_interval was 0, set it to %d", reaper_interval); } if(conn_expire_time == 0) { conn_expire_time=(long) 1000 * 60 * 5; log.warn("conn_expire_time was 0, set it to %d", conn_expire_time); } server.connExpireTimeout(conn_expire_time).reaperInterval(reaper_interval); } // we first start threads in TP (http://jira.jboss.com/jira/browse/JGRP-626) super.start(); }