1 22 package org.jboss.test.perf.ejb; 23 24 import java.rmi.RemoteException ; 25 import java.rmi.ServerException ; 26 import javax.ejb.CreateException ; 27 import javax.ejb.RemoveException ; 28 import javax.ejb.SessionContext ; 29 import javax.naming.Context ; 30 import javax.naming.InitialContext ; 31 import javax.rmi.PortableRemoteObject ; 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 43 public class ClientSessionBean implements javax.ejb.SessionBean 44 { 45 private static Logger log = Logger.getLogger(ClientSessionBean.class); 46 private String entityName; 47 48 public void create(int low, int high) 49 throws CreateException , RemoteException 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 ce) 60 { 61 throw ce; 62 } 63 catch(Exception e) 64 { 65 log.error("create failed", e); 66 throw new CreateException (e.toString()); 67 } 68 } 69 70 public void remove(int low, int high) 71 throws RemoveException , RemoteException 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 e) 82 { 83 throw new RemoteException ("remove failure", e); 84 } 85 } 86 87 public void read(int id) throws RemoteException 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 e) 98 { 99 throw new RemoteException ("read failure", e); 100 } 101 } 102 103 public void read(int low, int high) throws RemoteException 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 e) 114 { 115 throw new RemoteException ("read failure", e); 116 } 117 } 118 119 public void write(int id) throws RemoteException 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 e) 130 { 131 throw new RemoteException ("write failure", e); 132 } 133 } 134 135 public void write(int low, int high) throws RemoteException 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 e) 146 { 147 throw new RemoteException ("write failure", e); 148 } 149 } 150 151 public void setSessionContext(SessionContext context) 152 { 153 } 154 public void ejbCreate(String entityName) throws CreateException 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 169 { 170 Context context = new InitialContext (); 171 Object 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 |