<commit_before>package edu.rice.rubbos.client;

import edu.rice.rubbos.beans.TimeManagement;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.lang.Runtime;
import java.net.URL;
import java.util.GregorianCalendar;
import java.util.Random;
import java.util.Vector;

/**
 * RUBBoS client emulator. 
 * This class plays random user sessions emulating a Web browser.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a> and <a href="mailto:<EMAIL>"><NAME></a>
 * @version 1.0
 */
public class ClientEmulator
{
  private RUBBoSProperties rubbos = null;        // access to rubbos.properties file
  private URLGenerator    urlGen = null;        // URL generator corresponding to the version to be used (PHP, EJB or Servlets)
  private static float    slowdownFactor = 0;
  private static boolean  endOfSimulation = false;

  /**
   * Creates a new <code>ClientEmulator</code> instance.
   * The program is stopped on any error reading the configuration files.
   */
  public ClientEmulator()
  {
    // Initialization, check that all files are ok
    rubbos = new RUBBoSProperties();
    urlGen = rubbos.checkPropertiesFileAndGetURLGenerator();
    if (urlGen == null)
      Runtime.getRuntime().exit(1);
    // Check that the transition table is ok and print it
    TransitionTable transition = new TransitionTable(rubbos.getNbOfColumns(), rubbos.getNbOfRows(), null, rubbos.useTPCWThinkTime());
    if (!transition.ReadExcelTextFile(rubbos.getUserTransitionTable()))
      Runtime.getRuntime().exit(1);
    else
      transition.displayMatrix("User");
    if (!transition.ReadExcelTextFile(rubbos.getAuthorTransitionTable()))
      Runtime.getRuntime().exit(1);
    else
      transition.displayMatrix("Author");
  }


  /**
   * Updates the slowdown factor.
   *
   * @param newValue new slowdown value
   */
  private synchronized void setSlowDownFactor(float newValue)
  {
    slowdownFactor = newValue;
  }


  /**
   * Get the slowdown factor corresponding to current ramp (up, session or down).
   */
  public static synchronized float getSlowDownFactor()
  {
    return slowdownFactor;
  }


  /**
   * Set the end of the current simulation
   */
  private synchronized void setEndOfSimulation()
  {
    endOfSimulation = true;
  }


  /**
   * True if end of simulation has been reached.
   */
  public static synchronized boolean isEndOfSimulation()
  {
    return endOfSimulation;
  }


  /**
   * Main program take an optional output file argument only 
   * if it is run on as a remote client.
   *
   * @param args optional output file if run as remote client
   */
  public static void main(String[] args)
  {
    GregorianCalendar startDate;
    GregorianCalendar endDate;
    GregorianCalendar upRampDate;
    GregorianCalendar runSessionDate;
    GregorianCalendar downRampDate;
    GregorianCalendar endDownRampDate;
    Process           webServerMonitor = null;
    Process           cjdbcServerMonitor = null;
    Process           dbServerMonitor = null;
    Process           clientMonitor = null;
    Process[]         remoteClientMonitor = null;
    Process[]         remoteClient = null;
    String            reportDir = "";
    String            tmpDir = "/tmp/";
    boolean           isMainClient = args.length == 0; // Check if we are the main client

    if (isMainClient)
    { 
      // Start by creating a report directory and redirecting output to an index.html file
      System.out.println("RUBBoS client emulator - (C) Rice University/INRIA 2001\n");
      reportDir = "/vagrant/"+TimeManagement.currentDateToString()+"/";
      try
      {
        System.out.println("Creating report directory "+reportDir);
        File dir = new File(reportDir);
        dir.mkdirs();
        if (!dir.isDirectory())
        {
          System.out.println("Unable to create "+reportDir+" using current directory instead");
          reportDir = "./";
        }
        else
          reportDir = dir.getCanonicalPath()+"/";
        System.out.println("Redirecting output to '"+reportDir+"index.html'");
        PrintStream outputStream = new PrintStream(new FileOutputStream(reportDir+"index.html"));
        System.out.println("Please wait while experiment is running ...");<commit_msg>Restore bench result directory<commit_after>package edu.rice.rubbos.client;

import edu.rice.rubbos.beans.TimeManagement;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.lang.Runtime;
import java.net.URL;
import java.util.GregorianCalendar;
import java.util.Random;
import java.util.Vector;

/**
 * RUBBoS client emulator. 
 * This class plays random user sessions emulating a Web browser.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a> and <a href="mailto:<EMAIL>"><NAME></a>
 * @version 1.0
 */
public class ClientEmulator
{
  private RUBBoSProperties rubbos = null;        // access to rubbos.properties file
  private URLGenerator    urlGen = null;        // URL generator corresponding to the version to be used (PHP, EJB or Servlets)
  private static float    slowdownFactor = 0;
  private static boolean  endOfSimulation = false;

  /**
   * Creates a new <code>ClientEmulator</code> instance.
   * The program is stopped on any error reading the configuration files.
   */
  public ClientEmulator()
  {
    // Initialization, check that all files are ok
    rubbos = new RUBBoSProperties();
    urlGen = rubbos.checkPropertiesFileAndGetURLGenerator();
    if (urlGen == null)
      Runtime.getRuntime().exit(1);
    // Check that the transition table is ok and print it
    TransitionTable transition = new TransitionTable(rubbos.getNbOfColumns(), rubbos.getNbOfRows(), null, rubbos.useTPCWThinkTime());
    if (!transition.ReadExcelTextFile(rubbos.getUserTransitionTable()))
      Runtime.getRuntime().exit(1);
    else
      transition.displayMatrix("User");
    if (!transition.ReadExcelTextFile(rubbos.getAuthorTransitionTable()))
      Runtime.getRuntime().exit(1);
    else
      transition.displayMatrix("Author");
  }


  /**
   * Updates the slowdown factor.
   *
   * @param newValue new slowdown value
   */
  private synchronized void setSlowDownFactor(float newValue)
  {
    slowdownFactor = newValue;
  }


  /**
   * Get the slowdown factor corresponding to current ramp (up, session or down).
   */
  public static synchronized float getSlowDownFactor()
  {
    return slowdownFactor;
  }


  /**
   * Set the end of the current simulation
   */
  private synchronized void setEndOfSimulation()
  {
    endOfSimulation = true;
  }


  /**
   * True if end of simulation has been reached.
   */
  public static synchronized boolean isEndOfSimulation()
  {
    return endOfSimulation;
  }


  /**
   * Main program take an optional output file argument only 
   * if it is run on as a remote client.
   *
   * @param args optional output file if run as remote client
   */
  public static void main(String[] args)
  {
    GregorianCalendar startDate;
    GregorianCalendar endDate;
    GregorianCalendar upRampDate;
    GregorianCalendar runSessionDate;
    GregorianCalendar downRampDate;
    GregorianCalendar endDownRampDate;
    Process           webServerMonitor = null;
    Process           cjdbcServerMonitor = null;
    Process           dbServerMonitor = null;
    Process           clientMonitor = null;
    Process[]         remoteClientMonitor = null;
    Process[]         remoteClient = null;
    String            reportDir = "";
    String            tmpDir = "/tmp/";
    boolean           isMainClient = args.length == 0; // Check if we are the main client

    if (isMainClient)
    { 
      // Start by creating a report directory and redirecting output to an index.html file
      System.out.println("RUBBoS client emulator - (C) Rice University/INRIA 2001\n");
      reportDir = "bench/"+TimeManagement.currentDateToString()+"/";
      try
      {
        System.out.println("Creating report directory "+reportDir);
        File dir = new File(reportDir);
        dir.mkdirs();
        if (!dir.isDirectory())
        {
          System.out.println("Unable to create "+reportDir+" using current directory instead");
          reportDir = "./";
        }
        else
          reportDir = dir.getCanonicalPath()+"/";
        System.out.println("Redirecting output to '"+reportDir+"index.html'");
        PrintStream outputStream = new PrintStream(new FileOutputStream(reportDir+"index.html"));
        System.out.println("Please wait while experiment is running ...");
{'fraction_non_alphanumeric': 0.09944814899977006, 'fraction_numerical': 0.0025293170843872156, 'mean_word_length': 3.014305491462852, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5210165', 'n_tokens_mistral': 2493, 'n_tokens_neox': 2378, 'n_words': 705}