/*
 * Created on Nov 17, 2004
 *
 */

import java.io.File;
import java.util.HashMap;

import javax.naming.Context;
import javax.naming.NamingException;

import weblogic.jndi.Environment;
import worklist.TaskCreationSync;

import com.bea.wli.bpm.proxy.JpdProxy;
import com.bea.worklistSample.inputData.InputDataDocument;

/**
 * @author samratr
 *
 */
public class TaskCreationDriver
implements Runnable
{
  private static final int THREAD_COUNT=1;

  private CreateAndAssignTasks client;
  private HashMap props;
  private int iterationCount;

  public TaskCreationDriver()
  {
    client = new CreateAndAssignTasks();
    props = new HashMap();
    iterationCount = 1;
  }

  public TaskCreationDriver(int iterationCount)
  {
    this();
    this.iterationCount = iterationCount;
  }

  public void run()
  {
    try
    {
      props.put("input.document.store", System.getProperty("input.document.store"));
      client.init(props);

      for(int i=0; i<iterationCount; i++)
        client.execute();
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }
  }


  public static void main(String[] args)
  {
    TaskCreationDriver client = new TaskCreationDriver();

    try
    {
      int totalIterationCount = 1;
      String strRepeatCount = System.getProperty("repeat.count");

      if(strRepeatCount!=null)
        totalIterationCount = Integer.parseInt(strRepeatCount);

      for(int i=0; i<THREAD_COUNT; i++)
      {
        int localIterationCount = totalIterationCount / THREAD_COUNT;
        if(i==0) localIterationCount += totalIterationCount%THREAD_COUNT;

        if(localIterationCount>0)
          new Thread(new TaskCreationDriver(localIterationCount)).start();
      }
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }
  }

}

