1 22 package org.jboss.test.dtm.ejb; 23 24 import java.rmi.RemoteException ; 25 26 import javax.ejb.EJBException ; 27 import javax.naming.Context ; 28 import javax.naming.InitialContext ; 29 import javax.rmi.PortableRemoteObject ; 30 31 import org.jboss.logging.Logger; 32 import org.jboss.test.dtm.interfaces.Account; 33 import org.jboss.test.dtm.interfaces.AccountHome; 34 import org.jboss.test.util.ejb.SessionSupport; 35 36 42 public class WorkerBean 43 extends SessionSupport 44 { 45 private static transient Logger log = 46 Logger.getLogger(WorkerBean.class); 47 48 private String testName; 49 private Account account1, account2; 50 51 public void ejbCreate(String name) 52 { 53 this.testName = name; 54 log = Logger.getLogger(WorkerBean.class.getName() + "#" + testName); 55 log.debug("ejbCreate(" + name + "), ctx=" + sessionCtx); 56 initAccounts(); 57 } 58 59 public void setBalances(int value1, int value2) 60 { 61 try 62 { 63 account1.setBalance(value1); 64 account2.setBalance(value2); 65 } 66 catch (RemoteException e) 67 { 68 throw new EJBException (e); 69 } 70 } 71 72 public int[] getBalances() 73 { 74 try 75 { 76 int[] balances = new int[2]; 77 balances[0] = account1.getBalance(); 78 balances[1] = account2.getBalance(); 79 return balances; 80 } 81 catch (RemoteException e) 82 { 83 throw new EJBException (e); 84 } 85 } 86 87 public void addToBalances(int value) 88 { 89 try 90 { 91 account1.addToBalance(value); 92 account2.addToBalance(value); 93 } 94 catch (RemoteException e) 95 { 96 throw new EJBException (e); 97 } 98 } 99 100 public void setRollbackOnly() 101 { 102 sessionCtx.setRollbackOnly(); 103 } 104 105 public void tellFirstAccountToSetRollbackOnly() 106 { 107 try 108 { 109 account1.setRollbackOnly(); 110 } 111 catch (RemoteException e) 112 { 113 throw new EJBException (e); 114 } 115 } 116 117 public void tellSecondAccountToSetRollbackOnly() 118 { 119 try 120 { 121 account2.setRollbackOnly(); 122 } 123 catch (RemoteException e) 124 { 125 throw new EJBException (e); 126 } 127 } 128 129 private void initAccounts() 130 { 131 try 132 { 133 Object objref; 134 AccountHome home; 135 Context iniCtx = new InitialContext (); 136 137 objref = iniCtx.lookup("java:comp/env/ejb/Account1"); 138 home = (AccountHome) 139 PortableRemoteObject.narrow(objref, AccountHome.class); 140 account1 = home.create("account1", 0); 141 142 objref = iniCtx.lookup("java:comp/env/ejb/Account2"); 143 home = (AccountHome) 144 PortableRemoteObject.narrow(objref, AccountHome.class); 145 account2 = home.create("account2", 0); 146 147 } 148 catch (Exception e) 149 { 150 throw new EJBException (e); 151 } 152 } 153 154 } 155 | Popular Tags |