Source Code Cross Referenced for SampleClient.java in  » J2EE » JOnAS-4.8.6 » samplehttp » client » 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 » J2EE » JOnAS 4.8.6 » samplehttp.client 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package samplehttp.client;
002:
003:        //Import statements
004:        import java.io.*;
005:
006:        import java.net.*;
007:
008:        class SenderThread extends Thread {
009:
010:            private String m_host;
011:            private int m_port;
012:            private String m_treattime;
013:            private int m_loops;
014:            private long m_wait;
015:            private long m_time;
016:            private int m_fejb;
017:
018:            public SenderThread(String host, int port, String treattime,
019:                    String wait, int loops, int fejb) {
020:                m_host = host;
021:                m_port = port;
022:                m_treattime = treattime;
023:                Long w = new Long(wait.trim());
024:                m_wait = w.longValue();
025:                m_loops = loops;
026:                m_fejb = fejb;
027:            }
028:
029:            public void run() {
030:                System.out.println("Running a SenderThread...");
031:                long d_begin = System.currentTimeMillis();
032:                Sender s = new Sender(m_host, "samplehttp/SampleServlet",
033:                        m_port, m_treattime, m_fejb);
034:                try {
035:                    for (int l = 0; l < m_loops; l++) {
036:                        s.execute();
037:                        Thread.currentThread().sleep(m_wait);
038:                    }
039:                } catch (Exception e) {
040:                    System.out.println(">>>  SenderThread. Exception caught = "
041:                            + e);
042:                }
043:                long d_end = System.currentTimeMillis();
044:                m_time = d_end - d_begin;
045:            }
046:
047:            public long getTime() {
048:                return m_time;
049:            }
050:        }
051:
052:        public class SampleClient {
053:
054:            private static final int m_MAXTHREADS = 500;
055:            private static int poolsize = 1;
056:            private static int port;
057:            private static int loops = 1;
058:            private static String wait = "1000"; // Wait between 2 requests default = 1second
059:            private static String treattime = "10"; // Treatment time in servlet default = 10 ms
060:            private static String host;
061:            private static int flgejb = 0;
062:
063:            public static void main(String args[]) {
064:
065:                // Get command args
066:                for (int argn = 0; argn < args.length; argn++) {
067:                    String s_arg = args[argn];
068:                    String sarg;
069:                    Integer i_arg;
070:
071:                    if ((argn + 1 < args.length)
072:                            && (s_arg.equals("-h") == true)) {
073:                        host = args[++argn];
074:
075:                    } else if ((argn + 1 < args.length)
076:                            && (s_arg.equals("-p") == true)) {
077:                        s_arg = args[++argn];
078:                        i_arg = java.lang.Integer.valueOf(s_arg);
079:                        port = i_arg.intValue();
080:                    } else if ((argn + 1 < args.length)
081:                            && (s_arg.equals("-n") == true)) {
082:                        s_arg = args[++argn];
083:                        i_arg = java.lang.Integer.valueOf(s_arg);
084:                        poolsize = i_arg.intValue();
085:                    } else if ((argn + 1 < args.length)
086:                            && (s_arg.equals("-l") == true)) {
087:                        s_arg = args[++argn];
088:                        i_arg = java.lang.Integer.valueOf(s_arg);
089:                        loops = i_arg.intValue();
090:                    } else if ((argn + 1 < args.length)
091:                            && (s_arg.equals("-t") == true)) {
092:                        s_arg = args[++argn];
093:                        treattime = s_arg;
094:                    } else if ((argn + 1 < args.length)
095:                            && (s_arg.equals("-w") == true)) {
096:                        s_arg = args[++argn];
097:                        wait = s_arg;
098:
099:                    } else if (s_arg.equals("-ejb") == true) {
100:                        flgejb = 1;
101:                    } else if (s_arg.equals("-ejbl") == true) {
102:                        flgejb = 2;
103:                    } else if (s_arg.equals("-ejbc") == true) {
104:                        flgejb = 3;
105:                    } else if (s_arg.equals("-?") == true) {
106:                        usage();
107:                        System.exit(0);
108:                    } else {
109:                        usage();
110:                        System.exit(2);
111:                    }
112:                }
113:
114:                long tbegin = System.currentTimeMillis();
115:                // Start pool of client threads
116:                SenderThread t_thr[] = new SenderThread[m_MAXTHREADS];
117:                long ttime[] = new long[m_MAXTHREADS];
118:                for (int p = 0; p < poolsize; p++) {
119:                    t_thr[p] = new SenderThread(host, port, treattime, wait,
120:                            loops, flgejb);
121:                    t_thr[p].start();
122:                }
123:                for (int p = 0; p < poolsize; p++) {
124:                    try {
125:                        t_thr[p].join();
126:                        ttime[p] = t_thr[p].getTime();
127:
128:                    } catch (InterruptedException e) {
129:                        System.out
130:                                .println("ERROR: Problem in SenderThread.join():\n"
131:                                        + e);
132:                        System.exit(2);
133:                    }
134:                }
135:                long tend = System.currentTimeMillis();
136:                long time = tend - tbegin;
137:                System.out.println("Fin de l'essai avec nb clients= "
138:                        + poolsize + " timetowait betwwen requests = " + wait);
139:                System.out.println("nb loops in client = " + loops
140:                        + " treatment time in servlet = " + treattime);
141:                System.out.print("using ejb = ");
142:                if (flgejb == 0)
143:                    System.out.println("no");
144:                if (flgejb == 1)
145:                    System.out.println("yes via remote interface");
146:                if (flgejb == 2)
147:                    System.out.println("yes via local interface");
148:                if (flgejb == 3)
149:                    System.out
150:                            .println("yes via remote interface + getConnection");
151:
152:                System.out.println("Time : " + time);
153:            }
154:
155:            private static void usage() {
156:                System.out
157:                        .println("Usage: jclient -cp ...  samplehttp.client.SampleClient <args>");
158:                System.out.println("  -h  <host>            hostname");
159:                System.out.println("  -p <port>       port number ");
160:                System.out
161:                        .println("  -n <thread>     number of client threads");
162:                System.out
163:                        .println("  -t <treatmenttime>     treatment time in servlet");
164:                System.out
165:                        .println("  -w <timetowait>     time to wait in thread client");
166:                System.out
167:                        .println("  -l <nbloops>     nb loops in each thread client");
168:                System.out.println("  -ejb       call ejb in servlet");
169:                System.out
170:                        .println("  -ejbl      call ejb via local interface in servlet");
171:                System.out
172:                        .println("  -ejbc      call ejb + getconnectionin servlet");
173:
174:            }
175:
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.