KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > testbyvalue > bean > RootStatelessSessionBean


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.testbyvalue.bean;
23
24 import org.jboss.test.testbyvalue.interfaces.ByValueStatelessSessionHome;
25 import org.jboss.test.testbyvalue.interfaces.ByValueStatelessSession;
26 import org.jboss.test.testbyvalue.interfaces.ByReferenceStatelessSessionHome;
27 import org.jboss.test.testbyvalue.interfaces.ByReferenceStatelessSession;
28 import org.jboss.test.testbyvalue.interfaces.ByValueEntityHome;
29 import org.jboss.test.testbyvalue.interfaces.ByValueEntity;
30
31 import java.rmi.*;
32 import javax.ejb.*;
33 import javax.naming.InitialContext JavaDoc;
34 import javax.naming.Context JavaDoc;
35 import javax.rmi.PortableRemoteObject JavaDoc;
36
37 /**
38  * $Id: RootStatelessSessionBean.java 58115 2006-11-04 08:42:14Z scott.stark@jboss.org $
39  * @author Clebert Suconic
40  */

41 public class RootStatelessSessionBean implements SessionBean
42 {
43    org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass());
44    private SessionContext sessionContext;
45
46    public void ejbCreate() throws RemoteException, CreateException
47    {
48    }
49
50    public void ejbActivate() throws RemoteException
51    {
52    }
53
54    public void ejbPassivate() throws RemoteException
55    {
56    }
57
58    public void ejbRemove() throws RemoteException
59    {
60    }
61
62    public void setSessionContext(SessionContext context) throws RemoteException
63    {
64       sessionContext = context;
65
66       //Exception e = new Exception("in set Session context");
67
//log.debug("failed", e);
68
}
69
70     public long doTestByValue(int iterations) throws Exception JavaDoc
71     {
72
73         Context JavaDoc ctx = new InitialContext JavaDoc();
74         Object JavaDoc objhome =
75                 ctx.lookup("java:comp/env/ejb/CalledByValue");
76
77         ByValueStatelessSessionHome home = (ByValueStatelessSessionHome) PortableRemoteObject.narrow(objhome, ByValueStatelessSessionHome.class);
78         ByValueStatelessSession session = home.create();
79
80         ClassWithProperty property = new ClassWithProperty();
81
82         property.setX(1000);
83
84         long initTime = System.currentTimeMillis();
85
86
87         for (int i=0;i<iterations;i++)
88         {
89             session.doTestByValue(property);
90
91             if (property.getX()!=1000)
92             {
93                 throw new RuntimeException JavaDoc("Property was changed in a call-by-value operation");
94             }
95         }
96
97         return System.currentTimeMillis() - initTime;
98     }
99
100     public long doTestByReference(int iterations) throws Exception JavaDoc
101     {
102         Context JavaDoc ctx = new InitialContext JavaDoc();
103         Object JavaDoc objhome =
104                 ctx.lookup("java:comp/env/ejb/CalledByReference");
105
106         ByReferenceStatelessSessionHome home = (ByReferenceStatelessSessionHome) PortableRemoteObject.narrow(objhome, ByReferenceStatelessSessionHome.class);
107         ByReferenceStatelessSession session = home.create();
108
109         ClassWithProperty property = new ClassWithProperty();
110
111         property.setX(1000);
112
113         long initTime = System.currentTimeMillis();
114
115
116         for (int i=0;i<iterations;i++)
117         {
118             session.doTestByReference(property);
119
120             if (property.getX()==1000)
121             {
122                 throw new RuntimeException JavaDoc("Property was not changed in a call-by-reference operation");
123             }
124
125             property.setX(1000);
126         }
127
128         return System.currentTimeMillis() - initTime;
129     }
130
131     public long doTestEntity(int iterations) throws Exception JavaDoc
132     {
133         Context JavaDoc ctx = new InitialContext JavaDoc();
134         Object JavaDoc objhome =
135                 ctx.lookup("java:comp/env/ejb/TestByValueEntity");
136
137         ByValueEntityHome home = (ByValueEntityHome) PortableRemoteObject.narrow(objhome, ByValueEntityHome.class);
138         ByValueEntity entity = home.create();
139
140         ClassWithProperty property = new ClassWithProperty();
141
142         property.setX(1000);
143
144         long initTime = System.currentTimeMillis();
145
146
147         for (int i=0;i<iterations;i++)
148         {
149             entity.doByValueTest(property);
150
151             if (property.getX()!=1000)
152             {
153                 throw new RuntimeException JavaDoc("Property was changed in a call-by-value operation");
154             }
155
156             property.setX(1000);
157         }
158
159         return System.currentTimeMillis() - initTime;
160     }
161
162     public long doTestEntityByReference(int iterations) throws Exception JavaDoc
163     {
164         Context JavaDoc ctx = new InitialContext JavaDoc();
165         Object JavaDoc objhome =
166                 ctx.lookup("java:comp/env/ejb/TestByReferenceEntity");
167
168         ByValueEntityHome home = (ByValueEntityHome) PortableRemoteObject.narrow(objhome, ByValueEntityHome.class);
169         ByValueEntity entity = home.create();
170
171         ClassWithProperty property = new ClassWithProperty();
172
173         property.setX(1000);
174
175         long initTime = System.currentTimeMillis();
176
177
178         for (int i=0;i<iterations;i++)
179         {
180             entity.doByValueTest(property);
181
182             if (property.getX()==1000)
183             {
184                 throw new RuntimeException JavaDoc("Property was not changed in a call-by-reference operation");
185             }
186
187             property.setX(1000);
188         }
189
190         return System.currentTimeMillis() - initTime;
191     }
192
193 }
194
Popular Tags