protected void start(InetAddress srv_addr, int srv_port, boolean nio) throws Exception { client=nio? new NioClient(InetAddress.getLocalHost(), 0, srv_addr, srv_port) : new TcpClient(InetAddress.getLocalHost(), 0, srv_addr, srv_port); client.receiver(this); client.addConnectionListener(this); client.start(); send(String.format("%s joined", name)); eventLoop(); client.stop(); }
/** * 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)); }
public RouterStub(IpAddress local, IpAddress remote, boolean use_nio, CloseListener l) { this.local=local; this.remote=remote; this.use_nio=use_nio; this.close_listener=l; client=use_nio? new NioClient(local, remote) : new TcpClient(local, remote); client.receiver(this); client.addConnectionListener(this); client.socketConnectionTimeout(sock_conn_timeout).tcpNodelay(tcp_nodelay); }
/** * Creates a stub to a remote GossipRouter * @param bind_addr The local address to bind to. If null, one will be picked * @param bind_port The local port. If 0, a random port will be used * @param router_host The address of the remote {@link GossipRouter} * @param router_port The port on which the remote GossipRouter is listening * @param use_nio Whether to use blocking or non-blocking IO * @param l The {@link org.jgroups.stack.RouterStub.CloseListener} */ public RouterStub(InetAddress bind_addr, int bind_port, InetAddress router_host, int router_port, boolean use_nio, CloseListener l) { local=new IpAddress(bind_addr, bind_port); this.remote=new IpAddress(router_host, router_port); this.use_nio=use_nio; this.close_listener=l; client=use_nio? new NioClient(bind_addr, bind_port, router_host, router_port) : new TcpClient(bind_addr, bind_port, router_host, router_port); client.addConnectionListener(this); client.receiver(this); client.socketConnectionTimeout(sock_conn_timeout).tcpNodelay(tcp_nodelay); }
protected void start(InetAddress srv_addr, int srv_port, boolean nio) throws Exception { client=nio? new NioClient(InetAddress.getLocalHost(), 0, srv_addr, srv_port) : new TcpClient(InetAddress.getLocalHost(), 0, srv_addr, srv_port); client.receiver(this); client.addConnectionListener(this); client.start(); send(String.format("%s joined", name)); eventLoop(); client.stop(); }
/** * 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)); }
public RouterStub(IpAddress local, IpAddress remote, boolean use_nio, CloseListener l) { this.local=local; this.remote=remote; this.use_nio=use_nio; this.close_listener=l; client=use_nio? new NioClient(local, remote) : new TcpClient(local, remote); client.receiver(this); client.addConnectionListener(this); client.socketConnectionTimeout(sock_conn_timeout).tcpNodelay(tcp_nodelay); }
/** * Creates a stub to a remote GossipRouter * @param bind_addr The local address to bind to. If null, one will be picked * @param bind_port The local port. If 0, a random port will be used * @param router_host The address of the remote {@link GossipRouter} * @param router_port The port on which the remote GossipRouter is listening * @param use_nio Whether to use blocking or non-blocking IO * @param l The {@link org.jgroups.stack.RouterStub.CloseListener} */ public RouterStub(InetAddress bind_addr, int bind_port, InetAddress router_host, int router_port, boolean use_nio, CloseListener l) { local=new IpAddress(bind_addr, bind_port); this.remote=new IpAddress(router_host, router_port); this.use_nio=use_nio; this.close_listener=l; client=use_nio? new NioClient(bind_addr, bind_port, router_host, router_port) : new TcpClient(bind_addr, bind_port, router_host, router_port); client.addConnectionListener(this); client.receiver(this); client.socketConnectionTimeout(sock_conn_timeout).tcpNodelay(tcp_nodelay); }