001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: A_remthread.java 2626 2003-06-19 07:33:27Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.stests.manac;
027:
028: import java.rmi.RemoteException;
029: import javax.ejb.RemoveException;
030: import javax.naming.Context;
031: import javax.rmi.PortableRemoteObject;
032:
033: /**
034: * Stress Test with create/remove
035: * @author Philippe Durieux
036: */
037: public class A_remthread extends Thread {
038: String managerName;
039: String name;
040: int accounts;
041: int loops;
042: Context ictx;
043:
044: public A_remthread(String mName, int num, Context ictx,
045: int accounts, int loops) {
046: managerName = mName;
047: name = managerName + "_remac_" + num;
048: setName(name);
049: this .ictx = ictx;
050: this .accounts = accounts;
051: this .loops = loops;
052: }
053:
054: /**
055: * random returns an integer between 0 and max - 1
056: */
057: private int random(int max) throws RemoteException {
058: double d = Math.random();
059: int ret = (int) (max * d);
060: return ret;
061: }
062:
063: public void run() {
064:
065: // Create a session bean
066: ManagerHome mgrHome = null;
067: Manager mgr = null;
068: try {
069: mgrHome = (ManagerHome) PortableRemoteObject.narrow(ictx
070: .lookup(managerName), ManagerHome.class);
071: mgr = mgrHome.create(F_remove.initialValue);
072: } catch (Exception e) {
073: System.out.println("Cannot Create Session:" + e);
074: return;
075: }
076:
077: try {
078: // main loop
079: boolean ok = true;
080: for (int i = 0; i < loops; i++) {
081: // Choose an account randomly
082: int a1 = random(accounts);
083: // Remove it or Create it randomly
084: int value = random(100);
085: if (value < 10) {
086: mgr.delAccount(a1);
087: } else {
088: mgr.getAccount(a1);
089: }
090: }
091:
092: // delete Session
093: mgr.remove();
094: } catch (RemoteException e) {
095: System.out.println("Thread " + name + " : " + e);
096: F_remove.threadfail = true;
097: } catch (RemoveException e) {
098: System.out.println("Thread " + name
099: + " Cannot remove bean: " + e);
100: F_remove.threadfail = true;
101: }
102: }
103: }
|