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_readthread extends Thread { 39 String managerName; 40 String name; 41 int accounts; 42 int loops; 43 Context ictx; 44 45 public A_readthread(String mName, int num, Context ictx, int accounts, int loops) { 46 managerName = mName; 47 name = managerName + "_readac_" + num; 48 setName(name); 49 this.ictx = ictx; 50 this.accounts = accounts; 51 this.loops = loops; 52 } 53 54 57 private int random(int max) throws RemoteException { 58 double d = Math.random(); 59 int ret = (int) (max * d); 60 return ret; 61 } 62 63 public void run() { 64 65 ManagerHome mgrHome = null; 67 Manager mgr = null; 68 try { 69 mgrHome = (ManagerHome) PortableRemoteObject.narrow(ictx.lookup(managerName), ManagerHome.class); 70 mgr = mgrHome.create(F_read.initialValue); 71 } catch (Exception e) { 72 System.out.println("Cannot Create Session:" + e); 73 return; 74 } 75 76 try { 77 78 int d1 = random(accounts); 80 int d2 = random(accounts); 81 int c1 = random(accounts); 82 int c2 = random(accounts); 83 mgr.setAccounts(d1, d2, c1, c2); 85 86 boolean ok = true; 88 for (int i = 0; i < loops; i++) { 89 int minval = mgr.readBalances(); 90 if (minval < 0) { 91 System.out.println("Bad read value " + minval); 92 F_read.threadfail = true; 93 break; 94 } 95 } 96 mgr.remove(); 98 } catch (RemoteException e) { 99 System.out.println("Thread " + name + " : " + e); 100 F_read.threadfail = true; 101 } catch (RemoveException e) { 102 System.out.println("Thread " + name + " Cannot remove session: " + e); 103 F_read.threadfail = true; 104 } 105 } 106 } 107 | Popular Tags |