Search in sources :

Example 11 with RegistryContext

use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.

the class AdvanceSessionTimeCommand method execute.

@Override
public Long execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    SessionPseudoClock sessionClock = ksession.<SessionPseudoClock>getSessionClock();
    sessionClock.advanceTime(amount, unit);
    long result = sessionClock.getCurrentTime();
    ExecutionResultImpl results = ((RegistryContext) context).lookup(ExecutionResultImpl.class);
    if (results != null) {
        results.getResults().put(this.outIdentifier, result);
    }
    return result;
}
Also used : SessionPseudoClock(org.kie.api.time.SessionPseudoClock) ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext)

Example 12 with RegistryContext

use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.

the class DisposeCommand method execute.

public Void execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    ksession.dispose();
    return null;
}
Also used : KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext)

Example 13 with RegistryContext

use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.

the class GetGlobalCommand method execute.

public Object execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    Object object = ksession.getGlobal(identifier);
    ExecutionResultImpl results = ((RegistryContext) context).lookup(ExecutionResultImpl.class);
    if (results != null) {
        results.getResults().put((this.outIdentifier != null) ? this.outIdentifier : this.identifier, object);
    }
    return object;
}
Also used : ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext)

Example 14 with RegistryContext

use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.

the class ApplyPmmlModelCommand method execute.

@Override
public PMML4Result execute(Context context) {
    PMML4Result resultHolder = new PMML4Result(requestData.getCorrelationId());
    RequestContextImpl ctx = (RequestContextImpl) context;
    KieBase kbase = ((RegistryContext) context).lookup(KieBase.class);
    if (kbase == null) {
        System.out.println("KieBase not found in context!");
        return null;
    } else {
        KieContainer kcont = ((KnowledgeBaseImpl) kbase).getKieContainer();
        kcont.getKieBaseNames().forEach(n -> {
            System.out.println(n);
        });
        kbase.getKiePackages().forEach(kp -> {
            System.out.println("Package: " + kp.getName());
        });
    }
    return null;
// RuleUnitExecutor executor = RuleUnitExecutor.create().bind(kbase);
// DataSource<PMMLRequestData> data = executor.newDataSource("request", this.requestData);
// DataSource<PMML4Result> resultData = executor.newDataSource("results", resultHolder);
// System.out.println("Setting result: "+resultHolder);
// ctx.lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, resultHolder);
// return resultHolder;
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) KieBase(org.kie.api.KieBase) RequestContextImpl(org.drools.core.command.RequestContextImpl) RegistryContext(org.drools.core.command.impl.RegistryContext) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) KieContainer(org.kie.api.runtime.KieContainer)

Example 15 with RegistryContext

use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.

the class SetGlobalCommand method execute.

public Object execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    if (this.outIdentifier != null) {
        ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, object);
    }
    ksession.setGlobal(this.identifier, this.object);
    // returning the object is necessary for drools-simulator
    return this.object;
}
Also used : ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext)

Aggregations

RegistryContext (org.drools.core.command.impl.RegistryContext)58 KieSession (org.kie.api.runtime.KieSession)52 ExecutionResultImpl (org.drools.core.runtime.impl.ExecutionResultImpl)20 EntryPoint (org.kie.api.runtime.rule.EntryPoint)12 FactHandle (org.kie.api.runtime.rule.FactHandle)10 ArrayList (java.util.ArrayList)8 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)7 InternalFactHandle (org.drools.core.common.InternalFactHandle)6 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)4 HashMap (java.util.HashMap)3 RequestContextImpl (org.drools.core.command.RequestContextImpl)3 Context (org.kie.api.runtime.Context)3 KieContainer (org.kie.api.runtime.KieContainer)3 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 EntryPointCreator (org.drools.core.command.EntryPointCreator)2 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)2 KieServices (org.kie.api.KieServices)2 CorrelationAwareProcessRuntime (org.kie.internal.process.CorrelationAwareProcessRuntime)2