Source Code Cross Referenced for RpcDispatcherSpeedTest.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:        package org.jgroups.tests;
002:
003:        import org.jgroups.*;
004:        import org.jgroups.blocks.GroupRequest;
005:        import org.jgroups.blocks.MethodCall;
006:        import org.jgroups.blocks.MethodLookup;
007:        import org.jgroups.blocks.RpcDispatcher;
008:        import org.jgroups.util.Util;
009:
010:        import java.lang.reflect.Method;
011:
012:        /**
013:         * Interactive test for measuring group RPCs using different invocation techniques.
014:         * @author Bela Ban
015:         * @version $Revision: 1.13.2.1 $
016:         */
017:        public class RpcDispatcherSpeedTest implements  MembershipListener {
018:            Channel channel;
019:            RpcDispatcher disp;
020:            String props = null;
021:            boolean server = false; // role is client by default
022:            int num = 1000;
023:            int mode = OLD;
024:            static final int OLD = 1;
025:            static final int METHOD = 2;
026:            static final int TYPES = 3;
027:            static final int SIGNATURE = 4;
028:            static final int ID = 5;
029:            static final long TIMEOUT = 10000;
030:            static final Class LONG_CLASS = long.class;
031:            static final String LONG = long.class.getName();
032:            final Method[] METHODS = new Method[1];
033:            final Object[] EMPTY_OBJECT_ARRAY = new Object[] {};
034:            final Class[] EMPTY_CLASS_ARRAY = new Class[] {};
035:            final String[] EMPTY_STRING_ARRAY = new String[] {};
036:
037:            public RpcDispatcherSpeedTest(String props, boolean server,
038:                    int num, int mode) throws NoSuchMethodException {
039:                this .props = props;
040:                this .server = server;
041:                this .num = num;
042:                this .mode = mode;
043:                initMethods();
044:            }
045:
046:            final void initMethods() throws NoSuchMethodException {
047:                Class cl = this .getClass();
048:                METHODS[0] = cl.getMethod("measure", null);
049:            }
050:
051:            public long measure() throws Exception {
052:                return System.currentTimeMillis();
053:            }
054:
055:            public void start() throws Exception {
056:                channel = new JChannel(props);
057:                channel.setOpt(Channel.LOCAL, Boolean.FALSE);
058:                disp = new RpcDispatcher(channel, null, this , this , false, // no deadlock detection
059:                        false); // no concurrent processing on incoming method calls
060:                // disp.setConcurrentProcessing(true);
061:
062:                disp.setMethodLookup(new MethodLookup() {
063:
064:                    public Method findMethod(short id) {
065:                        return METHODS[0];
066:                    }
067:                });
068:
069:                channel.connect("RpcDispatcherSpeedTestGroup");
070:
071:                try {
072:                    if (server) {
073:                        System.out
074:                                .println("-- Started as server. Press ctrl-c to kill");
075:                        while (true) {
076:                            Util.sleep(10000);
077:                        }
078:                    } else {
079:                        invokeRpcs(num, mode);
080:                    }
081:                } catch (Throwable t) {
082:                    t.printStackTrace(System.err);
083:                } finally {
084:                    channel.close();
085:                    disp.stop();
086:                }
087:            }
088:
089:            void invokeRpcs(int num, int mode) throws Exception {
090:                long start, stop;
091:                int show = num / 10;
092:                Method measure_method = getClass().getMethod("measure",
093:                        EMPTY_CLASS_ARRAY);
094:                MethodCall measure_method_call = new MethodCall(measure_method,
095:                        EMPTY_OBJECT_ARRAY);
096:
097:                if (show <= 0)
098:                    show = 1;
099:                start = System.currentTimeMillis();
100:                switch (mode) {
101:                case OLD:
102:                    System.out.println("-- invoking " + num
103:                            + " methods using mode=OLD");
104:                    for (int i = 1; i <= num; i++) {
105:                        disp.callRemoteMethods(null, "measure",
106:                                EMPTY_OBJECT_ARRAY, EMPTY_CLASS_ARRAY,
107:                                GroupRequest.GET_ALL, TIMEOUT);
108:                        if (i % show == 0)
109:                            System.out.println(i);
110:                    }
111:                    break;
112:
113:                case METHOD:
114:                    System.out.println("-- invoking " + num
115:                            + " methods using mode=METHOD");
116:                    for (int i = 1; i <= num; i++) {
117:                        disp.callRemoteMethods(null, measure_method_call,
118:                                GroupRequest.GET_ALL, TIMEOUT);
119:                        if (i % show == 0)
120:                            System.out.println(i);
121:                    }
122:                    break;
123:
124:                case TYPES:
125:                    System.out.println("-- invoking " + num
126:                            + " methods using mode=TYPES");
127:                    for (int i = 1; i <= num; i++) {
128:                        disp.callRemoteMethods(null, "measure",
129:                                EMPTY_OBJECT_ARRAY, EMPTY_CLASS_ARRAY,
130:                                GroupRequest.GET_ALL, TIMEOUT);
131:                        if (i % show == 0)
132:                            System.out.println(i);
133:                    }
134:                    break;
135:
136:                case SIGNATURE:
137:                    System.out.println("-- invoking " + num
138:                            + " methods using mode=SIGNATURE");
139:                    for (int i = 1; i <= num; i++) {
140:                        disp.callRemoteMethods(null, "measure",
141:                                EMPTY_OBJECT_ARRAY, EMPTY_STRING_ARRAY,
142:                                GroupRequest.GET_ALL, TIMEOUT);
143:                        if (i % show == 0)
144:                            System.out.println(i);
145:                    }
146:                    break;
147:                case ID:
148:                    System.out.println("-- invoking " + num
149:                            + " methods using mode=ID");
150:                    measure_method_call = new MethodCall((short) 0, null);
151:                    for (int i = 1; i <= num; i++) {
152:                        disp.callRemoteMethods(null, measure_method_call,
153:                                GroupRequest.GET_ALL, TIMEOUT);
154:                        if (i % show == 0)
155:                            System.out.println(i);
156:                    }
157:                    break;
158:                default:
159:                    break;
160:                }
161:                stop = System.currentTimeMillis();
162:                printStats(stop - start, num);
163:            }
164:
165:            void printStats(long total_time, int num) {
166:                double throughput = ((double) num)
167:                        / ((double) total_time / 1000.0);
168:                System.out.println("time for " + num + " remote calls was "
169:                        + total_time + ", avg=" + (total_time / (double) num)
170:                        + "ms/invocation, " + (long) throughput + " calls/sec");
171:            }
172:
173:            public void viewAccepted(View new_view) {
174:                System.out.println("-- new view: " + new_view);
175:            }
176:
177:            public void suspect(Address suspected_mbr) {
178:                ;
179:            }
180:
181:            public void block() {
182:                ;
183:            }
184:
185:            public static void main(String[] args) {
186:                String props = null;
187:                boolean server = false;
188:                int num = 1000;
189:                RpcDispatcherSpeedTest test;
190:                int mode = OLD;
191:
192:                for (int i = 0; i < args.length; i++) {
193:                    if ("-props".equals(args[i])) {
194:                        props = args[++i];
195:                        continue;
196:                    }
197:                    if ("-server".equals(args[i])) {
198:                        server = true;
199:                        continue;
200:                    }
201:                    if ("-num".equals(args[i])) {
202:                        num = Integer.parseInt(args[++i]);
203:                        continue;
204:                    }
205:                    if ("-mode".equals(args[i])) {
206:                        String m = args[++i].toLowerCase().trim();
207:                        if ("old".equals(m))
208:                            mode = OLD;
209:                        else if ("method".equals(m))
210:                            mode = METHOD;
211:                        else if ("types".equals(m))
212:                            mode = TYPES;
213:                        else if ("signature".equals(m))
214:                            mode = SIGNATURE;
215:                        else if ("ID".equals(m) || "id".equals(m)) {
216:                            mode = ID;
217:                        } else {
218:                            System.err.println("mode " + m + " is invalid");
219:                            help();
220:                            return;
221:                        }
222:                        continue;
223:                    }
224:                    help();
225:                    return;
226:                }
227:
228:                try {
229:                    test = new RpcDispatcherSpeedTest(props, server, num, mode);
230:                    test.start();
231:                } catch (Exception e) {
232:                    e.printStackTrace();
233:                }
234:            }
235:
236:            static void help() {
237:                System.out
238:                        .println("RpcDispatcherSpeedTest [-help] [-props <props>] "
239:                                + "[-server] [-num <number of calls>] [-mode <mode>]");
240:                System.out
241:                        .println("mode can be either 'old', 'method', 'types', signature' or 'id'");
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.