1 3 package org.jgroups.protocols; 4 5 6 import org.jgroups.Address; 7 import org.jgroups.Event; 8 import org.jgroups.Message; 9 import org.jgroups.stack.IpAddress; 10 11 import java.util.*; 12 13 14 32 public class TCPPING extends Discovery { 33 int port_range=1; 35 36 ArrayList initial_hosts=null; final static String name="TCPPING"; 38 39 40 41 public String getName() { 42 return name; 43 } 44 45 46 47 public boolean setProperties(Properties props) { 48 String str; 49 50 str=props.getProperty("port_range"); if(str != null) { port_range=Integer.parseInt(str); 53 if (port_range < 1) { 54 port_range = 1; 55 } 56 props.remove("port_range"); 57 } 58 59 str=props.getProperty("initial_hosts"); 60 if(str != null) { 61 props.remove("initial_hosts"); 62 initial_hosts=createInitialHosts(str); 63 } 64 65 return super.setProperties(props); 66 } 67 68 69 public void localAddressSet(Address addr) { 70 if(initial_hosts != null && addr != null) { 72 if(initial_hosts.contains(addr)) { 73 initial_hosts.remove(addr); 74 if(log.isDebugEnabled()) log.debug("[SET_LOCAL_ADDRESS]: removing my own address (" + addr + 75 ") from initial_hosts; initial_hosts=" + initial_hosts); 76 } 77 } 78 } 79 80 81 public void sendGetMembersRequest() { 82 Message msg; 83 84 for(Iterator it=initial_hosts.iterator(); it.hasNext();) { 85 Address addr=(Address)it.next(); 86 msg=new Message(addr, null, null); 90 msg.putHeader(name, new PingHeader(PingHeader.GET_MBRS_REQ, null)); 91 92 if(log.isTraceEnabled()) log.trace("[FIND_INITIAL_MBRS] sending PING request to " + msg.getDest()); 93 passDown(new Event(Event.MSG, msg)); 94 } 95 } 96 97 98 99 100 101 104 private ArrayList createInitialHosts(String l) { 105 StringTokenizer tok=new StringTokenizer(l, ","); 106 String t; 107 IpAddress addr; 108 ArrayList retval=new ArrayList(); 109 110 while(tok.hasMoreTokens()) { 111 try { 112 t=tok.nextToken(); 113 String host=t.substring(0, t.indexOf('[')); 114 int port=Integer.parseInt(t.substring(t.indexOf('[') + 1, t.indexOf(']'))); 115 for(int i=port; i < port + port_range; i++) { 116 addr=new IpAddress(host, i); 117 retval.add(addr); 118 } 119 } 120 catch(NumberFormatException e) { 121 if(log.isErrorEnabled()) log.error("exeption is " + e); 122 } 123 } 124 125 return retval; 126 } 127 128 } 129 130 | Popular Tags |