User: starksm
Date: 01/07/13 10:14:33
Modified: src/main/org/jboss/test/perf/ejb SessionBean.java
TxSessionBean.java
Added: src/main/org/jboss/test/perf/ejb ClientSessionBean.java
Log:
Add timing tests of bean-bean calls
Revision Changes Path
1.2 +122 -104 jbosstest/src/main/org/jboss/test/perf/ejb/SessionBean.java
Index: SessionBean.java
===================================================================
RCS file:
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/perf/ejb/SessionBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SessionBean.java 2000/08/25 13:43:43 1.1
+++ SessionBean.java 2001/07/13 17:14:33 1.2
@@ -1,121 +1,139 @@
package org.jboss.test.perf.ejb;
// SessionBean.java
+import java.rmi.RemoteException;
+import java.rmi.ServerException;
+import javax.ejb.CreateException;
+import javax.ejb.RemoveException;
+import javax.ejb.SessionContext;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.rmi.PortableRemoteObject;
+
import org.jboss.test.perf.interfaces.EntityHome;
import org.jboss.test.perf.interfaces.Entity;
import org.jboss.test.perf.interfaces.EntityPK;
-public class SessionBean implements javax.ejb.SessionBean {
+public class SessionBean implements javax.ejb.SessionBean
+{
+ private EntityHome entityHome;
+
+ public void setSessionContext(SessionContext context)
+ {
+ }
+
+ public void ejbCreate(String entityName) throws CreateException
+ {
+ try
+ {
+ Context context = new InitialContext();
+ Object ref = context.lookup(entityName);
+ entityHome = (EntityHome) PortableRemoteObject.narrow(ref,
EntityHome.class);
+ }
+ catch(NamingException e)
+ {
+ throw new CreateException("Cound not resolve name: " + e);
+ }
+ }
- private EntityHome _entityHome;
+ private Entity findByPrimaryKey(int key) throws java.rmi.RemoteException
+ {
+ try
+ {
+ EntityPK primaryKey = new EntityPK(key);
+ return entityHome.findByPrimaryKey(primaryKey);
+ }
+ catch(javax.ejb.FinderException e)
+ {
+ throw new ServerException("Cound not find Entity: " + key, e);
+ }
+ }
- public void setSessionContext(javax.ejb.SessionContext context) {
- }
+ private java.util.Enumeration findInRange(int min, int max) throws
java.rmi.RemoteException
+ {
+ try
+ {
+ return entityHome.findInRange(min, max);
+ }
+ catch(javax.ejb.FinderException e)
+ {
+ throw new ServerException("Cound not findInRange(" + min + ", " + max +
"): ", e);
+ }
+ }
- public void ejbCreate(String entityName) throws javax.ejb.CreateException {
- try {
- javax.naming.Context context = new javax.naming.InitialContext();
- Object ref = context.lookup(entityName);
-
- _entityHome = (EntityHome) ref;
- /** CHANGES: Note that WebLogic does not support the EJB Spec
- ** compliant way of casting, this code is commented out
- ** and a Java cast is used to enable code compilation
- _entityHome = (EntityHome) javax.rmi.PortableRemoteObject.narrow(ref,
EntityHome.class);
- **/
- }
- catch(javax.naming.NamingException e) {
- throw new javax.ejb.CreateException("Cound not resolve name: " + e);
- }
- }
-
- private Entity findByPrimaryKey(int key) throws java.rmi.RemoteException {
- try {
- EntityPK primaryKey = new EntityPK(key);
- return _entityHome.findByPrimaryKey(primaryKey);
- }
- catch(javax.ejb.FinderException e) {
- throw new java.rmi.ServerException("Cound not find Entity: " + key, e);
- }
- }
-
- private java.util.Enumeration findInRange(int min, int max) throws
java.rmi.RemoteException {
- try {
- return _entityHome.findInRange(min, max);
- }
- catch(javax.ejb.FinderException e) {
- throw new java.rmi.ServerException
- ("Cound not findInRange(" + min + ", " + max + "): ", e);
- }
- }
-
- public void create(int low, int high)
- throws java.rmi.RemoteException, javax.ejb.CreateException {
- for(int i = low; i < high; i++) {
- _entityHome.create(i, 0);
- }
- }
-
- public void remove(int low, int high)
- throws java.rmi.RemoteException, javax.ejb.RemoveException {
- if(low + 1 == high) {
- Entity entity = findByPrimaryKey(low);
- entity.remove();
- }
- else {
- java.util.Enumeration elements = findInRange(low, high);
- while(elements.hasMoreElements()) {
- Entity entity = (Entity) elements.nextElement();
- entity.remove();
- }
- }
- }
-
- public void read(int id) throws java.rmi.RemoteException {
- Entity entity = findByPrimaryKey(id);
- entity.read();
- }
-
- public void read(int low, int high) throws java.rmi.RemoteException {
- java.util.Enumeration elements = findInRange(low, high);
- while(elements.hasMoreElements()) {
- Entity entity = (Entity) elements.nextElement();
- /** CHANGES: Note that WebLogic does not support the EJB Spec
- ** compliant way of casting, this code is commented out
- ** and a Java cast is used to enable code compilation
- Entity entity = (Entity)
javax.rmi.PortableRemoteObject.narrow(elements.nextElement(), Entity.class);
- **/
+ public void create(int low, int high)
+ throws CreateException, RemoteException
+ {
+ for(int i = low; i < high; i++)
+ {
+ entityHome.create(i, 0);
+ }
+ }
+
+ public void remove(int low, int high)
+ throws RemoveException, RemoteException
+ {
+ if(low + 1 == high)
+ {
+ Entity entity = findByPrimaryKey(low);
+ entity.remove();
+ }
+ else
+ {
+ java.util.Enumeration elements = findInRange(low, high);
+ while(elements.hasMoreElements())
+ {
+ Entity entity = (Entity) elements.nextElement();
+ entity.remove();
+ }
+ }
+ }
+
+ public void read(int id) throws RemoteException
+ {
+ Entity entity = findByPrimaryKey(id);
entity.read();
- }
- }
+ }
+
+ public void read(int low, int high) throws RemoteException
+ {
+ java.util.Enumeration elements = findInRange(low, high);
+ while(elements.hasMoreElements())
+ {
+ Entity entity = (Entity) elements.nextElement();
+ entity.read();
+ }
+ }
- public void write(int id) throws java.rmi.RemoteException {
- Entity entity = findByPrimaryKey(id);
- int value = entity.read();
- entity.write(value + 1);
- }
-
- public void write(int low, int high) throws java.rmi.RemoteException {
- java.util.Enumeration elements = findInRange(low, high);
- while(elements.hasMoreElements()) {
- Entity entity = (Entity) elements.nextElement();
- /** CHANGES: Note that WebLogic does not support the EJB Spec
- ** compliant way of casting, this code is commented out
- ** and a Java cast is used to enable code compilation
- Entity entity = (Entity)
javax.rmi.PortableRemoteObject.narrow(elements.nextElement(), Entity.class);
- **/
+ public void write(int id) throws RemoteException
+ {
+ Entity entity = findByPrimaryKey(id);
int value = entity.read();
entity.write(value + 1);
- }
- }
+ }
- public void ejbRemove() {
- }
-
- public void ejbActivate() {
- }
-
- public void ejbPassivate() {
- }
+ public void write(int low, int high) throws RemoteException
+ {
+ java.util.Enumeration elements = findInRange(low, high);
+ while(elements.hasMoreElements())
+ {
+ Entity entity = (Entity) elements.nextElement();
+ int value = entity.read();
+ entity.write(value + 1);
+ }
+ }
+ public void ejbRemove()
+ {
+ }
+
+ public void ejbActivate()
+ {
+ }
+
+ public void ejbPassivate()
+ {
+ }
+
}
1.2 +205 -205 jbosstest/src/main/org/jboss/test/perf/ejb/TxSessionBean.java
Index: TxSessionBean.java
===================================================================
RCS file:
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/perf/ejb/TxSessionBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TxSessionBean.java 2001/07/11 08:30:33 1.1
+++ TxSessionBean.java 2001/07/13 17:14:33 1.2
@@ -1,205 +1,205 @@
-package org.jboss.test.perf.ejb;
-
-import java.rmi.RemoteException;
-import javax.ejb.CreateException;
-import javax.ejb.EJBException;
-import javax.ejb.SessionBean;
-import javax.ejb.SessionContext;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import org.jboss.test.perf.interfaces.TxSession;
-
-public class TxSessionBean implements SessionBean
-{
- private SessionContext sessionContext;
- private InitialContext iniCtx;
-
- public void ejbCreate() throws CreateException
- {
- }
-
- public void ejbActivate()
- {
- System.out.println("TxSessionBean.ejbActivate() called");
- }
-
- public void ejbPassivate()
- {
- System.out.println("TxSessionBean.ejbPassivate() called");
- }
-
- public void ejbRemove()
- {
- System.out.println("TxSessionBean.ejbRemove() called");
- }
-
- public void setSessionContext(SessionContext context)
- {
- sessionContext = context;
- try
- {
- iniCtx = new InitialContext();
- }
- catch(NamingException e)
- {
- throw new EJBException(e);
- }
- }
-
- /*
- * This method is defined with "Required"
- */
- public String txRequired()
- {
- Transaction tx = getDaTransaction();
- if (tx == null)
- throw new EJBException("Required sees no transaction");
- else
- return ("required sees a transaction "+tx.hashCode());
- }
-
-
- /*
- * This method is defined with "Requires_new"
- */
- public String txRequiresNew()
- {
- Object tx =getDaTransaction();
- if (tx == null)
- throw new EJBException("RequiresNew sees no transaction");
- else
- return ("requiresNew sees a transaction "+tx.hashCode());
- }
-
- /*
- * testSupports is defined with Supports
- */
- public String txSupports()
- {
- Object tx =getDaTransaction();
- if (tx == null)
- return "supports sees no transaction";
- else
- return "supports sees a transaction "+tx.hashCode();
- }
-
- /*
- * This method is defined with "Mandatory"
- */
- public String txMandatory()
- {
- Object tx =getDaTransaction();
- if (tx == null)
- throw new EJBException("Mandatory sees no transaction");
- else
- return ("mandatory sees a transaction "+tx.hashCode());
- }
-
- /*
- * This method is defined with "Never"
- */
- public String txNever()
- {
- Object tx =getDaTransaction();
- if (tx == null)
- return "never sees no transaction";
- else
- throw new EJBException("txNever sees a transaction");
- }
-
- /*
- * This method is defined with "TxNotSupported"
- */
- public String txNotSupported()
- {
- Object tx =getDaTransaction();
- if (tx == null)
- return "notSupported sees no transaction";
- else
- throw new EJBException("txNotSupported sees a transaction");
- }
-
- /*
- * This method is defined with "Required" and it passes it to a Supports Tx
- */
- public String requiredToSupports() throws RemoteException
- {
- String message;
- Object tx =getDaTransaction();
- if (tx == null)
- throw new EJBException("Required doesn't see a transaction");
- else
- message = "Required sees a transaction "+tx.hashCode()+ " Supports should
see the same ";
-
- message = message + ((TxSession) sessionContext.getEJBObject()).txSupports();
-
- // And after invocation we should have the same transaction
- tx =getDaTransaction();
- if (tx == null)
- throw new EJBException("Required doesn't see a transaction COMING BACK");
- else
- return message + " on coming back Required sees a transaction
"+tx.hashCode() ;
-
- }
-
- /*
- * This method is defined with "Required" and it passes it to a Mandatory Tx
- */
- public String requiredToMandatory() throws RemoteException
- {
- String message;
- Object tx =getDaTransaction();
- if (tx == null)
- throw new EJBException("Required doesn't see a transaction");
- else
- message = "Required sees a transaction "+tx.hashCode()+ " NotSupported
should see the same ";
-
-
- message = message + ((TxSession) sessionContext.getEJBObject()).txMandatory();
-
- // And after invocation we should have the same transaction
- tx =getDaTransaction();
- if (tx == null)
- throw new EJBException("Required doesn't see a transaction COMING BACK");
- else
- return message + " on coming back Required sees a transaction
"+tx.hashCode() ;
- }
-
- public String requiredToRequiresNew() throws RemoteException
- {
- String message;
- Object tx =getDaTransaction();
- if (tx == null)
- throw new EJBException("Required doesn't see a transaction");
- else
- message = "Required sees a transaction "+tx.hashCode()+ " Requires new
should see a new transaction ";
-
- message = message + ((TxSession)
sessionContext.getEJBObject()).txRequiresNew();
-
- // And after invocation we should have the same transaction
- tx =getDaTransaction();
- if (tx == null)
- throw new EJBException("Required doesn't see a transaction COMING BACK");
- else
- return message + " on coming back Required sees a transaction
"+tx.hashCode() ;
- }
-
- private Transaction getDaTransaction()
- {
- Transaction t = null;
- try
- {
- TransactionManager tm = (TransactionManager)
iniCtx.lookup("java:/TransactionManager");
- t = tm.getTransaction();
- }
- catch(Exception e)
- {
- }
- return t;
- }
-
-}
+package org.jboss.test.perf.ejb;
+
+import java.rmi.RemoteException;
+import javax.ejb.CreateException;
+import javax.ejb.EJBException;
+import javax.ejb.SessionBean;
+import javax.ejb.SessionContext;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.jboss.test.perf.interfaces.TxSession;
+
+public class TxSessionBean implements SessionBean
+{
+ private SessionContext sessionContext;
+ private InitialContext iniCtx;
+
+ public void ejbCreate() throws CreateException
+ {
+ }
+
+ public void ejbActivate()
+ {
+ System.out.println("TxSessionBean.ejbActivate() called");
+ }
+
+ public void ejbPassivate()
+ {
+ System.out.println("TxSessionBean.ejbPassivate() called");
+ }
+
+ public void ejbRemove()
+ {
+ System.out.println("TxSessionBean.ejbRemove() called");
+ }
+
+ public void setSessionContext(SessionContext context)
+ {
+ sessionContext = context;
+ try
+ {
+ iniCtx = new InitialContext();
+ }
+ catch(NamingException e)
+ {
+ throw new EJBException(e);
+ }
+ }
+
+ /*
+ * This method is defined with "Required"
+ */
+ public String txRequired()
+ {
+ Transaction tx = getDaTransaction();
+ if (tx == null)
+ throw new EJBException("Required sees no transaction");
+ else
+ return ("required sees a transaction "+tx.hashCode());
+ }
+
+
+ /*
+ * This method is defined with "Requires_new"
+ */
+ public String txRequiresNew()
+ {
+ Object tx =getDaTransaction();
+ if (tx == null)
+ throw new EJBException("RequiresNew sees no transaction");
+ else
+ return ("requiresNew sees a transaction "+tx.hashCode());
+ }
+
+ /*
+ * testSupports is defined with Supports
+ */
+ public String txSupports()
+ {
+ Object tx =getDaTransaction();
+ if (tx == null)
+ return "supports sees no transaction";
+ else
+ return "supports sees a transaction "+tx.hashCode();
+ }
+
+ /*
+ * This method is defined with "Mandatory"
+ */
+ public String txMandatory()
+ {
+ Object tx =getDaTransaction();
+ if (tx == null)
+ throw new EJBException("Mandatory sees no transaction");
+ else
+ return ("mandatory sees a transaction "+tx.hashCode());
+ }
+
+ /*
+ * This method is defined with "Never"
+ */
+ public String txNever()
+ {
+ Object tx =getDaTransaction();
+ if (tx == null)
+ return "never sees no transaction";
+ else
+ throw new EJBException("txNever sees a transaction");
+ }
+
+ /*
+ * This method is defined with "TxNotSupported"
+ */
+ public String txNotSupported()
+ {
+ Object tx =getDaTransaction();
+ if (tx == null)
+ return "notSupported sees no transaction";
+ else
+ throw new EJBException("txNotSupported sees a transaction");
+ }
+
+ /*
+ * This method is defined with "Required" and it passes it to a Supports Tx
+ */
+ public String requiredToSupports() throws RemoteException
+ {
+ String message;
+ Object tx =getDaTransaction();
+ if (tx == null)
+ throw new EJBException("Required doesn't see a transaction");
+ else
+ message = "Required sees a transaction "+tx.hashCode()+ " Supports should
see the same ";
+
+ message = message + ((TxSession) sessionContext.getEJBObject()).txSupports();
+
+ // And after invocation we should have the same transaction
+ tx =getDaTransaction();
+ if (tx == null)
+ throw new EJBException("Required doesn't see a transaction COMING BACK");
+ else
+ return message + " on coming back Required sees a transaction
"+tx.hashCode() ;
+
+ }
+
+ /*
+ * This method is defined with "Required" and it passes it to a Mandatory Tx
+ */
+ public String requiredToMandatory() throws RemoteException
+ {
+ String message;
+ Object tx =getDaTransaction();
+ if (tx == null)
+ throw new EJBException("Required doesn't see a transaction");
+ else
+ message = "Required sees a transaction "+tx.hashCode()+ " NotSupported
should see the same ";
+
+
+ message = message + ((TxSession) sessionContext.getEJBObject()).txMandatory();
+
+ // And after invocation we should have the same transaction
+ tx =getDaTransaction();
+ if (tx == null)
+ throw new EJBException("Required doesn't see a transaction COMING BACK");
+ else
+ return message + " on coming back Required sees a transaction
"+tx.hashCode() ;
+ }
+
+ public String requiredToRequiresNew() throws RemoteException
+ {
+ String message;
+ Object tx =getDaTransaction();
+ if (tx == null)
+ throw new EJBException("Required doesn't see a transaction");
+ else
+ message = "Required sees a transaction "+tx.hashCode()+ " Requires new
should see a new transaction ";
+
+ message = message + ((TxSession)
sessionContext.getEJBObject()).txRequiresNew();
+
+ // And after invocation we should have the same transaction
+ tx = getDaTransaction();
+ if (tx == null)
+ throw new EJBException("Required doesn't see a transaction COMING BACK");
+ else
+ return message + " on coming back Required sees a transaction
"+tx.hashCode() ;
+ }
+
+ private Transaction getDaTransaction()
+ {
+ Transaction t = null;
+ try
+ {
+ TransactionManager tm = (TransactionManager)
iniCtx.lookup("java:/TransactionManager");
+ t = tm.getTransaction();
+ }
+ catch(Exception e)
+ {
+ }
+ return t;
+ }
+
+}
1.1
jbosstest/src/main/org/jboss/test/perf/ejb/ClientSessionBean.java
Index: ClientSessionBean.java
===================================================================
package org.jboss.test.perf.ejb;
// SessionBean.java
import java.rmi.RemoteException;
import java.rmi.ServerException;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.ejb.SessionContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import org.jboss.test.perf.interfaces.SessionHome;
import org.jboss.test.perf.interfaces.Session;
/** An implementation of the Session interface that delegates its calls
to the SessionBean implementation to test session to session bean timings.
*/
public class ClientSessionBean implements javax.ejb.SessionBean
{
private String entityName;
public void create(int low, int high)
throws CreateException, RemoteException
{
try
{
long start = System.currentTimeMillis();
Session bean = lookupSession();
bean.create(low, high);
long end = System.currentTimeMillis();
System.out.println("create ran in: "+(end - start));
}
catch(Exception e)
{
throw new CreateException(e.toString());
}
}
public void remove(int low, int high)
throws RemoveException, RemoteException
{
try
{
long start = System.currentTimeMillis();
Session bean = lookupSession();
bean.remove(low, high);
long end = System.currentTimeMillis();
System.out.println("remove ran in: "+(end - start));
}
catch(Exception e)
{
throw new RemoteException("remove failure", e);
}
}
public void read(int id) throws RemoteException
{
try
{
long start = System.currentTimeMillis();
Session bean = lookupSession();
bean.read(id);
long end = System.currentTimeMillis();
System.out.println("read ran in: "+(end - start));
}
catch(Exception e)
{
throw new RemoteException("read failure", e);
}
}
public void read(int low, int high) throws RemoteException
{
try
{
long start = System.currentTimeMillis();
Session bean = lookupSession();
bean.read(low, high);
long end = System.currentTimeMillis();
System.out.println("read ran in: "+(end - start));
}
catch(Exception e)
{
throw new RemoteException("read failure", e);
}
}
public void write(int id) throws RemoteException
{
try
{
long start = System.currentTimeMillis();
Session bean = lookupSession();
bean.write(id);
long end = System.currentTimeMillis();
System.out.println("write ran in: "+(end - start));
}
catch(Exception e)
{
throw new RemoteException("write failure", e);
}
}
public void write(int low, int high) throws RemoteException
{
try
{
long start = System.currentTimeMillis();
Session bean = lookupSession();
bean.write(low, high);
long end = System.currentTimeMillis();
System.out.println("write ran in: "+(end - start));
}
catch(Exception e)
{
throw new RemoteException("write failure", e);
}
}
public void setSessionContext(SessionContext context)
{
}
public void ejbCreate(String entityName) throws CreateException
{
this.entityName = entityName;
}
public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}
private Session lookupSession() throws Exception
{
Context context = new InitialContext();
Object ref = context.lookup("Session");
SessionHome home = (SessionHome) PortableRemoteObject.narrow(ref,
SessionHome.class);
Session bean = home.create(entityName);
return bean;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development