Search in sources :

Example 1 with KieSessionType

use of org.kie.api.builder.model.KieSessionModel.KieSessionType in project kiegroup-examples by tkobayas.

the class MyKieServerWarmupEventListener method internalWarmupFireOnly.

private void internalWarmupFireOnly(KieContainerInstance containerInstance) {
    LOGGER.info("  internalWarmupFireOnly");
    KieContainer kieContainer = containerInstance.getKieContainer();
    Collection<String> kieBaseNames = kieContainer.getKieBaseNames();
    // warmup all kieSessions
    kieBaseNames.stream().flatMap(kieBaseName -> kieContainer.getKieSessionNamesInKieBase(kieBaseName).stream()).forEach(kieSessionName -> {
        LOGGER.info("warmup : kieSessionName = {}", kieSessionName);
        KieSessionType type = kieContainer.getKieSessionModel(kieSessionName).getType();
        if (type == KieSessionType.STATEFUL) {
            KieSession kieSession = kieContainer.newKieSession(kieSessionName);
            kieSession.fireAllRules();
            kieSession.dispose();
        } else {
            StatelessKieSession statelessKieSession = kieContainer.newStatelessKieSession(kieSessionName);
            final List<Command> cmds = new ArrayList<Command>();
            cmds.add(CommandFactory.newFireAllRules());
            BatchExecutionCommand batchExecutionCommand = CommandFactory.newBatchExecution(cmds);
            final ExecutionResults batchResult = (ExecutionResults) statelessKieSession.execute(batchExecutionCommand);
        }
    });
}
Also used : Command(org.kie.api.command.Command) Logger(org.slf4j.Logger) Collection(java.util.Collection) ExecutionResults(org.kie.api.runtime.ExecutionResults) LoggerFactory(org.slf4j.LoggerFactory) KieContainer(org.kie.api.runtime.KieContainer) KieContainerResource(org.kie.server.api.model.KieContainerResource) CommandFactory(org.kie.internal.command.CommandFactory) Constructor(java.lang.reflect.Constructor) KieContainerInstance(org.kie.server.services.api.KieContainerInstance) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayList(java.util.ArrayList) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) KieSessionType(org.kie.api.builder.model.KieSessionModel.KieSessionType) KieServerConfigItem(org.kie.server.api.model.KieServerConfigItem) List(java.util.List) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) Optional(java.util.Optional) KieServer(org.kie.server.services.api.KieServer) KieSession(org.kie.api.runtime.KieSession) KieServerEventListener(org.kie.server.services.api.KieServerEventListener) Command(org.kie.api.command.Command) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) ExecutionResults(org.kie.api.runtime.ExecutionResults) ArrayList(java.util.ArrayList) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) KieSessionType(org.kie.api.builder.model.KieSessionModel.KieSessionType) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) KieContainer(org.kie.api.runtime.KieContainer)

Aggregations

Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 KieSessionType (org.kie.api.builder.model.KieSessionModel.KieSessionType)1 BatchExecutionCommand (org.kie.api.command.BatchExecutionCommand)1 Command (org.kie.api.command.Command)1 ExecutionResults (org.kie.api.runtime.ExecutionResults)1 KieContainer (org.kie.api.runtime.KieContainer)1 KieSession (org.kie.api.runtime.KieSession)1 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)1 CommandFactory (org.kie.internal.command.CommandFactory)1 KieContainerResource (org.kie.server.api.model.KieContainerResource)1 KieServerConfigItem (org.kie.server.api.model.KieServerConfigItem)1 KieContainerInstance (org.kie.server.services.api.KieContainerInstance)1 KieServer (org.kie.server.services.api.KieServer)1 KieServerEventListener (org.kie.server.services.api.KieServerEventListener)1 Logger (org.slf4j.Logger)1