KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > perf > ejb > ClientSessionBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.perf.ejb;
23
24 import java.rmi.RemoteException JavaDoc;
25 import java.rmi.ServerException JavaDoc;
26 import javax.ejb.CreateException JavaDoc;
27 import javax.ejb.RemoveException JavaDoc;
28 import javax.ejb.SessionContext JavaDoc;
29 import javax.naming.Context JavaDoc;
30 import javax.naming.InitialContext JavaDoc;
31 import javax.rmi.PortableRemoteObject JavaDoc;
32
33 import org.jboss.logging.Logger;
34
35 import org.jboss.test.perf.interfaces.SessionHome;
36 import org.jboss.test.perf.interfaces.Session;
37
38 /** An implementation of the Session interface that delegates its calls
39  to the SessionBean implementation to test session to session bean timings.
40
41 @version $Revision: 58115 $
42 */

43 public class ClientSessionBean implements javax.ejb.SessionBean JavaDoc
44 {
45    private static Logger log = Logger.getLogger(ClientSessionBean.class);
46    private String JavaDoc entityName;
47
48    public void create(int low, int high)
49       throws CreateException JavaDoc, RemoteException JavaDoc
50    {
51       try
52       {
53          long start = System.currentTimeMillis();
54          Session bean = lookupSession();
55          bean.create(low, high);
56          long end = System.currentTimeMillis();
57          log.debug("create ran in: "+(end - start));
58       }
59       catch (CreateException JavaDoc ce)
60       {
61          throw ce;
62       }
63       catch(Exception JavaDoc e)
64       {
65          log.error("create failed", e);
66          throw new CreateException JavaDoc(e.toString());
67       }
68    }
69
70    public void remove(int low, int high)
71       throws RemoveException JavaDoc, RemoteException JavaDoc
72    {
73       try
74       {
75          long start = System.currentTimeMillis();
76          Session bean = lookupSession();
77          bean.remove(low, high);
78          long end = System.currentTimeMillis();
79          log.debug("remove ran in: "+(end - start));
80       }
81       catch(Exception JavaDoc e)
82       {
83          throw new RemoteException JavaDoc("remove failure", e);
84       }
85    }
86
87    public void read(int id) throws RemoteException JavaDoc
88    {
89       try
90       {
91          long start = System.currentTimeMillis();
92          Session bean = lookupSession();
93          bean.read(id);
94          long end = System.currentTimeMillis();
95          log.debug("read ran in: "+(end - start));
96       }
97       catch(Exception JavaDoc e)
98       {
99          throw new RemoteException JavaDoc("read failure", e);
100       }
101    }
102
103    public void read(int low, int high) throws RemoteException JavaDoc
104    {
105       try
106       {
107          long start = System.currentTimeMillis();
108          Session bean = lookupSession();
109          bean.read(low, high);
110          long end = System.currentTimeMillis();
111          log.debug("read ran in: "+(end - start));
112       }
113       catch(Exception JavaDoc e)
114       {
115          throw new RemoteException JavaDoc("read failure", e);
116       }
117    }
118
119    public void write(int id) throws RemoteException JavaDoc
120    {
121       try
122       {
123          long start = System.currentTimeMillis();
124          Session bean = lookupSession();
125          bean.write(id);
126          long end = System.currentTimeMillis();
127          log.debug("write ran in: "+(end - start));
128       }
129       catch(Exception JavaDoc e)
130       {
131          throw new RemoteException JavaDoc("write failure", e);
132       }
133    }
134
135    public void write(int low, int high) throws RemoteException JavaDoc
136    {
137       try
138       {
139          long start = System.currentTimeMillis();
140          Session bean = lookupSession();
141          bean.write(low, high);
142          long end = System.currentTimeMillis();
143          log.debug("write ran in: "+(end - start));
144       }
145       catch(Exception JavaDoc e)
146       {
147          throw new RemoteException JavaDoc("write failure", e);
148       }
149    }
150
151    public void setSessionContext(SessionContext JavaDoc context)
152    {
153    }
154    public void ejbCreate(String JavaDoc entityName) throws CreateException JavaDoc
155    {
156       this.entityName = entityName;
157    }
158    public void ejbRemove()
159    {
160    }
161    public void ejbActivate()
162    {
163    }
164    public void ejbPassivate()
165    {
166    }
167
168    private Session lookupSession() throws Exception JavaDoc
169    {
170       Context JavaDoc context = new InitialContext JavaDoc();
171       Object JavaDoc ref = context.lookup("java:comp/env/ejb/Session");
172       SessionHome home = (SessionHome) PortableRemoteObject.narrow(ref, SessionHome.class);
173       Session bean = home.create(entityName);
174       return bean;
175    }
176
177 }
178
Popular Tags