public KieBase newKieBase(String kBaseName, KieBaseConfiguration conf) {
   ResultsImpl msgs = new ResultsImpl();
   KieBase kBase = createKieBase(getKieBaseModelImpl(kBaseName), kProject, msgs, conf);
   if (kBase == null) {
     // build error, throw runtime exception
     throw new RuntimeException("Error while creating KieBase" + msgs.filterMessages(Level.ERROR));
   }
   return kBase;
 }
 public KieBase getKieBase(String kBaseName) {
   KieBase kBase = kBases.get(kBaseName);
   if (kBase == null) {
     KieBaseModelImpl kBaseModel = getKieBaseModelImpl(kBaseName);
     synchronized (kBaseModel) {
       kBase = kBases.get(kBaseName);
       if (kBase == null) {
         ResultsImpl msgs = new ResultsImpl();
         kBase = createKieBase(kBaseModel, kProject, msgs, null);
         if (kBase == null) {
           // build error, throw runtime exception
           throw new RuntimeException(
               "Error while creating KieBase" + msgs.filterMessages(Level.ERROR));
         }
         kBases.put(kBaseName, kBase);
       }
     }
   }
   return kBase;
 }
  private void rebuildAll(
      ReleaseId newReleaseId,
      ResultsImpl results,
      InternalKieModule newKM,
      List<String> modifiedClasses,
      KieBaseModel kieBaseModel,
      KnowledgeBuilderImpl kbuilder,
      CompositeKnowledgeBuilder ckbuilder) {
    Set<String> modifiedPackages = new HashSet<String>();
    if (!modifiedClasses.isEmpty()) {
      ClassLoader rootClassLoader = kbuilder.getRootClassLoader();
      if (rootClassLoader instanceof ProjectClassLoader) {
        ProjectClassLoader projectClassLoader = (ProjectClassLoader) rootClassLoader;
        projectClassLoader.reinitTypes();
        for (String resourceName : modifiedClasses) {
          String className = convertResourceToClassName(resourceName);
          byte[] bytes = newKM.getBytes(resourceName);
          Class<?> clazz = projectClassLoader.defineClass(className, resourceName, bytes);
          modifiedPackages.add(clazz.getPackage().getName());
        }
        kbuilder.setAllRuntimesDirty(modifiedPackages);
      }
    }

    ckbuilder.build();

    PackageBuilderErrors errors = kbuilder.getErrors();
    if (!errors.isEmpty()) {
      for (KnowledgeBuilderError error : errors.getErrors()) {
        results.addMessage(error);
      }
      log.error(
          "Unable to update KieBase: "
              + kieBaseModel.getName()
              + " to release "
              + newReleaseId
              + "\n"
              + errors.toString());
    }

    if (!modifiedClasses.isEmpty()) {
      kbuilder.rewireClassObjectTypes(modifiedPackages);
    }
  }
  protected Results<Input, Output> executeBenchmarkPlan(BenchmarkPlan<Input, Output> plan) {
    this.publishProgress("executing " + plan.getName());
    ResultsImpl<Input, Output> results = new ResultsImpl<Input, Output>(plan);

    for (Metric<BenchmarkPlan<Input, Output>, ?> globalMetric : plan.getGlobalMetrics()) {
      results.addGlobalMeasure(globalMetric.getName(), globalMetric.calculate(plan));
    }

    List<Loader<Input>> inputs = plan.getInputs();
    List<Component<Input, Output>> components = plan.getComponents();

    for (int c = 0; c < components.size(); c++) {
      for (Metric<Component<Input, Output>, ?> componentMetric : plan.getComponentMetrics()) {
        results.addComponentMeasure(
            c, componentMetric.getName(), componentMetric.calculate(components.get(c)));
      }
    }

    int currentOperation = 0;
    int totalOperations = inputs.size() * components.size();

    for (int i = 0; i < inputs.size(); i++) {
      Loader<Input> inputLoader = inputs.get(i);
      inputLoader.loadElement();
      Input input = inputLoader.getElement();

      for (Metric<Input, ?> inputMetric : plan.getInputMetrics()) {
        results.addInputMeasure(i, inputMetric.getName(), inputMetric.calculate(input));
      }

      for (int c = 0; c < components.size(); c++) {
        Component<Input, Output> component = components.get(c);

        currentOperation++;
        if (currentOperation % 100 == 0)
          this.publishProgress(
              "executing "
                  + plan.getName()
                  + ": operation "
                  + currentOperation
                  + " of "
                  + totalOperations);

        for (OperationMetric<Input, Output, ?> operationMetric : plan.getOperationMetrics()) {
          operationMetric.onBeforeOperation(input, component);
        }
        System.gc();
        Output output = component.execute(input);
        for (OperationMetric<Input, Output, ?> operationMetric : plan.getOperationMetrics()) {
          results.addOperationMeasure(
              i, c, operationMetric.getName(), operationMetric.calculate(output));
        }

        if (plan.getDelayBetweenOperationsMillis() > 0) {
          synchronized (this) {
            try {
              wait(plan.getDelayBetweenOperationsMillis());
            } catch (InterruptedException exeption) {
              exeption.printStackTrace();
            }
          }
        }
      }

      inputLoader.releaseElement();
    }
    return results;
  }