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.testbyvalue.bean;
023:
024: import org.jboss.test.testbyvalue.interfaces.ByValueStatelessSessionHome;
025: import org.jboss.test.testbyvalue.interfaces.ByValueStatelessSession;
026: import org.jboss.test.testbyvalue.interfaces.ByReferenceStatelessSessionHome;
027: import org.jboss.test.testbyvalue.interfaces.ByReferenceStatelessSession;
028: import org.jboss.test.testbyvalue.interfaces.ByValueEntityHome;
029: import org.jboss.test.testbyvalue.interfaces.ByValueEntity;
030:
031: import java.rmi.*;
032: import javax.ejb.*;
033: import javax.naming.InitialContext;
034: import javax.naming.Context;
035: import javax.rmi.PortableRemoteObject;
036:
037: /**
038: * $Id: RootStatelessSessionBean.java 57211 2006-09-26 12:39:46Z dimitris@jboss.org $
039: * @author Clebert Suconic
040: */
041: public class RootStatelessSessionBean implements SessionBean {
042: org.apache.log4j.Category log = org.apache.log4j.Category
043: .getInstance(getClass());
044: private SessionContext sessionContext;
045:
046: public void ejbCreate() throws RemoteException, CreateException {
047: }
048:
049: public void ejbActivate() throws RemoteException {
050: }
051:
052: public void ejbPassivate() throws RemoteException {
053: }
054:
055: public void ejbRemove() throws RemoteException {
056: }
057:
058: public void setSessionContext(SessionContext context)
059: throws RemoteException {
060: sessionContext = context;
061:
062: //Exception e = new Exception("in set Session context");
063: //log.debug("failed", e);
064: }
065:
066: public long doTestByValue(int iterations) throws Exception {
067:
068: Context ctx = new InitialContext();
069: Object objhome = ctx.lookup("java:comp/env/ejb/CalledByValue");
070:
071: ByValueStatelessSessionHome home = (ByValueStatelessSessionHome) PortableRemoteObject
072: .narrow(objhome, ByValueStatelessSessionHome.class);
073: ByValueStatelessSession session = home.create();
074:
075: ClassWithProperty property = new ClassWithProperty();
076:
077: property.setX(1000);
078:
079: long initTime = System.currentTimeMillis();
080:
081: for (int i = 0; i < iterations; i++) {
082: session.doTestByValue(property);
083:
084: if (property.getX() != 1000) {
085: throw new RuntimeException(
086: "Property was changed in a call-by-value operation");
087: }
088: }
089:
090: return System.currentTimeMillis() - initTime;
091: }
092:
093: public long doTestByReference(int iterations) throws Exception {
094: Context ctx = new InitialContext();
095: Object objhome = ctx
096: .lookup("java:comp/env/ejb/CalledByReference");
097:
098: ByReferenceStatelessSessionHome home = (ByReferenceStatelessSessionHome) PortableRemoteObject
099: .narrow(objhome, ByReferenceStatelessSessionHome.class);
100: ByReferenceStatelessSession session = home.create();
101:
102: ClassWithProperty property = new ClassWithProperty();
103:
104: property.setX(1000);
105:
106: long initTime = System.currentTimeMillis();
107:
108: for (int i = 0; i < iterations; i++) {
109: session.doTestByReference(property);
110:
111: if (property.getX() == 1000) {
112: throw new RuntimeException(
113: "Property was not changed in a call-by-reference operation");
114: }
115:
116: property.setX(1000);
117: }
118:
119: return System.currentTimeMillis() - initTime;
120: }
121:
122: public long doTestEntity(int iterations) throws Exception {
123: Context ctx = new InitialContext();
124: Object objhome = ctx
125: .lookup("java:comp/env/ejb/TestByValueEntity");
126:
127: ByValueEntityHome home = (ByValueEntityHome) PortableRemoteObject
128: .narrow(objhome, ByValueEntityHome.class);
129: ByValueEntity entity = home.create();
130:
131: ClassWithProperty property = new ClassWithProperty();
132:
133: property.setX(1000);
134:
135: long initTime = System.currentTimeMillis();
136:
137: for (int i = 0; i < iterations; i++) {
138: entity.doByValueTest(property);
139:
140: if (property.getX() != 1000) {
141: throw new RuntimeException(
142: "Property was changed in a call-by-value operation");
143: }
144:
145: property.setX(1000);
146: }
147:
148: return System.currentTimeMillis() - initTime;
149: }
150:
151: public long doTestEntityByReference(int iterations)
152: throws Exception {
153: Context ctx = new InitialContext();
154: Object objhome = ctx
155: .lookup("java:comp/env/ejb/TestByReferenceEntity");
156:
157: ByValueEntityHome home = (ByValueEntityHome) PortableRemoteObject
158: .narrow(objhome, ByValueEntityHome.class);
159: ByValueEntity entity = home.create();
160:
161: ClassWithProperty property = new ClassWithProperty();
162:
163: property.setX(1000);
164:
165: long initTime = System.currentTimeMillis();
166:
167: for (int i = 0; i < iterations; i++) {
168: entity.doByValueTest(property);
169:
170: if (property.getX() == 1000) {
171: throw new RuntimeException(
172: "Property was not changed in a call-by-reference operation");
173: }
174:
175: property.setX(1000);
176: }
177:
178: return System.currentTimeMillis() - initTime;
179: }
180:
181: }
|