Search in sources :

Example 1 with EventProcessingOption

use of org.kie.api.conf.EventProcessingOption in project opennms by OpenNMS.

the class DroolsCorrelationEngine method initialize.

/**
 * <p>initialize</p>
 *
 * @throws java.lang.Exception if any.
 */
public void initialize() throws Exception {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kFileSystem = ks.newKieFileSystem();
    loadRules(kFileSystem);
    KieBuilder kbuilder = ks.newKieBuilder(kFileSystem);
    kbuilder.buildAll();
    if (kbuilder.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
        LOG.warn("Unable to initialize Drools engine: {}", kbuilder.getResults().getMessages(Level.ERROR));
        throw new IllegalStateException("Unable to initialize Drools engine: " + kbuilder.getResults().getMessages(Level.ERROR));
    }
    KieContainer kContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
    AssertBehaviour behaviour = AssertBehaviour.determineAssertBehaviour(m_assertBehaviour);
    RuleBaseConfiguration ruleBaseConfig = new RuleBaseConfiguration();
    ruleBaseConfig.setAssertBehaviour(behaviour);
    EventProcessingOption eventProcessingOption = EventProcessingOption.CLOUD;
    if (m_eventProcessingMode != null && m_eventProcessingMode.toLowerCase().equals("stream")) {
        eventProcessingOption = EventProcessingOption.STREAM;
        m_isStreaming = true;
    }
    ruleBaseConfig.setEventProcessingMode(eventProcessingOption);
    m_kieBase = kContainer.newKieBase(ruleBaseConfig);
    m_kieSession = m_kieBase.newKieSession();
    m_kieSession.setGlobal("engine", this);
    for (final Map.Entry<String, Object> entry : m_globals.entrySet()) {
        m_kieSession.setGlobal(entry.getKey(), entry.getValue());
    }
    if (m_persistState != null && m_persistState) {
        unmarshallStateFromDisk(true);
    }
    if (m_isStreaming) {
        new Thread(() -> {
            Logging.putPrefix(getClass().getSimpleName() + '-' + getName());
            m_kieSession.fireUntilHalt();
        }, "FireTask").start();
    }
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) EventProcessingOption(org.kie.api.conf.EventProcessingOption) RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) AssertBehaviour(org.drools.core.RuleBaseConfiguration.AssertBehaviour) KieBuilder(org.kie.api.builder.KieBuilder) HashMap(java.util.HashMap) Map(java.util.Map) KieContainer(org.kie.api.runtime.KieContainer)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 RuleBaseConfiguration (org.drools.core.RuleBaseConfiguration)1 AssertBehaviour (org.drools.core.RuleBaseConfiguration.AssertBehaviour)1 KieServices (org.kie.api.KieServices)1 KieBuilder (org.kie.api.builder.KieBuilder)1 KieFileSystem (org.kie.api.builder.KieFileSystem)1 EventProcessingOption (org.kie.api.conf.EventProcessingOption)1 KieContainer (org.kie.api.runtime.KieContainer)1