001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.perf.ejb;
023:
024: import java.rmi.RemoteException;
025: import java.rmi.ServerException;
026: import javax.ejb.CreateException;
027: import javax.ejb.RemoveException;
028: import javax.ejb.SessionContext;
029: import javax.naming.Context;
030: import javax.naming.InitialContext;
031: import javax.rmi.PortableRemoteObject;
032:
033: import org.apache.log4j.Logger;
034:
035: import org.jboss.test.perf.interfaces.SessionHome;
036: import org.jboss.test.perf.interfaces.Session;
037:
038: /** An implementation of the Session interface that delegates its calls
039: to the SessionBean implementation to test session to session bean timings.
040:
041: @version $Revision: 57211 $
042: */
043: public class ClientSessionBean implements javax.ejb.SessionBean {
044: private static Logger log = Logger
045: .getLogger(ClientSessionBean.class);
046: private String entityName;
047:
048: public void create(int low, int high) throws CreateException,
049: RemoteException {
050: try {
051: long start = System.currentTimeMillis();
052: Session bean = lookupSession();
053: bean.create(low, high);
054: long end = System.currentTimeMillis();
055: log.debug("create ran in: " + (end - start));
056: } catch (CreateException ce) {
057: throw ce;
058: } catch (Exception e) {
059: log.error("create failed", e);
060: throw new CreateException(e.toString());
061: }
062: }
063:
064: public void remove(int low, int high) throws RemoveException,
065: RemoteException {
066: try {
067: long start = System.currentTimeMillis();
068: Session bean = lookupSession();
069: bean.remove(low, high);
070: long end = System.currentTimeMillis();
071: log.debug("remove ran in: " + (end - start));
072: } catch (Exception e) {
073: throw new RemoteException("remove failure", e);
074: }
075: }
076:
077: public void read(int id) throws RemoteException {
078: try {
079: long start = System.currentTimeMillis();
080: Session bean = lookupSession();
081: bean.read(id);
082: long end = System.currentTimeMillis();
083: log.debug("read ran in: " + (end - start));
084: } catch (Exception e) {
085: throw new RemoteException("read failure", e);
086: }
087: }
088:
089: public void read(int low, int high) throws RemoteException {
090: try {
091: long start = System.currentTimeMillis();
092: Session bean = lookupSession();
093: bean.read(low, high);
094: long end = System.currentTimeMillis();
095: log.debug("read ran in: " + (end - start));
096: } catch (Exception e) {
097: throw new RemoteException("read failure", e);
098: }
099: }
100:
101: public void write(int id) throws RemoteException {
102: try {
103: long start = System.currentTimeMillis();
104: Session bean = lookupSession();
105: bean.write(id);
106: long end = System.currentTimeMillis();
107: log.debug("write ran in: " + (end - start));
108: } catch (Exception e) {
109: throw new RemoteException("write failure", e);
110: }
111: }
112:
113: public void write(int low, int high) throws RemoteException {
114: try {
115: long start = System.currentTimeMillis();
116: Session bean = lookupSession();
117: bean.write(low, high);
118: long end = System.currentTimeMillis();
119: log.debug("write ran in: " + (end - start));
120: } catch (Exception e) {
121: throw new RemoteException("write failure", e);
122: }
123: }
124:
125: public void setSessionContext(SessionContext context) {
126: }
127:
128: public void ejbCreate(String entityName) throws CreateException {
129: this .entityName = entityName;
130: }
131:
132: public void ejbRemove() {
133: }
134:
135: public void ejbActivate() {
136: }
137:
138: public void ejbPassivate() {
139: }
140:
141: private Session lookupSession() throws Exception {
142: Context context = new InitialContext();
143: Object ref = context.lookup("java:comp/env/ejb/Session");
144: SessionHome home = (SessionHome) PortableRemoteObject.narrow(
145: ref, SessionHome.class);
146: Session bean = home.create(entityName);
147: return bean;
148: }
149:
150: }
|