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


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 2005-2006 Bull S.A.S
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: MyEjb1SLR.java 7938 2006-01-25 17:15:26Z pelletib $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.sampleCluster2.ejb;
025:
026:        import java.util.Date;
027:        import java.util.Properties;
028:
029:        import javax.ejb.CreateException;
030:        import javax.ejb.SessionBean;
031:        import javax.ejb.SessionContext;
032:        import javax.naming.InitialContext;
033:        import javax.naming.NamingException;
034:
035:        import org.objectweb.jonas.common.JProp;
036:        import org.objectweb.jonas.common.Log;
037:
038:        import org.objectweb.util.monolog.api.BasicLevel;
039:        import org.objectweb.util.monolog.api.Logger;
040:
041:        /**
042:         * @author goebelg
043:         * Implementation of a stateless session bean
044:         */
045:        public class MyEjb1SLR implements  SessionBean {
046:
047:            /**
048:             *
049:             */
050:            private static final long serialVersionUID = 1L;
051:
052:            /**
053:             * After how many invokes an entity bean is created
054:             */
055:            private static final int DIV = 10;
056:
057:            /**
058:             * Sets the session Context
059:             * @param ctx the session context
060:             */
061:            public void setSessionContext(SessionContext ctx) {
062:                if (logger == null) {
063:                    logger = Log.getLogger("org.objectweb.jonas_tests");
064:                }
065:                logger.log(BasicLevel.DEBUG, "");
066:            }
067:
068:            /**
069:             * removes the ejb
070:             */
071:            public void ejbRemove() {
072:                logger.log(BasicLevel.DEBUG, "");
073:            }
074:
075:            /**
076:             * creates the ejb
077:             */
078:            public void ejbCreate() {
079:
080:                logger.log(BasicLevel.DEBUG, "");
081:                jonasInstanceName = "unknown";
082:
083:                try {
084:                    JProp jp = JProp.getInstance();
085:                    jonasInstanceName = jp.getValue("jonas.name");
086:                } catch (Exception e) {
087:                    logger.log(BasicLevel.FATAL,
088:                            "Error while creating MyEjb1SLR : "
089:                                    + e.getMessage());
090:                }
091:
092:                logger.log(BasicLevel.DEBUG, "ejbCreate()->" + this .toString());
093:            }
094:
095:            /**
096:             * Passivate of the ejb
097:             */
098:            public void ejbPassivate() {
099:                logger.log(BasicLevel.DEBUG, "");
100:            }
101:
102:            /**
103:             * Activation of the ejb
104:             */
105:            public void ejbActivate() {
106:                logger.log(BasicLevel.DEBUG, "");
107:            }
108:
109:            /**
110:             * Access a property stored in the JOnAS instance executing the EJB
111:             * container.
112:             * @param prop Name of the property
113:             * @return The value of the property
114:             */
115:            public String getProperty(String prop) {
116:                String s = "unknown";
117:                try {
118:                    JProp jp = JProp.getInstance();
119:                    s = jp.getValue(prop);
120:                } catch (Exception e) {
121:                    logger.log(BasicLevel.FATAL, "Error while getProperty : "
122:                            + e.getMessage());
123:                }
124:                return s;
125:            }
126:
127:            /**
128:             * Throw a MyException
129:             * @throws MyException application exception
130:             */
131:            public void throwMyException() throws MyException {
132:                throw new MyException("From EjbSLR1(" + jonasInstanceName + ")");
133:            }
134:
135:            /**
136:             * Retreive some information of the JOnAS instance executing the EJB
137:             * container The names of the properties are : EJB server, EJB id, EJB
138:             * instance calls, EJB total calls - EJB server : name of the JOnAS instance -
139:             * EJB id : toString() of the MyEjb1 - EJB instance calls : number of calls
140:             * to this EJB instance - EJB total calls : number of calls to this EJB for
141:             * all instance of class MyEjb1
142:             * @return The Properties
143:             */
144:            public Properties getInfoProps() {
145:                updateStatistics();
146:                Properties p = new Properties();
147:                p.setProperty("EJB server", jonasInstanceName);
148:                p.setProperty("EJB id", this .toString());
149:                p.setProperty("EJB total calls", (new Integer(
150:                        allInstancesTotalCallsCount)).toString());
151:                p.setProperty("EJB server entity created",
152:                        entityJonasInstanceName);
153:                return p;
154:            }
155:
156:            /**
157:             * Updates the properties described above
158:             */
159:            private void updateStatistics() {
160:                allInstancesTotalCallsCount++;
161:
162:                // create an entity bean every 10 times
163:                if ((allInstancesTotalCallsCount % DIV) == 0) {
164:                    // creating a new entity bean
165:                    logger.log(BasicLevel.INFO, "Trying to create the entity");
166:                    Date date = new Date();
167:                    MyEntityLocal entity = createEntity(Long.toString(date
168:                            .getTime()));
169:                    logger
170:                            .log(BasicLevel.INFO,
171:                                    "Finished to create the entity");
172:                    entityJonasInstanceName = entity.getJOnASName();
173:                } else {
174:                    entityJonasInstanceName = "No entity Bean created";
175:                }
176:
177:                logger.log(BasicLevel.INFO, "JOnAS=" + jonasInstanceName
178:                        + " ; ejb=" + this .toString() + " ; total calls="
179:                        + allInstancesTotalCallsCount + " ; entity created on="
180:                        + entityJonasInstanceName);
181:            }
182:
183:            /**
184:             * Creates a new Entity bean with the time as parameter
185:             * @param valeur The current time as string
186:             * @return A new Entity Bean
187:             */
188:            private MyEntityLocal createEntity(String valeur) {
189:                InitialContext cntx;
190:                MyEntityLocal result = null;
191:                try {
192:                    cntx = new InitialContext();
193:                    MyEntityLocalHome entityHome = (MyEntityLocalHome) cntx
194:                            .lookup("MyEntityHome_L");
195:                    result = entityHome.create(valeur);
196:                } catch (NamingException e) {
197:                    logger.log(BasicLevel.FATAL, "Naming exception : "
198:                            + e.getMessage());
199:                } catch (CreateException e) {
200:                    logger.log(BasicLevel.FATAL, "Create exception : "
201:                            + e.getMessage());
202:                }
203:                return result;
204:            }
205:
206:            /**
207:             * The logger
208:             */
209:            private static Logger logger = null;
210:
211:            /**
212:             * the node name of the jonas instance where an
213:             * entity bean has bean created
214:             */
215:            private String entityJonasInstanceName = "unknown";
216:
217:            /**
218:             * the node name of the jonas instance where the
219:             * session bean is executed
220:             */
221:            private String jonasInstanceName = "unknown";
222:
223:            /**
224:             * counts all the instances created of this class in
225:             * that JVM
226:             */
227:            private static int allInstancesTotalCallsCount = 0;
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.