Exemplo n.º 1
0
    @Override
    public void run() {
      if (m_txnRate == -1) {
        if (m_sampler != null) {
          m_sampler.start();
        }
        try {
          runLoop();
        } catch (final IOException e) {
        } catch (final InterruptedException e) {
        }
      } else {
        System.err.println(
            "Running rate controlled m_txnRate == "
                + m_txnRate
                + " m_txnsPerMillisecond == "
                + m_txnsPerMillisecond);
        System.err.flush();
        rateControlledRunLoop();
      }

      if (m_exitOnCompletion) {
        System.exit(0);
      }
    }
Exemplo n.º 2
0
 /**
  * Derived classes implementing a main that will be invoked at the start of the app should call
  * this main to instantiate themselves
  *
  * @param clientClass Derived class to instantiate
  * @param args
  * @param startImmediately Whether to start the client thread immediately or not.
  */
 public static void main(
     final Class<? extends ClientMain> clientClass,
     final String args[],
     final boolean startImmediately) {
   try {
     final Constructor<? extends ClientMain> constructor =
         clientClass.getConstructor(new Class<?>[] {new String[0].getClass()});
     final ClientMain clientMain = constructor.newInstance(new Object[] {args});
     if (startImmediately) {
       final ControlWorker worker = clientMain.new ControlWorker();
       worker.start();
       // Wait for the worker to finish
       worker.join();
     } else {
       clientMain.start();
     }
   } catch (final Exception e) {
     e.printStackTrace();
     System.exit(-1);
   }
 }
Exemplo n.º 3
0
    public void run() {
      String command = "";
      final InputStreamReader reader = new InputStreamReader(System.in);
      final BufferedReader in = new BufferedReader(reader);

      // transition to ready and send ready message
      if (m_controlState == ControlState.PREPARING) {
        System.out.printf("%d,%s\n", System.currentTimeMillis(), ControlState.READY.display);
        m_controlState = ControlState.READY;
      } else {
        System.err.println("Error - not starting prepared!");
        System.err.println(m_controlState.display + " " + m_reason);
      }

      while (true) {
        try {
          command = in.readLine();
        } catch (final IOException e) {
          // Hm. quit?
          System.err.println("Error on standard input: " + e.getMessage());
          System.exit(-1);
        }

        if (command.equalsIgnoreCase("START")) {
          if (m_controlState != ControlState.READY) {
            setState(ControlState.ERROR, "START when not READY.");
            answerWithError();
            continue;
          }
          answerStart();
          m_controlState = ControlState.RUNNING;
        } else if (command.equalsIgnoreCase("POLL")) {
          if (m_controlState != ControlState.RUNNING) {
            setState(ControlState.ERROR, "POLL when not RUNNING.");
            answerWithError();
            continue;
          }
          answerPoll();
        } else if (command.equalsIgnoreCase("STOP")) {
          if (m_controlState == ControlState.RUNNING) {
            try {
              if (m_sampler != null) {
                m_sampler.setShouldStop();
                m_sampler.join();
              }
              m_voltClient.close();
              if (m_checkTables) {
                checkTables();
              }
            } catch (InterruptedException e) {
              System.exit(0);
            }
            System.exit(0);
          }
          System.err.println("Error: STOP when not RUNNING");
          System.exit(-1);
        } else {
          System.err.println("Error on standard input: unknown command " + command);
          System.exit(-1);
        }
      }
    }