1 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 ; 34 import javax.naming.Context ; 35 import javax.rmi.PortableRemoteObject ; 36 37 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 } 69 70 public long doTestByValue(int iterations) throws Exception 71 { 72 73 Context ctx = new InitialContext (); 74 Object 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 ("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 101 { 102 Context ctx = new InitialContext (); 103 Object 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 ("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 132 { 133 Context ctx = new InitialContext (); 134 Object 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 ("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 163 { 164 Context ctx = new InitialContext (); 165 Object 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 ("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 |