예제 #1
0
  public StatelessKieSession newStatelessKieSession(
      String kSessionName, KieSessionConfiguration conf) {
    KieSessionModelImpl kSessionModel =
        (KieSessionModelImpl) kProject.getKieSessionModel(kSessionName);
    if (kSessionModel == null) {
      log.error("Unknown KieSession name: " + kSessionName);
      return null;
    }
    if (kSessionModel.getType() == KieSessionModel.KieSessionType.STATEFUL) {
      throw new RuntimeException(
          "Trying to create a stateless KieSession from a stateful KieSessionModel: "
              + kSessionName);
    }
    KieBase kBase = getKieBase(kSessionModel.getKieBaseModel().getName());
    if (kBase == null) {
      log.error("Unknown KieBase name: " + kSessionModel.getKieBaseModel().getName());
      return null;
    }

    StatelessKieSession statelessKieSession =
        kBase.newStatelessKieSession(
            conf != null ? conf : getKnowledgeSessionConfiguration(kSessionModel));
    wireListnersAndWIHs(kSessionModel, statelessKieSession);
    registerLoggers(kSessionModel, statelessKieSession);
    statelessKSessions.put(kSessionName, statelessKieSession);
    return statelessKieSession;
  }
예제 #2
0
  @Test
  public void testArrays() throws Exception {
    String text = "package test_mvel;\n";
    text += "import " + TestObject.class.getCanonicalName() + ";\n";
    text += "import function " + TestObject.class.getCanonicalName() + ".array;\n";
    text += "no-loop true\n";
    text += "dialect \"mvel\"\n";
    text += "rule \"1\"\n";
    text += "salience 1\n";
    text += "when\n";
    text += "    $fact: TestObject()\n";
    text += "    eval($fact.checkHighestPriority(\"mvel\", 2))\n";
    text +=
        "    eval($fact.stayHasDaysOfWeek(\"mvel\", false, new String[][]{{\"2008-04-01\", \"2008-04-10\"}}))\n";
    text += "then\n";
    text += "    $fact.applyValueAddPromo(1,2,3,4,\"mvel\");\n";
    text += "end";

    KieBase kieBase = loadKnowledgeBaseFromString(text.replaceAll("mvel", "java"), text);
    StatelessKieSession statelessKieSession = kieBase.newStatelessKieSession();

    List<String> list = new ArrayList<String>();
    statelessKieSession.execute(new TestObject(list));

    assertEquals(6, list.size());

    assertTrue(
        list.containsAll(
            Arrays.asList(
                "TestObject.checkHighestPriority: java|2",
                "TestObject.stayHasDaysOfWeek: java|false|[2008-04-01, 2008-04-10]",
                "TestObject.checkHighestPriority: mvel|2",
                "TestObject.stayHasDaysOfWeek: mvel|false|[2008-04-01, 2008-04-10]",
                "TestObject.applyValueAddPromo: 1|2|3|4|mvel",
                "TestObject.applyValueAddPromo: 1|2|3|4|java")));
  }