public void handleConnect() { if (cluster_name == null || local_addr == null) log.error(Util.getMessage("GroupaddrOrLocaladdrIsNullCannotRegisterWithGossipRouterS")); else { InetAddress bind_addr=getTransport().getBindAddress(); log.trace("registering " + local_addr + " under " + cluster_name + " with GossipRouter"); stubManager.destroyStubs(); PhysicalAddress physical_addr = (PhysicalAddress) down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr)); stubManager = new RouterStubManager(this, cluster_name, local_addr, NameCache.get(local_addr), physical_addr, reconnect_interval).useNio(this.use_nio); for (InetSocketAddress host : initial_hosts) { RouterStub stub=stubManager.createAndRegisterStub(new IpAddress(bind_addr, 0), new IpAddress(host.getAddress(), host.getPort())); stub.socketConnectionTimeout(sock_conn_timeout); } stubManager.connectStubs(); } }
protected void moveStubToReconnects(RouterStub stub) { if(stub == null) return; remove(stub); if(add(new Target(stub.local(), stub.remote(), stub.receiver()))) { log.debug("connection to %s closed, trying to re-establish connection", stub.remote()); startReconnector(); } }
public void handleDisconnect() { stubManager.disconnectStubs(); }
public RouterStub createAndRegisterStub(IpAddress local, IpAddress router_addr) { RouterStub stub=new RouterStub(local, router_addr, use_nio, this); RouterStub old_stub=unregisterStub(router_addr); if(old_stub != null) old_stub.destroy(); add(stub); return stub; }
public void init() throws Exception { super.init(); stubManager = RouterStubManager.emptyGossipClientStubManager(this).useNio(this.use_nio); // we cannot use TCPGOSSIP together with TUNNEL (https://jira.jboss.org/jira/browse/JGRP-1101) TP transport=getTransport(); if(transport instanceof TUNNEL) throw new IllegalStateException("TCPGOSSIP cannot be used with TUNNEL; use either TUNNEL:PING or " + "TCP:TCPGOSSIP as valid configurations"); }
@ManagedOperation public void addInitialHost(String hostname, int port) { //if there is such a stub already, remove and destroy it removeInitialHost(hostname, port); //now re-add it InetSocketAddress isa = new InetSocketAddress(hostname, port); initial_hosts.add(isa); stubManager.createAndRegisterStub(null, new IpAddress(isa.getAddress(), isa.getPort())); stubManager.connectStubs(); // tries to connect all unconnected stubs }
protected boolean reconnect(Target target) { RouterStub stub=new RouterStub(target.bind_addr, target.router_addr, this.use_nio, this).receiver(target.receiver); if(!add(stub)) return false; try { stub.connect(this.cluster_name, this.local_addr, this.logical_name, this.phys_addr); log.debug("re-established connection to %s successfully for group=%s and address=%s", stub.remote(), this.cluster_name, this.local_addr); return true; } catch(Throwable t) { remove(stub); return false; } }
public void destroy() { stubManager.destroyStubs(); super.destroy(); }
public void sendToAllMembers(final String group, Address sender, final byte[] data, final int offset, final int length) throws Exception { stubManager.forAny( stub -> { try { if(log.isTraceEnabled()) log.trace("sent a message to all members, GR used %s", stub.gossipRouterAddress()); stub.sendToAllMembers(group, sender, data, offset, length); } catch (Exception ex) { log.warn("failed sending a message to all members, router used %s", stub.gossipRouterAddress()); } }); }
public static RouterStubManager emptyGossipClientStubManager(Protocol p) { return new RouterStubManager(p,null,null,null, null,0L); }
@Override public void findMembers(List<Address> members, boolean initial_discovery, Responses responses) { if(this.cluster_name == null) { log.error(Util.getMessage("ClusternameIsNullCannotGetMembership")); return; } log.trace("fetching members from GossipRouter(s)"); stubManager.forEach( stub -> { try { stub.getMembers(TCPGOSSIP.this.cluster_name, TCPGOSSIP.this); } catch(Throwable t) { log.warn("failed fetching members from %s: %s, cause: %s", stub.gossipRouterAddress(), t, t.getCause()); } }); }
public void init() throws Exception { super.init(); if (timer == null) throw new Exception("timer cannot be retrieved from protocol stack"); if(gossip_router_hosts.isEmpty()) throw new IllegalStateException("gossip_router_hosts needs to contain at least one address of a GossipRouter"); log.debug("GossipRouters are:" + gossip_router_hosts.toString()); stubManager = RouterStubManager.emptyGossipClientStubManager(this).useNio(this.use_nio); sock = getSocketFactory().createDatagramSocket("jgroups.tunnel.ucast_sock", bind_port, bind_addr); }
public RouterStub createAndRegisterStub(IpAddress local, IpAddress router_addr) { RouterStub stub=new RouterStub(local, router_addr, use_nio, this); RouterStub old_stub=unregisterStub(router_addr); if(old_stub != null) old_stub.destroy(); add(stub); return stub; }
@ManagedOperation public void addInitialHost(String hostname, int port) { //if there is such a stub already, remove and destroy it removeInitialHost(hostname, port); //now re-add it InetSocketAddress isa = new InetSocketAddress(hostname, port); initial_hosts.add(isa); stubManager.createAndRegisterStub(null, new IpAddress(isa.getAddress(), isa.getPort())); stubManager.connectStubs(); // tries to connect all unconnected stubs }
protected boolean reconnect(Target target) { RouterStub stub=new RouterStub(target.bind_addr, target.router_addr, this.use_nio, this).receiver(target.receiver); if(!add(stub)) return false; try { stub.connect(this.cluster_name, this.local_addr, this.logical_name, this.phys_addr); log.debug("re-established connection to %s successfully for group=%s and address=%s", stub.remote(), this.cluster_name, this.local_addr); return true; } catch(Throwable t) { remove(stub); return false; } }
public void destroy() { stubManager.destroyStubs(); Util.close(sock); super.destroy(); }
public void sendToSingleMember(final String group, final Address dest, Address sender, final byte[] data, final int offset, final int length) throws Exception { stubManager.forAny( stub -> { try { if(log.isTraceEnabled()) log.trace("sent a message to %s (router used %s)", dest, stub.gossipRouterAddress()); stub.sendToMember(group, dest, sender, data, offset, length); } catch (Exception ex) { log.warn("failed sending a message to %s (router used %s):", dest, stub.gossipRouterAddress(), ex); } }); }
public static RouterStubManager emptyGossipClientStubManager(Protocol p) { return new RouterStubManager(p,null,null,null, null,0L); }