Ejemplo n.º 1
0
  /**
   * Output an instance after filtering but do not remove from the output queue.
   *
   * @return the instance that has most recently been filtered (or null if the queue is empty).
   * @throws NullPointerException if no input structure has been defined
   */
  public Instance outputPeek() {

    if (m_OutputFormat == null) {
      throw new NullPointerException("No output instance format defined");
    }
    if (m_OutputQueue.empty()) {
      return null;
    }
    Instance result = (Instance) m_OutputQueue.peek();
    return result;
  }
Ejemplo n.º 2
0
  /**
   * Returns the number of instances pending output
   *
   * @return the number of instances pending output
   * @throws NullPointerException if no input structure has been defined
   */
  public int numPendingOutput() {

    if (m_OutputFormat == null) {
      throw new NullPointerException("No output instance format defined");
    }
    return m_OutputQueue.size();
  }
Ejemplo n.º 3
0
  /**
   * Adds an output instance to the queue. The derived class should use this method for each output
   * instance it makes available.
   *
   * @param instance the instance to be added to the queue.
   */
  protected void push(Instance instance) {

    if (instance != null) {
      if (instance.dataset() != null) copyValues(instance, false);
      instance.setDataset(m_OutputFormat);
      m_OutputQueue.push(instance);
    }
  }
Ejemplo n.º 4
0
 /** Overides runExperiment in Experiment */
 @Override
 public void runExperiment() {
   int totalHosts = m_remoteHostsQueue.size();
   // Try to launch sub experiments on all available hosts
   for (int i = 0; i < totalHosts; i++) {
     availableHost(-1);
   }
 }
Ejemplo n.º 5
0
  /**
   * Pushes a host back onto the queue of available hosts and attempts to launch a waiting
   * experiment (if any).
   *
   * @param hostNum the index of the host to push back onto the queue of available hosts
   */
  protected synchronized void availableHost(int hostNum) {
    if (hostNum >= 0) {
      if (m_remoteHostFailureCounts[hostNum] < MAX_FAILURES) {
        m_remoteHostsQueue.push(new Integer(hostNum));
      } else {
        notifyListeners(
            false,
            true,
            false,
            "Max failures exceeded for host "
                + ((String) m_remoteHosts.elementAt(hostNum))
                + ". Removed from host list.");
        m_removedHosts++;
      }
    }

    // check for all sub exp complete or all hosts failed or failed count
    // exceeded
    if (m_failedCount == (MAX_FAILURES * m_remoteHosts.size())) {
      abortExperiment();
      notifyListeners(
          false, true, true, "Experiment aborted! Max failures " + "exceeded on all remote hosts.");
      return;
    }

    if ((getSplitByDataSet() && (m_baseExperiment.getDatasets().size() == m_finishedCount))
        || (getSplitByProperty() && (m_baseExperiment.getPropertyArrayLength() == m_finishedCount))
        || (!getSplitByDataSet()
            && !getSplitByProperty()
            && (getRunUpper() - getRunLower() + 1) == m_finishedCount)) {
      notifyListeners(false, true, false, "Experiment completed successfully.");
      notifyListeners(false, true, true, postExperimentInfo());
      return;
    }

    if (checkForAllFailedHosts()) {
      return;
    }

    if (m_experimentAborted
        && (m_remoteHostsQueue.size() + m_removedHosts) == m_remoteHosts.size()) {
      notifyListeners(false, true, true, "Experiment aborted. All remote tasks " + "finished.");
    }

    if (!m_subExpQueue.empty() && !m_experimentAborted) {
      if (!m_remoteHostsQueue.empty()) {
        int availHost, waitingExp;
        try {
          availHost = ((Integer) m_remoteHostsQueue.pop()).intValue();
          waitingExp = ((Integer) m_subExpQueue.pop()).intValue();
          launchNext(waitingExp, availHost);
        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }
    }
  }
Ejemplo n.º 6
0
  /**
   * Signify that this batch of input to the filter is finished. If the filter requires all
   * instances prior to filtering, output() may now be called to retrieve the filtered instances.
   * Any subsequent instances filtered should be filtered based on setting obtained from the first
   * batch (unless the inputFormat has been re-assigned or new options have been set). This default
   * implementation assumes all instance processing occurs during inputFormat() and input().
   *
   * @return true if there are instances pending output
   * @throws NullPointerException if no input structure has been defined,
   * @throws Exception if there was a problem finishing the batch.
   */
  public boolean batchFinished() throws Exception {

    if (m_InputFormat == null) {
      throw new NullPointerException("No input instance format defined");
    }
    flushInput();
    m_NewBatch = true;
    m_FirstBatchDone = true;

    if (m_OutputQueue.empty()) {
      // Clear out references to old strings/relationals occasionally
      if ((m_OutputStringAtts.getAttributeIndices().length > 0)
          || (m_OutputRelAtts.getAttributeIndices().length > 0)) {
        m_OutputFormat = m_OutputFormat.stringFreeStructure();
        m_OutputStringAtts =
            new StringLocator(m_OutputFormat, m_OutputStringAtts.getAllowedIndices());
      }
    }

    return (numPendingOutput() != 0);
  }
Ejemplo n.º 7
0
 /**
  * Push an experiment back on the queue of waiting experiments
  *
  * @param expNum the index of the experiment to push onto the queue
  */
 protected synchronized void waitingExperiment(int expNum) {
   m_subExpQueue.push(new Integer(expNum));
 }
Ejemplo n.º 8
0
  /**
   * Prepares a remote experiment for running, creates sub experiments
   *
   * @throws Exception if an error occurs
   */
  @Override
  public void initialize() throws Exception {
    if (m_baseExperiment == null) {
      throw new Exception("No base experiment specified!");
    }

    m_experimentAborted = false;
    m_finishedCount = 0;
    m_failedCount = 0;
    m_RunNumber = getRunLower();
    m_DatasetNumber = 0;
    m_PropertyNumber = 0;
    m_CurrentProperty = -1;
    m_CurrentInstances = null;
    m_Finished = false;

    if (m_remoteHosts.size() == 0) {
      throw new Exception("No hosts specified!");
    }
    // initialize all remote hosts to available
    m_remoteHostsStatus = new int[m_remoteHosts.size()];
    m_remoteHostFailureCounts = new int[m_remoteHosts.size()];

    m_remoteHostsQueue = new Queue();
    // prime the hosts queue
    for (int i = 0; i < m_remoteHosts.size(); i++) {
      m_remoteHostsQueue.push(new Integer(i));
    }

    // set up sub experiments
    m_subExpQueue = new Queue();
    int numExps;
    if (getSplitByDataSet()) {
      numExps = m_baseExperiment.getDatasets().size();
    } else if (getSplitByProperty()) {
      numExps = m_baseExperiment.getPropertyArrayLength();
    } else {
      numExps = getRunUpper() - getRunLower() + 1;
    }
    m_subExperiments = new Experiment[numExps];
    m_subExpComplete = new int[numExps];
    // create copy of base experiment
    SerializedObject so = new SerializedObject(m_baseExperiment);

    if (getSplitByDataSet()) {
      for (int i = 0; i < m_baseExperiment.getDatasets().size(); i++) {
        m_subExperiments[i] = (Experiment) so.getObject();
        // one for each data set
        DefaultListModel temp = new DefaultListModel();
        temp.addElement(m_baseExperiment.getDatasets().get(i));
        m_subExperiments[i].setDatasets(temp);
        m_subExpQueue.push(new Integer(i));
      }
    } else if (getSplitByProperty()) {
      for (int i = 0; i < m_baseExperiment.getPropertyArrayLength(); i++) {
        m_subExperiments[i] = (Experiment) so.getObject();
        Object[] a = new Object[1];
        a[0] = m_baseExperiment.getPropertyArrayValue(i);
        m_subExperiments[i].setPropertyArray(a);
        m_subExpQueue.push(new Integer(i));
      }
    } else {
      for (int i = getRunLower(); i <= getRunUpper(); i++) {
        m_subExperiments[i - getRunLower()] = (Experiment) so.getObject();
        // one run for each sub experiment
        m_subExperiments[i - getRunLower()].setRunLower(i);
        m_subExperiments[i - getRunLower()].setRunUpper(i);

        m_subExpQueue.push(new Integer(i - getRunLower()));
      }
    }
  }