Source Code Cross Referenced for A_thread.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » stests » manac » 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 » org.objectweb.jonas.stests.manac 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         * 
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         * 
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         * 
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: A_thread.java 3862 2003-12-09 12:37:39Z durieuxp $
023:         * --------------------------------------------------------------------------
024:         */
025:
026:        package org.objectweb.jonas.stests.manac;
027:
028:        import java.rmi.RemoteException;
029:        import javax.ejb.RemoveException;
030:        import javax.naming.Context;
031:        import javax.rmi.PortableRemoteObject;
032:
033:        /**
034:         * Stress Test
035:         * @author Philippe Durieux
036:         */
037:        public class A_thread extends Thread {
038:            String managerName;
039:            String name;
040:            int accounts;
041:            int delay;
042:            int loops;
043:            int amount;
044:            Context ictx;
045:            int checklevel;
046:
047:            public A_thread(String mName, int num, Context ictx, int accounts,
048:                    int delay, int loops, int amount, int checklevel) {
049:                managerName = mName;
050:                name = managerName + "_manac_" + num;
051:                setName(name);
052:                this .ictx = ictx;
053:                this .accounts = accounts;
054:                this .delay = delay;
055:                this .loops = loops;
056:                this .amount = amount;
057:                this .checklevel = checklevel;
058:            }
059:
060:            /**
061:             * random returns an integer between 0 and max - 1
062:             */
063:            private int random(int max) throws RemoteException {
064:                double d = Math.random();
065:                int ret = (int) (max * d);
066:                return ret;
067:            }
068:
069:            public void run() {
070:
071:                // Create a session bean
072:                ManagerHome mgrHome = null;
073:                Manager mgr = null;
074:                try {
075:                    mgrHome = (ManagerHome) PortableRemoteObject.narrow(ictx
076:                            .lookup(managerName), ManagerHome.class);
077:                    mgr = mgrHome.create(A_manac.initialValue);
078:                } catch (Exception e) {
079:                    System.out.println("Cannot Create Session:" + e);
080:                    return;
081:                }
082:
083:                try {
084:                    // Set delay and value to move.
085:                    if (delay > 0) {
086:                        mgr.setDelay(delay);
087:                    }
088:                    if (amount > 0) {
089:                        mgr.setValue(amount);
090:                    }
091:
092:                    // main loop
093:                    boolean ok = true;
094:                    for (int i = 0; i < loops; i++) {
095:                        // Choose the 4 accounts randomly
096:                        int d1 = random(accounts);
097:                        int d2 = random(accounts);
098:                        int c1 = random(accounts);
099:                        int c2 = random(accounts);
100:                        if (amount < 0) {
101:                            // make a simple withdraw.
102:                            try {
103:                                mgr.withdraw(d1, c1, -amount);
104:                            } catch (RemoteException r) {
105:                                System.out
106:                                        .println("Exception (ignored) raised on withdraw:"
107:                                                + r);
108:                            }
109:                        } else {
110:                            // Set these accounts in session bean
111:                            try {
112:                                mgr.setAccounts(d1, d2, c1, c2);
113:                            } catch (RemoteException r) {
114:                                System.out.println("Bad Account Setting:" + r);
115:                                A_manac.threadfail = true;
116:                                break;
117:                            }
118:                            // make the transfert
119:                            try {
120:                                mgr.movement();
121:                            } catch (RemoteException r) {
122:                                // movement raised exception. ignoring...
123:                                System.out
124:                                        .println("Exception (ignored) raised on movement:"
125:                                                + r);
126:                            }
127:                        }
128:                        if (checklevel >= 2) {
129:                            // Check accounts that were debited
130:                            if (!mgr.checkAccount(d1)) {
131:                                System.out
132:                                        .println("Bad Account after move on account "
133:                                                + d1);
134:                                ok = false;
135:                            }
136:                            if (!mgr.checkAccount(d2)) {
137:                                System.out
138:                                        .println("Bad Account after move on account "
139:                                                + d2);
140:                                ok = false;
141:                            }
142:                            if (!ok) {
143:                                System.out
144:                                        .println("Stopping this session because some accounts are not ok");
145:                                A_manac.threadfail = true;
146:                                break;
147:                            }
148:                        }
149:                    }
150:                    // delete Session
151:                    mgr.remove();
152:                } catch (RemoteException e) {
153:                    System.out.println("Thread " + name + " : " + e);
154:                    A_manac.threadfail = true;
155:                } catch (RemoveException e) {
156:                    System.out.println("Thread " + name
157:                            + " Cannot remove session: " + e);
158:                    A_manac.threadfail = true;
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.