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


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999-2004 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: Client.java 4618 2004-04-19 06:39:30Z benoitf $
023:         * --------------------------------------------------------------------------
024:         */package lb;
025:
026:        import java.rmi.RemoteException;
027:
028:        import javax.naming.Context;
029:        import javax.naming.InitialContext;
030:        import javax.naming.NamingException;
031:
032:        /**
033:         * Client of the lb JOnAS example
034:         * @author Helene Joanin
035:         */
036:        public class Client {
037:
038:            static Context initialContext = null;
039:
040:            static ManagerHome home = null;
041:
042:            static Manager manager = null;
043:
044:            static boolean m_noinit = false;
045:
046:            static int m_accounts = 4;
047:
048:            static int m_valmove = 100;
049:
050:            static int m_loops = 10;
051:
052:            static int inival = 1000;
053:
054:            public static void main(String[] args) {
055:
056:                // Get command args
057:                for (int argn = 0; argn < args.length; argn++) {
058:                    String s_arg = args[argn];
059:                    Integer i_arg;
060:                    if (s_arg.equals("-ni")) {
061:                        m_noinit = true;
062:                    } else if (s_arg.equals("-a")) {
063:                        s_arg = args[++argn];
064:                        i_arg = java.lang.Integer.valueOf(s_arg);
065:                        m_accounts = i_arg.intValue();
066:                    } else if (s_arg.equals("-m")) {
067:                        s_arg = args[++argn];
068:                        i_arg = java.lang.Integer.valueOf(s_arg);
069:                        m_valmove = i_arg.intValue();
070:                    } else if (s_arg.equals("-l")) {
071:                        s_arg = args[++argn];
072:                        i_arg = java.lang.Integer.valueOf(s_arg);
073:                        m_loops = i_arg.intValue();
074:                    } else {
075:                        usage();
076:                        fatalError("wrong usage");
077:                    }
078:                }
079:
080:                info("Calling lb.Client with : -a " + m_accounts + " -m "
081:                        + m_valmove + " -l " + m_loops);
082:
083:                // Get InitialContext
084:                try {
085:                    initialContext = new InitialContext();
086:                } catch (NamingException e) {
087:                    fatalError("Cannot get InitialContext: " + e);
088:                }
089:
090:                // Create manager session bean
091:                try {
092:                    home = (ManagerHome) javax.rmi.PortableRemoteObject.narrow(
093:                            initialContext.lookup("ManagerHome"),
094:                            ManagerHome.class);
095:                    manager = home.create(inival);
096:                } catch (Exception e) {
097:                    fatalError("Cannot create manager: " + e);
098:                }
099:
100:                // Create all accounts if noinit==false
101:                if (!m_noinit) {
102:                    info("Re-initialization of the accounts database table");
103:                    try {
104:                        manager.createAll(m_accounts);
105:                    } catch (Exception e) {
106:                        fatalError("Cannot create initial accounts: " + e);
107:                    }
108:                }
109:
110:                // Set move value
111:                try {
112:                    manager.setValue(m_valmove);
113:                } catch (Exception e) {
114:                    fatalError("Cannot init Session: " + e);
115:                }
116:
117:                // main loop
118:                try {
119:                    for (int i = 0; i < m_loops; i++) {
120:                        // Choose the 2 accounts randomly
121:                        int d1 = random(m_accounts);
122:                        int c1 = random(m_accounts);
123:                        info("  Movement " + d1 + " -> " + c1 + "");
124:                        // Set these accounts in session bean
125:                        manager.setAccounts(d1, c1);
126:                        // make the transfert
127:                        try {
128:                            manager.movement();
129:                        } catch (RemoteException r) {
130:                            error("movement raised exception. ignoring...");
131:                        }
132:                        // Check account that was debited
133:                        if (manager.checkAccount(d1) == false) {
134:                            error("Bad Account after move on account " + d1);
135:                            error("Stopping this session because some accounts are not ok");
136:                            break;
137:                        }
138:                    }
139:                } catch (Exception e) {
140:                    fatalError("Exception in main loop :" + e);
141:                }
142:
143:                // Check all accounts
144:                try {
145:                    if (manager.checkAll() == false) {
146:                        error("FAIL when checking all accounts");
147:                    } else {
148:                        info("PASS when checking all accounts");
149:                    }
150:                } catch (RemoteException e) {
151:                    error("checkAll() :" + e);
152:                }
153:
154:                // remove session bean
155:                try {
156:                    manager.remove();
157:                } catch (Exception e) {
158:                    error("Cannot remove manager session: " + e);
159:                }
160:
161:            }
162:
163:            /**
164:             * Returns an integer between 0 and max-1
165:             */
166:            static int random(int max) {
167:
168:                double d = Math.random();
169:                int ret = (int) (max * d);
170:                return ret;
171:            }
172:
173:            /**
174:             * Display the usage
175:             */
176:            static void usage() {
177:                info("lb.Client [-ni] [-a accounts] [-m value] [-l loops]");
178:            }
179:
180:            /**
181:             * Display the given information message
182:             */
183:            static void info(String infoMsg) {
184:                System.out.println(infoMsg);
185:            }
186:
187:            /**
188:             * Display the given error message
189:             */
190:            static void error(String errMsg) {
191:                System.out.println("lb.Client error: " + errMsg);
192:            }
193:
194:            /**
195:             * Display the given error message and exits
196:             */
197:            static void fatalError(String errMsg) {
198:                System.out.println("lb.Client fatal error: " + errMsg);
199:                System.exit(2);
200:            }
201:
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.