public void start() throws Exception { for(int i=bind_port; i <= bind_port+port_range; i++) { try { sock=getSocketFactory().createDatagramSocket("jgroups.bping.sock", i); break; } catch(Throwable t) { if(i > bind_port+port_range) throw new RuntimeException("failed to open a port in range [" + bind_port + " - " + (bind_port+port_range) + "]", t); } } if (null == sock) throw new RuntimeException("failed to open a port in range [" + bind_port + " - " + (bind_port+port_range) + "]"); sock.setBroadcast(true); startReceiver(); super.start(); }
public void stop() { Util.close(sock); sock=null; receiver=null; super.stop(); }
protected void sendDiscoveryRequest(String cluster_name, List<Address> members_to_find, boolean initial_discovery) throws Exception { PingData data=null; if(!use_ip_addrs || !initial_discovery) { PhysicalAddress physical_addr=(PhysicalAddress)down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr)); // https://issues.jboss.org/browse/JGRP-1670 data=new PingData(local_addr, false, NameCache.get(local_addr), physical_addr); if(members_to_find != null && members_to_find.size() <= max_members_in_discovery_request) data.mbrs(members_to_find); } // message needs to have DONT_BUNDLE flag: if A sends message M to B, and we need to fetch B's physical // address, then the bundler thread blocks until the discovery request has returned. However, we cannot send // the discovery *request* until the bundler thread has returned from sending M PingHeader hdr=new PingHeader(PingHeader.GET_MBRS_REQ).clusterName(cluster_name).initialDiscovery(initial_discovery); Message msg=new Message(null).putHeader(getId(),hdr) .setFlag(Message.Flag.INTERNAL,Message.Flag.DONT_BUNDLE,Message.Flag.OOB) .setTransientFlag(Message.TransientFlag.DONT_LOOPBACK); if(data != null) msg.setBuffer(marshal(data)); sendMcastDiscoveryRequest(msg); }
public void init() throws Exception { super.init(); log.debug("bind_addr=%s, mcast_addr=%s, mcast_port=%d", bind_addr, mcast_addr, mcast_port); }
Event view_event=new Event(Event.TMP_VIEW, makeView(new Vector(gossip_rsps))); msg=new Message(dest, null, null); // unicast msg msg.setFlag(Message.OOB); msg.putHeader(getName(), new PingHeader(PingHeader.GET_MBRS_REQ, null)); down_prot.down(new Event(Event.MSG, msg)); msg=new Message(null); msg.setFlag(Message.OOB); msg.putHeader(getName(), new PingHeader(PingHeader.GET_MBRS_REQ, null)); for(Enumeration en=initial_hosts.elements(); en.hasMoreElements();) { hlist=(List)en.nextElement(); msg=new Message(null); // mcast msg msg.setFlag(Message.OOB); msg.putHeader(getName(), hdr); // needs to be getName(), so we might get "MPING" ! sendMcastDiscoveryRequest(msg);
public Object down(Event evt) { switch (evt.getType()) { case Event.CONNECT: case Event.CONNECT_WITH_STATE_TRANSFER: case Event.CONNECT_USE_FLUSH: case Event.CONNECT_WITH_STATE_TRANSFER_USE_FLUSH: clusterName = (String) evt.getArg(); break; } return super.down(evt); }
@SuppressWarnings("unchecked") public Object up(Event evt) { if(evt.getType() == Event.CONFIG) { if(bind_addr == null) { Map<String,Object> config=evt.getArg(); bind_addr=(InetAddress)config.get("bind_addr"); } return up_prot.up(evt); } return super.up(evt); }
public static void main(String[] args) throws Exception { Protocol[] prot_stack={ new UDP().setValue("bind_addr", InetAddress.getByName("127.0.0.1")), new PING(), new MERGE3(), new FD_SOCK(),
@Override public void destroy() { _connectTimeout = 0; _readTimeout = 0; _operationAttempts = 0; _operationSleep = 0l; super.destroy(); }
public void init() throws Exception { super.init(); dest_addr=InetAddress.getByName(dest); if(log.isDebugEnabled()) log.debug("listening on " + bind_port); }
public Object down(Event evt) { switch (evt.getType()) { case Event.CONNECT: case Event.CONNECT_WITH_STATE_TRANSFER: case Event.CONNECT_USE_FLUSH: case Event.CONNECT_WITH_STATE_TRANSFER_USE_FLUSH: clusterName = (String) evt.getArg(); break; } return super.down(evt); }
public Object up(Event evt) { if(evt.getType() == Event.CONFIG) { if(bind_addr == null) { Map config=(Map)evt.getArg(); bind_addr=(InetAddress)config.get("bind_addr"); } return up_prot.up(evt); } return super.up(evt); }
public static void main(String[] args) throws Exception { Protocol[] prot_stack={ new UDP().setValue("bind_addr", InetAddress.getByName("127.0.0.1")), new PING(), new MERGE3(), new FD_SOCK(),
@Override public void destroy() { _connectTimeout = 0; _readTimeout = 0; _operationAttempts = 0; _operationSleep = 0l; super.destroy(); }
protected void sendDiscoveryRequest(String cluster_name, List<Address> members_to_find, boolean initial_discovery) throws Exception { PingData data=null; if(!use_ip_addrs || !initial_discovery) { PhysicalAddress physical_addr=(PhysicalAddress)down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr)); // https://issues.jboss.org/browse/JGRP-1670 data=new PingData(local_addr, false, NameCache.get(local_addr), physical_addr); if(members_to_find != null && members_to_find.size() <= max_members_in_discovery_request) data.mbrs(members_to_find); } // message needs to have DONT_BUNDLE flag: if A sends message M to B, and we need to fetch B's physical // address, then the bundler thread blocks until the discovery request has returned. However, we cannot send // the discovery *request* until the bundler thread has returned from sending M PingHeader hdr=new PingHeader(PingHeader.GET_MBRS_REQ).clusterName(cluster_name).initialDiscovery(initial_discovery); Message msg=new Message(null).putHeader(getId(),hdr) .setFlag(Message.Flag.INTERNAL,Message.Flag.DONT_BUNDLE,Message.Flag.OOB) .setTransientFlag(Message.TransientFlag.DONT_LOOPBACK); if(data != null) msg.setBuffer(marshal(data)); sendMcastDiscoveryRequest(msg); }
public void stop() { receiver=null; Util.close(mcast_sock); mcast_sock=null; super.stop(); }
super.start();
public void init() throws Exception { super.init(); log.debug("bind_addr=%s, mcast_addr=%s, mcast_port=%d", bind_addr, mcast_addr, mcast_port); }
@SuppressWarnings("unchecked") public Object up(Event evt) { if(evt.getType() == Event.CONFIG) { if(bind_addr == null) { Map<String,Object> config=evt.getArg(); bind_addr=(InetAddress)config.get("bind_addr"); } return up_prot.up(evt); } return super.up(evt); }
public void stop() { receiver=null; Util.close(mcast_sock); mcast_sock=null; super.stop(); }