/*
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999 Bull S.A.
 * Contact: jonas-team@objectweb.org
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas.stests.appli;

import java.rmi.RemoteException;

import javax.ejb.RemoveException;


/**
 * Appli Test 
 * @author Philippe Coq
 */
public class A_thread extends Thread {
    OrderEntryClerkHome home;
    int num;
    int orders;
    int lines;
    int numThread;

    public A_thread(OrderEntryClerkHome home, int numThread, int orders, int lines) {
        this.home = home;
        this.numThread = numThread;
        this.orders = orders;
        this.lines = lines;
    }


    public void run() {

        // Create a OrderEntryClerk bean
        OrderEntryClerk oecbean = null;

        try {
            oecbean = home.create();
        } catch (Exception e) {
            System.out.println("Cannot Create OrderEntryClerk bean:" + e);
            return;
        }

        try {
            

            // main loop
            for (int i = 0; i < orders; i++) {
                oecbean.setCustomer(new Integer(numThread+1));
                for (int j = 0; j < lines; j++) {
                    oecbean.addOrderLine(new Integer(j+1),j+2);
                }
                String numorder = oecbean.placeOrder();  
            }
            // delete Session
            oecbean.remove();
        } catch (RemoteException e) {
            System.out.println("Thread " + numThread + " : " + e);
 
        } catch (RemoveException e) {
            System.out.println("Thread " + numThread + " Cannot remove session: " + e);
 
        }
    }
}
