Source Code Cross Referenced for LocalGatewayBean.java in  » Inversion-of-Control » carbon » org » sape » carbon » services » ejb » local » test » 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 » Inversion of Control » carbon » org.sape.carbon.services.ejb.local.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the Sapient Public License
003:         * Version 1.0 (the "License"); you may not use this file except in compliance
004:         * with the License. You may obtain a copy of the License at
005:         * http://carbon.sf.net/License.html.
006:         *
007:         * Software distributed under the License is distributed on an "AS IS" basis,
008:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009:         * the specific language governing rights and limitations under the License.
010:         *
011:         * The Original Code is The Carbon Component Framework.
012:         *
013:         * The Initial Developer of the Original Code is Sapient Corporation
014:         *
015:         * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
016:         */
017:
018:        package org.sape.carbon.services.ejb.local.test;
019:
020:        import java.rmi.RemoteException;
021:
022:        import javax.ejb.CreateException;
023:        import javax.ejb.EJBLocalHome;
024:        import javax.ejb.SessionBean;
025:        import javax.ejb.SessionContext;
026:        import javax.naming.Context;
027:        import javax.naming.NamingException;
028:
029:        import org.apache.commons.logging.Log;
030:        import org.apache.commons.logging.LogFactory;
031:
032:        import org.sape.carbon.core.component.Lookup;
033:        import org.sape.carbon.core.config.Config;
034:
035:        import org.sape.carbon.services.ejb.EnterpriseBeanConfiguration;
036:        import org.sape.carbon.services.ejb.HomeFactoryException;
037:        import org.sape.carbon.services.ejb.local.LocalHomeFactory;
038:        import org.sape.carbon.services.jndi.InitialContextFactory;
039:        import org.sape.carbon.services.jndi.InitialContextFactoryConfiguration;
040:
041:        /**
042:         * <p>Bean implementation for the LocalGatewayBean
043:         *
044:         * Copyright 2002 Sapient
045:         * @see LocalGateway
046:         * @see LocalGatewayHome
047:         * @version $Revision: 1.10 $
048:         * @author $Author: dvoet $ $Date: 2003/11/05 17:45:16 $
049:         */
050:        public class LocalGatewayBean implements  SessionBean {
051:
052:            /**
053:             * Path of the remote home factory test component
054:             */
055:            public static final String TEST_INITIAL_CONTEXT_FACTORY = "/ejb/test/TestInitialContextFactory";
056:
057:            /**
058:             * Provides a handle to Apache-commons logger
059:             */
060:            private Log log = LogFactory.getLog(this .getClass());
061:
062:            /**
063:             * Contains the SessionContext attribute for this instance
064:             */
065:            protected SessionContext ctx;
066:
067:            private LocalHomeFactory homeFactory;
068:
069:            public void ejbCreate() throws CreateException {
070:
071:                this .homeFactory = (LocalHomeFactory) Lookup.getInstance()
072:                        .fetchComponent(
073:                                LocalHomeFactoryTest.TEST_LOCAL_HOME_FACTORY);
074:            }
075:
076:            public void ejbActivate() {
077:
078:            }
079:
080:            public void ejbPassivate() {
081:
082:            }
083:
084:            public void ejbRemove() {
085:
086:            }
087:
088:            /**
089:             * Returns the SessionContext associated with this instance.
090:             *
091:             * @return javax.ejb.SessionContext
092:             */
093:            public SessionContext getSessionContext() {
094:                return ctx;
095:            }
096:
097:            /**
098:             * Assigns the SessionContext of the current instance to the provided
099:             * parameter.
100:             *
101:             * @param ctx the SessionContext to assign to this instance.
102:             */
103:            public void setSessionContext(SessionContext ctx) {
104:                this .ctx = ctx;
105:            }
106:
107:            /**
108:             * Returns the name of the class of this object, used for debugging
109:             * purposes.
110:             *
111:             * @return String Identification
112:             */
113:            public String id() {
114:                return (this .getClass().getName());
115:            }
116:
117:            /**
118:             * @see Tester
119:             */
120:            public void testLocalHomeFactoryNamingException()
121:                    throws HomeFactoryException, RemoteException {
122:
123:                EJBLocalHome ejbHome = null;
124:
125:                // Perform the test using the LocalHomeFactory
126:                ejbHome = this .homeFactory
127:                        .lookup(LocalHomeFactoryTest.TEST_NONEXISTANT_EJB);
128:            }
129:
130:            /**
131:             * @see Tester
132:             */
133:            public void testLocalHomeFactoryLookup()
134:                    throws HomeFactoryException, RemoteException {
135:
136:                EJBLocalHome ejbHome = null;
137:
138:                ejbHome = this .homeFactory
139:                        .lookup(LocalHomeFactoryTest.TEST_LOCAL_EJB);
140:            }
141:
142:            /**
143:             * @see Tester
144:             */
145:            public void testLocalHomeFactoryLookupWithContext()
146:                    throws HomeFactoryException, NamingException,
147:                    RemoteException {
148:
149:                EJBLocalHome ejbHome = null;
150:
151:                InitialContextFactory factory = (InitialContextFactory) Lookup
152:                        .getInstance().fetchComponent(
153:                                TEST_INITIAL_CONTEXT_FACTORY);
154:                Context context = factory.getContext();
155:
156:                ejbHome = this .homeFactory.lookup(
157:                        LocalHomeFactoryTest.TEST_LOCAL_EJB, context);
158:            }
159:
160:            /**
161:             * @see Tester
162:             */
163:            public void testLocalHomeFactoryLookupWithCredentials()
164:                    throws HomeFactoryException, RemoteException {
165:
166:                InitialContextFactoryConfiguration factoryConfig = (InitialContextFactoryConfiguration) Config
167:                        .getInstance().fetchConfiguration(
168:                                TEST_INITIAL_CONTEXT_FACTORY);
169:
170:                EJBLocalHome ejbHome = null;
171:
172:                ejbHome = this .homeFactory.lookup(
173:                        LocalHomeFactoryTest.TEST_LOCAL_EJB, factoryConfig
174:                                .getEnvironment(Context.SECURITY_PRINCIPAL),
175:                        factoryConfig
176:                                .getEnvironment(Context.SECURITY_CREDENTIALS));
177:            }
178:
179:            /**
180:             * @see Tester
181:             */
182:            public void testLocalHomeCachePerformance()
183:                    throws HomeFactoryException, RemoteException {
184:
185:                long startTime = 0;
186:                long elapsedTime = 0;
187:
188:                EJBLocalHome ejbHome = null;
189:
190:                if (log.isInfoEnabled()) {
191:                    log.info("Testing EJB home cache performance");
192:
193:                    // Measure non-cached performance
194:                    log
195:                            .info("Performing "
196:                                    + LocalHomeCachePerformanceTest.TEST_LOOKUP_ITERATIONS
197:                                    + " home interface lookups for EJB: "
198:                                    + LocalHomeFactoryTest.TEST_LOCAL_EJB
199:                                    + " without using cache");
200:                }
201:
202:                // Set the start time
203:                startTime = System.currentTimeMillis();
204:
205:                // Loop
206:                for (long i = 0; i < LocalHomeCachePerformanceTest.TEST_LOOKUP_ITERATIONS; i++) {
207:
208:                    ejbHome = this .homeFactory
209:                            .lookup(LocalHomeFactoryTest.TEST_LOCAL_EJB);
210:                }
211:
212:                // Print the elapsed time
213:                elapsedTime = System.currentTimeMillis() - startTime;
214:
215:                if (log.isInfoEnabled()) {
216:                    log.info("Total elapsed time: " + elapsedTime);
217:                    log
218:                            .info("Lookups/Second: "
219:                                    + ((double) LocalHomeCachePerformanceTest.TEST_LOOKUP_ITERATIONS
220:                                            / elapsedTime * 1000) + " lps");
221:                }
222:
223:                // Measure cached lookup performance
224:                EnterpriseBeanConfiguration ejbDetails = homeFactory
225:                        .getEJBDetails(LocalHomeFactoryTest.TEST_LOCAL_EJB);
226:
227:                if (ejbDetails != null) {
228:                    ejbDetails.setCacheable(true);
229:                } else {
230:                    throw new RuntimeException(
231:                            "Test of EJB home cache performance failed; "
232:                                    + "unable to retrieve EJB details for logical name: "
233:                                    + LocalHomeFactoryTest.TEST_LOCAL_EJB);
234:                }
235:
236:                if (log.isInfoEnabled()) {
237:                    log
238:                            .info("Performing "
239:                                    + LocalHomeCachePerformanceTest.TEST_LOOKUP_ITERATIONS
240:                                    + " home interface lookups for EJB: "
241:                                    + LocalHomeFactoryTest.TEST_LOCAL_EJB
242:                                    + " using cache");
243:                }
244:
245:                // Set the start time
246:                startTime = System.currentTimeMillis();
247:
248:                for (long i = 0; i < LocalHomeCachePerformanceTest.TEST_LOOKUP_ITERATIONS; i++) {
249:
250:                    ejbHome = this .homeFactory
251:                            .lookup(LocalHomeFactoryTest.TEST_LOCAL_EJB);
252:                }
253:
254:                // Print the elapsed time
255:                elapsedTime = System.currentTimeMillis() - startTime;
256:
257:                if (log.isInfoEnabled()) {
258:                    log.info("Total elapsed time: " + elapsedTime);
259:                    log
260:                            .info("Lookups/Second: "
261:                                    + ((double) LocalHomeCachePerformanceTest.TEST_LOOKUP_ITERATIONS
262:                                            / elapsedTime * 1000) + " lps");
263:                }
264:            }
265:        }
ww__w__._ja_v__a2___s_.c_o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.