01: // $Id: WANPING.java,v 1.11 2006/04/23 12:52:54 belaban Exp $
02:
03: package org.jgroups.protocols;
04:
05: import org.jgroups.Event;
06: import org.jgroups.Message;
07: import org.jgroups.util.List;
08:
09: import java.util.Enumeration;
10: import java.util.Properties;
11: import java.util.StringTokenizer;
12:
13: /**
14: * Similar to TCPPING, except that the initial host list is specified as a list of logical pipe names.
15: */
16: public class WANPING extends Discovery {
17: int port_range = 5; // number of ports to be probed for initial membership
18: List initial_hosts = null; // hosts to be contacted for the initial membership
19:
20: public String getName() {
21: return "WANPING";
22: }
23:
24: public boolean setProperties(Properties props) {
25: String str;
26: str = props.getProperty("port_range"); // if member cannot be contacted on base port,
27: if (str != null) { // how many times can we increment the port
28: port_range = Integer.parseInt(str);
29: props.remove("port_range");
30: }
31:
32: str = props.getProperty("initial_hosts");
33: if (str != null) {
34: props.remove("initial_hosts");
35: initial_hosts = createInitialHosts(str);
36: if (log.isInfoEnabled())
37: log.info("initial_hosts: " + initial_hosts);
38: }
39:
40: if (initial_hosts == null || initial_hosts.size() == 0) {
41: log
42: .error("WANPING.setProperties(): hosts to contact for initial membership "
43: + "not specified. Cannot determine coordinator !");
44: return false;
45: }
46: return super .setProperties(props);
47: }
48:
49: public void sendGetMembersRequest() {
50: Message msg, copy;
51: PingHeader hdr;
52: String h;
53:
54: hdr = new PingHeader(PingHeader.GET_MBRS_REQ, null);
55: msg = new Message(null);
56: msg.putHeader(getName(), hdr);
57:
58: for (Enumeration en = initial_hosts.elements(); en
59: .hasMoreElements();) {
60: h = (String) en.nextElement();
61: copy = msg.copy();
62: copy.setDest(new WanPipeAddress(h));
63: passDown(new Event(Event.MSG, copy));
64: }
65: }
66:
67: /* -------------------------- Private methods ---------------------------- */
68:
69: /**
70: * Input is "pipe1,pipe2". Return List of Strings
71: */
72: private List createInitialHosts(String l) {
73: List tmp = new List();
74: StringTokenizer tok = new StringTokenizer(l, ",");
75: String t;
76:
77: while (tok.hasMoreTokens()) {
78: try {
79: t = tok.nextToken();
80: tmp.add(t.trim());
81: } catch (NumberFormatException e) {
82: log.error("WANPING.createInitialHosts(): " + e);
83: }
84: }
85: return tmp;
86: }
87:
88: }
|