1 25 26 package org.objectweb.jonas.stests.manac; 27 28 import java.rmi.RemoteException ; 29 import javax.ejb.RemoveException ; 30 import javax.naming.Context ; 31 import javax.rmi.PortableRemoteObject ; 32 33 34 38 public class A_thread extends Thread { 39 String managerName; 40 String name; 41 int accounts; 42 int delay; 43 int loops; 44 int amount; 45 Context ictx; 46 int checklevel; 47 48 public A_thread(String mName, int num, Context ictx, int accounts, int delay, int loops, int amount, int checklevel) { 49 managerName = mName; 50 name = managerName + "_manac_" + num; 51 setName(name); 52 this.ictx = ictx; 53 this.accounts = accounts; 54 this.delay = delay; 55 this.loops = loops; 56 this.amount = amount; 57 this.checklevel = checklevel; 58 } 59 60 63 private int random(int max) throws RemoteException { 64 double d = Math.random(); 65 int ret = (int) (max * d); 66 return ret; 67 } 68 69 public void run() { 70 71 ManagerHome mgrHome = null; 73 Manager mgr = null; 74 try { 75 mgrHome = (ManagerHome) PortableRemoteObject.narrow(ictx.lookup(managerName), 76 ManagerHome.class); 77 mgr = mgrHome.create(A_manac.initialValue); 78 } catch (Exception e) { 79 System.out.println("Cannot Create Session:" + e); 80 return; 81 } 82 83 try { 84 if (delay > 0) { 86 mgr.setDelay(delay); 87 } 88 if (amount > 0) { 89 mgr.setValue(amount); 90 } 91 92 boolean ok = true; 94 for (int i = 0; i < loops; i++) { 95 int d1 = random(accounts); 97 int d2 = random(accounts); 98 int c1 = random(accounts); 99 int c2 = random(accounts); 100 if (amount < 0) { 101 try { 103 mgr.withdraw(d1, c1, -amount); 104 } catch (RemoteException r) { 105 System.out.println("Exception (ignored) raised on withdraw:" + r); 106 } 107 } else { 108 try { 110 mgr.setAccounts(d1, d2, c1, c2); 111 } catch (RemoteException r) { 112 System.out.println("Bad Account Setting:" + r); 113 A_manac.threadfail = true; 114 break; 115 } 116 try { 118 mgr.movement(); 119 } catch (RemoteException r) { 120 System.out.println("Exception (ignored) raised on movement:" + r); 122 } 123 } 124 if (checklevel >= 2) { 125 if (! mgr.checkAccount(d1)) { 127 System.out.println("Bad Account after move on account " + d1); 128 ok = false; 129 } 130 if (! mgr.checkAccount(d2)) { 131 System.out.println("Bad Account after move on account " + d2); 132 ok = false; 133 } 134 if (!ok) { 135 System.out.println("Stopping this session because some accounts are not ok"); 136 A_manac.threadfail = true; 137 break; 138 } 139 } 140 } 141 mgr.remove(); 143 } catch (RemoteException e) { 144 System.out.println("Thread " + name + " : " + e); 145 A_manac.threadfail = true; 146 } catch (RemoveException e) { 147 System.out.println("Thread " + name + " Cannot remove session: " + e); 148 A_manac.threadfail = true; 149 } 150 } 151 } 152 | Popular Tags |