/**
   * Main method test of continuous update for SP operation time example
   *
   * @param url Database JDBC URL to connect with
   * @param username Database username
   * @param password Database password
   * @param providerId ID of example provider
   * @param serviceId ID of example service
   * @throws InitialisationException thrown on failure to initialise class due to invalid input
   *     parameters
   */
  private static void continuousUpdateSpOperation(
      String url, String username, String password, String providerId, String serviceId)
      throws InitialisationException {

    // The risk values to set in this example
    final double initialRiskValue = 1.0;
    final double newRiskValueOne = 1.1;

    // GRAPHTYPE_SP_OPERATION_SLA_RISKLEVEL
    RiskPropagator riskPropagator =
        new RiskPropagator(
            url,
            username,
            password,
            RiskPropagator.PROVIDERTYPE_SP,
            RiskPropagator.SERVICEPHASE_OPERATION,
            providerId,
            serviceId,
            RiskPropagator.GRAPHTYPE_SP_OPERATION_SLA_RISKLEVEL);
    // Initial value we want to save
    riskPropagator.setRiskValue(initialRiskValue);

    // Check to see riskPropagatorOne is running (i.e this would be used
    // in a while loop to start the riskPropagator instance once only
    // instead of duplicating code outside the while loop to set the
    // first risk value)
    if (!riskPropagator.isExecuting()) {
      // Start up the thread committing the initial value to the
      // database
      riskPropagator.start();
    }

    try {
      // Let the riskPropagator commit this value some more
      Thread.sleep(THREAD_SLEEP_LONG);
      // New value we want to set some time later
      riskPropagator.setRiskValue(newRiskValueOne);
      Thread.sleep(THREAD_SLEEP_LONG);
      // Check to see if the thread is still running before we try to kill
      // it
      if (riskPropagator.isExecuting()) {
        // Stop the thread from committing values to the database
        riskPropagator.kill();
      }
    } catch (InterruptedException e) {
      LOGGER.error("RiskPropagator Test: Thread interrupted", e);
      return;
    }
  }
  /**
   * Main method test of continuous update for IP operation time example
   *
   * @param url Database JDBC URL to connect with
   * @param username Database username
   * @param password Database password
   * @param providerId ID of example provider
   * @param serviceId ID of example service
   * @throws InitialisationException thrown on failure to initialise class due to invalid input
   *     parameters
   */
  private static void continuousUpdateIpOperation(
      String url, String username, String password, String providerId, String serviceId)
      throws InitialisationException {

    /** NOTE: See continuousUpdateSpOperation() for detailed explanation of code and annotations. */

    // The risk values to set in this example
    final double initialRiskValue = 1.0;
    final double newRiskValueOne = 1.1;
    final double newRiskValueTwo = 1.2;
    final double newRiskValueThree = 1.3;
    final double newRiskValueFour = 1.4;

    // Concurrently add values for:
    // GRAPHTYPE_IP_OPERATION_PHYSICAL_HOST_RISKLEVEL
    // GRAPHTYPE_IP_OPERATION_VIRTUAL_MACHINE_RISKLEVEL
    // GRAPHTYPE_IP_OPERATION_SLA_RISKLEVEL
    // GRAPHTYPE_IP_OPERATION_TOTAL_RISKLEVEL
    RiskPropagator riskPropagatorOne =
        new RiskPropagator(
            url,
            username,
            password,
            RiskPropagator.PROVIDERTYPE_IP,
            RiskPropagator.SERVICEPHASE_OPERATION,
            providerId,
            serviceId,
            RiskPropagator.GRAPHTYPE_IP_OPERATION_PHYSICAL_HOST_RISKLEVEL);

    riskPropagatorOne.setRiskValue(initialRiskValue);
    RiskPropagator riskPropagatorTwo =
        new RiskPropagator(
            url,
            username,
            password,
            RiskPropagator.PROVIDERTYPE_IP,
            RiskPropagator.SERVICEPHASE_OPERATION,
            providerId,
            serviceId,
            RiskPropagator.GRAPHTYPE_IP_OPERATION_VIRTUAL_MACHINE_RISKLEVEL);
    riskPropagatorTwo.setRiskValue(initialRiskValue);
    RiskPropagator riskPropagatorThree =
        new RiskPropagator(
            url,
            username,
            password,
            RiskPropagator.PROVIDERTYPE_IP,
            RiskPropagator.SERVICEPHASE_OPERATION,
            providerId,
            serviceId,
            RiskPropagator.GRAPHTYPE_IP_OPERATION_SLA_RISKLEVEL);
    riskPropagatorThree.setRiskValue(initialRiskValue);
    RiskPropagator riskPropagatorFour =
        new RiskPropagator(
            url,
            username,
            password,
            RiskPropagator.PROVIDERTYPE_IP,
            RiskPropagator.SERVICEPHASE_OPERATION,
            providerId,
            serviceId,
            RiskPropagator.GRAPHTYPE_IP_OPERATION_TOTAL_RISKLEVEL);
    riskPropagatorFour.setRiskValue(initialRiskValue);

    if (!riskPropagatorOne.isExecuting()) {
      riskPropagatorOne.start();
    }
    if (!riskPropagatorTwo.isExecuting()) {
      riskPropagatorTwo.start();
    }
    if (!riskPropagatorThree.isExecuting()) {
      riskPropagatorThree.start();
    }
    if (!riskPropagatorFour.isExecuting()) {
      riskPropagatorFour.start();
    }

    try {
      Thread.sleep(THREAD_SLEEP_LONG);
      riskPropagatorOne.setRiskValue(newRiskValueOne);
      riskPropagatorTwo.setRiskValue(newRiskValueTwo);
      riskPropagatorThree.setRiskValue(newRiskValueThree);
      riskPropagatorFour.setRiskValue(newRiskValueFour);
      Thread.sleep(THREAD_SLEEP_LONG);

      if (riskPropagatorOne.isExecuting()) {
        riskPropagatorOne.kill();
      }
      if (riskPropagatorTwo.isExecuting()) {
        riskPropagatorTwo.kill();
      }
      if (riskPropagatorThree.isExecuting()) {
        riskPropagatorThree.kill();
      }
      if (riskPropagatorFour.isExecuting()) {
        riskPropagatorFour.kill();
      }
    } catch (InterruptedException e) {
      LOGGER.error("RiskPropagator Test: Thread interrupted", e);
      return;
    }
  }