class WorkerLauncher {

  public boolean startSomeWorkers(int numberOfWorkers)
    throws EngineException {

    final int numberToStart =
      Math.min(numberOfWorkers, m_workers.length - m_nextWorkerIndex);

    for (int i = 0; i < numberToStart; ++i) {
      final int workerIndex = m_nextWorkerIndex;

      final Worker worker = m_workerFactory.create(System.out, System.err);

      synchronized (m_workers) {
        m_workers[workerIndex] = worker;
      }

      try {
        m_executor.execute(
          new InterruptibleRunnableAdapter(new WaitForWorkerTask(workerIndex)));
      }
      catch (RejectedExecutionException e) {
        m_logger.error("Failed to wait for " + worker.getIdentity().getName(),
                       e);
        worker.destroy();
        return false;
      }

      m_logger.info("worker " + worker.getIdentity().getName() + " started");

      ++m_nextWorkerIndex;
    }

    return m_workers.length > m_nextWorkerIndex;
  }

  public  WorkerLauncher(int numberOfWorkers,
                        WorkerFactory workerFactory,
                        Condition notifyOnFinish,
                        Logger logger);
    WorkerLauncher(ExecutorService executor,
                 int numberOfWorkers,
                 WorkerFactory workerFactory,
                 Condition notifyOnFinish,
                 Logger logger);

}