Source Code Cross Referenced for Ping.java in  » Net » JGroups-2.4.1-sp3 » org » jgroups » tests » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » JGroups 2.4.1 sp3 » org.jgroups.tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // $Id: Ping.java,v 1.7 2005/05/30 16:15:11 belaban Exp $
002:
003:        package org.jgroups.tests;
004:
005:        import org.jgroups.*;
006:        import org.jgroups.protocols.PingRsp;
007:        import org.jgroups.util.Util;
008:
009:        import java.util.Enumeration;
010:        import java.util.Hashtable;
011:        import java.util.Vector;
012:
013:        /**
014:         Determines the initial set of members given a group name and properties and prints them to stdout. Does not
015:         connect to the group, but - using a minimal stack of UPD/PING or TCP/TCPPING - only sends a FIND_INITIAL_MBRS
016:         down the stack (PING or TCPPING has to be present for this to work) and waits for FIND_INITIAL_MBRS_OK. When
017:         received, the results are printed and then the app terminates.<p>
018:         To connect to any group, it is essential that the groupname given (-group) is the same as the one of the group
019:         and the properties are the same as the bottom 2 layers of the group properties, e.g. if the group properties are:
020:         <pre>
021:         TCP(start_port=7800):TCPPING(initial_hosts=daddy.nms.fnc.fujitsu.com[7800];port_range=2;timeout=5000;num_initial_members=3;up_thread=true;down_thread=true):pbcast.STABLE(desired_avg_gossip=200000;down_thread=false;up_thread=false):pbcast.NAKACK(down_thread=true;up_thread=true;gc_lag=100;retransmit_timeout=3000):pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=false;down_thread=true;up_thread=true)
022:         </pre>
023:         ,then the stack properties should be:
024:         <pre>
025:         TCP(start_port=7800):TCPPING(initial_hosts=daddy.nms.fnc.fujitsu.com[7800];port_range=2;timeout=5000;num_initial_members=3)
026:         </pre>
027:         @author Bela Ban, June 12 2001
028:         */
029:        public class Ping implements  UpHandler {
030:            Channel channel = null;
031:            boolean print_all_events = false;
032:
033:            public Ping(String props, boolean trace, boolean printall)
034:                    throws Exception {
035:                print_all_events = printall;
036:                if (trace)
037:                    channel = new JChannel(props);
038:                channel.setUpHandler(this );
039:            }
040:
041:            public void go(String groupname) {
042:
043:                try {
044:                    channel.connect(groupname);
045:                    channel.down(Event.FIND_INITIAL_MBRS_EVT);
046:                } catch (Exception e) {
047:                    System.err.println("Ping.go(): " + e);
048:                    System.exit(1);
049:                }
050:            }
051:
052:            /** UpHandler interface */
053:            public void up(Event evt) {
054:                Vector v;
055:                PingRsp rsp;
056:
057:                if (evt.getType() == Event.FIND_INITIAL_MBRS_OK) {
058:                    v = (Vector) evt.getArg();
059:
060:                    System.out.println("Found " + v.size() + " members");
061:                    for (int i = 0; i < v.size(); i++) {
062:                        rsp = (PingRsp) v.elementAt(i);
063:                        System.out.println("Rsp #" + (i + 1) + ": " + rsp);
064:                    }
065:
066:                    if (v.size() > 0)
067:                        verifyCoordinator(v);
068:
069:                    System.exit(1);
070:                } else {
071:                    if (print_all_events)
072:                        System.out.println(">> " + evt);
073:                }
074:            }
075:
076:            static void verifyCoordinator(Vector rsps) {
077:                Hashtable votes = new Hashtable(); // coord address, list of members who voted for this guy
078:                PingRsp rsp;
079:                Vector v;
080:                Address coord, mbr;
081:
082:                for (int i = 0; i < rsps.size(); i++) {
083:                    rsp = (PingRsp) rsps.elementAt(i);
084:                    coord = rsp.getCoordAddress();
085:                    mbr = rsp.getAddress();
086:                    v = (Vector) votes.get(coord);
087:                    if (v == null) {
088:                        v = new Vector();
089:                        votes.put(coord, v);
090:                    }
091:                    if (!v.contains(mbr))
092:                        v.addElement(mbr);
093:                }
094:
095:                System.out.println("");
096:                if (votes.size() > 1)
097:                    System.err.println("*** Found more than 1 coordinator !");
098:
099:                printVotes(votes);
100:            }
101:
102:            static void printVotes(Hashtable votes) {
103:                Object key;
104:                Vector val;
105:                for (Enumeration e = votes.keys(); e.hasMoreElements();) {
106:                    key = e.nextElement();
107:                    val = (Vector) votes.get(key);
108:                    System.out.println("\n\nCoord: " + key);
109:                    System.out.println("Votes: " + val + '\n');
110:                }
111:            }
112:
113:            public static void main(String[] args) {
114:                Ping ping = null;
115:                boolean trace = false;
116:                String groupname = Util.shortName(Util.getHostname());
117:                boolean printall = false;
118:                String props = "UDP(mcast_addr=224.0.0.200;mcast_port=7500;ip_ttl=0;"
119:                        + "ucast_send_buf_size=30000;ucast_recv_buf_size=60000):"
120:                        + "PING(timeout=5000;num_initial_members=30)";
121:
122:                for (int i = 0; i < args.length; i++) {
123:                    if ("-help".equals(args[i])) {
124:                        usage();
125:                        return;
126:                    }
127:                    if ("-trace".equals(args[i])) {
128:                        trace = true;
129:                        continue;
130:                    }
131:                    if ("-printall".equals(args[i])) {
132:                        printall = true;
133:                        continue;
134:                    }
135:                    if ("-group".equals(args[i])) {
136:                        groupname = args[++i];
137:                        continue;
138:                    }
139:                    if ("-props".equals(args[i])) {
140:                        props = args[++i];
141:                        continue;
142:                    }
143:                    usage();
144:                    return;
145:                }
146:
147:                try {
148:                    ping = new Ping(props, trace, printall);
149:                    ping.go(groupname);
150:                } catch (Exception e) {
151:                    System.err.println("Ping.main(): " + e);
152:                    System.exit(0);
153:                }
154:            }
155:
156:            static void usage() {
157:                System.out
158:                        .println("Ping [-help] [-trace] [-group <groupname>] [-props <properties>] [-printall]");
159:            }
160:
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.