1 3 package org.jgroups.protocols; 4 5 6 import org.jgroups.Event; 7 import org.jgroups.Message; 8 import org.jgroups.util.List; 9 10 import java.util.Enumeration ; 11 import java.util.Properties ; 12 import java.util.StringTokenizer ; 13 14 15 18 public class WANPING extends Discovery { 19 int port_range=5; List initial_hosts=null; 22 23 public String getName() { 24 return "WANPING"; 25 } 26 27 28 public boolean setProperties(Properties props) { 29 String str; 30 str=props.getProperty("port_range"); if(str != null) { port_range=Integer.parseInt(str); 33 props.remove("port_range"); 34 } 35 36 str=props.getProperty("initial_hosts"); 37 if(str != null) { 38 props.remove("initial_hosts"); 39 initial_hosts=createInitialHosts(str); 40 if(log.isInfoEnabled()) log.info("initial_hosts: " + initial_hosts); 41 } 42 43 if(initial_hosts == null || initial_hosts.size() == 0) { 44 System.err.println("WANPING.setProperties(): hosts to contact for initial membership " + 45 "not specified. Cannot determine coordinator !"); 46 return false; 47 } 48 return super.setProperties(props); 49 } 50 51 public void sendGetMembersRequest() { 52 Message msg, copy; 53 PingHeader hdr; 54 String h; 55 56 hdr=new PingHeader(PingHeader.GET_MBRS_REQ, null); 57 msg=new Message(null, null, null); 58 msg.putHeader(getName(), hdr); 59 60 for(Enumeration en=initial_hosts.elements(); en.hasMoreElements();) { 61 h=(String )en.nextElement(); 62 copy=msg.copy(); 63 copy.setDest(new WanPipeAddress(h)); 64 passDown(new Event(Event.MSG, copy)); 65 } 66 } 67 68 69 70 71 72 75 private List createInitialHosts(String l) { 76 List tmp=new List(); 77 StringTokenizer tok=new StringTokenizer (l, ","); 78 String t; 79 80 while(tok.hasMoreTokens()) { 81 try { 82 t=tok.nextToken(); 83 tmp.add(t.trim()); 84 } 85 catch(NumberFormatException e) { 86 System.err.println("WANPING.createInitialHosts(): " + e); 87 } 88 } 89 return tmp; 90 } 91 92 93 } 94 95 | Popular Tags |