KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > sampleCluster2 > ejb > MyStatefulSFR


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s):
22  * --------------------------------------------------------------------------
23  * $Id: MyStatefulSFR.java,v 1.4 2005/04/05 06:26:27 goebelg Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.sampleCluster2.ejb;
28
29
30 import java.util.ArrayList JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 import javax.ejb.SessionBean JavaDoc;
34 import javax.ejb.SessionContext JavaDoc;
35 import javax.ejb.SessionSynchronization JavaDoc;
36
37 import org.objectweb.jonas.common.JProp;
38 import org.objectweb.jonas.common.Log;
39
40 import org.objectweb.util.monolog.api.BasicLevel;
41 import org.objectweb.util.monolog.api.Logger;
42
43 /**
44  *
45  */

46 public class MyStatefulSFR implements SessionBean JavaDoc, SessionSynchronization JavaDoc {
47
48     /**
49      *
50      */

51     private static final long serialVersionUID = 1L;
52
53     /**
54      * After the transaction begun
55      */

56     public void afterBegin() {
57         logger.log(BasicLevel.DEBUG, "");
58     }
59
60     /**
61      * before the commit is executed
62      */

63     public void beforeCompletion() {
64         logger.log(BasicLevel.DEBUG, "");
65     }
66
67     /**
68      * after the commit or rollback
69      * @param committed true -> commit, false -> rollback
70      */

71     public void afterCompletion(boolean committed) {
72         logger.log(BasicLevel.DEBUG, "");
73     }
74
75     /**
76      * Set the session context
77      * @param ctx the session context
78      */

79     public void setSessionContext(SessionContext JavaDoc ctx) {
80         if (logger == null) {
81             logger = Log.getLogger("org.objectweb.jonas_tests");
82         }
83         logger.log(BasicLevel.DEBUG, "");
84     }
85
86     /**
87      * removes the ejb
88      */

89     public void ejbRemove() {
90         logger.log(BasicLevel.DEBUG, "");
91     }
92
93     /**
94      * creation of the ejb
95      */

96     public void ejbCreate() {
97         logger.log(BasicLevel.DEBUG, "");
98         creatorJonasInstanceName = "unknown";
99
100         try {
101             JProp jp = JProp.getInstance();
102             creatorJonasInstanceName = jp.getValue("jonas.name");
103         } catch (Exception JavaDoc e) {
104             logger.log(BasicLevel.FATAL, e.getMessage());
105         }
106
107         log = new ArrayList JavaDoc(MAXSIZE);
108
109         logger.log(BasicLevel.DEBUG, "ejbCreate()->" + this.toString());
110
111     }
112
113     /**
114      * Passivate of the ejb
115      */

116     public void ejbPassivate() {
117         logger.log(BasicLevel.DEBUG, "");
118     }
119
120     /**
121      * activation of the ejb
122      */

123     public void ejbActivate() {
124         logger.log(BasicLevel.DEBUG, "");
125     }
126
127     /**
128      * Keep the parameter in a list. Note : the parameter represents a line in
129      * the "session servlet output" screen
130      * @param s The string to keep.
131      * @throws RemoteException
132      */

133     public void log(java.lang.String JavaDoc s) {
134         logger.log(BasicLevel.DEBUG, "");
135
136         if (log.size() == MAXSIZE) {
137             Iterator JavaDoc iter = log.iterator();
138             iter.next();
139             iter.remove();
140         }
141
142         log.add(s);
143     }
144
145     /**
146      * Retreive all the data in the log table Note : The return value is the
147      * data shown in the "session servlet output" screen
148      * @return All the logged data
149      * @throws RemoteException
150      */

151     public java.lang.StringBuffer JavaDoc getLogDump() {
152         logger.log(BasicLevel.DEBUG, "");
153
154         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
155         sb.append("JOnAS instance=");
156         sb.append(creatorJonasInstanceName);
157         sb.append(" ; EJB=");
158         sb.append(this.toString());
159         sb.append("\n");
160         sb.append("Owner: ");
161         sb.append(callerHTTPSessionId);
162         sb.append("\n");
163         Iterator JavaDoc iter = log.iterator();
164         int i = 0;
165
166         sb
167                 .append("<table border=1><tr><td>servlet running on</td><td>stateless bean created on</td><td>statless bean total calls</td><td>entity bean created on</td></tr>");
168         while (iter.hasNext()) {
169             sb.append(iter.next());
170         }
171         sb.append("</table>");
172
173         logger.log(BasicLevel.INFO, sb.toString());
174         return sb;
175     }
176
177     /**
178      * Set the http sessionid of the caller.
179      * @param s The sessionid of the caller.
180      * @throws RemoteException
181      */

182     public void setHTTPSessionId(java.lang.String JavaDoc s) {
183         logger.log(BasicLevel.DEBUG, "");
184         callerHTTPSessionId = s;
185     }
186
187     /**
188      * Get the stored http sessionid of the caller.
189      * @return The stored sessionid.
190      * @throws RemoteException
191      */

192     public java.lang.String JavaDoc getHTTPSessionId() {
193         logger.log(BasicLevel.DEBUG, "");
194         return callerHTTPSessionId;
195     }
196
197     /**
198      * The JOnAS node name where the bean is executed
199      */

200     private String JavaDoc creatorJonasInstanceName = "unknown";
201
202     /**
203      * The logger
204      */

205     private static Logger logger = null;
206
207
208     /**
209      * The maximum number of values to conserve
210      */

211     private static final int MAXSIZE = 20;
212
213     /**
214      * The log output
215      */

216     private ArrayList JavaDoc log = null;
217
218     /**
219      * caller http session id
220      */

221     private String JavaDoc callerHTTPSessionId = null;
222
223 }
224
225
Popular Tags