From 9a976d5b0d32836083fe6619b2e42a072d2cd2d9 Mon Sep 17 00:00:00 2001 From: Mario Fusco Date: Tue, 6 Dec 2016 08:39:31 +0100 Subject: [PATCH] [DROOLS-1353] define ExecutableRunner interface (#1022) --- .../simulation/BatchRunFluentTest.java | 133 +++++++------- .../org/drools/core/SessionConfiguration.java | 4 +- .../core/SessionConfigurationDelegate.java | 6 +- .../drools/core/SessionConfigurationImpl.java | 27 ++- .../core/audit/WorkingMemoryLogger.java | 2 +- ...WrappedStatefulKnowledgeSessionForRHS.java | 5 - .../core/command/ConversationContext.java | 24 --- .../command/ConversationContextManager.java | 21 ++- .../core/command/EndConversationCommand.java | 6 +- .../drools/core/command/ExecuteCommand.java | 4 +- .../drools/core/command/FinishedCommand.java | 2 +- .../core/command/GetKieContainerCommand.java | 2 +- .../core/command/GetSessionClockCommand.java | 2 +- .../core/command/GetVariableCommand.java | 9 +- .../core/command/JoinConversationCommand.java | 6 +- ...wledgeBaseAddKnowledgePackagesCommand.java | 2 +- .../command/LeaveConversationCommand.java | 4 +- .../core/command/NewKieSessionCommand.java | 2 +- ...wKnowledgeBuilderConfigurationCommand.java | 2 +- .../org/drools/core/command/OutCommand.java | 7 +- .../core/command/RequestContextImpl.java | 55 +++--- .../SetVariableCommandFromCommand.java | 9 +- .../SetVariableCommandFromLastReturn.java | 13 +- .../command/SingleSessionCommandService.java | 7 +- .../command/StartConversationCommand.java | 2 +- .../core/command/assertion/AssertEquals.java | 2 +- .../builder/KnowledgeBuilderAddCommand.java | 2 +- .../KnowledgeBuilderGetErrorsCommand.java | 2 +- ...dgeBuilderGetKnowledgePackagesCommand.java | 2 +- .../KnowledgeBuilderHasErrorsCommand.java | 2 +- .../builder/NewKnowledgeBuilderCommand.java | 2 +- .../command/impl/AbstractInterceptor.java | 29 ++-- .../command/impl/AsynchronousInterceptor.java | 9 +- .../command/impl/CommandBasedEntryPoint.java | 32 ++-- .../CommandBasedStatefulKnowledgeSession.java | 162 +++++++++--------- .../drools/core/command/impl/ContextImpl.java | 2 +- .../command/impl/ContextImplWithEviction.java | 2 +- .../command/impl/DefaultCommandService.java | 39 ----- .../core/command/impl/ExecutableCommand.java | 5 +- .../command/impl/FireAllRulesInterceptor.java | 27 ++- .../core/command/impl/LoggingInterceptor.java | 14 +- .../core/command/impl/RegistryContext.java | 5 +- .../runtime/AddEventListenerCommand.java | 2 +- .../runtime/BatchExecutionCommandImpl.java | 4 +- .../runtime/DestroySessionCommand.java | 14 +- .../core/command/runtime/DisposeCommand.java | 7 +- .../command/runtime/GetCalendarsCommand.java | 2 +- .../command/runtime/GetChannelsCommand.java | 2 +- .../runtime/GetEnvironmentCommand.java | 2 +- .../command/runtime/GetFactCountCommand.java | 2 +- .../GetFactCountInEntryPointCommand.java | 2 +- .../command/runtime/GetGlobalCommand.java | 2 +- .../command/runtime/GetGlobalsCommand.java | 2 +- .../core/command/runtime/GetIdCommand.java | 2 +- .../runtime/GetKnowledgeBaseCommand.java | 2 +- .../runtime/KBuilderSetPropertyCommand.java | 2 +- .../runtime/RegisterChannelCommand.java | 2 +- .../runtime/RemoveEventListenerCommand.java | 2 +- .../command/runtime/SetGlobalCommand.java | 2 +- .../runtime/UnregisterChannelCommand.java | 2 +- .../process/AbortProcessInstanceCommand.java | 2 +- .../runtime/process/AbortWorkItemCommand.java | 2 +- .../process/CompleteWorkItemCommand.java | 2 +- ...reateCorrelatedProcessInstanceCommand.java | 2 +- .../process/CreateProcessInstanceCommand.java | 2 +- .../GetProcessEventListenersCommand.java | 2 +- .../runtime/process/GetProcessIdsCommand.java | 2 +- ...rocessInstanceByCorrelationKeyCommand.java | 2 +- .../process/GetProcessInstanceCommand.java | 2 +- .../process/GetProcessInstancesCommand.java | 2 +- .../runtime/process/GetWorkItemCommand.java | 2 +- .../process/GetWorkItemIdsCommand.java | 2 +- .../runtime/process/ReTryWorkItemCommand.java | 2 +- .../RegisterWorkItemHandlerCommand.java | 2 +- .../SetProcessInstanceVariablesCommand.java | 2 +- .../runtime/process/SignalEventCommand.java | 2 +- .../StartCorrelatedProcessCommand.java | 2 +- .../runtime/process/StartProcessCommand.java | 2 +- .../process/StartProcessInstanceCommand.java | 2 +- .../rule/AgendaGroupSetFocusCommand.java | 2 +- .../rule/ClearActivationGroupCommand.java | 2 +- .../runtime/rule/ClearAgendaCommand.java | 2 +- .../runtime/rule/ClearAgendaGroupCommand.java | 2 +- .../rule/ClearRuleFlowGroupCommand.java | 2 +- .../command/runtime/rule/DeleteCommand.java | 2 +- .../rule/DeleteFromEntryPointCommand.java | 2 +- .../runtime/rule/DeleteObjectCommand.java | 2 +- .../runtime/rule/EnableAuditLogCommand.java | 2 +- .../runtime/rule/FireAllRulesCommand.java | 2 +- .../runtime/rule/FireUntilHaltCommand.java | 2 +- .../rule/FromExternalFactHandleCommand.java | 2 +- .../rule/GetAgendaEventListenersCommand.java | 2 +- .../runtime/rule/GetEntryPointCommand.java | 2 +- .../runtime/rule/GetEntryPointsCommand.java | 2 +- .../runtime/rule/GetFactHandleCommand.java | 2 +- .../GetFactHandleInEntryPointCommand.java | 2 +- .../runtime/rule/GetFactHandlesCommand.java | 2 +- .../GetFactHandlesInEntryPointCommand.java | 2 +- .../runtime/rule/GetObjectCommand.java | 2 +- .../rule/GetObjectInEntryPointCommand.java | 2 +- .../runtime/rule/GetObjectsCommand.java | 2 +- .../rule/GetObjectsInEntryPointCommand.java | 2 +- .../GetRuleRuntimeEventListenersCommand.java | 2 +- .../command/runtime/rule/HaltCommand.java | 2 +- .../runtime/rule/InsertElementsCommand.java | 2 +- .../runtime/rule/InsertObjectCommand.java | 2 +- .../rule/InsertObjectInEntryPointCommand.java | 2 +- .../command/runtime/rule/ModifyCommand.java | 2 +- .../command/runtime/rule/QueryCommand.java | 2 +- .../command/runtime/rule/UpdateCommand.java | 2 +- .../rule/UpdateInEntryPointCommand.java | 2 +- .../core/fluent/impl/BaseBatchFluent.java | 24 ++- .../impl/Batch.java} | 17 +- .../drools/core/fluent/impl/BatchImpl.java | 17 +- .../core/fluent/impl/CommandRegister.java | 16 ++ .../core/fluent/impl/ExecutableImpl.java | 22 ++- .../core/fluent/impl/FluentBuilderImpl.java | 18 +- .../fluent/impl/FluentComponentFactory.java | 17 +- .../drools/core/fluent/impl/GetCommand.java | 18 +- .../core/fluent/impl/GetContextCommand.java | 22 ++- .../core/fluent/impl/InternalExecutable.java | 33 ++++ .../fluent/impl/KieContainerFluentImpl.java | 16 ++ .../fluent/impl/KieSessionFluentImpl.java | 16 ++ .../core/fluent/impl/NewContextCommand.java | 26 ++- .../core/fluent/impl/PseudoClockRunner.java | 63 ++++--- .../drools/core/fluent/impl/SetCommand.java | 20 ++- .../fluent/impl/SetVarAsRegistryEntry.java | 19 +- .../impl/StatefulKnowledgeSessionImpl.java | 29 +--- .../ChainableRunner.java} | 16 +- .../core/runtime/InternalLocalRunner.java | 73 ++++++++ .../CommandServiceTimerJobFactoryManager.java | 6 +- .../core/world/impl/ContextManagerImpl.java | 2 +- .../rule/ExecuteCommandDisconnectedTest.java | 12 +- .../rule/GetFactHandlesCommandTest.java | 32 ++-- .../core/reteoo/test/JUnitNodeTestRunner.java | 4 +- ...andService.java => PersistableRunner.java} | 140 +++++++-------- .../PersistenceContextManager.java | 14 +- .../TransactionSynchronizationContainer.java | 7 +- .../jpa/JDKCallableJobCommand.java | 2 +- .../persistence/jpa/JpaJDKTimerService.java | 22 +-- .../jpa/JpaTimeJobFactoryManager.java | 12 +- .../persistence/jpa/JpaTimerJobInstance.java | 6 +- .../jpa/KnowledgeStoreServiceImpl.java | 60 +++---- .../jpa/OptimisticLockRetryInterceptor.java | 48 +++--- .../jta/TransactionLockInterceptor.java | 24 +-- .../jta/JtaTransactionManagerTest.java | 4 +- .../jta/TransactionTestCommand.java | 4 +- .../JpaPersistentStatefulSessionTest.java | 6 +- .../session/AgendaRuleFlowGroupsTest.java | 4 +- ...aOptLockPersistentStatefulSessionTest.java | 4 +- .../JpaPersistentStatefulSessionTest.java | 46 +++-- .../session/ReloadSessionTest.java | 2 +- .../session/RuleFlowGroupRollbackTest.java | 2 +- .../integrationtests/MultithreadTest.java | 6 +- .../parser/ExternalSheetListenerTest.java | 2 +- 155 files changed, 1013 insertions(+), 791 deletions(-) delete mode 100644 drools-core/src/main/java/org/drools/core/command/ConversationContext.java delete mode 100644 drools-core/src/main/java/org/drools/core/command/impl/DefaultCommandService.java rename drools-core/src/main/java/org/drools/core/{command/Interceptor.java => fluent/impl/Batch.java} (56%) create mode 100644 drools-core/src/main/java/org/drools/core/fluent/impl/InternalExecutable.java rename drools-core/src/main/java/org/drools/core/{command/CommandService.java => runtime/ChainableRunner.java} (61%) create mode 100644 drools-core/src/main/java/org/drools/core/runtime/InternalLocalRunner.java rename drools-persistence-jpa/src/main/java/org/drools/persistence/{SingleSessionCommandService.java => PersistableRunner.java} (83%) diff --git a/drools-compiler/src/test/java/org/drools/compiler/simulation/BatchRunFluentTest.java b/drools-compiler/src/test/java/org/drools/compiler/simulation/BatchRunFluentTest.java index cea5fe17eec..1a57a6853be 100644 --- a/drools-compiler/src/test/java/org/drools/compiler/simulation/BatchRunFluentTest.java +++ b/drools-compiler/src/test/java/org/drools/compiler/simulation/BatchRunFluentTest.java @@ -1,16 +1,32 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.drools.compiler.simulation; import org.drools.compiler.CommonTestMethodBase; import org.drools.compiler.Message; import org.drools.core.command.RequestContextImpl; import org.drools.core.fluent.impl.FluentBuilderImpl; -import org.drools.core.fluent.impl.PseudoClockRunner; import org.junit.Test; import org.kie.api.KieServices; import org.kie.api.builder.KieModule; import org.kie.api.builder.ReleaseId; import org.kie.api.io.ResourceType; -import org.kie.internal.fluent.RequestContext; +import org.kie.api.runtime.ExecutableRunner; +import org.kie.api.runtime.RequestContext; import org.kie.internal.fluent.Scope; import org.kie.internal.fluent.runtime.FluentBuilder; import org.kie.internal.fluent.runtime.KieSessionFluent; @@ -32,9 +48,7 @@ public class BatchRunFluentTest extends CommonTestMethodBase { @Test public void testOutName() { - PseudoClockRunner runner = new PseudoClockRunner(); - - FluentBuilder f = new FluentBuilderImpl(); + FluentBuilder f = FluentBuilder.create(); f.newApplicationContext("app1") .getKieContainer(releaseId).newSession() @@ -43,17 +57,15 @@ public void testOutName() { .getGlobal("outS").out("outS") .dispose(); - RequestContext requestContext = (RequestContext) runner.execute( f.getExecutable() ); + RequestContext requestContext = ExecutableRunner.create().execute( f.getExecutable() ); - assertEquals("h1", requestContext.getOut().get("outS")); + assertEquals("h1", requestContext.get("outS")); } @Test public void testOutWithPriorSetAndNoName() { - PseudoClockRunner runner = new PseudoClockRunner(); - - FluentBuilder f = new FluentBuilderImpl(); + FluentBuilder f = FluentBuilder.create(); f.newApplicationContext("app1") .getKieContainer(releaseId).newSession() @@ -62,17 +74,15 @@ public void testOutWithPriorSetAndNoName() { .getGlobal("outS").set("outS").out() .dispose(); - RequestContextImpl requestContext = (RequestContextImpl) runner.execute(f.getExecutable()); + RequestContext requestContext = ExecutableRunner.create().execute(f.getExecutable()); - assertEquals("h1", requestContext.getOut().get("outS")); + assertEquals("h1", requestContext.get("outS")); assertEquals("h1", requestContext.get("outS")); } @Test public void testOutWithoutPriorSetAndNoName() { - PseudoClockRunner runner = new PseudoClockRunner(); - - FluentBuilder f = new FluentBuilderImpl(); + FluentBuilder f = FluentBuilder.create(); f.newApplicationContext("app1") .getKieContainer(releaseId).newSession() @@ -82,9 +92,9 @@ public void testOutWithoutPriorSetAndNoName() { .dispose(); try { - RequestContextImpl requestContext = (RequestContextImpl) runner.execute(f.getExecutable()); + RequestContext requestContext = ExecutableRunner.create().execute(f.getExecutable()); - assertEquals("h1", requestContext.getOut().get("out1")); + assertEquals("h1", requestContext.get("out1")); fail("Must throw Exception, as no prior set was called and no name given to out"); } catch ( Exception e ) { @@ -93,9 +103,7 @@ public void testOutWithoutPriorSetAndNoName() { @Test public void testSetAndGetWithCommandRegisterWithEnds() { - PseudoClockRunner runner = new PseudoClockRunner(); - - FluentBuilder f = new FluentBuilderImpl(); + FluentBuilder f = FluentBuilder.create(); f.newApplicationContext("app1") // create two sessions, and assign names @@ -116,18 +124,16 @@ public void testSetAndGetWithCommandRegisterWithEnds() { .get("s2", KieSessionFluent.class) .getGlobal("outS").out("outS2").dispose(); - RequestContextImpl requestContext = (RequestContextImpl) runner.execute(f.getExecutable()); + RequestContext requestContext = ExecutableRunner.create().execute(f.getExecutable()); // Check that nothing went to the 'out' - assertEquals("h1", requestContext.getOut().get("outS1")); - assertEquals("h2", requestContext.getOut().get("outS2")); + assertEquals("h1", requestContext.get("outS1")); + assertEquals("h2", requestContext.get("outS2")); } @Test public void testSetAndGetWithCommandRegisterWithoutEnds() { - PseudoClockRunner runner = new PseudoClockRunner(); - - FluentBuilder f = new FluentBuilderImpl(); + FluentBuilder f = FluentBuilder.create(); f.newApplicationContext("app1") // create two sessions, and assign names @@ -148,19 +154,20 @@ public void testSetAndGetWithCommandRegisterWithoutEnds() { .get("s2", KieSessionFluent.class) .getGlobal("outS").out("outS2").dispose(); - RequestContextImpl requestContext = (RequestContextImpl) runner.execute(f.getExecutable()); + RequestContext requestContext = ExecutableRunner.create().execute(f.getExecutable()); // Check that nothing went to the 'out' - assertEquals("h1", requestContext.getOut().get("outS1")); - assertEquals("h2", requestContext.getOut().get("outS2")); + assertEquals("h1", requestContext.get("outS1")); + assertEquals("h2", requestContext.get("outS2")); } @Test - public void testConversationIdIncreases() { - PseudoClockRunner runner = new PseudoClockRunner(); + public void testDifferentConversationIds() { + ExecutableRunner runner = ExecutableRunner.create(); + RequestContext requestContext = runner.createContext(); - FluentBuilder f = new FluentBuilderImpl(); + FluentBuilder f = FluentBuilder.create(); f.newApplicationContext("app1").startConversation() .getKieContainer(releaseId).newSession() @@ -168,22 +175,18 @@ public void testConversationIdIncreases() { .fireAllRules() .dispose(); - RequestContextImpl requestContext = (RequestContextImpl) runner.execute(f.getExecutable()); + runner.execute(f.getExecutable(), requestContext); - long conversationId = requestContext.getConversationContext().getConversationId(); - assertEquals(0, conversationId); + String conversationId = requestContext.getConversationContext().getName(); - requestContext = (RequestContextImpl) runner.execute(f.getExecutable()); + runner.execute(f.getExecutable(), requestContext); - conversationId = requestContext.getConversationContext().getConversationId(); - assertEquals(1, conversationId); + assertNotEquals(conversationId, requestContext.getConversationContext().getName()); } @Test public void testRequestScope() { - PseudoClockRunner runner = new PseudoClockRunner(); - - FluentBuilder f = new FluentBuilderImpl(); + FluentBuilder f = FluentBuilder.create(); f.newApplicationContext("app1") .getKieContainer(releaseId).newSession() @@ -192,10 +195,10 @@ public void testRequestScope() { .getGlobal("outS").set("outS1") // Request is default .dispose(); - RequestContextImpl requestContext = (RequestContextImpl) runner.execute(f.getExecutable()); + RequestContext requestContext = ExecutableRunner.create().execute(f.getExecutable()); // Check that nothing went to the 'out' - assertNull(requestContext.getOut().get("outS")); + assertNull(requestContext.get("outS")); assertNull(requestContext.getApplicationContext().get("outS1") ); assertNull(requestContext.getConversationContext() ); assertEquals("h1", requestContext.get("outS1") ); @@ -203,9 +206,9 @@ public void testRequestScope() { @Test public void testApplicationScope() { - PseudoClockRunner runner = new PseudoClockRunner(); + ExecutableRunner runner = ExecutableRunner.create(); - FluentBuilder f = new FluentBuilderImpl(); + FluentBuilder f = FluentBuilder.create(); f.newApplicationContext("app1") .getKieContainer(releaseId).newSession() @@ -214,10 +217,10 @@ public void testApplicationScope() { .getGlobal("outS").set("outS1", Scope.APPLICATION) .dispose(); - RequestContextImpl requestContext = (RequestContextImpl) runner.execute(f.getExecutable()); + RequestContext requestContext = runner.execute(f.getExecutable()); // Check that nothing went to the 'out' - assertEquals(null, requestContext.getOut().get("outS")); + assertEquals(null, requestContext.get("outS")); assertEquals("h1", requestContext.getApplicationContext().get("outS1") ); // Make another request, add to application context, assert old and new values are there. @@ -238,9 +241,9 @@ public void testApplicationScope() { @Test public void testConversationScope() { - PseudoClockRunner runner = new PseudoClockRunner(); + ExecutableRunner runner = ExecutableRunner.create(); - FluentBuilder f = new FluentBuilderImpl(); + FluentBuilder f = FluentBuilder.create(); f.newApplicationContext("app1").startConversation() .getKieContainer(releaseId).newSession() @@ -252,9 +255,9 @@ public void testConversationScope() { RequestContextImpl requestContext = (RequestContextImpl) runner.execute(f.getExecutable()); // check that nothing went to the 'out' - assertEquals(null, requestContext.getOut().get("outS")); + assertEquals(null, requestContext.get("outS")); - long conversationId = requestContext.getConversationContext().getConversationId(); + String conversationId = requestContext.getConversationContext().getName(); assertEquals("h1", requestContext.getConversationContext().get("outS1") ); @@ -283,9 +286,9 @@ public void testConversationScope() { @Test public void testContextScopeSearching() { - PseudoClockRunner runner = new PseudoClockRunner(); + ExecutableRunner runner = ExecutableRunner.create(); - FluentBuilder f = new FluentBuilderImpl(); + FluentBuilder f = FluentBuilder.create(); // Check that get() will search up to Application, when no request or conversation values f.newApplicationContext("app1") @@ -295,9 +298,9 @@ public void testContextScopeSearching() { .getGlobal("outS").set("outS1", Scope.APPLICATION) .get("outS1").out() .dispose(); - RequestContextImpl requestContext = (RequestContextImpl) runner.execute(f.getExecutable()); + RequestContext requestContext = runner.execute(f.getExecutable()); - assertEquals("h1", requestContext.getOut().get("outS1")); + assertEquals("h1", requestContext.get("outS1")); assertEquals("h1", requestContext.getApplicationContext().get("outS1") ); assertEquals("h1", requestContext.get("outS1") ); @@ -311,9 +314,9 @@ public void testContextScopeSearching() { .getGlobal("outS").set("outS1", Scope.CONVERSATION) .get("outS1").out() .dispose(); - requestContext = (RequestContextImpl) runner.execute(f.getExecutable()); + requestContext = runner.execute(f.getExecutable()); - assertEquals("h2", requestContext.getOut().get("outS1")); + assertEquals("h2", requestContext.get("outS1")); assertEquals("h1", requestContext.getApplicationContext().get("outS1") ); assertEquals("h2", requestContext.getConversationContext().get("outS1") ); assertEquals("h2", requestContext.get("outS1") ); @@ -322,16 +325,16 @@ public void testContextScopeSearching() { // Check that get() will search directly to Request, thus over-riding Application and Conversation scoped values f = new FluentBuilderImpl(); - f.getApplicationContext("app1").joinConversation(requestContext.getConversationContext().getConversationId()) + f.getApplicationContext("app1").joinConversation(requestContext.getConversationContext().getName()) .getKieContainer(releaseId).newSession() .insert("h3") .fireAllRules() .getGlobal("outS").set("outS1", Scope.REQUEST) .get("outS1").out() .dispose(); - requestContext = (RequestContextImpl) runner.execute(f.getExecutable()); + requestContext = runner.execute(f.getExecutable()); - assertEquals("h3", requestContext.getOut().get("outS1")); + assertEquals("h3", requestContext.get("outS1")); assertEquals("h1", requestContext.getApplicationContext().get("outS1") ); assertEquals("h2", requestContext.getConversationContext().get("outS1") ); assertEquals("h3", requestContext.get("outS1") ); @@ -341,9 +344,9 @@ public void testContextScopeSearching() { @Test public void testAfter() { - PseudoClockRunner runner = new PseudoClockRunner( 0); + ExecutableRunner runner = ExecutableRunner.create(0L); - FluentBuilder f = new FluentBuilderImpl(); + FluentBuilder f = FluentBuilder.create(); // Check that get() will search up to Application, when no request or conversation values f.after(1000).newApplicationContext("app1") @@ -361,10 +364,10 @@ public void testAfter() { .getGlobal("timeNow").out("timeNow2") .dispose(); - RequestContextImpl requestContext = (RequestContextImpl) runner.execute(f.getExecutable()); + RequestContext requestContext = runner.execute(f.getExecutable()); - assertEquals(1000l, requestContext.getOut().get("timeNow1")); - assertEquals(2000l, requestContext.getOut().get("timeNow2")); + assertEquals(1000l, requestContext.get("timeNow1")); + assertEquals(2000l, requestContext.get("timeNow2")); } public static KieModule createAndDeployJar( KieServices ks, diff --git a/drools-core/src/main/java/org/drools/core/SessionConfiguration.java b/drools-core/src/main/java/org/drools/core/SessionConfiguration.java index 98540a29733..6528b49ad31 100644 --- a/drools-core/src/main/java/org/drools/core/SessionConfiguration.java +++ b/drools-core/src/main/java/org/drools/core/SessionConfiguration.java @@ -16,12 +16,12 @@ package org.drools.core; -import org.drools.core.command.CommandService; import org.drools.core.process.instance.WorkItemManagerFactory; import org.drools.core.time.TimerService; import org.drools.core.time.impl.TimerJobFactoryManager; import org.drools.core.util.StringUtils; import org.kie.api.runtime.Environment; +import org.kie.api.runtime.ExecutableRunner; import org.kie.api.runtime.KieSessionConfiguration; import org.kie.api.runtime.conf.BeliefSystemTypeOption; import org.kie.api.runtime.conf.ClockTypeOption; @@ -101,7 +101,7 @@ public final TimerJobFactoryManager getTimerJobFactoryManager() { public abstract String getSignalManagerFactory(); - public abstract CommandService getCommandService(KnowledgeBase kbase, Environment environment); + public abstract ExecutableRunner getRunner( KnowledgeBase kbase, Environment environment ); public abstract TimerService newTimerService(); diff --git a/drools-core/src/main/java/org/drools/core/SessionConfigurationDelegate.java b/drools-core/src/main/java/org/drools/core/SessionConfigurationDelegate.java index 766508425fa..446ff5e2d02 100644 --- a/drools-core/src/main/java/org/drools/core/SessionConfigurationDelegate.java +++ b/drools-core/src/main/java/org/drools/core/SessionConfigurationDelegate.java @@ -16,10 +16,10 @@ package org.drools.core; -import org.drools.core.command.CommandService; import org.drools.core.process.instance.WorkItemManagerFactory; import org.drools.core.time.TimerService; import org.kie.api.runtime.Environment; +import org.kie.api.runtime.ExecutableRunner; import org.kie.api.runtime.conf.QueryListenerOption; import org.kie.api.runtime.conf.TimedRuleExecutionFilter; import org.kie.api.runtime.process.WorkItemHandler; @@ -204,8 +204,8 @@ public String getSignalManagerFactory() { } @Override - public CommandService getCommandService( KnowledgeBase kbase, Environment environment ) { - return delegate.getCommandService( kbase, environment ); + public ExecutableRunner getRunner( KnowledgeBase kbase, Environment environment ) { + return delegate.getRunner( kbase, environment ); } @Override diff --git a/drools-core/src/main/java/org/drools/core/SessionConfigurationImpl.java b/drools-core/src/main/java/org/drools/core/SessionConfigurationImpl.java index b61f1fb27c6..3ab968c9070 100644 --- a/drools-core/src/main/java/org/drools/core/SessionConfigurationImpl.java +++ b/drools-core/src/main/java/org/drools/core/SessionConfigurationImpl.java @@ -16,13 +16,13 @@ package org.drools.core; -import org.drools.core.command.CommandService; import org.drools.core.common.ProjectClassLoader; import org.drools.core.process.instance.WorkItemManagerFactory; import org.drools.core.time.TimerService; import org.drools.core.util.ConfFileUtils; import org.drools.core.util.MVELSafeHelper; import org.kie.api.runtime.Environment; +import org.kie.api.runtime.ExecutableRunner; import org.kie.api.runtime.KieSessionConfiguration; import org.kie.api.runtime.conf.BeliefSystemTypeOption; import org.kie.api.runtime.conf.ClockTypeOption; @@ -83,11 +83,11 @@ public class SessionConfigurationImpl extends SessionConfiguration { private Map workItemHandlers; private WorkItemManagerFactory workItemManagerFactory; - private CommandService commandService; + private ExecutableRunner runner; private transient ClassLoader classLoader; - private TimerJobFactoryType timerJobFactoryType; + private TimerJobFactoryType timerJobFactoryType; public void writeExternal(ObjectOutput out) throws IOException { out.writeObject( chainedProperties ); @@ -356,13 +356,12 @@ public String getSignalManagerFactory() { "org.jbpm.process.instance.event.DefaultSignalManagerFactory" ); } - public CommandService getCommandService(KnowledgeBase kbase, - Environment environment) { - if ( this.commandService == null ) { + public ExecutableRunner getRunner( KnowledgeBase kbase, Environment environment ) { + if ( this.runner == null ) { initCommandService( kbase, environment ); } - return this.commandService; + return this.runner; } @SuppressWarnings("unchecked") @@ -374,19 +373,19 @@ private void initCommandService(KnowledgeBase kbase, return; } - Class clazz = null; + Class clazz = null; try { - clazz = (Class) this.classLoader.loadClass( className ); + clazz = (Class) this.classLoader.loadClass( className ); } catch ( ClassNotFoundException e ) { } if ( clazz != null ) { try { - this.commandService = clazz.getConstructor( KnowledgeBase.class, - KieSessionConfiguration.class, - Environment.class ).newInstance( kbase, - this, - environment ); + this.runner = clazz.getConstructor( KnowledgeBase.class, + KieSessionConfiguration.class, + Environment.class ).newInstance( kbase, + this, + environment ); } catch ( Exception e ) { throw new IllegalArgumentException( "Unable to instantiate command service '" + className + "'", e ); diff --git a/drools-core/src/main/java/org/drools/core/audit/WorkingMemoryLogger.java b/drools-core/src/main/java/org/drools/core/audit/WorkingMemoryLogger.java index 71e82d6bb7d..c219e47b7bb 100644 --- a/drools-core/src/main/java/org/drools/core/audit/WorkingMemoryLogger.java +++ b/drools-core/src/main/java/org/drools/core/audit/WorkingMemoryLogger.java @@ -159,7 +159,7 @@ public WorkingMemoryLogger(final KnowledgeRuntimeEventManager session) { statelessSession.getKnowledgeBase().addEventListener( (KieBaseEventListener) this ); } else if (session instanceof CommandBasedStatefulKnowledgeSession) { StatefulKnowledgeSessionImpl statefulSession = - ((StatefulKnowledgeSessionImpl)(( RegistryContext)((CommandBasedStatefulKnowledgeSession) session).getCommandService().getContext()).lookup( KieSession.class)); + ((StatefulKnowledgeSessionImpl)(( RegistryContext)((CommandBasedStatefulKnowledgeSession) session).getRunner().createContext()).lookup( KieSession.class )); isPhreak = statefulSession.getKnowledgeBase().getConfiguration().isPhreakEnabled(); InternalWorkingMemory eventManager = statefulSession; eventManager.addEventListener( (RuleRuntimeEventListener) this ); diff --git a/drools-core/src/main/java/org/drools/core/base/WrappedStatefulKnowledgeSessionForRHS.java b/drools-core/src/main/java/org/drools/core/base/WrappedStatefulKnowledgeSessionForRHS.java index bd1825472fa..6aca86f8fa0 100644 --- a/drools-core/src/main/java/org/drools/core/base/WrappedStatefulKnowledgeSessionForRHS.java +++ b/drools-core/src/main/java/org/drools/core/base/WrappedStatefulKnowledgeSessionForRHS.java @@ -58,7 +58,6 @@ import org.kie.api.runtime.rule.ViewChangedEventListener; import org.kie.api.time.SessionClock; import org.kie.internal.KnowledgeBase; -import org.kie.internal.command.Context; import org.kie.internal.event.rule.RuleEventListener; import org.kie.internal.process.CorrelationKey; import org.kie.internal.runtime.KnowledgeRuntime; @@ -172,10 +171,6 @@ public T execute(Command command) { return delegate.execute(command); } - public T execute(Context context, Command command) { - return delegate.execute(context, command); - } - public void initInitialFact(InternalKnowledgeBase kBase, MarshallerReaderContext context) { delegate.initInitialFact(kBase, context); } diff --git a/drools-core/src/main/java/org/drools/core/command/ConversationContext.java b/drools-core/src/main/java/org/drools/core/command/ConversationContext.java deleted file mode 100644 index a69286180cb..00000000000 --- a/drools-core/src/main/java/org/drools/core/command/ConversationContext.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.drools.core.command; - -import org.drools.core.command.impl.ContextImpl; -import org.kie.internal.command.Context; -import org.kie.internal.command.ContextManager; - -public class ConversationContext extends ContextImpl { - - private long conversationId; - - public ConversationContext(long conversationId, ContextManager manager, Context delegate) { - super(Long.toString(conversationId), manager, delegate); - } - - public ConversationContext(long conversationId, ContextManager manager) { - super(Long.toString(conversationId), manager); - this.conversationId = conversationId; - - } - - public long getConversationId() { - return conversationId; - } -} diff --git a/drools-core/src/main/java/org/drools/core/command/ConversationContextManager.java b/drools-core/src/main/java/org/drools/core/command/ConversationContextManager.java index 91e53a44f6e..2672441beb7 100644 --- a/drools-core/src/main/java/org/drools/core/command/ConversationContextManager.java +++ b/drools-core/src/main/java/org/drools/core/command/ConversationContextManager.java @@ -1,44 +1,43 @@ package org.drools.core.command; -import org.drools.core.command.RequestContextImpl; -import org.kie.internal.command.Context; - import org.drools.core.command.impl.ContextImpl; +import org.kie.api.runtime.Context; import java.util.HashMap; import java.util.Map; +import java.util.UUID; public class ConversationContextManager { - private Map conversationContexts; + private Map conversationContexts; private long counter; public ConversationContextManager() { - conversationContexts = new HashMap(); + conversationContexts = new HashMap(); } public void startConversation(RequestContextImpl requestContext) { - long conversationId = counter++; - ConversationContext ctx = new ConversationContext(conversationId, null); + String conversationId = UUID.randomUUID().toString(); + ContextImpl ctx = new ContextImpl( conversationId, null); conversationContexts.put(conversationId, ctx); requestContext.setConversationContext(ctx); } - public void joinConversation(RequestContextImpl requestContext, long conversationId) { - ConversationContext ctx = (ConversationContext) conversationContexts.get(conversationId); + public void joinConversation(RequestContextImpl requestContext, String conversationId) { + Context ctx = conversationContexts.get( conversationId ); if ( ctx == null ) { throw new RuntimeException("Conversation cannot be found"); } requestContext.setConversationContext(ctx); } - public void leaveConversation(RequestContextImpl requestContext, long conversationId) { + public void leaveConversation(RequestContextImpl requestContext, String conversationId) { throw new UnsupportedOperationException("Need to implement"); } - public void endConversation(RequestContextImpl requestContext, long conversationId) { + public void endConversation(RequestContextImpl requestContext, String conversationId) { conversationContexts.remove(conversationId); requestContext.setConversationContext(null); } diff --git a/drools-core/src/main/java/org/drools/core/command/EndConversationCommand.java b/drools-core/src/main/java/org/drools/core/command/EndConversationCommand.java index 9a81267b406..480f58bd90b 100644 --- a/drools-core/src/main/java/org/drools/core/command/EndConversationCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/EndConversationCommand.java @@ -1,16 +1,16 @@ package org.drools.core.command; import org.drools.core.command.impl.ExecutableCommand; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class EndConversationCommand implements ExecutableCommand { - private long conversationId; + private String conversationId; public EndConversationCommand() { } - public EndConversationCommand(long conversationId) { + public EndConversationCommand(String conversationId) { this.conversationId = conversationId; } diff --git a/drools-core/src/main/java/org/drools/core/command/ExecuteCommand.java b/drools-core/src/main/java/org/drools/core/command/ExecuteCommand.java index a05414ddf52..edad5044958 100644 --- a/drools-core/src/main/java/org/drools/core/command/ExecuteCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/ExecuteCommand.java @@ -25,7 +25,7 @@ import org.kie.api.runtime.ExecutionResults; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import java.util.HashMap; @@ -62,7 +62,7 @@ public ExecutionResults execute(Context context) { ExecutionResults kresults = null; if( ksession instanceof StatefulKnowledgeSessionImpl ) { - kresults = ((StatefulKnowledgeSessionImpl)ksession).execute(context, this.command ); + kresults = ksession.execute(this.command ); } else { // Graceful failure diff --git a/drools-core/src/main/java/org/drools/core/command/FinishedCommand.java b/drools-core/src/main/java/org/drools/core/command/FinishedCommand.java index bb528877b69..b318a09027a 100644 --- a/drools-core/src/main/java/org/drools/core/command/FinishedCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/FinishedCommand.java @@ -17,7 +17,7 @@ package org.drools.core.command; import org.drools.core.command.impl.ExecutableCommand; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class FinishedCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/GetKieContainerCommand.java b/drools-core/src/main/java/org/drools/core/command/GetKieContainerCommand.java index f9f3d72a06d..02645d0f960 100644 --- a/drools-core/src/main/java/org/drools/core/command/GetKieContainerCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/GetKieContainerCommand.java @@ -21,7 +21,7 @@ import org.kie.api.KieServices; import org.kie.api.builder.ReleaseId; import org.kie.api.runtime.KieContainer; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class GetKieContainerCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/GetSessionClockCommand.java b/drools-core/src/main/java/org/drools/core/command/GetSessionClockCommand.java index bc24b86a0fb..f0cd412b167 100644 --- a/drools-core/src/main/java/org/drools/core/command/GetSessionClockCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/GetSessionClockCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; import org.kie.api.time.SessionClock; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class GetSessionClockCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/GetVariableCommand.java b/drools-core/src/main/java/org/drools/core/command/GetVariableCommand.java index fb82ad3a2d9..193f576b181 100644 --- a/drools-core/src/main/java/org/drools/core/command/GetVariableCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/GetVariableCommand.java @@ -16,15 +16,16 @@ package org.drools.core.command; +import org.drools.core.command.impl.ExecutableCommand; +import org.drools.core.command.impl.RegistryContext; +import org.kie.api.runtime.Context; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlSchemaType; -import org.drools.core.command.impl.ExecutableCommand; -import org.kie.internal.command.Context; - @XmlRootElement(name="get-variable-command") @XmlAccessorType(XmlAccessType.FIELD) public class GetVariableCommand implements ExecutableCommand { @@ -56,7 +57,7 @@ public Object execute(Context ctx) { if ( this.contextName == null ) { targetCtx = ctx; } else { - targetCtx = ctx.getContextManager().getContext( this.contextName ); + targetCtx = ( (RegistryContext) ctx ).getContextManager().getContext( this.contextName ); } return targetCtx.get( identifier); diff --git a/drools-core/src/main/java/org/drools/core/command/JoinConversationCommand.java b/drools-core/src/main/java/org/drools/core/command/JoinConversationCommand.java index 706026e7810..1f02ea66f18 100644 --- a/drools-core/src/main/java/org/drools/core/command/JoinConversationCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/JoinConversationCommand.java @@ -1,13 +1,13 @@ package org.drools.core.command; import org.drools.core.command.impl.ExecutableCommand; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class JoinConversationCommand implements ExecutableCommand { - private long conversationId; + private String conversationId; - public JoinConversationCommand(long conversationId) { + public JoinConversationCommand(String conversationId) { this.conversationId = conversationId; } diff --git a/drools-core/src/main/java/org/drools/core/command/KnowledgeBaseAddKnowledgePackagesCommand.java b/drools-core/src/main/java/org/drools/core/command/KnowledgeBaseAddKnowledgePackagesCommand.java index 5820b305bf5..89f0037d00a 100644 --- a/drools-core/src/main/java/org/drools/core/command/KnowledgeBaseAddKnowledgePackagesCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/KnowledgeBaseAddKnowledgePackagesCommand.java @@ -21,7 +21,7 @@ import org.kie.api.KieBase; import org.kie.internal.KnowledgeBase; import org.kie.internal.builder.KnowledgeBuilder; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class KnowledgeBaseAddKnowledgePackagesCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/LeaveConversationCommand.java b/drools-core/src/main/java/org/drools/core/command/LeaveConversationCommand.java index a16d31a2969..b4753ecf0a6 100644 --- a/drools-core/src/main/java/org/drools/core/command/LeaveConversationCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/LeaveConversationCommand.java @@ -1,7 +1,7 @@ package org.drools.core.command; import org.drools.core.command.impl.ExecutableCommand; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class LeaveConversationCommand implements ExecutableCommand { @@ -12,7 +12,7 @@ public LeaveConversationCommand() { public Void execute(Context context) { RequestContextImpl reqContext = (RequestContextImpl)context; ConversationContextManager cvnManager = reqContext.getConversationManager(); - cvnManager.leaveConversation(reqContext, reqContext.getConversationContext().getConversationId()); + cvnManager.leaveConversation(reqContext, reqContext.getConversationContext().getName()); return (Void) null; } diff --git a/drools-core/src/main/java/org/drools/core/command/NewKieSessionCommand.java b/drools-core/src/main/java/org/drools/core/command/NewKieSessionCommand.java index d9f127dbe9d..2f0641734c1 100644 --- a/drools-core/src/main/java/org/drools/core/command/NewKieSessionCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/NewKieSessionCommand.java @@ -22,7 +22,7 @@ import org.kie.api.builder.ReleaseId; import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class NewKieSessionCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/NewKnowledgeBuilderConfigurationCommand.java b/drools-core/src/main/java/org/drools/core/command/NewKnowledgeBuilderConfigurationCommand.java index dcffc61b3cd..4db24e6fcaf 100644 --- a/drools-core/src/main/java/org/drools/core/command/NewKnowledgeBuilderConfigurationCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/NewKnowledgeBuilderConfigurationCommand.java @@ -18,7 +18,7 @@ import org.drools.core.command.impl.ExecutableCommand; import org.kie.internal.builder.KnowledgeBuilderFactory; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; /** * diff --git a/drools-core/src/main/java/org/drools/core/command/OutCommand.java b/drools-core/src/main/java/org/drools/core/command/OutCommand.java index 45cdbb377f9..7ea6c8172a6 100644 --- a/drools-core/src/main/java/org/drools/core/command/OutCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/OutCommand.java @@ -1,7 +1,8 @@ package org.drools.core.command; import org.drools.core.command.impl.ExecutableCommand; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; +import org.kie.api.runtime.RequestContext; public class OutCommand implements ExecutableCommand { @@ -16,7 +17,7 @@ public OutCommand(String name) { @Override public T execute(Context context) { - T returned = (T) ((RequestContextImpl)context).getLastReturned(); + T returned = (T) ((RequestContext)context).getResult(); String actualName; if ( this.name != null ) { @@ -28,7 +29,7 @@ public T execute(Context context) { } } - ((RequestContextImpl)context).getOut().put(actualName, returned); + context.set(actualName, returned); return returned; } diff --git a/drools-core/src/main/java/org/drools/core/command/RequestContextImpl.java b/drools-core/src/main/java/org/drools/core/command/RequestContextImpl.java index 5cd8ca2a30a..7da5ad1c462 100644 --- a/drools-core/src/main/java/org/drools/core/command/RequestContextImpl.java +++ b/drools-core/src/main/java/org/drools/core/command/RequestContextImpl.java @@ -17,34 +17,34 @@ package org.drools.core.command; import org.drools.core.command.impl.ContextImpl; -import org.kie.internal.command.Context; +import org.drools.core.runtime.impl.ExecutionResultImpl; +import org.kie.api.KieBase; +import org.kie.api.runtime.Context; +import org.kie.api.runtime.KieSession; +import org.kie.api.runtime.RequestContext; import org.kie.internal.command.ContextManager; -import org.kie.internal.fluent.RequestContext; - -import java.util.HashMap; -import java.util.Map; public class RequestContextImpl extends ContextImpl implements RequestContext { - private ContextImpl appContext; - private ConversationContext conversationContext; + private Context appContext; + private Context conversationContext; private ConversationContextManager cvnManager; - private final long requestId; - - private Object lastReturned; + private Object result; private String lastSet; - private final Map out = new HashMap(); - private Exception exception; + public RequestContextImpl() { + register( ExecutionResultImpl.class, new ExecutionResultImpl() ); + } + public RequestContextImpl(long requestId, ContextManager ctxManager, ConversationContextManager cvnManager) { super(Long.toString(requestId), ctxManager); - this.requestId = requestId; this.cvnManager = cvnManager; + register( ExecutionResultImpl.class, new ExecutionResultImpl() ); } public Context getApplicationContext() { @@ -55,11 +55,11 @@ public void setApplicationContext(Context appContext) { this.appContext = (ContextImpl)appContext; } - public ConversationContext getConversationContext() { + public Context getConversationContext() { return conversationContext; } - public void setConversationContext(ConversationContext conversationContext) { + public void setConversationContext(Context conversationContext ) { this.conversationContext = conversationContext; } @@ -86,21 +86,25 @@ public Object get(String identifier) { } @Override - public long getRequestId() { - return requestId; + public Object getResult() { + return result; } @Override - public long getConversationId() { - return conversationContext.getConversationId(); + public void setResult( Object result ) { + this.result = result; } - public Object getLastReturned() { - return lastReturned; + @Override + public RequestContext with( KieBase kieBase ) { + register( KieBase.class, kieBase ); + return this; } - public void setLastReturned(Object lastReturned) { - this.lastReturned = lastReturned; + @Override + public RequestContext with( KieSession kieSession ) { + register( KieSession.class, kieSession ); + return this; } public String getLastSet() { @@ -111,11 +115,6 @@ public void setLastSetOrGet(String lastSet) { this.lastSet = lastSet; } - @Override - public Map getOut() { - return out; - } - public Exception getException() { return exception; } diff --git a/drools-core/src/main/java/org/drools/core/command/SetVariableCommandFromCommand.java b/drools-core/src/main/java/org/drools/core/command/SetVariableCommandFromCommand.java index 4f500f9fdde..5dc6ca1ef11 100644 --- a/drools-core/src/main/java/org/drools/core/command/SetVariableCommandFromCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/SetVariableCommandFromCommand.java @@ -17,9 +17,10 @@ package org.drools.core.command; import org.drools.core.command.impl.ExecutableCommand; +import org.drools.core.command.impl.RegistryContext; import org.drools.core.world.impl.ContextManagerImpl; import org.kie.api.command.Command; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class SetVariableCommandFromCommand implements @@ -38,10 +39,10 @@ public SetVariableCommandFromCommand(String contextName, public Void execute(Context context) { if ( this.contextName == null ) { - context.getContextManager().getContext( ContextManagerImpl.ROOT ).set( this.identifier, - ((ExecutableCommand) this.cmd).execute( context ) ); + ( (RegistryContext) context ).getContextManager().getContext( ContextManagerImpl.ROOT ).set( this.identifier, + ((ExecutableCommand) this.cmd).execute( context ) ); } else { - context.getContextManager().getContext( this.contextName ).set( this.identifier, + ( (RegistryContext) context ).getContextManager().getContext( this.contextName ).set( this.identifier, ((ExecutableCommand) this.cmd).execute( context ) ); } return null; diff --git a/drools-core/src/main/java/org/drools/core/command/SetVariableCommandFromLastReturn.java b/drools-core/src/main/java/org/drools/core/command/SetVariableCommandFromLastReturn.java index 4330b3e1bf4..aa8a705dc94 100644 --- a/drools-core/src/main/java/org/drools/core/command/SetVariableCommandFromLastReturn.java +++ b/drools-core/src/main/java/org/drools/core/command/SetVariableCommandFromLastReturn.java @@ -16,15 +16,16 @@ package org.drools.core.command; -import java.util.HashMap; -import java.util.Map; - -import org.kie.api.runtime.rule.FactHandle; import org.drools.core.command.impl.ExecutableCommand; +import org.drools.core.command.impl.RegistryContext; import org.drools.core.common.InternalFactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.rule.FactHandle; +import org.kie.api.runtime.Context; import org.kie.internal.fluent.Scope; +import java.util.HashMap; +import java.util.Map; + public class SetVariableCommandFromLastReturn implements ExecutableCommand { @@ -55,7 +56,7 @@ public Object execute(Context context) { if ( this.contextName == null ) { targetCtx = context; } else { - targetCtx = context.getContextManager().getContext( this.contextName ); + targetCtx = ( (RegistryContext) context ).getContextManager().getContext( this.contextName ); } GetDefaultValue sim = (GetDefaultValue) context.get( "simulator" ); diff --git a/drools-core/src/main/java/org/drools/core/command/SingleSessionCommandService.java b/drools-core/src/main/java/org/drools/core/command/SingleSessionCommandService.java index 562206a58ac..4827c5e8b06 100644 --- a/drools-core/src/main/java/org/drools/core/command/SingleSessionCommandService.java +++ b/drools-core/src/main/java/org/drools/core/command/SingleSessionCommandService.java @@ -17,8 +17,13 @@ package org.drools.core.command; -public interface SingleSessionCommandService extends CommandService { +import org.drools.core.runtime.InternalLocalRunner; +import org.kie.api.runtime.KieSession; + +public interface SingleSessionCommandService extends InternalLocalRunner { + KieSession getKieSession(); Long getSessionId(); + void dispose(); void destroy(); } diff --git a/drools-core/src/main/java/org/drools/core/command/StartConversationCommand.java b/drools-core/src/main/java/org/drools/core/command/StartConversationCommand.java index 84f6b544504..f35bb3609ed 100644 --- a/drools-core/src/main/java/org/drools/core/command/StartConversationCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/StartConversationCommand.java @@ -1,7 +1,7 @@ package org.drools.core.command; import org.drools.core.command.impl.ExecutableCommand; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class StartConversationCommand implements ExecutableCommand { diff --git a/drools-core/src/main/java/org/drools/core/command/assertion/AssertEquals.java b/drools-core/src/main/java/org/drools/core/command/assertion/AssertEquals.java index 43b023e21a1..5c2994e4526 100644 --- a/drools-core/src/main/java/org/drools/core/command/assertion/AssertEquals.java +++ b/drools-core/src/main/java/org/drools/core/command/assertion/AssertEquals.java @@ -23,7 +23,7 @@ import org.drools.core.util.MVELSafeHelper; import org.drools.core.util.StringUtils; import org.kie.api.command.Command; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class AssertEquals implements diff --git a/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderAddCommand.java b/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderAddCommand.java index 736817a615a..505003cd539 100644 --- a/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderAddCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderAddCommand.java @@ -22,7 +22,7 @@ import org.kie.api.io.ResourceConfiguration; import org.kie.api.io.ResourceType; import org.kie.internal.builder.KnowledgeBuilder; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class KnowledgeBuilderAddCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderGetErrorsCommand.java b/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderGetErrorsCommand.java index 0bbb7aca40e..cc1b081c0cc 100644 --- a/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderGetErrorsCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderGetErrorsCommand.java @@ -21,7 +21,7 @@ import org.drools.core.runtime.impl.ExecutionResultImpl; import org.kie.internal.builder.KnowledgeBuilder; import org.kie.internal.builder.KnowledgeBuilderErrors; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class KnowledgeBuilderGetErrorsCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderGetKnowledgePackagesCommand.java b/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderGetKnowledgePackagesCommand.java index 701ef5ec4d5..534340e84c6 100644 --- a/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderGetKnowledgePackagesCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderGetKnowledgePackagesCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.drools.core.runtime.impl.ExecutionResultImpl; import org.kie.internal.builder.KnowledgeBuilder; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.definition.KnowledgePackage; import java.util.Collection; diff --git a/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderHasErrorsCommand.java b/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderHasErrorsCommand.java index 8a2b3e2ddb7..358781f5eb1 100644 --- a/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderHasErrorsCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/builder/KnowledgeBuilderHasErrorsCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.drools.core.runtime.impl.ExecutionResultImpl; import org.kie.internal.builder.KnowledgeBuilder; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class KnowledgeBuilderHasErrorsCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/builder/NewKnowledgeBuilderCommand.java b/drools-core/src/main/java/org/drools/core/command/builder/NewKnowledgeBuilderCommand.java index 045ff237728..2fa16102c40 100644 --- a/drools-core/src/main/java/org/drools/core/command/builder/NewKnowledgeBuilderCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/builder/NewKnowledgeBuilderCommand.java @@ -24,7 +24,7 @@ import org.kie.internal.builder.KnowledgeBuilder; import org.kie.internal.builder.KnowledgeBuilderConfiguration; import org.kie.internal.builder.KnowledgeBuilderFactory; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class NewKnowledgeBuilderCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/impl/AbstractInterceptor.java b/drools-core/src/main/java/org/drools/core/command/impl/AbstractInterceptor.java index 90abbe8fd94..e2a0af27b89 100644 --- a/drools-core/src/main/java/org/drools/core/command/impl/AbstractInterceptor.java +++ b/drools-core/src/main/java/org/drools/core/command/impl/AbstractInterceptor.java @@ -16,29 +16,26 @@ package org.drools.core.command.impl; -import org.drools.core.command.CommandService; -import org.drools.core.command.Interceptor; -import org.kie.api.command.Command; -import org.kie.internal.command.Context; +import org.drools.core.fluent.impl.PseudoClockRunner; +import org.drools.core.runtime.ChainableRunner; +import org.kie.api.runtime.Context; +import org.kie.api.runtime.Executable; +import org.kie.api.runtime.ExecutableRunner; +import org.kie.api.runtime.RequestContext; -public abstract class AbstractInterceptor implements Interceptor { +public abstract class AbstractInterceptor extends PseudoClockRunner implements ChainableRunner { - private CommandService next; + private ExecutableRunner next; - public Context getContext() { - return next.getContext(); + public void setNext(ExecutableRunner runner) { + this.next = runner; } - public void setNext(CommandService commandService) { - this.next = commandService; - } - - public CommandService getNext() { + public ExecutableRunner getNext() { return next; } - protected T executeNext(Command command) { - return next.execute(command); + protected void executeNext( Executable executable, Context ctx ) { + next.execute(executable, ( (RequestContext) ctx ) ); } - } diff --git a/drools-core/src/main/java/org/drools/core/command/impl/AsynchronousInterceptor.java b/drools-core/src/main/java/org/drools/core/command/impl/AsynchronousInterceptor.java index 9c355d459a1..7f3ee095e80 100644 --- a/drools-core/src/main/java/org/drools/core/command/impl/AsynchronousInterceptor.java +++ b/drools-core/src/main/java/org/drools/core/command/impl/AsynchronousInterceptor.java @@ -16,18 +16,19 @@ package org.drools.core.command.impl; -import org.kie.api.command.Command; +import org.kie.api.runtime.Executable; +import org.kie.api.runtime.RequestContext; public class AsynchronousInterceptor extends AbstractInterceptor { - public T execute(final Command command) { + public RequestContext execute( Executable executable, RequestContext ctx ) { new Thread(new Runnable() { public void run() { - executeNext(command); + executeNext(executable, ctx); } }).start(); - return null; + return ctx; } } diff --git a/drools-core/src/main/java/org/drools/core/command/impl/CommandBasedEntryPoint.java b/drools-core/src/main/java/org/drools/core/command/impl/CommandBasedEntryPoint.java index e7d5e8c1e3e..21dde381117 100644 --- a/drools-core/src/main/java/org/drools/core/command/impl/CommandBasedEntryPoint.java +++ b/drools-core/src/main/java/org/drools/core/command/impl/CommandBasedEntryPoint.java @@ -15,7 +15,7 @@ package org.drools.core.command.impl; -import org.drools.core.command.CommandService; +import org.kie.api.runtime.ExecutableRunner; import org.drools.core.command.runtime.GetFactCountInEntryPointCommand; import org.drools.core.command.runtime.rule.DeleteFromEntryPointCommand; import org.drools.core.command.runtime.rule.GetFactHandleInEntryPointCommand; @@ -32,11 +32,11 @@ public class CommandBasedEntryPoint implements EntryPoint { - private final CommandService commandService; + private final ExecutableRunner runner; private final String entryPoint; - public CommandBasedEntryPoint(CommandService commandService, String entryPoint) { - this.commandService = commandService; + public CommandBasedEntryPoint( ExecutableRunner runner, String entryPoint ) { + this.runner = runner; this.entryPoint = entryPoint; } @@ -47,7 +47,7 @@ public String getEntryPointId() { @Override public FactHandle insert(Object object) { - return commandService.execute( new InsertObjectInEntryPointCommand( object, entryPoint ) ); + return runner.execute( new InsertObjectInEntryPointCommand( object, entryPoint ) ); } @Override @@ -57,56 +57,56 @@ public void retract(FactHandle handle) { @Override public void delete(FactHandle handle) { - commandService.execute( new DeleteFromEntryPointCommand( handle, entryPoint ) ); + runner.execute( new DeleteFromEntryPointCommand( handle, entryPoint ) ); } @Override public void delete(FactHandle handle, FactHandle.State fhState) { - commandService.execute( new DeleteFromEntryPointCommand( handle, entryPoint, fhState ) ); + runner.execute( new DeleteFromEntryPointCommand( handle, entryPoint, fhState ) ); } @Override public void update(FactHandle handle, Object object) { - commandService.execute( new UpdateInEntryPointCommand( handle, object, entryPoint ) ); + runner.execute( new UpdateInEntryPointCommand( handle, object, entryPoint ) ); } @Override public void update(FactHandle handle, Object object, String... modifiedProperties) { - commandService.execute( new UpdateInEntryPointCommand( handle, object, entryPoint, modifiedProperties ) ); + runner.execute( new UpdateInEntryPointCommand( handle, object, entryPoint, modifiedProperties ) ); } @Override public FactHandle getFactHandle(Object object) { - return commandService.execute( new GetFactHandleInEntryPointCommand(object, entryPoint) ); + return runner.execute( new GetFactHandleInEntryPointCommand(object, entryPoint) ); } @Override public Object getObject(FactHandle factHandle) { - return commandService.execute( new GetObjectInEntryPointCommand(factHandle, entryPoint) ); + return runner.execute( new GetObjectInEntryPointCommand(factHandle, entryPoint) ); } @Override public Collection getObjects() { - return commandService.execute( new GetObjectsInEntryPointCommand(null, entryPoint) ); + return runner.execute( new GetObjectsInEntryPointCommand(null, entryPoint) ); } @Override public Collection getObjects(ObjectFilter filter) { - return commandService.execute( new GetObjectsInEntryPointCommand(filter, entryPoint) ); + return runner.execute( new GetObjectsInEntryPointCommand(filter, entryPoint) ); } @Override public Collection getFactHandles() { - return (Collection) commandService.execute( new GetFactHandlesInEntryPointCommand(entryPoint) ); + return (Collection) runner.execute( new GetFactHandlesInEntryPointCommand(entryPoint) ); } @Override public Collection getFactHandles(ObjectFilter filter) { - return (Collection) commandService.execute( new GetFactHandlesInEntryPointCommand(entryPoint, filter) ); + return (Collection) runner.execute( new GetFactHandlesInEntryPointCommand(entryPoint, filter) ); } @Override public long getFactCount() { - return commandService.execute( new GetFactCountInEntryPointCommand(entryPoint) ); + return runner.execute( new GetFactCountInEntryPointCommand(entryPoint) ); } } diff --git a/drools-core/src/main/java/org/drools/core/command/impl/CommandBasedStatefulKnowledgeSession.java b/drools-core/src/main/java/org/drools/core/command/impl/CommandBasedStatefulKnowledgeSession.java index ce59adc6cf0..583eb80d867 100644 --- a/drools-core/src/main/java/org/drools/core/command/impl/CommandBasedStatefulKnowledgeSession.java +++ b/drools-core/src/main/java/org/drools/core/command/impl/CommandBasedStatefulKnowledgeSession.java @@ -16,9 +16,8 @@ package org.drools.core.command.impl; -import org.drools.core.command.CommandService; +import org.kie.api.runtime.ExecutableRunner; import org.drools.core.command.GetSessionClockCommand; -import org.drools.core.command.Interceptor; import org.drools.core.command.runtime.AddEventListenerCommand; import org.drools.core.command.runtime.DestroySessionCommand; import org.drools.core.command.runtime.DisposeCommand; @@ -111,12 +110,12 @@ public class CommandBasedStatefulKnowledgeSession extends AbstractRuntime implements StatefulKnowledgeSession, CorrelationAwareProcessRuntime { - private CommandService commandService; + private ExecutableRunner runner; private transient WorkItemManager workItemManager; private transient Agenda agenda; - public CommandBasedStatefulKnowledgeSession(CommandService commandService) { - this.commandService = commandService; + public CommandBasedStatefulKnowledgeSession(ExecutableRunner runner ) { + this.runner = runner; } /** @@ -124,37 +123,37 @@ public CommandBasedStatefulKnowledgeSession(CommandService commandService) { */ @Deprecated public int getId() { - return commandService.execute( new GetIdCommand() ).intValue(); + return runner.execute( new GetIdCommand() ).intValue(); } public long getIdentifier() { - return commandService.execute( new GetIdCommand() ); + return runner.execute( new GetIdCommand() ); } public ProcessInstance getProcessInstance(long id) { GetProcessInstanceCommand command = new GetProcessInstanceCommand(); command.setProcessInstanceId( id ); - return commandService.execute( command ); + return runner.execute( command ); } public ProcessInstance getProcessInstance(long id, boolean readOnly) { GetProcessInstanceCommand command = new GetProcessInstanceCommand(); command.setProcessInstanceId( id ); command.setReadOnly( readOnly ); - return commandService.execute( command ); + return runner.execute( command ); } public void abortProcessInstance(long id) { AbortProcessInstanceCommand command = new AbortProcessInstanceCommand(); command.setProcessInstanceId( id ); - commandService.execute( command ); + runner.execute( command ); } - public CommandService getCommandService() { - return commandService; + public ExecutableRunner getRunner() { + return runner; } public Collection getProcessInstances() { - return this.commandService.execute( new GetProcessInstancesCommand() ); + return runner.execute( new GetProcessInstancesCommand() ); } public WorkItemManager getWorkItemManager() { @@ -165,13 +164,13 @@ public void completeWorkItem(long id, CompleteWorkItemCommand command = new CompleteWorkItemCommand(); command.setWorkItemId( id ); command.setResults( results ); - commandService.execute( command ); + runner.execute( command ); } public void abortWorkItem(long id) { AbortWorkItemCommand command = new AbortWorkItemCommand(); command.setWorkItemId( id ); - commandService.execute( command ); + runner.execute( command ); } public void registerWorkItemHandler(String workItemName, @@ -179,13 +178,13 @@ public void registerWorkItemHandler(String workItemName, RegisterWorkItemHandlerCommand command = new RegisterWorkItemHandlerCommand(); command.setWorkItemName( workItemName ); command.setHandler( handler ); - commandService.execute( command ); + runner.execute( command ); } public WorkItem getWorkItem(long id) { GetWorkItemCommand command = new GetWorkItemCommand(); command.setWorkItemId( id ); - return commandService.execute( command ); + return runner.execute( command ); } public void clear() { @@ -211,13 +210,13 @@ public void internalExecuteWorkItem(WorkItem workItem) { @Override public void signalEvent(String type, Object event) { SignalEventCommand command = new SignalEventCommand(type, event); - commandService.execute(command); + runner.execute(command); } @Override public void signalEvent(String type, Object event, long processInstanceId) { SignalEventCommand command = new SignalEventCommand(processInstanceId, type, event); - commandService.execute(command); + runner.execute(command); } @Override @@ -228,7 +227,7 @@ public void dispose() { @Override public void retryWorkItem( Long workItemID, Map params ) { ReTryWorkItemCommand command = new ReTryWorkItemCommand(workItemID,params); - commandService.execute( command ); + runner.execute( command ); } }; } @@ -239,7 +238,7 @@ public void signalEvent(String type, Object event) { SignalEventCommand command = new SignalEventCommand( type, event ); - commandService.execute( command ); + runner.execute( command ); } public void signalEvent(String type, @@ -248,7 +247,7 @@ public void signalEvent(String type, SignalEventCommand command = new SignalEventCommand( processInstanceId, type, event ); - commandService.execute( command ); + runner.execute( command ); } public ProcessInstance startProcess(String processId) { @@ -261,7 +260,7 @@ public ProcessInstance startProcess(String processId, StartProcessCommand command = new StartProcessCommand(); command.setProcessId( processId ); command.setParameters( parameters ); - return commandService.execute( command ); + return runner.execute( command ); } public ProcessInstance createProcessInstance(String processId, @@ -269,64 +268,64 @@ public ProcessInstance createProcessInstance(String processId, CreateProcessInstanceCommand command = new CreateProcessInstanceCommand(); command.setProcessId( processId ); command.setParameters( parameters ); - return commandService.execute( command ); + return runner.execute( command ); } public ProcessInstance startProcessInstance(long processInstanceId) { StartProcessInstanceCommand command = new StartProcessInstanceCommand(); command.setProcessInstanceId( processInstanceId ); - return commandService.execute( command ); + return runner.execute( command ); } public void dispose() { - commandService.execute( new DisposeCommand() ); + runner.execute( new DisposeCommand() ); } public void destroy() { - commandService.execute( new DestroySessionCommand(commandService)); + runner.execute( new DestroySessionCommand(runner)); } public int fireAllRules() { - return this.commandService.execute( new FireAllRulesCommand() ); + return this.runner.execute( new FireAllRulesCommand() ); } public int fireAllRules(int max) { - return this.commandService.execute( new FireAllRulesCommand( max ) ); + return this.runner.execute( new FireAllRulesCommand( max ) ); } public int fireAllRules(AgendaFilter agendaFilter) { - return this.commandService.execute( new FireAllRulesCommand( agendaFilter ) ); + return this.runner.execute( new FireAllRulesCommand( agendaFilter ) ); } public int fireAllRules(AgendaFilter agendaFilter, int max) { - return this.commandService.execute( new FireAllRulesCommand( agendaFilter, max ) ); + return this.runner.execute( new FireAllRulesCommand( agendaFilter, max ) ); } public void fireUntilHalt() { - this.commandService.execute( new FireUntilHaltCommand() ); + this.runner.execute( new FireUntilHaltCommand() ); } public void fireUntilHalt(AgendaFilter agendaFilter) { - this.commandService.execute( new FireUntilHaltCommand( agendaFilter ) ); + this.runner.execute( new FireUntilHaltCommand( agendaFilter ) ); } public KnowledgeBase getKieBase() { - return this.commandService.execute( new GetKnowledgeBaseCommand() ); + return this.runner.execute( new GetKnowledgeBaseCommand() ); } public void registerChannel(String name, Channel channel) { - this.commandService.execute( new RegisterChannelCommand( name, + this.runner.execute( new RegisterChannelCommand( name, channel ) ); } public void unregisterChannel(String name) { - this.commandService.execute( new UnregisterChannelCommand( name ) ); + this.runner.execute( new UnregisterChannelCommand( name ) ); } @SuppressWarnings("unchecked") public Map getChannels() { - return (Map) this.commandService.execute( new GetChannelsCommand() ); + return (Map) this.runner.execute( new GetChannelsCommand() ); } public Agenda getAgenda() { @@ -334,7 +333,7 @@ public Agenda getAgenda() { agenda = new Agenda() { public void clear() { ClearAgendaCommand command = new ClearAgendaCommand(); - commandService.execute( command ); + runner.execute( command ); } public ActivationGroup getActivationGroup(final String name) { @@ -342,7 +341,7 @@ public ActivationGroup getActivationGroup(final String name) { public void clear() { ClearActivationGroupCommand command = new ClearActivationGroupCommand(); command.setName( name ); - commandService.execute( command ); + runner.execute( command ); } public String getName() { @@ -356,7 +355,7 @@ public AgendaGroup getAgendaGroup(final String name) { public void clear() { ClearAgendaGroupCommand command = new ClearAgendaGroupCommand(); command.setName( name ); - commandService.execute( command ); + runner.execute( command ); } public String getName() { @@ -366,7 +365,7 @@ public String getName() { public void setFocus() { AgendaGroupSetFocusCommand command = new AgendaGroupSetFocusCommand(); command.setName( name ); - commandService.execute( command ); + runner.execute( command ); } }; } @@ -376,7 +375,7 @@ public RuleFlowGroup getRuleFlowGroup(final String name) { public void clear() { ClearRuleFlowGroupCommand command = new ClearRuleFlowGroupCommand(); command.setName( name ); - commandService.execute( command ); + runner.execute( command ); } public String getName() { @@ -390,16 +389,16 @@ public String getName() { } public FactHandle getFactHandle(Object object) { - return this.commandService.execute( new GetFactHandleCommand( object ) ); + return this.runner.execute( new GetFactHandleCommand( object ) ); } public Collection getFactHandles() { - return (Collection) this.commandService.execute( new GetFactHandlesCommand() ); + return (Collection) this.runner.execute( new GetFactHandlesCommand() ); } public Collection getFactHandles(ObjectFilter filter) { - return (Collection) this.commandService.execute( new GetFactHandlesCommand( filter ) ); + return (Collection) this.runner.execute( new GetFactHandlesCommand( filter ) ); } public Collection getObjects() { @@ -407,29 +406,29 @@ public Collection getObjects() { } public Collection getObjects(ObjectFilter filter) { - Collection result = commandService.execute( new GetObjectsCommand( filter ) ); + Collection result = runner.execute( new GetObjectsCommand( filter ) ); return result; } @SuppressWarnings("unchecked") public T getSessionClock() { - return (T) this.commandService.execute( new GetSessionClockCommand() ); + return (T) this.runner.execute( new GetSessionClockCommand() ); } public EntryPoint getEntryPoint(String name) { - return this.commandService.execute( new GetEntryPointCommand( name ) ); + return this.runner.execute( new GetEntryPointCommand( name ) ); } public Collection< ? extends EntryPoint> getEntryPoints() { - return this.commandService.execute( new GetEntryPointsCommand() ); + return this.runner.execute( new GetEntryPointsCommand() ); } public void halt() { - this.commandService.execute( new HaltCommand() ); + this.runner.execute( new HaltCommand() ); } public FactHandle insert(Object object) { - return commandService.execute( new InsertObjectCommand( object ) ); + return runner.execute( new InsertObjectCommand( object ) ); } public void submit( AtomicAction action ) { @@ -437,100 +436,100 @@ public void submit( AtomicAction action ) { } @Override - public T getKieRuntime(Class cls) { + public T getKieRuntime( Class cls ) { throw new UnsupportedOperationException( "Retrieving runtimes is not supported throught the command based session at this time." ); } public void retract(FactHandle handle) { - commandService.execute( new DeleteCommand( handle ) ); + runner.execute( new DeleteCommand( handle ) ); } public void delete(FactHandle handle) { - commandService.execute( new DeleteCommand( handle ) ); + runner.execute( new DeleteCommand( handle ) ); } public void delete(FactHandle handle, FactHandle.State fhState) { - commandService.execute( new DeleteCommand( handle, fhState ) ); + runner.execute( new DeleteCommand( handle, fhState ) ); } public void update(FactHandle handle, Object object) { - commandService.execute( new UpdateCommand( handle, + runner.execute( new UpdateCommand( handle, object ) ); } public void update(FactHandle handle, Object object, String... modifiedProperties) { - commandService.execute( new UpdateCommand( handle, + runner.execute( new UpdateCommand( handle, object, modifiedProperties ) ); } public void addEventListener(RuleRuntimeEventListener listener) { - commandService.execute(new AddEventListenerCommand(listener)); + runner.execute(new AddEventListenerCommand(listener)); } public void addEventListener(AgendaEventListener listener) { - commandService.execute( new AddEventListenerCommand( listener ) ); + runner.execute( new AddEventListenerCommand( listener ) ); } public Collection getAgendaEventListeners() { - return commandService.execute( new GetAgendaEventListenersCommand() ); + return runner.execute( new GetAgendaEventListenersCommand() ); } public Collection getRuleRuntimeEventListeners() { - return commandService.execute( new GetRuleRuntimeEventListenersCommand() ); + return runner.execute( new GetRuleRuntimeEventListenersCommand() ); } public void removeEventListener(RuleRuntimeEventListener listener) { - commandService.execute( new RemoveEventListenerCommand( listener ) ); + runner.execute( new RemoveEventListenerCommand( listener ) ); } public void removeEventListener(AgendaEventListener listener) { - commandService.execute( new RemoveEventListenerCommand( listener ) ); + runner.execute( new RemoveEventListenerCommand( listener ) ); } public void addEventListener(ProcessEventListener listener) { - commandService.execute( new AddEventListenerCommand( listener ) ); + runner.execute( new AddEventListenerCommand( listener ) ); } public Collection getProcessEventListeners() { - return commandService.execute( new GetProcessEventListenersCommand() ); + return runner.execute( new GetProcessEventListenersCommand() ); } public void removeEventListener(ProcessEventListener listener) { - commandService.execute( new RemoveEventListenerCommand( listener ) ); + runner.execute( new RemoveEventListenerCommand( listener ) ); } public Object getGlobal(String identifier) { - return commandService.execute( new GetGlobalCommand( identifier ) ); + return runner.execute( new GetGlobalCommand( identifier ) ); } public void setGlobal(String identifier, Object object) { - this.commandService.execute( new SetGlobalCommand( identifier, + this.runner.execute( new SetGlobalCommand( identifier, object ) ); } public Globals getGlobals() { - return commandService.execute( new GetGlobalsCommand() ); + return runner.execute( new GetGlobalsCommand() ); } public Calendars getCalendars() { - return commandService.execute( new GetCalendarsCommand() ); + return runner.execute( new GetCalendarsCommand() ); } public Object getObject(FactHandle factHandle) { - return commandService.execute( new GetObjectCommand( factHandle ) ); + return runner.execute( new GetObjectCommand( factHandle ) ); } public Environment getEnvironment() { - return commandService.execute( new GetEnvironmentCommand() ); + return runner.execute( new GetEnvironmentCommand() ); } public T execute(Command command) { - return (T) this.commandService.execute( command ); + return (T) this.runner.execute( command ); } public QueryResults getQueryResults(String query, @@ -538,7 +537,7 @@ public QueryResults getQueryResults(String query, QueryCommand cmd = new QueryCommand( (String)null, query, arguments ); - return this.commandService.execute( cmd ); + return this.runner.execute( cmd ); } public String getEntryPointId() { @@ -546,7 +545,7 @@ public String getEntryPointId() { } public long getFactCount() { - return commandService.execute( new GetFactCountCommand() ); + return runner.execute( new GetFactCountCommand() ); } public LiveQuery openLiveQuery(String query, @@ -557,32 +556,27 @@ public LiveQuery openLiveQuery(String query, } public KieSessionConfiguration getSessionConfiguration() { - return ((RegistryContext) commandService.getContext()).lookup( KieSession.class ).getSessionConfiguration(); - } - - public void addInterceptor(Interceptor interceptor) { - interceptor.setNext(this.commandService); - this.commandService = interceptor; + return ((RegistryContext) runner.createContext()).lookup( KieSession.class ).getSessionConfiguration(); } @Override public ProcessInstance startProcess(String processId, CorrelationKey correlationKey, Map parameters) { - return this.commandService.execute(new StartCorrelatedProcessCommand(processId, correlationKey, parameters)); + return this.runner.execute(new StartCorrelatedProcessCommand(processId, correlationKey, parameters)); } @Override public ProcessInstance createProcessInstance(String processId, CorrelationKey correlationKey, Map parameters) { - return this.commandService.execute( + return this.runner.execute( new CreateCorrelatedProcessInstanceCommand(processId, correlationKey, parameters)); } @Override public ProcessInstance getProcessInstance(CorrelationKey correlationKey) { - return this.commandService.execute(new GetProcessInstanceByCorrelationKeyCommand(correlationKey)); + return this.runner.execute(new GetProcessInstanceByCorrelationKeyCommand(correlationKey)); } } diff --git a/drools-core/src/main/java/org/drools/core/command/impl/ContextImpl.java b/drools-core/src/main/java/org/drools/core/command/impl/ContextImpl.java index 1be2cc52d19..1ae2cbca427 100644 --- a/drools-core/src/main/java/org/drools/core/command/impl/ContextImpl.java +++ b/drools-core/src/main/java/org/drools/core/command/impl/ContextImpl.java @@ -17,7 +17,7 @@ package org.drools.core.command.impl; import org.drools.core.world.impl.ContextManagerImpl; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.command.ContextManager; import java.util.HashMap; diff --git a/drools-core/src/main/java/org/drools/core/command/impl/ContextImplWithEviction.java b/drools-core/src/main/java/org/drools/core/command/impl/ContextImplWithEviction.java index d6bd1ed6d3f..4e10f1b6c19 100644 --- a/drools-core/src/main/java/org/drools/core/command/impl/ContextImplWithEviction.java +++ b/drools-core/src/main/java/org/drools/core/command/impl/ContextImplWithEviction.java @@ -22,7 +22,7 @@ import java.util.logging.Level; import java.util.logging.Logger; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.command.ContextManager; public class ContextImplWithEviction extends ContextImpl{ diff --git a/drools-core/src/main/java/org/drools/core/command/impl/DefaultCommandService.java b/drools-core/src/main/java/org/drools/core/command/impl/DefaultCommandService.java deleted file mode 100644 index 87e7e0d1fb9..00000000000 --- a/drools-core/src/main/java/org/drools/core/command/impl/DefaultCommandService.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2010 Red Hat, Inc. and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.drools.core.command.impl; - -import org.drools.core.command.CommandService; -import org.kie.api.command.Command; -import org.kie.internal.command.Context; - -public class DefaultCommandService implements CommandService { - - private Context context; - - public DefaultCommandService(Context context) { - this.context = context; - } - - public Context getContext() { - return context; - } - - public T execute(Command command) { - return ((ExecutableCommand)command).execute( context ); - } - -} diff --git a/drools-core/src/main/java/org/drools/core/command/impl/ExecutableCommand.java b/drools-core/src/main/java/org/drools/core/command/impl/ExecutableCommand.java index 7993519c820..07870c606d2 100644 --- a/drools-core/src/main/java/org/drools/core/command/impl/ExecutableCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/impl/ExecutableCommand.java @@ -16,10 +16,13 @@ package org.drools.core.command.impl; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public interface ExecutableCommand extends org.kie.api.command.Command { T execute(Context context); + default boolean canRunInTransaction() { + return true; + } } diff --git a/drools-core/src/main/java/org/drools/core/command/impl/FireAllRulesInterceptor.java b/drools-core/src/main/java/org/drools/core/command/impl/FireAllRulesInterceptor.java index 1d90c107b21..539ee38bfbc 100644 --- a/drools-core/src/main/java/org/drools/core/command/impl/FireAllRulesInterceptor.java +++ b/drools-core/src/main/java/org/drools/core/command/impl/FireAllRulesInterceptor.java @@ -21,19 +21,34 @@ import org.drools.core.command.runtime.process.StartProcessCommand; import org.drools.core.command.runtime.process.StartProcessInstanceCommand; import org.drools.core.command.runtime.rule.FireAllRulesCommand; +import org.drools.core.fluent.impl.Batch; +import org.drools.core.fluent.impl.InternalExecutable; import org.kie.api.command.Command; +import org.kie.api.runtime.Executable; +import org.kie.api.runtime.RequestContext; public class FireAllRulesInterceptor extends AbstractInterceptor { - public T execute(Command command) { - T result = executeNext(command); - if (requiresFireAllRules(command)) { - executeNext(new FireAllRulesCommand()); + public RequestContext execute( Executable executable, RequestContext ctx ) { + executeNext(executable, ctx); + if (requiresFireAllRules( ( (InternalExecutable) executable ))) { + new FireAllRulesCommand().execute( ctx ); } - return result; + return ctx; } - protected boolean requiresFireAllRules(Command command) { + protected boolean requiresFireAllRules(InternalExecutable executable ) { + for (Batch batch : executable.getBatches()) { + for (Command command : batch.getCommands()) { + if (requiresFireAllRules( command )) { + return true; + } + } + } + return false; + } + + protected boolean requiresFireAllRules(Command command) { return command instanceof AbortWorkItemCommand || command instanceof CompleteWorkItemCommand || command instanceof SignalEventCommand diff --git a/drools-core/src/main/java/org/drools/core/command/impl/LoggingInterceptor.java b/drools-core/src/main/java/org/drools/core/command/impl/LoggingInterceptor.java index dd60766a1d2..346ed2cf731 100644 --- a/drools-core/src/main/java/org/drools/core/command/impl/LoggingInterceptor.java +++ b/drools-core/src/main/java/org/drools/core/command/impl/LoggingInterceptor.java @@ -16,7 +16,8 @@ package org.drools.core.command.impl; -import org.kie.api.command.Command; +import org.kie.api.runtime.Executable; +import org.kie.api.runtime.RequestContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,11 +26,10 @@ public class LoggingInterceptor extends AbstractInterceptor { protected static final transient Logger logger = LoggerFactory.getLogger(LoggingInterceptor.class); - public T execute(Command command) { - logger.info("Executing --> " + command); - T result = executeNext(command); - logger.info("Done executing --> " + command); - return result; + public RequestContext execute( Executable executable, RequestContext ctx ) { + logger.info("Executing --> " + executable); + executeNext(executable, ctx); + logger.info("Done executing --> " + executable); + return ctx; } - } diff --git a/drools-core/src/main/java/org/drools/core/command/impl/RegistryContext.java b/drools-core/src/main/java/org/drools/core/command/impl/RegistryContext.java index 64f2cefbd77..60fa3512d5b 100644 --- a/drools-core/src/main/java/org/drools/core/command/impl/RegistryContext.java +++ b/drools-core/src/main/java/org/drools/core/command/impl/RegistryContext.java @@ -16,11 +16,14 @@ package org.drools.core.command.impl; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; +import org.kie.internal.command.ContextManager; public interface RegistryContext extends Context { RegistryContext register(Class clazz, T instance); T lookup(Class clazz); + + ContextManager getContextManager(); } diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/AddEventListenerCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/AddEventListenerCommand.java index 56545664ed8..3e932443a02 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/AddEventListenerCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/AddEventListenerCommand.java @@ -22,7 +22,7 @@ import org.kie.api.event.rule.AgendaEventListener; import org.kie.api.event.rule.RuleRuntimeEventListener; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class AddEventListenerCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/BatchExecutionCommandImpl.java b/drools-core/src/main/java/org/drools/core/command/runtime/BatchExecutionCommandImpl.java index fb471b8bbfc..3ad4bc9d2c9 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/BatchExecutionCommandImpl.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/BatchExecutionCommandImpl.java @@ -39,8 +39,8 @@ import org.drools.core.command.runtime.rule.QueryCommand; import org.kie.api.command.Command; import org.kie.api.runtime.ExecutionResults; -import org.kie.internal.command.Context; -import org.kie.internal.fluent.Batch; +import org.kie.api.runtime.Context; +import org.drools.core.fluent.impl.Batch; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/DestroySessionCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/DestroySessionCommand.java index 6d74221496f..9fa656c7882 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/DestroySessionCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/DestroySessionCommand.java @@ -15,25 +15,25 @@ */ package org.drools.core.command.runtime; -import org.drools.core.command.CommandService; +import org.kie.api.runtime.ExecutableRunner; import org.drools.core.command.SingleSessionCommandService; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class DestroySessionCommand extends DisposeCommand { - private CommandService commandService; + private ExecutableRunner runner; public DestroySessionCommand() { } - public DestroySessionCommand(CommandService commandService) { - this.commandService = commandService; + public DestroySessionCommand(ExecutableRunner runner ) { + this.runner = runner; } public Void execute(Context context) { - if (commandService != null && commandService instanceof SingleSessionCommandService) { - ((SingleSessionCommandService) commandService).destroy(); + if (runner != null && runner instanceof SingleSessionCommandService) { + ((SingleSessionCommandService) runner).destroy(); } super.execute(context); return null; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/DisposeCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/DisposeCommand.java index e8391bfb3dd..37782eac8a7 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/DisposeCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/DisposeCommand.java @@ -19,7 +19,7 @@ import org.drools.core.command.impl.ExecutableCommand; import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -32,7 +32,7 @@ public class DisposeCommand ExecutableCommand { public Void execute(Context context) { - KieSession ksession = ((RegistryContext)context).lookup( KieSession.class ); + KieSession ksession = ( (RegistryContext) context ).lookup( KieSession.class ); ksession.dispose(); return null; } @@ -41,4 +41,7 @@ public String toString() { return "ksession.dispose();"; } + public boolean canRunInTransaction() { + return false; + } } diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/GetCalendarsCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/GetCalendarsCommand.java index baa65a775d1..0108ad5af3d 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/GetCalendarsCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/GetCalendarsCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.Calendars; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class GetCalendarsCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/GetChannelsCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/GetChannelsCommand.java index a61c18f7c35..4dce2799f45 100755 --- a/drools-core/src/main/java/org/drools/core/command/runtime/GetChannelsCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/GetChannelsCommand.java @@ -19,7 +19,7 @@ import org.drools.core.command.impl.ExecutableCommand; import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class GetChannelsCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/GetEnvironmentCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/GetEnvironmentCommand.java index 24986a789b0..0b581cfa3c6 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/GetEnvironmentCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/GetEnvironmentCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.Environment; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class GetEnvironmentCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/GetFactCountCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/GetFactCountCommand.java index 7289c72c519..34466984c43 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/GetFactCountCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/GetFactCountCommand.java @@ -19,7 +19,7 @@ import org.drools.core.command.impl.ExecutableCommand; import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/GetFactCountInEntryPointCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/GetFactCountInEntryPointCommand.java index 68f3a3de650..1873006b967 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/GetFactCountInEntryPointCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/GetFactCountInEntryPointCommand.java @@ -19,7 +19,7 @@ import org.drools.core.command.impl.ExecutableCommand; import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class GetFactCountInEntryPointCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/GetGlobalCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/GetGlobalCommand.java index 72550be46dc..b859e88e8d1 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/GetGlobalCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/GetGlobalCommand.java @@ -21,7 +21,7 @@ import org.drools.core.command.impl.RegistryContext; import org.drools.core.runtime.impl.ExecutionResultImpl; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/GetGlobalsCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/GetGlobalsCommand.java index a3693d51c0e..df7c451a828 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/GetGlobalsCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/GetGlobalsCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.Globals; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class GetGlobalsCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/GetIdCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/GetIdCommand.java index fc1c472fd93..7f81a605834 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/GetIdCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/GetIdCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.drools.core.impl.StatefulKnowledgeSessionImpl; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/GetKnowledgeBaseCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/GetKnowledgeBaseCommand.java index 57457e49439..fb38aa8f88f 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/GetKnowledgeBaseCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/GetKnowledgeBaseCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; import org.kie.internal.KnowledgeBase; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class GetKnowledgeBaseCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/KBuilderSetPropertyCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/KBuilderSetPropertyCommand.java index 089f7d66730..b3a513b5749 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/KBuilderSetPropertyCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/KBuilderSetPropertyCommand.java @@ -18,7 +18,7 @@ import org.drools.core.command.impl.ExecutableCommand; import org.kie.internal.builder.KnowledgeBuilderConfiguration; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; /** * diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/RegisterChannelCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/RegisterChannelCommand.java index a5ae907577d..017349699d5 100755 --- a/drools-core/src/main/java/org/drools/core/command/runtime/RegisterChannelCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/RegisterChannelCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.Channel; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class RegisterChannelCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/RemoveEventListenerCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/RemoveEventListenerCommand.java index 6de31d19b63..d8c286e01c8 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/RemoveEventListenerCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/RemoveEventListenerCommand.java @@ -22,7 +22,7 @@ import org.kie.api.event.rule.AgendaEventListener; import org.kie.api.event.rule.RuleRuntimeEventListener; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class RemoveEventListenerCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/SetGlobalCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/SetGlobalCommand.java index b4146eae3cb..4272f4a98cf 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/SetGlobalCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/SetGlobalCommand.java @@ -22,7 +22,7 @@ import org.drools.core.runtime.impl.ExecutionResultImpl; import org.drools.core.xml.jaxb.util.JaxbUnknownAdapter; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/UnregisterChannelCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/UnregisterChannelCommand.java index 11daa8cb948..7dcf773549c 100755 --- a/drools-core/src/main/java/org/drools/core/command/runtime/UnregisterChannelCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/UnregisterChannelCommand.java @@ -19,7 +19,7 @@ import org.drools.core.command.impl.ExecutableCommand; import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class UnregisterChannelCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/AbortProcessInstanceCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/AbortProcessInstanceCommand.java index 4590b56aaca..2a8bcedf1a0 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/AbortProcessInstanceCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/AbortProcessInstanceCommand.java @@ -19,7 +19,7 @@ import org.drools.core.command.impl.ExecutableCommand; import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.command.ProcessInstanceIdCommand; import javax.xml.bind.annotation.XmlAccessType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/AbortWorkItemCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/AbortWorkItemCommand.java index f2a08ebe9e4..a9d63c5c031 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/AbortWorkItemCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/AbortWorkItemCommand.java @@ -19,7 +19,7 @@ import org.drools.core.command.impl.ExecutableCommand; import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/CompleteWorkItemCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/CompleteWorkItemCommand.java index 45029c47023..66a813fd0d8 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/CompleteWorkItemCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/CompleteWorkItemCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.drools.core.xml.jaxb.util.JaxbMapAdapter; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/CreateCorrelatedProcessInstanceCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/CreateCorrelatedProcessInstanceCommand.java index 1e52de81666..42ec4e5115d 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/CreateCorrelatedProcessInstanceCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/CreateCorrelatedProcessInstanceCommand.java @@ -23,7 +23,7 @@ import org.drools.core.xml.jaxb.util.JaxbMapAdapter; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.process.ProcessInstance; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.command.CorrelationKeyCommand; import org.kie.internal.jaxb.CorrelationKeyXmlAdapter; import org.kie.internal.process.CorrelationAwareProcessRuntime; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/CreateProcessInstanceCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/CreateProcessInstanceCommand.java index 594b501028c..2901a53048c 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/CreateProcessInstanceCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/CreateProcessInstanceCommand.java @@ -23,7 +23,7 @@ import org.drools.core.xml.jaxb.util.JaxbMapAdapter; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.process.ProcessInstance; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessEventListenersCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessEventListenersCommand.java index d5347fae1db..598158c7adf 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessEventListenersCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessEventListenersCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.event.process.ProcessEventListener; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessIdsCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessIdsCommand.java index fe08cff1f2b..db5555feca8 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessIdsCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessIdsCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.definition.process.Process; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessInstanceByCorrelationKeyCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessInstanceByCorrelationKeyCommand.java index 90b008dc015..604b60c4da6 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessInstanceByCorrelationKeyCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessInstanceByCorrelationKeyCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.process.ProcessInstance; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.command.CorrelationKeyCommand; import org.kie.internal.jaxb.CorrelationKeyXmlAdapter; import org.kie.internal.process.CorrelationAwareProcessRuntime; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessInstanceCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessInstanceCommand.java index 335b3758ce2..56af23338ce 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessInstanceCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessInstanceCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.process.ProcessInstance; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.command.ProcessInstanceIdCommand; import javax.xml.bind.annotation.XmlAccessType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessInstancesCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessInstancesCommand.java index cc0a70d33e1..050f3f231d0 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessInstancesCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/GetProcessInstancesCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.process.ProcessInstance; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/GetWorkItemCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/GetWorkItemCommand.java index 140a3bbb27a..a79e9de96cc 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/GetWorkItemCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/GetWorkItemCommand.java @@ -22,7 +22,7 @@ import org.drools.core.process.instance.WorkItem; import org.drools.core.process.instance.WorkItemManager; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/GetWorkItemIdsCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/GetWorkItemIdsCommand.java index 414c084ceaf..fc5c38786e5 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/GetWorkItemIdsCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/GetWorkItemIdsCommand.java @@ -22,7 +22,7 @@ import org.drools.core.process.instance.WorkItem; import org.drools.core.process.instance.WorkItemManager; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/ReTryWorkItemCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/ReTryWorkItemCommand.java index 07efcb2f62a..0ac148971fb 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/ReTryWorkItemCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/ReTryWorkItemCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.drools.core.xml.jaxb.util.JaxbMapAdapter; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/RegisterWorkItemHandlerCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/RegisterWorkItemHandlerCommand.java index 1cc0a39c305..016ff283bc4 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/RegisterWorkItemHandlerCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/RegisterWorkItemHandlerCommand.java @@ -22,7 +22,7 @@ import org.drools.core.xml.jaxb.util.JaxbUnknownAdapter; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.process.WorkItemHandler; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/SetProcessInstanceVariablesCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/SetProcessInstanceVariablesCommand.java index 96a00584572..ec00bfef9ea 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/SetProcessInstanceVariablesCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/SetProcessInstanceVariablesCommand.java @@ -22,7 +22,7 @@ import org.kie.api.runtime.KieSession; import org.kie.api.runtime.process.ProcessInstance; import org.kie.api.runtime.process.WorkflowProcessInstance; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.command.ProcessInstanceIdCommand; import javax.xml.bind.annotation.XmlAccessType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/SignalEventCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/SignalEventCommand.java index 37755b06391..3778b3e0836 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/SignalEventCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/SignalEventCommand.java @@ -21,7 +21,7 @@ import org.drools.core.xml.jaxb.util.JaxbUnknownAdapter; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.process.ProcessInstance; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.command.ProcessInstanceIdCommand; import org.kie.internal.jaxb.CorrelationKeyXmlAdapter; import org.kie.internal.process.CorrelationAwareProcessRuntime; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/StartCorrelatedProcessCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/StartCorrelatedProcessCommand.java index 2c920f2ff25..85d7d2a21b8 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/StartCorrelatedProcessCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/StartCorrelatedProcessCommand.java @@ -23,7 +23,7 @@ import org.drools.core.xml.jaxb.util.JaxbMapAdapter; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.process.ProcessInstance; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.command.CorrelationKeyCommand; import org.kie.internal.jaxb.CorrelationKeyXmlAdapter; import org.kie.internal.process.CorrelationAwareProcessRuntime; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/StartProcessCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/StartProcessCommand.java index fe459e5e0b0..442d7f2cf2e 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/StartProcessCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/StartProcessCommand.java @@ -23,7 +23,7 @@ import org.drools.core.xml.jaxb.util.JaxbMapAdapter; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.process.ProcessInstance; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/process/StartProcessInstanceCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/process/StartProcessInstanceCommand.java index 9ad03611447..b987ea98fc6 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/process/StartProcessInstanceCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/process/StartProcessInstanceCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.process.ProcessInstance; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.command.ProcessInstanceIdCommand; import javax.xml.bind.annotation.XmlAccessType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/AgendaGroupSetFocusCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/AgendaGroupSetFocusCommand.java index 9c1cb247458..5a4814cdf24 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/AgendaGroupSetFocusCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/AgendaGroupSetFocusCommand.java @@ -19,7 +19,7 @@ import org.drools.core.command.impl.ExecutableCommand; import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearActivationGroupCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearActivationGroupCommand.java index a236e15ec45..d19a22f76bf 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearActivationGroupCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearActivationGroupCommand.java @@ -19,7 +19,7 @@ import org.drools.core.command.impl.ExecutableCommand; import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearAgendaCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearAgendaCommand.java index 45dc6c416c1..9c82d87e0f7 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearAgendaCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearAgendaCommand.java @@ -19,7 +19,7 @@ import org.drools.core.command.impl.ExecutableCommand; import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearAgendaGroupCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearAgendaGroupCommand.java index 049587221c7..1219058db46 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearAgendaGroupCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearAgendaGroupCommand.java @@ -19,7 +19,7 @@ import org.drools.core.command.impl.ExecutableCommand; import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearRuleFlowGroupCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearRuleFlowGroupCommand.java index 3f3d3c24e58..96243600caa 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearRuleFlowGroupCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/ClearRuleFlowGroupCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.drools.core.impl.StatefulKnowledgeSessionImpl; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/DeleteCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/DeleteCommand.java index e868e85165d..78a5efdfe00 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/DeleteCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/DeleteCommand.java @@ -21,7 +21,7 @@ import org.drools.core.common.DisconnectedFactHandle; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/DeleteFromEntryPointCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/DeleteFromEntryPointCommand.java index abcfb19d8ae..673563d5ddc 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/DeleteFromEntryPointCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/DeleteFromEntryPointCommand.java @@ -21,7 +21,7 @@ import org.drools.core.common.DisconnectedFactHandle; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/DeleteObjectCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/DeleteObjectCommand.java index 16b89b40133..ade3eacac50 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/DeleteObjectCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/DeleteObjectCommand.java @@ -23,7 +23,7 @@ import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.EntryPoint; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/EnableAuditLogCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/EnableAuditLogCommand.java index be84ea5411f..e6811e5279c 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/EnableAuditLogCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/EnableAuditLogCommand.java @@ -4,7 +4,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.KieServices; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/FireAllRulesCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/FireAllRulesCommand.java index 23d837ba0b7..cce364ec9cd 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/FireAllRulesCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/FireAllRulesCommand.java @@ -23,7 +23,7 @@ import org.drools.core.runtime.impl.ExecutionResultImpl; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.AgendaFilter; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/FireUntilHaltCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/FireUntilHaltCommand.java index 6f50b3fb025..456ccf440d3 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/FireUntilHaltCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/FireUntilHaltCommand.java @@ -22,7 +22,7 @@ import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.AgendaFilter; import org.kie.api.runtime.rule.StatefulRuleSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/FromExternalFactHandleCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/FromExternalFactHandleCommand.java index b7884185416..8599b8c44d9 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/FromExternalFactHandleCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/FromExternalFactHandleCommand.java @@ -20,7 +20,7 @@ import org.drools.core.common.InternalFactHandle; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import java.util.Collection; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetAgendaEventListenersCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetAgendaEventListenersCommand.java index c030f5c199c..12bbd78ef5d 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetAgendaEventListenersCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetAgendaEventListenersCommand.java @@ -20,7 +20,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.event.rule.AgendaEventListener; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import java.util.Collection; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetEntryPointCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetEntryPointCommand.java index 70a11afcf5f..4b4994ab10e 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetEntryPointCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetEntryPointCommand.java @@ -21,7 +21,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.EntryPoint; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class GetEntryPointCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetEntryPointsCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetEntryPointsCommand.java index f461cf4384d..fb6f7eb48da 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetEntryPointsCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetEntryPointsCommand.java @@ -21,7 +21,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.EntryPoint; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import java.util.ArrayList; import java.util.Collection; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandleCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandleCommand.java index d6efe899aeb..29e5a8b8281 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandleCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandleCommand.java @@ -21,7 +21,7 @@ import org.drools.core.common.InternalFactHandle; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class GetFactHandleCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandleInEntryPointCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandleInEntryPointCommand.java index 1a96493ec1a..41bfd941055 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandleInEntryPointCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandleInEntryPointCommand.java @@ -22,7 +22,7 @@ import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.EntryPoint; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class GetFactHandleInEntryPointCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandlesCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandlesCommand.java index f1db6b07b5b..5744bbd938b 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandlesCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandlesCommand.java @@ -23,7 +23,7 @@ import org.kie.api.runtime.KieSession; import org.kie.api.runtime.ObjectFilter; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandlesInEntryPointCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandlesInEntryPointCommand.java index cc284123b2c..796448bdcdb 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandlesInEntryPointCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetFactHandlesInEntryPointCommand.java @@ -23,7 +23,7 @@ import org.kie.api.runtime.ObjectFilter; import org.kie.api.runtime.rule.EntryPoint; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import java.util.ArrayList; import java.util.Collection; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectCommand.java index 50247c057ac..8639fd44e22 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectCommand.java @@ -24,7 +24,7 @@ import org.drools.core.runtime.impl.ExecutionResultImpl; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectInEntryPointCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectInEntryPointCommand.java index 89a8b627530..36b0f25a296 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectInEntryPointCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectInEntryPointCommand.java @@ -24,7 +24,7 @@ import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.EntryPoint; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectsCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectsCommand.java index 5994d3110df..422e228c7c1 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectsCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectsCommand.java @@ -24,7 +24,7 @@ import org.kie.api.runtime.ClassObjectFilter; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.ObjectFilter; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectsInEntryPointCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectsInEntryPointCommand.java index 78cc0445711..a5e46e1c31a 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectsInEntryPointCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetObjectsInEntryPointCommand.java @@ -25,7 +25,7 @@ import org.kie.api.runtime.KieSession; import org.kie.api.runtime.ObjectFilter; import org.kie.api.runtime.rule.EntryPoint; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetRuleRuntimeEventListenersCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetRuleRuntimeEventListenersCommand.java index 18258d0fd22..d773c24ffdf 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetRuleRuntimeEventListenersCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/GetRuleRuntimeEventListenersCommand.java @@ -19,7 +19,7 @@ import org.drools.core.command.impl.RegistryContext; import org.kie.api.event.rule.RuleRuntimeEventListener; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import java.util.Collection; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/HaltCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/HaltCommand.java index 63f5d89cd2e..1c2f33a19d7 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/HaltCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/HaltCommand.java @@ -19,7 +19,7 @@ import org.drools.core.command.impl.ExecutableCommand; import org.drools.core.command.impl.RegistryContext; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class HaltCommand implements diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/InsertElementsCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/InsertElementsCommand.java index 270bc02c5ff..6959445b5c7 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/InsertElementsCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/InsertElementsCommand.java @@ -25,7 +25,7 @@ import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.EntryPoint; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/InsertObjectCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/InsertObjectCommand.java index 07a0ef99720..675f22db5b5 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/InsertObjectCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/InsertObjectCommand.java @@ -26,7 +26,7 @@ import org.drools.core.xml.jaxb.util.JaxbUnknownAdapter; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/InsertObjectInEntryPointCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/InsertObjectInEntryPointCommand.java index 6a22fd41dea..4f6dfefff88 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/InsertObjectInEntryPointCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/InsertObjectInEntryPointCommand.java @@ -24,7 +24,7 @@ import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.EntryPoint; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/ModifyCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/ModifyCommand.java index 6755d4862d1..72d2195fd00 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/ModifyCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/ModifyCommand.java @@ -24,7 +24,7 @@ import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.EntryPoint; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/QueryCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/QueryCommand.java index 29a93bfb349..7ca4abcb8f9 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/QueryCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/QueryCommand.java @@ -25,7 +25,7 @@ import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.QueryResults; import org.kie.api.runtime.rule.Variable; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/UpdateCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/UpdateCommand.java index 4a1da6704ab..38d30344c0d 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/UpdateCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/UpdateCommand.java @@ -22,7 +22,7 @@ import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.EntryPoint; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/command/runtime/rule/UpdateInEntryPointCommand.java b/drools-core/src/main/java/org/drools/core/command/runtime/rule/UpdateInEntryPointCommand.java index c78e4bbeb6c..4b22f11fad7 100644 --- a/drools-core/src/main/java/org/drools/core/command/runtime/rule/UpdateInEntryPointCommand.java +++ b/drools-core/src/main/java/org/drools/core/command/runtime/rule/UpdateInEntryPointCommand.java @@ -22,7 +22,7 @@ import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.EntryPoint; import org.kie.api.runtime.rule.FactHandle; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/drools-core/src/main/java/org/drools/core/fluent/impl/BaseBatchFluent.java b/drools-core/src/main/java/org/drools/core/fluent/impl/BaseBatchFluent.java index 90d8c232559..160218a1e45 100644 --- a/drools-core/src/main/java/org/drools/core/fluent/impl/BaseBatchFluent.java +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/BaseBatchFluent.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.drools.core.fluent.impl; import org.drools.core.command.*; @@ -106,8 +122,8 @@ public T startConversation() { } @Override - public T joinConversation(long id) { - fluentCtx.addCommand(new JoinConversationCommand(id)); + public T joinConversation(String uuid) { + fluentCtx.addCommand(new JoinConversationCommand(uuid)); return (T) this; } @@ -118,8 +134,8 @@ public T leaveConversation() { } @Override - public T endConversation(long id) { - fluentCtx.addCommand(new EndConversationCommand(id)); + public T endConversation(String uuid) { + fluentCtx.addCommand(new EndConversationCommand(uuid)); return (T) this; } diff --git a/drools-core/src/main/java/org/drools/core/command/Interceptor.java b/drools-core/src/main/java/org/drools/core/fluent/impl/Batch.java similarity index 56% rename from drools-core/src/main/java/org/drools/core/command/Interceptor.java rename to drools-core/src/main/java/org/drools/core/fluent/impl/Batch.java index ebc976501a8..a8f2784bf62 100644 --- a/drools-core/src/main/java/org/drools/core/command/Interceptor.java +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/Batch.java @@ -1,11 +1,11 @@ /* - * Copyright 2010 Red Hat, Inc. and/or its affiliates. + * Copyright 2016 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -14,13 +14,18 @@ * limitations under the License. */ -package org.drools.core.command; +package org.drools.core.fluent.impl; +import org.kie.api.command.BatchExecutionCommand; +import org.kie.api.command.Command; -public interface Interceptor extends CommandService { +import java.util.List; - void setNext(CommandService commandService); +public interface Batch extends BatchExecutionCommand { - CommandService getNext(); + long getDistance(); + Batch addCommand(Command cmd); + + List getCommands(); } diff --git a/drools-core/src/main/java/org/drools/core/fluent/impl/BatchImpl.java b/drools-core/src/main/java/org/drools/core/fluent/impl/BatchImpl.java index 5be9909aa6e..786404e7fa0 100644 --- a/drools-core/src/main/java/org/drools/core/fluent/impl/BatchImpl.java +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/BatchImpl.java @@ -1,7 +1,22 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.drools.core.fluent.impl; import org.kie.api.command.Command; -import org.kie.internal.fluent.Batch; import java.util.ArrayList; import java.util.List; diff --git a/drools-core/src/main/java/org/drools/core/fluent/impl/CommandRegister.java b/drools-core/src/main/java/org/drools/core/fluent/impl/CommandRegister.java index dcf17a43025..bf8846e60c9 100644 --- a/drools-core/src/main/java/org/drools/core/fluent/impl/CommandRegister.java +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/CommandRegister.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.drools.core.fluent.impl; import org.kie.api.KieBase; diff --git a/drools-core/src/main/java/org/drools/core/fluent/impl/ExecutableImpl.java b/drools-core/src/main/java/org/drools/core/fluent/impl/ExecutableImpl.java index d6e510ef5cb..23385fca01c 100644 --- a/drools-core/src/main/java/org/drools/core/fluent/impl/ExecutableImpl.java +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/ExecutableImpl.java @@ -1,14 +1,28 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.drools.core.fluent.impl; -import org.kie.internal.fluent.Batch; -import org.kie.internal.fluent.Executable; -import org.kie.internal.fluent.runtime.FluentBuilder; import org.kie.api.command.Command; +import org.kie.internal.fluent.runtime.FluentBuilder; import java.util.ArrayList; import java.util.List; -public class ExecutableImpl implements Executable { +public class ExecutableImpl implements InternalExecutable { private FluentComponentFactory factory; private FluentBuilder fluentBuilder; diff --git a/drools-core/src/main/java/org/drools/core/fluent/impl/FluentBuilderImpl.java b/drools-core/src/main/java/org/drools/core/fluent/impl/FluentBuilderImpl.java index 09657956672..1972173fd49 100644 --- a/drools-core/src/main/java/org/drools/core/fluent/impl/FluentBuilderImpl.java +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/FluentBuilderImpl.java @@ -1,8 +1,24 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.drools.core.fluent.impl; import org.drools.core.command.GetKieContainerCommand; import org.kie.api.builder.ReleaseId; -import org.kie.internal.fluent.Executable; +import org.kie.api.runtime.Executable; import org.kie.internal.fluent.runtime.FluentBuilder; import org.kie.internal.fluent.runtime.KieContainerFluent; diff --git a/drools-core/src/main/java/org/drools/core/fluent/impl/FluentComponentFactory.java b/drools-core/src/main/java/org/drools/core/fluent/impl/FluentComponentFactory.java index 7590450d868..c0c4a901178 100644 --- a/drools-core/src/main/java/org/drools/core/fluent/impl/FluentComponentFactory.java +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/FluentComponentFactory.java @@ -1,5 +1,20 @@ -package org.drools.core.fluent.impl; +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.drools.core.fluent.impl; import org.kie.internal.fluent.runtime.FluentBuilder; import org.kie.internal.fluent.runtime.KieContainerFluent; diff --git a/drools-core/src/main/java/org/drools/core/fluent/impl/GetCommand.java b/drools-core/src/main/java/org/drools/core/fluent/impl/GetCommand.java index 1c843320171..bf45eaf12d6 100644 --- a/drools-core/src/main/java/org/drools/core/fluent/impl/GetCommand.java +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/GetCommand.java @@ -1,8 +1,24 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.drools.core.fluent.impl; import org.drools.core.command.RequestContextImpl; import org.drools.core.command.impl.ExecutableCommand; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.fluent.Scope; public class GetCommand implements ExecutableCommand { diff --git a/drools-core/src/main/java/org/drools/core/fluent/impl/GetContextCommand.java b/drools-core/src/main/java/org/drools/core/fluent/impl/GetContextCommand.java index 3a8d8abf082..11adc09e2cc 100644 --- a/drools-core/src/main/java/org/drools/core/fluent/impl/GetContextCommand.java +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/GetContextCommand.java @@ -1,9 +1,25 @@ -package org.drools.core.fluent.impl; +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.drools.core.fluent.impl; import org.drools.core.command.RequestContextImpl; import org.drools.core.command.impl.ExecutableCommand; -import org.kie.internal.command.Context; +import org.drools.core.command.impl.RegistryContext; +import org.kie.api.runtime.Context; public class GetContextCommand implements ExecutableCommand { private String name; @@ -14,7 +30,7 @@ public GetContextCommand(String name) { @Override public Void execute(Context context) { - Context returned = context.getContextManager().getContext(name); + Context returned = ( (RegistryContext) context ).getContextManager().getContext( name ); ((RequestContextImpl)context).setApplicationContext(returned); return null; } diff --git a/drools-core/src/main/java/org/drools/core/fluent/impl/InternalExecutable.java b/drools-core/src/main/java/org/drools/core/fluent/impl/InternalExecutable.java new file mode 100644 index 00000000000..5e85bc928b7 --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/InternalExecutable.java @@ -0,0 +1,33 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.drools.core.fluent.impl; + +import org.drools.core.command.impl.ExecutableCommand; +import org.kie.api.runtime.Executable; + +import java.util.List; + +public interface InternalExecutable extends Executable { + List getBatches(); + + default boolean canRunInTransaction() { + return getBatches().stream() + .flatMap( batch -> batch.getCommands().stream() ) + .map( ExecutableCommand.class::cast ) + .allMatch( ExecutableCommand::canRunInTransaction ); + } +} diff --git a/drools-core/src/main/java/org/drools/core/fluent/impl/KieContainerFluentImpl.java b/drools-core/src/main/java/org/drools/core/fluent/impl/KieContainerFluentImpl.java index 44ef739f577..acd5e0cd28e 100644 --- a/drools-core/src/main/java/org/drools/core/fluent/impl/KieContainerFluentImpl.java +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/KieContainerFluentImpl.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.drools.core.fluent.impl; import org.drools.core.command.NewKieSessionCommand; diff --git a/drools-core/src/main/java/org/drools/core/fluent/impl/KieSessionFluentImpl.java b/drools-core/src/main/java/org/drools/core/fluent/impl/KieSessionFluentImpl.java index 83d9fc97c1f..a17c528cb70 100644 --- a/drools-core/src/main/java/org/drools/core/fluent/impl/KieSessionFluentImpl.java +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/KieSessionFluentImpl.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.drools.core.fluent.impl; import org.drools.core.command.runtime.DisposeCommand; diff --git a/drools-core/src/main/java/org/drools/core/fluent/impl/NewContextCommand.java b/drools-core/src/main/java/org/drools/core/fluent/impl/NewContextCommand.java index 9c90bad9a79..43a806cc294 100644 --- a/drools-core/src/main/java/org/drools/core/fluent/impl/NewContextCommand.java +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/NewContextCommand.java @@ -1,8 +1,25 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.drools.core.fluent.impl; import org.drools.core.command.RequestContextImpl; import org.drools.core.command.impl.ExecutableCommand; -import org.kie.internal.command.Context; +import org.drools.core.command.impl.RegistryContext; +import org.kie.api.runtime.Context; public class NewContextCommand implements ExecutableCommand { private String name; @@ -13,13 +30,8 @@ public NewContextCommand(String name) { @Override public Void execute(Context context) { - Context returned = context.getContextManager().createContext(name); + Context returned = ( (RegistryContext) context ).getContextManager().createContext( name ); ((RequestContextImpl)context).setApplicationContext(returned); -// return returned; -// -// T returned = (T) context.get("returned"); -// return returned; - return null; } } diff --git a/drools-core/src/main/java/org/drools/core/fluent/impl/PseudoClockRunner.java b/drools-core/src/main/java/org/drools/core/fluent/impl/PseudoClockRunner.java index 7365f8cee78..f94a2be9c23 100644 --- a/drools-core/src/main/java/org/drools/core/fluent/impl/PseudoClockRunner.java +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/PseudoClockRunner.java @@ -19,13 +19,14 @@ import org.drools.core.command.ConversationContextManager; import org.drools.core.command.RequestContextImpl; import org.drools.core.command.impl.ExecutableCommand; +import org.drools.core.runtime.InternalLocalRunner; import org.drools.core.time.SessionPseudoClock; import org.drools.core.world.impl.ContextManagerImpl; import org.kie.api.command.Command; +import org.kie.api.runtime.Context; +import org.kie.api.runtime.Executable; import org.kie.api.runtime.KieSession; -import org.kie.internal.command.Context; -import org.kie.internal.fluent.Batch; -import org.kie.internal.fluent.Executable; +import org.kie.api.runtime.RequestContext; import java.util.Comparator; import java.util.HashMap; @@ -35,15 +36,17 @@ import java.util.Set; import java.util.concurrent.TimeUnit; -public class PseudoClockRunner { - private PriorityQueue queue = new PriorityQueue(BatchSorter.instance); - private Set ksessions = new HashSet(); +public class PseudoClockRunner implements InternalLocalRunner { - private final Map appContexts = new HashMap(); + private final Map appContexts = new HashMap<>(); private ConversationContextManager cvnManager = new ConversationContextManager(); private long counter; - private long startTime; + private Set ksessions = new HashSet<>(); + + private PriorityQueue queue = new PriorityQueue<>( BatchSorter.instance); + + private final long startTime; public PseudoClockRunner() { this(System.currentTimeMillis()); @@ -53,15 +56,14 @@ public PseudoClockRunner( long startTime ) { this.startTime = startTime; } - public Map getAppContexts() { - return appContexts; - } - - public Context execute(Executable executable) { - return execute( executable, createContext() ); + @Override + public RequestContext execute( Executable executable, RequestContext ctx ) { + executeBatches( ( (InternalExecutable) executable ), ctx ); + executeQueue( ctx ); + return ctx; } - public Context execute( Executable executable, Context ctx ) { + private void executeBatches( InternalExecutable executable, RequestContext ctx ) { for (Batch batch : executable.getBatches()) { if ( batch.getDistance() == 0L ) { executeBatch( batch, ctx ); @@ -69,7 +71,9 @@ public Context execute( Executable executable, Context ctx ) { queue.add( batch ); } } + } + private void executeQueue( RequestContext ctx ) { while ( !queue.isEmpty() ) { Batch batch = queue.remove(); long timeNow = startTime + batch.getDistance(); @@ -80,9 +84,7 @@ public Context execute( Executable executable, Context ctx ) { for (Command cmd : batch.getCommands() ) { Object returned = ((ExecutableCommand)cmd).execute( ctx ); if ( returned != null ) { - if (ctx instanceof RequestContextImpl) { - ( (RequestContextImpl) ctx ).setLastReturned( returned ); - } + ctx.setResult( returned ); if ( returned instanceof KieSession ) { KieSession ksession = ( KieSession ) returned; updateKieSessionTime(timeNow, batch.getDistance(), ksession); // make sure all sessions are set to timeNow @@ -91,35 +93,24 @@ public Context execute( Executable executable, Context ctx ) { } } } - - return ctx; } - private void executeBatch( Batch batch, Context ctx ) { - long timeNow = startTime; + private void executeBatch( Batch batch, RequestContext ctx ) { // anything with a temporal distance of 0 is executed now // everything else must be handled by a priority queue and timer afterwards. for (Command cmd : batch.getCommands() ) { Object returned = ((ExecutableCommand)cmd).execute( ctx ); if ( returned != null ) { - if (ctx instanceof RequestContextImpl) { - ( (RequestContextImpl) ctx ).setLastReturned( returned ); - } + ctx.setResult( returned ); if ( returned instanceof KieSession ) { KieSession ksession = ( KieSession ) returned; - updateKieSessionTime(timeNow, 0, ksession); // make sure all sessions are set to timeNow + updateKieSessionTime( startTime, 0, ksession ); // make sure all sessions are set to timeNow ksessions.add((KieSession)returned); } } } } - public RequestContextImpl createContext() { - return new RequestContextImpl( counter++, - new ContextManagerImpl( appContexts ), - cvnManager ); - } - private void updateKieSessionTime(long timeNow, long distance, KieSession ksession) { SessionPseudoClock clock = ksession.getSessionClock(); @@ -127,11 +118,10 @@ private void updateKieSessionTime(long timeNow, long distance, KieSession ksessi long newTime = startTime + distance; long currentTime = clock.getCurrentTime(); clock.advanceTime( newTime - currentTime, - TimeUnit.MILLISECONDS); + TimeUnit.MILLISECONDS ); } } - private static class BatchSorter implements Comparator { public static BatchSorter instance = new BatchSorter(); @@ -147,6 +137,11 @@ else if(o1.getDistance() < o2.getDistance()) { return 0; } + } + public RequestContext createContext() { + return new RequestContextImpl( counter++, + new ContextManagerImpl( appContexts ), + cvnManager ); } } diff --git a/drools-core/src/main/java/org/drools/core/fluent/impl/SetCommand.java b/drools-core/src/main/java/org/drools/core/fluent/impl/SetCommand.java index 3fc3c79f987..6f2291a4a53 100644 --- a/drools-core/src/main/java/org/drools/core/fluent/impl/SetCommand.java +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/SetCommand.java @@ -1,8 +1,24 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.drools.core.fluent.impl; import org.drools.core.command.RequestContextImpl; import org.drools.core.command.impl.ExecutableCommand; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.fluent.Scope; public class SetCommand implements ExecutableCommand { @@ -21,7 +37,7 @@ public SetCommand(String name, Scope scope) { @Override public T execute(Context context) { RequestContextImpl reqContext = (RequestContextImpl)context; - T returned = (T) reqContext.getLastReturned(); + T returned = (T) reqContext.getResult(); if ( scope == Scope.REQUEST ) { reqContext.set(name, returned); diff --git a/drools-core/src/main/java/org/drools/core/fluent/impl/SetVarAsRegistryEntry.java b/drools-core/src/main/java/org/drools/core/fluent/impl/SetVarAsRegistryEntry.java index 022e3826a36..99207b71f84 100644 --- a/drools-core/src/main/java/org/drools/core/fluent/impl/SetVarAsRegistryEntry.java +++ b/drools-core/src/main/java/org/drools/core/fluent/impl/SetVarAsRegistryEntry.java @@ -1,9 +1,24 @@ -package org.drools.core.fluent.impl; +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.drools.core.fluent.impl; import org.drools.core.command.impl.ContextImpl; import org.drools.core.command.impl.ExecutableCommand; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import java.util.Map; diff --git a/drools-core/src/main/java/org/drools/core/impl/StatefulKnowledgeSessionImpl.java b/drools-core/src/main/java/org/drools/core/impl/StatefulKnowledgeSessionImpl.java index 3408ea96888..f911df96520 100644 --- a/drools-core/src/main/java/org/drools/core/impl/StatefulKnowledgeSessionImpl.java +++ b/drools-core/src/main/java/org/drools/core/impl/StatefulKnowledgeSessionImpl.java @@ -28,9 +28,6 @@ import org.drools.core.base.NonCloningQueryViewListener; import org.drools.core.base.QueryRowWithSubruleIndex; import org.drools.core.base.StandardQueryViewChangedEventListener; -import org.drools.core.command.impl.ContextImpl; -import org.drools.core.command.impl.ExecutableCommand; -import org.drools.core.command.impl.RegistryContext; import org.drools.core.common.BaseNode; import org.drools.core.common.CompositeDefaultAgenda; import org.drools.core.common.ConcurrentNodeMemories; @@ -84,7 +81,6 @@ import org.drools.core.reteoo.TerminalNode; import org.drools.core.rule.Declaration; import org.drools.core.rule.EntryPointId; -import org.drools.core.runtime.impl.ExecutionResultImpl; import org.drools.core.runtime.process.InternalProcessRuntime; import org.drools.core.runtime.process.ProcessRuntimeFactory; import org.drools.core.runtime.rule.impl.LiveQueryImpl; @@ -99,7 +95,6 @@ import org.drools.core.time.TimerServiceFactory; import org.drools.core.util.bitmask.BitMask; import org.drools.core.util.index.TupleList; -import org.kie.api.KieBase; import org.kie.api.command.BatchExecutionCommand; import org.kie.api.command.Command; import org.kie.api.event.KieRuntimeEventManager; @@ -114,8 +109,10 @@ import org.kie.api.runtime.Channel; import org.kie.api.runtime.Environment; import org.kie.api.runtime.EnvironmentName; +import org.kie.api.runtime.ExecutableRunner; import org.kie.api.runtime.Globals; import org.kie.api.runtime.KieSession; +import org.kie.api.runtime.RequestContext; import org.kie.api.runtime.process.ProcessInstance; import org.kie.api.runtime.process.WorkItemHandler; import org.kie.api.runtime.process.WorkItemManager; @@ -126,7 +123,6 @@ import org.kie.api.runtime.rule.ViewChangedEventListener; import org.kie.api.time.SessionClock; import org.kie.internal.KnowledgeBase; -import org.kie.internal.command.Context; import org.kie.internal.event.rule.RuleEventListener; import org.kie.internal.marshalling.MarshallerFactory; import org.kie.internal.process.CorrelationAwareProcessRuntime; @@ -699,29 +695,16 @@ public Object[] toArray(Object[] array) { } public T execute(Command command) { - return execute( new ContextImpl(), command ); - } - - public T execute(Context context, - Command command) { - - ExecutionResultImpl results = ((RegistryContext) context).lookup( ExecutionResultImpl.class ); - if ( results == null ) { - results = new ExecutionResultImpl(); - ((RegistryContext) context).register( ExecutionResultImpl.class, results ); - } - - ((RegistryContext) context).register( KieBase.class, this.kBase ) - .register( KieSession.class, this ); + ExecutableRunner runner = ExecutableRunner.create(); + RequestContext context = runner.createContext().with( this.kBase ).with( this ); if ( !(command instanceof BatchExecutionCommand) ) { - return (T) ((ExecutableCommand) command).execute( context ); + return runner.execute( command, context ); } try { startBatchExecution(); - ((ExecutableCommand) command).execute( context ); - return (T) results; + return runner.execute( command, context ); } finally { endBatchExecution(); if (kBase.flushModifications()) { diff --git a/drools-core/src/main/java/org/drools/core/command/CommandService.java b/drools-core/src/main/java/org/drools/core/runtime/ChainableRunner.java similarity index 61% rename from drools-core/src/main/java/org/drools/core/command/CommandService.java rename to drools-core/src/main/java/org/drools/core/runtime/ChainableRunner.java index d9646824f88..acfa2322b08 100644 --- a/drools-core/src/main/java/org/drools/core/command/CommandService.java +++ b/drools-core/src/main/java/org/drools/core/runtime/ChainableRunner.java @@ -1,11 +1,11 @@ /* - * Copyright 2010 Red Hat, Inc. and/or its affiliates. + * Copyright 2016 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -14,13 +14,11 @@ * limitations under the License. */ -package org.drools.core.command; +package org.drools.core.runtime; -import org.kie.internal.command.Context; -import org.kie.api.runtime.CommandExecutor; - -public interface CommandService extends CommandExecutor { - - Context getContext(); +import org.kie.api.runtime.ExecutableRunner; +public interface ChainableRunner extends InternalLocalRunner { + void setNext(ExecutableRunner runner); + ExecutableRunner getNext(); } diff --git a/drools-core/src/main/java/org/drools/core/runtime/InternalLocalRunner.java b/drools-core/src/main/java/org/drools/core/runtime/InternalLocalRunner.java new file mode 100644 index 00000000000..d5e1aaf75db --- /dev/null +++ b/drools-core/src/main/java/org/drools/core/runtime/InternalLocalRunner.java @@ -0,0 +1,73 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.drools.core.runtime; + +import org.drools.core.command.impl.RegistryContext; +import org.drools.core.fluent.impl.Batch; +import org.drools.core.fluent.impl.BatchImpl; +import org.drools.core.fluent.impl.InternalExecutable; +import org.drools.core.runtime.impl.ExecutionResultImpl; +import org.kie.api.command.BatchExecutionCommand; +import org.kie.api.command.Command; +import org.kie.api.runtime.Context; +import org.kie.api.runtime.Executable; +import org.kie.api.runtime.ExecutableRunner; +import org.kie.api.runtime.RequestContext; + +import java.util.List; + +import static java.util.Collections.singletonList; + +public interface InternalLocalRunner extends ExecutableRunner { + default RequestContext execute(Executable executable) { + return execute( executable, createContext() ); + } + + default T execute( Command command ) { + Context ctx = execute( new SingleCommandExecutable( command ) ); + return command instanceof BatchExecutionCommand ? + (T) ( (RegistryContext) ctx ).lookup( ExecutionResultImpl.class ) : + (T) ( (RequestContext) ctx ).getResult(); + } + + default T execute( Command command, Context ctx ) { + execute( new SingleCommandExecutable( command ), (RequestContext) ctx ); + return command instanceof BatchExecutionCommand ? + (T) ( (RegistryContext) ctx ).lookup( ExecutionResultImpl.class ) : + (T) ( (RequestContext) ctx ).getResult(); + } + + class SingleBatchExecutable implements InternalExecutable { + private final Batch batch; + + public SingleBatchExecutable( Batch batch ) { + this.batch = batch; + } + + @Override + public List getBatches() { + return singletonList( batch ); + } + } + + class SingleCommandExecutable extends SingleBatchExecutable { + + public SingleCommandExecutable( Command command ) { + super(new BatchImpl().addCommand( command ) ); + } + } +} diff --git a/drools-core/src/main/java/org/drools/core/time/impl/CommandServiceTimerJobFactoryManager.java b/drools-core/src/main/java/org/drools/core/time/impl/CommandServiceTimerJobFactoryManager.java index c432e8c24d1..545f5fcf2f0 100644 --- a/drools-core/src/main/java/org/drools/core/time/impl/CommandServiceTimerJobFactoryManager.java +++ b/drools-core/src/main/java/org/drools/core/time/impl/CommandServiceTimerJobFactoryManager.java @@ -16,9 +16,9 @@ package org.drools.core.time.impl; -import org.drools.core.command.CommandService; +import org.kie.api.runtime.ExecutableRunner; public interface CommandServiceTimerJobFactoryManager extends TimerJobFactoryManager { - void setCommandService(CommandService commandService); - CommandService getCommandService(); + void setRunner(ExecutableRunner runner ); + ExecutableRunner getRunner(); } diff --git a/drools-core/src/main/java/org/drools/core/world/impl/ContextManagerImpl.java b/drools-core/src/main/java/org/drools/core/world/impl/ContextManagerImpl.java index c7485147b2d..edd48852203 100644 --- a/drools-core/src/main/java/org/drools/core/world/impl/ContextManagerImpl.java +++ b/drools-core/src/main/java/org/drools/core/world/impl/ContextManagerImpl.java @@ -21,7 +21,7 @@ import org.drools.core.command.impl.ExecutableCommand; import org.kie.api.command.Command; import org.kie.api.runtime.CommandExecutor; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.command.ContextManager; import java.util.HashMap; diff --git a/drools-core/src/test/java/org/drools/core/command/runtime/rule/ExecuteCommandDisconnectedTest.java b/drools-core/src/test/java/org/drools/core/command/runtime/rule/ExecuteCommandDisconnectedTest.java index 676b8d06dbc..30ecd5ac5ae 100644 --- a/drools-core/src/test/java/org/drools/core/command/runtime/rule/ExecuteCommandDisconnectedTest.java +++ b/drools-core/src/test/java/org/drools/core/command/runtime/rule/ExecuteCommandDisconnectedTest.java @@ -16,16 +16,15 @@ package org.drools.core.command.runtime.rule; import org.drools.core.command.ExecuteCommand; -import org.drools.core.command.impl.ContextImpl; -import org.drools.core.command.impl.DefaultCommandService; -import org.drools.core.command.impl.RegistryContext; import org.drools.core.common.DefaultFactHandle; import org.drools.core.runtime.impl.ExecutionResultImpl; import org.junit.Test; import org.kie.api.KieBase; import org.kie.api.command.BatchExecutionCommand; +import org.kie.api.runtime.ExecutableRunner; import org.kie.api.runtime.ExecutionResults; import org.kie.api.runtime.KieSession; +import org.kie.api.runtime.RequestContext; import org.kie.internal.KnowledgeBaseFactory; import org.kie.internal.command.CommandFactory; @@ -36,8 +35,6 @@ public class ExecuteCommandDisconnectedTest { - private DefaultCommandService commandService; - @Test public void executeDisconnected() { KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); @@ -45,10 +42,9 @@ public void executeDisconnected() { KieSession ksession = kbase.newKieSession(); ExecutionResultImpl localKresults = new ExecutionResultImpl(); - RegistryContext context = new ContextImpl().register( KieSession.class, ksession ) - .register( ExecutionResultImpl.class, localKresults ); + RequestContext context = RequestContext.create().with( ksession ); - commandService = new DefaultCommandService(context); + ExecutableRunner runner = ExecutableRunner.create(); List cmds = new ArrayList(); cmds.add(new InsertObjectCommand(new String("Hi!"), "handle")); diff --git a/drools-core/src/test/java/org/drools/core/command/runtime/rule/GetFactHandlesCommandTest.java b/drools-core/src/test/java/org/drools/core/command/runtime/rule/GetFactHandlesCommandTest.java index 88d5e3b0122..504f272db36 100644 --- a/drools-core/src/test/java/org/drools/core/command/runtime/rule/GetFactHandlesCommandTest.java +++ b/drools-core/src/test/java/org/drools/core/command/runtime/rule/GetFactHandlesCommandTest.java @@ -15,8 +15,7 @@ package org.drools.core.command.runtime.rule; -import org.drools.core.command.impl.ContextImpl; -import org.drools.core.command.impl.DefaultCommandService; +import org.kie.api.runtime.ExecutableRunner; import org.drools.core.command.impl.RegistryContext; import org.drools.core.common.InternalFactHandle; import org.junit.After; @@ -26,6 +25,7 @@ import org.kie.api.runtime.rule.FactHandle; import org.kie.internal.KnowledgeBase; import org.kie.internal.KnowledgeBaseFactory; +import org.kie.api.runtime.Context; import org.kie.internal.runtime.StatefulKnowledgeSession; import java.util.Collection; @@ -39,16 +39,16 @@ public class GetFactHandlesCommandTest { private StatefulKnowledgeSession ksession; - private DefaultCommandService commandService; + private ExecutableRunner runner; + private Context context; private Random random = new Random(); @Before public void setup() { KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); ksession = kbase.newStatefulKnowledgeSession(); - RegistryContext context = new ContextImpl().register( KieSession.class, ksession ); - commandService = new DefaultCommandService(context); - + runner = ExecutableRunner.create(); + context = ( (RegistryContext) runner.createContext() ).register( KieSession.class, ksession ); } @After @@ -59,7 +59,7 @@ public void cleanUp() { @Test public void getEmptyFactHandlesTest() { GetFactHandlesCommand command = new GetFactHandlesCommand(); - Object result = commandService.execute(command); + Object result = runner.execute(command, context); if( result instanceof Collection ) { assertNotNull(result); assertTrue(((Collection) result).isEmpty()); @@ -74,7 +74,7 @@ public void getOneFactHandleTest() { String randomFact = "" + random.nextLong(); ksession.insert(randomFact); GetFactHandlesCommand command = new GetFactHandlesCommand(); - Object result = commandService.execute(command); + Object result = runner.execute(command, context); verifyThatCollectionContains1FactHandleWithThisFact(randomFact, result); } @@ -91,7 +91,7 @@ public void getMultipleFactHandleTest() { } GetFactHandlesCommand command = new GetFactHandlesCommand(); - Object result = commandService.execute(command); + Object result = runner.execute(command, context); verifyThatCollectionContainsTheseFactHandle(factSet, result); } @@ -99,7 +99,7 @@ public void getMultipleFactHandleTest() { @Test public void getEmptyDisconnectedFactHandlesTest() { GetFactHandlesCommand command = new GetFactHandlesCommand(true); - Object result = commandService.execute(command); + Object result = runner.execute(command, context); if( result instanceof Collection ) { assertNotNull(result); assertTrue(((Collection) result).isEmpty()); @@ -117,17 +117,17 @@ public void getOneDisconnectedFactHandleTest() { // Retrieve and verify fact handle collections GetFactHandlesCommand command = new GetFactHandlesCommand(false); - Object result = commandService.execute(command); + Object result = runner.execute(command, context); verifyThatCollectionContains1FactHandleWithThisFact(randomFact, result); FactHandle factHandle = (FactHandle) ((Collection) result).toArray()[0]; command = new GetFactHandlesCommand(false); - result = commandService.execute(command); + result = runner.execute(command, context); verifyThatCollectionContains1FactHandleWithThisFact(randomFact, result); FactHandle connectedFactHandle = (FactHandle) ((Collection) result).toArray()[0]; command = new GetFactHandlesCommand(true); - result = commandService.execute(command); + result = runner.execute(command, context); verifyThatCollectionContains1FactHandleWithThisFact(randomFact, result); FactHandle disconnectedFactHandle = (FactHandle) ((Collection) result).toArray()[0]; @@ -149,17 +149,17 @@ public void getMultipleDisconnectedFactHandleTest() { } GetFactHandlesCommand command = new GetFactHandlesCommand(false); - Object result = commandService.execute(command); + Object result = runner.execute(command, context); verifyThatCollectionContainsTheseFactHandle(factSet, result); Collection factHandles = ((Collection) result); command = new GetFactHandlesCommand(false); - result = commandService.execute(command); + result = runner.execute(command, context); verifyThatCollectionContainsTheseFactHandle(factSet, result); Collection connectedFactHandles = ((Collection) result); command = new GetFactHandlesCommand(true); - result = commandService.execute(command); + result = runner.execute(command, context); verifyThatCollectionContainsTheseFactHandle(factSet, result); Collection disconnectedFactHandles = ((Collection) result); diff --git a/drools-core/src/test/java/org/drools/core/reteoo/test/JUnitNodeTestRunner.java b/drools-core/src/test/java/org/drools/core/reteoo/test/JUnitNodeTestRunner.java index 77ee1366cda..12a6fef7be1 100755 --- a/drools-core/src/test/java/org/drools/core/reteoo/test/JUnitNodeTestRunner.java +++ b/drools-core/src/test/java/org/drools/core/reteoo/test/JUnitNodeTestRunner.java @@ -59,7 +59,7 @@ public JUnitNodeTestRunner(Class< ? > clazz) { } /* (non-Javadoc) - * @see org.junit.runner.Runner#getDescription() + * @see org.junit.runner.ExecutableRunner#getDescription() */ @Override public Description getDescription() { @@ -67,7 +67,7 @@ public Description getDescription() { } /* (non-Javadoc) - * @see org.junit.runner.Runner#run(org.junit.runner.notification.RunNotifier) + * @see org.junit.runner.ExecutableRunner#run(org.junit.runner.notification.RunNotifier) */ @Override public void run(RunNotifier notifier) { diff --git a/drools-persistence-jpa/src/main/java/org/drools/persistence/SingleSessionCommandService.java b/drools-persistence-jpa/src/main/java/org/drools/persistence/PersistableRunner.java similarity index 83% rename from drools-persistence-jpa/src/main/java/org/drools/persistence/SingleSessionCommandService.java rename to drools-persistence-jpa/src/main/java/org/drools/persistence/PersistableRunner.java index 27927b55b62..a339490c281 100644 --- a/drools-persistence-jpa/src/main/java/org/drools/persistence/SingleSessionCommandService.java +++ b/drools-persistence-jpa/src/main/java/org/drools/persistence/PersistableRunner.java @@ -16,21 +16,18 @@ package org.drools.persistence; import org.drools.core.SessionConfiguration; -import org.drools.core.command.CommandService; -import org.drools.core.command.Interceptor; +import org.drools.core.command.SingleSessionCommandService; import org.drools.core.command.impl.AbstractInterceptor; -import org.drools.core.command.impl.ContextImpl; -import org.drools.core.command.impl.DefaultCommandService; -import org.drools.core.command.impl.RegistryContext; -import org.drools.core.command.runtime.DisposeCommand; -import org.drools.core.command.runtime.UnpersistableCommand; import org.drools.core.common.EndOperationListener; import org.drools.core.common.InternalKnowledgeRuntime; import org.drools.core.common.InternalWorkingMemory; +import org.drools.core.fluent.impl.InternalExecutable; +import org.drools.core.fluent.impl.PseudoClockRunner; import org.drools.core.impl.InternalKnowledgeBase; import org.drools.core.impl.StatefulKnowledgeSessionImpl; import org.drools.core.marshalling.impl.KieSessionInitializer; import org.drools.core.marshalling.impl.MarshallingConfigurationImpl; +import org.drools.core.runtime.ChainableRunner; import org.drools.core.runtime.process.InternalProcessRuntime; import org.drools.core.time.impl.CommandServiceTimerJobFactoryManager; import org.drools.core.time.impl.TimerJobFactoryManager; @@ -38,14 +35,13 @@ import org.drools.persistence.jpa.JpaPersistenceContextManager; import org.drools.persistence.jpa.processinstance.JPAWorkItemManager; import org.kie.api.KieBase; -import org.kie.api.command.BatchExecutionCommand; -import org.kie.api.command.Command; import org.kie.api.marshalling.ObjectMarshallingStrategy; import org.kie.api.runtime.Environment; import org.kie.api.runtime.EnvironmentName; +import org.kie.api.runtime.Executable; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.KieSessionConfiguration; -import org.kie.internal.command.Context; +import org.kie.api.runtime.RequestContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,26 +50,24 @@ import java.util.Iterator; import java.util.LinkedList; -public class SingleSessionCommandService - implements - org.drools.core.command.SingleSessionCommandService { +public class PersistableRunner implements SingleSessionCommandService { - private static Logger logger = LoggerFactory.getLogger( SingleSessionCommandService.class ); + private static Logger logger = LoggerFactory.getLogger( PersistableRunner.class ); private SessionInfo sessionInfo; private SessionMarshallingHelper marshallingHelper; private KieSession ksession; private Environment env; - private RegistryContext sessionContext; - private CommandService commandService; + private RequestContext sessionContext; + private ChainableRunner runner; private TransactionManager txm; private PersistenceContextManager jpm; private volatile boolean doRollback; - private LinkedList interceptors = new LinkedList(); + private LinkedList interceptors = new LinkedList(); public void checkEnvironment(Environment env) { if ( env.get( EnvironmentName.ENTITY_MANAGER_FACTORY ) == null && @@ -83,9 +77,9 @@ public void checkEnvironment(Environment env) { } } - public SingleSessionCommandService(KieBase kbase, - KieSessionConfiguration conf, - Environment env) { + public PersistableRunner( KieBase kbase, + KieSessionConfiguration conf, + Environment env ) { if ( conf == null ) { conf = SessionConfiguration.newInstance(); } @@ -143,13 +137,13 @@ protected void initNewKnowledgeSession(KieBase kbase, KieSessionConfiguration co ((InternalKnowledgeRuntime) this.ksession).setEndOperationListener( new EndOperationListenerImpl(this.txm, this.sessionInfo ) ); - this.sessionContext = new ContextImpl().register( KieSession.class, this.ksession ); + this.sessionContext = RequestContext.create().with( this.ksession ); - this.commandService = new TransactionInterceptor(sessionContext); + this.runner = new TransactionInterceptor(); TimerJobFactoryManager timerJobFactoryManager = ((InternalKnowledgeRuntime) ksession ).getTimerService().getTimerJobFactoryManager(); if (timerJobFactoryManager instanceof CommandServiceTimerJobFactoryManager) { - ( (CommandServiceTimerJobFactoryManager) timerJobFactoryManager ).setCommandService( this ); + ( (CommandServiceTimerJobFactoryManager) timerJobFactoryManager ).setRunner( this ); } } @@ -160,10 +154,10 @@ private void initKieSessionMBeans(KieSession ksession) { statefulKnowledgeSessionImpl.initMBeans(internalKnowledgeBase.getContainerId(), internalKnowledgeBase.getId(), "persistent"); } - public SingleSessionCommandService( Long sessionId, - KieBase kbase, - KieSessionConfiguration conf, - Environment env) { + public PersistableRunner( Long sessionId, + KieBase kbase, + KieSessionConfiguration conf, + Environment env ) { if ( conf == null ) { conf = SessionConfiguration.newInstance(); } @@ -254,12 +248,12 @@ protected void initExistingKnowledgeSession(Long sessionId, if ( this.sessionContext == null ) { // this should only happen when this class is first constructed - this.sessionContext = new ContextImpl().register( KieSession.class, this.ksession ); + this.sessionContext = RequestContext.create().with( this.ksession ); } - this.commandService = new TransactionInterceptor(sessionContext); + this.runner = new TransactionInterceptor(); // apply interceptors - Iterator iterator = this.interceptors.descendingIterator(); + Iterator iterator = this.interceptors.descendingIterator(); while (iterator.hasNext()) { addInterceptor(iterator.next(), false); } @@ -269,20 +263,20 @@ protected void initExistingKnowledgeSession(Long sessionId, public class JpaSessionInitializer implements KieSessionInitializer { - private final SingleSessionCommandService commandService; + private final PersistableRunner runner; - public JpaSessionInitializer( SingleSessionCommandService commandService ) { - this.commandService = commandService; + public JpaSessionInitializer( PersistableRunner runner ) { + this.runner = runner; } @Override public void init( KieSession ksession ) { - // The CommandService for the TimerJobFactoryManager must be set before any timer jobs are scheduled. - // Otherwise, if overdue jobs are scheduled (and then run before the .commandService field can be set), - // they will retrieve a null commandService (instead of a reference to this) and fail. + // The ExecutableRunner for the TimerJobFactoryManager must be set before any timer jobs are scheduled. + // Otherwise, if overdue jobs are scheduled (and then run before the .executorDelegate field can be set), + // they will retrieve a null executorDelegate (instead of a reference to this) and fail. TimerJobFactoryManager timerJobFactoryManager = ((InternalKnowledgeRuntime) ksession ).getTimerService().getTimerJobFactoryManager(); if (timerJobFactoryManager instanceof CommandServiceTimerJobFactoryManager) { - ( (CommandServiceTimerJobFactoryManager) timerJobFactoryManager ).setCommandService( commandService ); + ( (CommandServiceTimerJobFactoryManager) timerJobFactoryManager ).setRunner( runner ); } } } @@ -348,15 +342,11 @@ public void initTransactionManager(Environment env) { private static String SPRING_TM_CLASSNAME = "org.springframework.transaction.support.AbstractPlatformTransactionManager"; public static boolean isSpringTransactionManager( Class clazz ) { - if ( SPRING_TM_CLASSNAME.equals(clazz.getName()) ) { + if ( SPRING_TM_CLASSNAME.equals( clazz.getName() ) ) { return true; } // Try to find from the ancestors - if (clazz.getSuperclass() != null) - { - return isSpringTransactionManager(clazz.getSuperclass()); - } - return false; + return clazz.getSuperclass() != null && isSpringTransactionManager( clazz.getSuperclass() ); } public static class EndOperationListenerImpl @@ -376,19 +366,21 @@ public void endOperation(InternalKnowledgeRuntime kruntime) { } } - public Context getContext() { - return this.sessionContext; + public RequestContext createContext() { + return RequestContext.create().with( this.ksession ); } - public CommandService getCommandService() { - return this.commandService; + public ChainableRunner getChainableRunner() { + return runner; } - public synchronized T execute(Command command) { - return commandService.execute(command); + @Override + public synchronized RequestContext execute( Executable executable, RequestContext ctx ) { + runner.execute( executable, ctx ); + return ctx; } - private void rollbackTransaction(Exception t1, boolean transactionOwner) { + private void rollbackTransaction( Exception t1, boolean transactionOwner ) { rollbackTransaction(t1, transactionOwner, true); } @@ -457,9 +449,9 @@ private static class SynchronizationImpl extends OrderedTransactionSynchronization { - SingleSessionCommandService service; + PersistableRunner service; - public SynchronizationImpl(SingleSessionCommandService service) { + public SynchronizationImpl(PersistableRunner service ) { super(1, "SynchronizationImpl-"+service.toString()); this.service = service; } @@ -514,13 +506,13 @@ public KieSession getKieSession() { return this.ksession; } - public void addInterceptor(Interceptor interceptor) { + public void addInterceptor(ChainableRunner interceptor) { addInterceptor(interceptor, true); } - protected void addInterceptor(Interceptor interceptor, boolean store) { - interceptor.setNext( this.commandService ); - this.commandService = interceptor; + protected void addInterceptor( ChainableRunner interceptor, boolean store ) { + interceptor.setNext( this.runner ); + this.runner = interceptor; if (store) { // put it on a stack so it can be recreated upon rollback this.interceptors.push(interceptor); @@ -540,20 +532,16 @@ private void registerUpdateSync() { private class TransactionInterceptor extends AbstractInterceptor { - public TransactionInterceptor(Context context) { - setNext(new DefaultCommandService(context)); + public TransactionInterceptor() { + setNext(new PseudoClockRunner()); } @Override - public T execute(Command command) { - if (command instanceof UnpersistableCommand) { - throw new UnsupportedOperationException("Command " + command + " cannot be issued on a persisted session"); - } - - if (command instanceof DisposeCommand) { - T result = executeNext( command ); + public RequestContext execute( Executable executable, RequestContext context ) { + if ( !( (InternalExecutable) executable ).canRunInTransaction() ) { + executeNext(executable, context); jpm.dispose(); - return result; + return context; } // Open the entity manager before the transaction begins. @@ -562,9 +550,9 @@ public T execute(Command command) { boolean transactionOwner = false; try { transactionOwner = txm.begin(); - + persistenceContext.joinTransaction(); - + initExistingKnowledgeSession( sessionInfo.getId(), marshallingHelper.getKbase(), marshallingHelper.getConf(), @@ -584,21 +572,11 @@ public T execute(Command command) { } } - T result = null; - if( command instanceof BatchExecutionCommand) { - // Batch execution requires the extra logic in - // StatefulSessionKnowledgeImpl.execute(Context,Command); - result = ksession.execute(command); - } - else { - logger.trace("Executing " + command.getClass().getSimpleName()); - result = executeNext(command); - } + executeNext(executable, context); + registerUpdateSync(); txm.commit( transactionOwner ); - return result; - } catch ( RuntimeException re ) { rollbackTransaction( re, transactionOwner ); @@ -609,6 +587,8 @@ public T execute(Command command) { throw new RuntimeException( "Wrapped exception see cause", t1 ); } + + return context; } } diff --git a/drools-persistence-jpa/src/main/java/org/drools/persistence/PersistenceContextManager.java b/drools-persistence-jpa/src/main/java/org/drools/persistence/PersistenceContextManager.java index 0eaf1a37de7..3028daa63d0 100644 --- a/drools-persistence-jpa/src/main/java/org/drools/persistence/PersistenceContextManager.java +++ b/drools-persistence-jpa/src/main/java/org/drools/persistence/PersistenceContextManager.java @@ -15,13 +15,13 @@ package org.drools.persistence; -import javax.persistence.EntityManager; -import javax.transaction.Synchronization; - -import org.drools.core.command.CommandService; +import org.kie.api.runtime.ExecutableRunner; import org.kie.api.command.Command; import org.kie.api.runtime.KieSession; +import javax.persistence.EntityManager; +import javax.transaction.Synchronization; + public interface PersistenceContextManager { /** @@ -35,9 +35,9 @@ public interface PersistenceContextManager { PersistenceContext getCommandScopedPersistenceContext(); /** - * This method should be called at the beginning of a {@link CommandService#execute(org.kie.api.command.Command)} method, - * when the given {@link CommandService} instance is responsible for handling persistence. - * See the {@link SingleSessionCommandService} class. + * This method should be called at the beginning of a {@link ExecutableRunner#execute(org.kie.api.command.Command)} method, + * when the given {@link ExecutableRunner} instance is responsible for handling persistence. + * See the {@link PersistableRunner} class. *

* The first responsibility of this method is to make sure that the Command Scoped {@link EntityManager} (CSEM) joins * the ongoing transaction. diff --git a/drools-persistence-jpa/src/main/java/org/drools/persistence/TransactionSynchronizationContainer.java b/drools-persistence-jpa/src/main/java/org/drools/persistence/TransactionSynchronizationContainer.java index c3f6671875b..a4f42761e00 100644 --- a/drools-persistence-jpa/src/main/java/org/drools/persistence/TransactionSynchronizationContainer.java +++ b/drools-persistence-jpa/src/main/java/org/drools/persistence/TransactionSynchronizationContainer.java @@ -15,13 +15,12 @@ package org.drools.persistence; -import java.util.Iterator; -import java.util.Set; -import java.util.TreeSet; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Set; +import java.util.TreeSet; + public class TransactionSynchronizationContainer implements TransactionSynchronization { private static Logger logger = LoggerFactory.getLogger( TransactionSynchronizationContainer.class ); diff --git a/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JDKCallableJobCommand.java b/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JDKCallableJobCommand.java index 266c7df122f..23b7958ecb5 100644 --- a/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JDKCallableJobCommand.java +++ b/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JDKCallableJobCommand.java @@ -16,7 +16,7 @@ package org.drools.persistence.jpa; import org.drools.core.command.impl.ExecutableCommand; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; public class JDKCallableJobCommand implements diff --git a/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaJDKTimerService.java b/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaJDKTimerService.java index 33b57cac06f..a8faab796eb 100644 --- a/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaJDKTimerService.java +++ b/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaJDKTimerService.java @@ -16,12 +16,7 @@ package org.drools.persistence.jpa; -import java.util.Collection; -import java.util.Map; -import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentHashMap; - -import org.drools.core.command.CommandService; +import org.kie.api.runtime.ExecutableRunner; import org.drools.core.command.impl.ExecutableCommand; import org.drools.core.time.InternalSchedulerService; import org.drools.core.time.Job; @@ -32,10 +27,15 @@ import org.drools.core.time.impl.DefaultTimerJobInstance; import org.drools.core.time.impl.JDKTimerService; import org.drools.core.time.impl.TimerJobInstance; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; + /** * A default Scheduler implementation that uses the * JDK built-in ScheduledThreadPoolExecutor as the @@ -45,12 +45,12 @@ public class JpaJDKTimerService extends JDKTimerService { private static Logger logger = LoggerFactory.getLogger( JpaTimerJobInstance.class ); - private CommandService commandService; + private ExecutableRunner runner; private Map timerInstances; - public void setCommandService(CommandService commandService) { - this.commandService = commandService; + public void setCommandService(ExecutableRunner runner ) { + this.runner = runner; } public JpaJDKTimerService() { @@ -101,7 +101,7 @@ public JpaJDKCallableJob(Job job, public Void call() throws Exception { try { JDKCallableJobCommand command = new JDKCallableJobCommand( this ); - commandService.execute( command ); + runner.execute( command ); } catch(Exception e ) { logger.error("Unable to execute job!", e); throw e; diff --git a/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimeJobFactoryManager.java b/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimeJobFactoryManager.java index 9248dcf98dc..3b7d1e06510 100644 --- a/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimeJobFactoryManager.java +++ b/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimeJobFactoryManager.java @@ -15,7 +15,7 @@ package org.drools.persistence.jpa; -import org.drools.core.command.CommandService; +import org.kie.api.runtime.ExecutableRunner; import org.drools.core.time.InternalSchedulerService; import org.drools.core.time.Job; import org.drools.core.time.JobContext; @@ -30,14 +30,14 @@ public class JpaTimeJobFactoryManager extends ThreadSafeTrackableTimeJobFactoryManager implements CommandServiceTimerJobFactoryManager { - private CommandService commandService; + private ExecutableRunner runner; - public void setCommandService(CommandService commandService) { - this.commandService = commandService; + public void setRunner(ExecutableRunner runner ) { + this.runner = runner; } - public CommandService getCommandService() { - return commandService; + public ExecutableRunner getRunner() { + return runner; } public TimerJobInstance createTimerJobInstance(Job job, diff --git a/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimerJobInstance.java b/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimerJobInstance.java index ce8c252ac45..50c89f53066 100644 --- a/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimerJobInstance.java +++ b/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/JpaTimerJobInstance.java @@ -15,7 +15,7 @@ package org.drools.persistence.jpa; -import org.drools.core.command.CommandService; +import org.kie.api.runtime.ExecutableRunner; import org.drools.core.time.InternalSchedulerService; import org.drools.core.time.Job; import org.drools.core.time.JobContext; @@ -46,8 +46,8 @@ public JpaTimerJobInstance(Job job, public Void call() throws Exception { try { JDKCallableJobCommand command = new JDKCallableJobCommand( this ); - CommandService commandService = ( (CommandServiceTimerJobFactoryManager) ( (TimerService) scheduler ).getTimerJobFactoryManager() ).getCommandService(); - commandService.execute( command ); + ExecutableRunner runner = ( (CommandServiceTimerJobFactoryManager) ( (TimerService) scheduler ).getTimerJobFactoryManager() ).getRunner(); + runner.execute( command ); return null; } catch( Exception e ) { logger.error("Unable to execute timer job!", e); diff --git a/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/KnowledgeStoreServiceImpl.java b/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/KnowledgeStoreServiceImpl.java index d75e06146a5..6f86b9c77cc 100644 --- a/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/KnowledgeStoreServiceImpl.java +++ b/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/KnowledgeStoreServiceImpl.java @@ -15,22 +15,22 @@ */ package org.drools.persistence.jpa; +import org.kie.api.runtime.ExecutableRunner; import org.drools.core.SessionConfiguration; -import org.drools.core.command.CommandService; import org.drools.core.command.EntryPointCreator; import org.drools.core.command.impl.CommandBasedEntryPoint; import org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession; -import org.drools.persistence.SingleSessionCommandService; -import org.drools.persistence.jpa.processinstance.JPAWorkItemManagerFactory; import org.drools.core.process.instance.WorkItemManagerFactory; +import org.drools.persistence.PersistableRunner; +import org.drools.persistence.jpa.processinstance.JPAWorkItemManagerFactory; import org.kie.api.KieBase; import org.kie.api.persistence.jpa.KieStoreServices; import org.kie.api.runtime.CommandExecutor; import org.kie.api.runtime.Environment; import org.kie.api.runtime.KieSessionConfiguration; +import org.kie.api.runtime.conf.TimerJobFactoryOption; import org.kie.api.runtime.rule.EntryPoint; import org.kie.internal.runtime.StatefulKnowledgeSession; -import org.kie.api.runtime.conf.TimerJobFactoryOption; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -50,7 +50,7 @@ public KnowledgeStoreServiceImpl() { } protected void setDefaultImplementations() { - setCommandServiceClass( SingleSessionCommandService.class ); + setCommandServiceClass( PersistableRunner.class ); setProcessInstanceManagerFactoryClass( "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory" ); setWorkItemManagerFactoryClass( JPAWorkItemManagerFactory.class ); setProcessSignalManagerFactoryClass( "org.jbpm.persistence.processinstance.JPASignalManagerFactory" ); @@ -67,12 +67,12 @@ public StatefulKnowledgeSession newKieSession(KieBase kbase, throw new IllegalArgumentException( "Environment cannot be null" ); } - CommandService commandService = (CommandService) buildCommandService( kbase, - mergeConfig( configuration ), - environment ); - commandService.getContext().set(EntryPointCreator.class.getName(), - new CommandBasedEntryPointCreator(commandService)); - return new CommandBasedStatefulKnowledgeSession( commandService ); + ExecutableRunner runner = (ExecutableRunner) buildCommandService( kbase, + mergeConfig( configuration ), + environment ); + runner.createContext().set( EntryPointCreator.class.getName(), + new CommandBasedEntryPointCreator(runner) ); + return new CommandBasedStatefulKnowledgeSession( runner ); } public StatefulKnowledgeSession loadKieSession(int id, @@ -87,13 +87,13 @@ public StatefulKnowledgeSession loadKieSession(int id, throw new IllegalArgumentException( "Environment cannot be null" ); } - CommandService commandService = (CommandService) buildCommandService( new Long(id), - kbase, - mergeConfig( configuration ), - environment ); - commandService.getContext().set(EntryPointCreator.class.getName(), - new CommandBasedEntryPointCreator(commandService)); - return new CommandBasedStatefulKnowledgeSession( commandService ); + ExecutableRunner runner = (ExecutableRunner) buildCommandService( new Long( id), + kbase, + mergeConfig( configuration ), + environment ); + runner.createContext().set( EntryPointCreator.class.getName(), + new CommandBasedEntryPointCreator(runner) ); + return new CommandBasedStatefulKnowledgeSession( runner ); } public StatefulKnowledgeSession loadKieSession(Long id, @@ -108,24 +108,24 @@ public StatefulKnowledgeSession loadKieSession(Long id, throw new IllegalArgumentException( "Environment cannot be null" ); } - CommandService commandService = (CommandService) buildCommandService( id, - kbase, - mergeConfig( configuration ), - environment ); - commandService.getContext().set(EntryPointCreator.class.getName(), - new CommandBasedEntryPointCreator(commandService)); - return new CommandBasedStatefulKnowledgeSession( commandService ); + ExecutableRunner runner = (ExecutableRunner) buildCommandService( id, + kbase, + mergeConfig( configuration ), + environment ); + runner.createContext().set( EntryPointCreator.class.getName(), + new CommandBasedEntryPointCreator(runner) ); + return new CommandBasedStatefulKnowledgeSession( runner ); } public static class CommandBasedEntryPointCreator implements EntryPointCreator { - private final CommandService commandService; + private final ExecutableRunner runner; - public CommandBasedEntryPointCreator(CommandService commandService) { - this.commandService = commandService; + public CommandBasedEntryPointCreator(ExecutableRunner runner ) { + this.runner = runner; } public EntryPoint getEntryPoint(String entryPoint) { - return new CommandBasedEntryPoint( commandService, entryPoint ); + return new CommandBasedEntryPoint( runner, entryPoint ); } } @@ -194,7 +194,7 @@ private KieSessionConfiguration mergeConfig(KieSessionConfiguration configuratio public long getStatefulKnowledgeSessionId(StatefulKnowledgeSession ksession) { if ( ksession instanceof CommandBasedStatefulKnowledgeSession ) { - SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getCommandService(); + PersistableRunner commandService = (PersistableRunner) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); return commandService.getSessionId(); } throw new IllegalArgumentException( "StatefulKnowledgeSession must be an a CommandBasedStatefulKnowledgeSession" ); diff --git a/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/OptimisticLockRetryInterceptor.java b/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/OptimisticLockRetryInterceptor.java index 4d4d8040942..b56c899b243 100644 --- a/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/OptimisticLockRetryInterceptor.java +++ b/drools-persistence-jpa/src/main/java/org/drools/persistence/jpa/OptimisticLockRetryInterceptor.java @@ -16,15 +16,17 @@ package org.drools.persistence.jpa; -import javax.persistence.OptimisticLockException; - import org.drools.core.command.impl.AbstractInterceptor; -import org.kie.api.command.Command; +import org.kie.api.runtime.Executable; +import org.kie.api.runtime.RequestContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.persistence.OptimisticLockException; +import java.util.concurrent.atomic.AtomicInteger; + /** - * Interceptor that is capable of retrying command execution. It is intended to retry only if right exception + * ExecutableInterceptor that is capable of retrying command execution. It is intended to retry only if right exception * has been thrown. By default it will look for org.hibernate.StaleObjectStateException and only * then attempt to retry. * Since this is Hibernate specific class another can be given as system property to override default. Name of the @@ -51,6 +53,8 @@ public class OptimisticLockRetryInterceptor extends AbstractInterceptor { protected Class targetConstraintViolationExceptionClass; + private static final ThreadLocal invocationsCounter = new ThreadLocal<>(); + public OptimisticLockRetryInterceptor() { String clazz = System.getProperty("org.kie.optlock.exclass", "org.hibernate.StaleObjectStateException"); try { @@ -68,7 +72,23 @@ public OptimisticLockRetryInterceptor() { } @Override - public T execute(Command command) { + public final RequestContext execute( Executable executable, RequestContext ctx ) { + AtomicInteger counter = invocationsCounter.get(); + if (counter == null) { + counter = new AtomicInteger( 0 ); + invocationsCounter.set( counter ); + } + counter.incrementAndGet(); + try { + return internalExecute( executable, ctx ); + } finally { + if (counter.decrementAndGet() == 0) { + invocationsCounter.remove(); + } + } + } + + protected RequestContext internalExecute( Executable executable, RequestContext ctx ) { int attempt = 1; long sleepTime = delay; RuntimeException originException = null; @@ -79,7 +99,8 @@ public T execute(Command command) { } try { - return executeNext(command); + executeNext(executable, ctx); + return ctx; } catch (RuntimeException ex) { // in case there is another interceptor of this type in the stack don't handle it here @@ -108,7 +129,6 @@ public T execute(Command command) { } logger.warn("Retry failed after {} attempts", attempt); throw originException; - } protected boolean isCausedByOptimisticLockingFailure(Throwable throwable) { @@ -178,19 +198,7 @@ public void setTargetExceptionClass(Class targetExceptionClass) { } protected boolean hasInterceptorInStack() { - StackTraceElement[] elements = Thread.currentThread().getStackTrace(); - int counter = -1; - for (StackTraceElement element : elements) { - if (element.getClassName().equals(this.getClass().getName()) && element.getMethodName().equals("execute")) { - counter++; - } - // avoid iterating entire stack if possible - if (counter > 0) { - return true; - } - } - - return false; + return invocationsCounter.get().get() > 1; } } diff --git a/drools-persistence-jpa/src/main/java/org/drools/persistence/jta/TransactionLockInterceptor.java b/drools-persistence-jpa/src/main/java/org/drools/persistence/jta/TransactionLockInterceptor.java index 16ca21a359d..c370f50d750 100644 --- a/drools-persistence-jpa/src/main/java/org/drools/persistence/jta/TransactionLockInterceptor.java +++ b/drools-persistence-jpa/src/main/java/org/drools/persistence/jta/TransactionLockInterceptor.java @@ -16,24 +16,24 @@ package org.drools.persistence.jta; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.locks.ReentrantLock; - -import javax.transaction.Status; - import org.drools.core.command.impl.AbstractInterceptor; import org.drools.persistence.OrderedTransactionSynchronization; import org.drools.persistence.TransactionManager; import org.drools.persistence.TransactionManagerHelper; -import org.kie.api.command.Command; import org.kie.api.runtime.Environment; import org.kie.api.runtime.EnvironmentName; +import org.kie.api.runtime.Executable; +import org.kie.api.runtime.RequestContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.transaction.Status; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.locks.ReentrantLock; + /** - * Interceptor that will lock underlying CommandService until transaction completion. + * ExecutableInterceptor that will lock underlying Runner until transaction completion. * In case there is no transaction active lock is released directly. * * By default, interceptor is disabled and needs to be explicitly enabled in one of two ways: @@ -68,9 +68,10 @@ public TransactionLockInterceptor(Environment environment, String releaseTxKey) } @Override - public T execute(Command command) { + public RequestContext execute( Executable executable, RequestContext ctx ) { if (!active) { - return executeNext(command); + executeNext(executable, ctx); + return ctx; } // release before entering in case it failed previously to avoid deadlock releaseAfterFailure(); @@ -83,7 +84,7 @@ public T execute(Command command) { logger.debug("Lock taken by {}", Thread.currentThread().getName()); } try { - return executeNext(command); + executeNext(executable, ctx); } finally { if (locked) { logger.debug("About to register lock release handler by {}", Thread.currentThread().getName()); @@ -91,6 +92,7 @@ public T execute(Command command) { } releaseAfterFailure(); } + return ctx; } protected void release(TransactionManager txm) { diff --git a/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/JtaTransactionManagerTest.java b/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/JtaTransactionManagerTest.java index 046d9bc3d9f..fbf77acda12 100644 --- a/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/JtaTransactionManagerTest.java +++ b/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/JtaTransactionManagerTest.java @@ -17,7 +17,7 @@ import bitronix.tm.internal.BitronixRollbackException; import org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession; -import org.drools.persistence.SingleSessionCommandService; +import org.drools.persistence.PersistableRunner; import org.drools.persistence.TransactionManager; import org.drools.persistence.jpa.JpaPersistenceContextManager; import org.drools.persistence.util.DroolsPersistenceUtil; @@ -259,7 +259,7 @@ public void testSingleSessionCommandServiceAndJtaTransactionManagerTogether() th KnowledgeBase kbase = initializeKnowledgeBase(simpleRule); StatefulKnowledgeSession commandKSession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env ); commandKSession.getIdentifier(); // initialize CSEM - SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) commandKSession).getCommandService(); + PersistableRunner commandService = (PersistableRunner) ((CommandBasedStatefulKnowledgeSession) commandKSession).getRunner(); JpaPersistenceContextManager jpm = (JpaPersistenceContextManager) getValueOfField("jpm", commandService); TransactionTestObject mainObject = new TransactionTestObject(); diff --git a/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/TransactionTestCommand.java b/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/TransactionTestCommand.java index 220e667b139..f79d8f60ac1 100644 --- a/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/TransactionTestCommand.java +++ b/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/TransactionTestCommand.java @@ -25,7 +25,7 @@ import org.kie.api.runtime.KieSession; import org.kie.internal.KnowledgeBase; import org.kie.internal.KnowledgeBaseFactory; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.persistence.jpa.JPAKnowledgeService; import org.kie.internal.runtime.StatefulKnowledgeSession; @@ -93,7 +93,7 @@ public Void execute(Context context) { /** * Here's what's going on: - * If the SingleSessionCommandService (SSCS) & JtaTransactionManager (JTM) were _not_ aware of transactions, + * If the PersistableRunner (SSCS) & JtaTransactionManager (JTM) were _not_ aware of transactions, * -> then inserting the mainObject _before_ having inserted the subObject * would cause the operation/persist to fail and the transaction to fail. * - This is because the mainObject contains a foreign key referring to the subObject. diff --git a/drools-persistence-jpa/src/test/java/org/drools/persistence/kie/persistence/session/JpaPersistentStatefulSessionTest.java b/drools-persistence-jpa/src/test/java/org/drools/persistence/kie/persistence/session/JpaPersistentStatefulSessionTest.java index 153430c7aba..b41b51f7dec 100644 --- a/drools-persistence-jpa/src/test/java/org/drools/persistence/kie/persistence/session/JpaPersistentStatefulSessionTest.java +++ b/drools-persistence-jpa/src/test/java/org/drools/persistence/kie/persistence/session/JpaPersistentStatefulSessionTest.java @@ -22,7 +22,7 @@ import org.drools.core.command.impl.LoggingInterceptor; import org.drools.core.factmodel.traits.Traitable; import org.drools.core.time.SessionPseudoClock; -import org.drools.persistence.SingleSessionCommandService; +import org.drools.persistence.PersistableRunner; import org.drools.persistence.util.DroolsPersistenceUtil; import org.junit.After; import org.junit.Before; @@ -308,8 +308,8 @@ public void testInterceptor() { KieBase kbase = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).getKieBase(); KieSession ksession = ks.getStoreServices().newKieSession( kbase, null, env ); - SingleSessionCommandService sscs = (SingleSessionCommandService) - ((CommandBasedStatefulKnowledgeSession) ksession).getCommandService(); + PersistableRunner sscs = (PersistableRunner) + ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); sscs.addInterceptor(new LoggingInterceptor()); sscs.addInterceptor(new FireAllRulesInterceptor()); sscs.addInterceptor(new LoggingInterceptor()); diff --git a/drools-persistence-jpa/src/test/java/org/drools/persistence/session/AgendaRuleFlowGroupsTest.java b/drools-persistence-jpa/src/test/java/org/drools/persistence/session/AgendaRuleFlowGroupsTest.java index 03d7e5ea672..05256331c52 100644 --- a/drools-persistence-jpa/src/test/java/org/drools/persistence/session/AgendaRuleFlowGroupsTest.java +++ b/drools-persistence-jpa/src/test/java/org/drools/persistence/session/AgendaRuleFlowGroupsTest.java @@ -37,7 +37,7 @@ import org.kie.internal.KnowledgeBaseFactory; import org.kie.internal.builder.KnowledgeBuilder; import org.kie.internal.builder.KnowledgeBuilderFactory; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.persistence.jpa.JPAKnowledgeService; import org.kie.internal.utils.KieHelper; @@ -163,7 +163,7 @@ public void testAgendaGroupAndRuleFlowGroup() throws Exception { private KieSession stripSession(KieSession ksession) { if (ksession instanceof CommandBasedStatefulKnowledgeSession) { return ((RegistryContext)((CommandBasedStatefulKnowledgeSession) ksession). - getCommandService().getContext()).lookup( KieSession.class ); + getRunner().createContext()).lookup( KieSession.class ); } return ksession; diff --git a/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaOptLockPersistentStatefulSessionTest.java b/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaOptLockPersistentStatefulSessionTest.java index 34b2f77bc5a..f533341d8b5 100644 --- a/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaOptLockPersistentStatefulSessionTest.java +++ b/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaOptLockPersistentStatefulSessionTest.java @@ -16,7 +16,7 @@ package org.drools.persistence.session; import org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession; -import org.drools.persistence.SingleSessionCommandService; +import org.drools.persistence.PersistableRunner; import org.drools.persistence.jpa.OptimisticLockRetryInterceptor; import org.drools.persistence.util.DroolsPersistenceUtil; import org.hibernate.StaleObjectStateException; @@ -119,7 +119,7 @@ private class InsertAndFireThread extends Thread { @Override public void run() { StatefulKnowledgeSession ksession2 = JPAKnowledgeService.loadStatefulKnowledgeSession(ksessionId, kbase, null, createEnvironment(context) ); - SingleSessionCommandService sscs = (SingleSessionCommandService)((CommandBasedStatefulKnowledgeSession) ksession2).getCommandService(); + PersistableRunner sscs = (PersistableRunner)((CommandBasedStatefulKnowledgeSession) ksession2).getRunner(); OptimisticLockRetryInterceptor interceptor = new OptimisticLockRetryInterceptor(); // set higher delay so that the interceptor is not invoked multiple times on slow machines interceptor.setDelay(500); diff --git a/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaPersistentStatefulSessionTest.java b/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaPersistentStatefulSessionTest.java index f81913ffc63..b30322e0f25 100644 --- a/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaPersistentStatefulSessionTest.java +++ b/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaPersistentStatefulSessionTest.java @@ -18,12 +18,11 @@ import org.drools.compiler.Address; import org.drools.compiler.Person; import org.drools.core.SessionConfiguration; -import org.drools.core.command.CommandService; -import org.drools.core.command.Interceptor; import org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession; import org.drools.core.command.impl.FireAllRulesInterceptor; import org.drools.core.command.impl.LoggingInterceptor; -import org.drools.persistence.SingleSessionCommandService; +import org.drools.core.runtime.ChainableRunner; +import org.drools.persistence.PersistableRunner; import org.drools.persistence.util.DroolsPersistenceUtil; import org.junit.After; import org.junit.Before; @@ -58,13 +57,8 @@ import java.util.Properties; import java.util.concurrent.atomic.AtomicInteger; -import static org.drools.persistence.util.DroolsPersistenceUtil.DROOLS_PERSISTENCE_UNIT_NAME; -import static org.drools.persistence.util.DroolsPersistenceUtil.OPTIMISTIC_LOCKING; -import static org.drools.persistence.util.DroolsPersistenceUtil.PESSIMISTIC_LOCKING; -import static org.drools.persistence.util.DroolsPersistenceUtil.createEnvironment; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; +import static org.drools.persistence.util.DroolsPersistenceUtil.*; +import static org.junit.Assert.*; @RunWith(Parameterized.class) public class JpaPersistentStatefulSessionTest { @@ -321,8 +315,8 @@ public void testInterceptor() { kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() ); StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env ); - SingleSessionCommandService sscs = (SingleSessionCommandService) - ((CommandBasedStatefulKnowledgeSession) ksession).getCommandService(); + PersistableRunner sscs = (PersistableRunner) + ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); sscs.addInterceptor(new LoggingInterceptor()); sscs.addInterceptor(new FireAllRulesInterceptor()); sscs.addInterceptor(new LoggingInterceptor()); @@ -360,19 +354,19 @@ public void testInterceptorOnRollback() throws Exception{ kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() ); StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env ); - SingleSessionCommandService sscs = (SingleSessionCommandService) - ((CommandBasedStatefulKnowledgeSession) ksession).getCommandService(); + PersistableRunner sscs = (PersistableRunner) + ((CommandBasedStatefulKnowledgeSession) ksession).getRunner(); sscs.addInterceptor(new LoggingInterceptor()); sscs.addInterceptor(new FireAllRulesInterceptor()); sscs.addInterceptor(new LoggingInterceptor()); - CommandService internalCommandService = sscs.getCommandService(); + ChainableRunner runner = sscs.getChainableRunner(); - assertEquals(LoggingInterceptor.class, internalCommandService.getClass()); - internalCommandService = ((Interceptor) internalCommandService).getNext(); - assertEquals(FireAllRulesInterceptor.class, internalCommandService.getClass()); - internalCommandService = ((Interceptor) internalCommandService).getNext(); - assertEquals(LoggingInterceptor.class, internalCommandService.getClass()); + assertEquals(LoggingInterceptor.class, runner.getClass()); + runner = (ChainableRunner)runner.getNext(); + assertEquals(FireAllRulesInterceptor.class, runner.getClass()); + runner = (ChainableRunner)runner.getNext(); + assertEquals(LoggingInterceptor.class, runner.getClass()); UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction"); ut.begin(); @@ -383,13 +377,13 @@ public void testInterceptorOnRollback() throws Exception{ ksession.insert( 3 ); - internalCommandService = sscs.getCommandService(); + runner = sscs.getChainableRunner(); - assertEquals(LoggingInterceptor.class, internalCommandService.getClass()); - internalCommandService = ((Interceptor) internalCommandService).getNext(); - assertEquals(FireAllRulesInterceptor.class, internalCommandService.getClass()); - internalCommandService = ((Interceptor) internalCommandService).getNext(); - assertEquals(LoggingInterceptor.class, internalCommandService.getClass()); + assertEquals(LoggingInterceptor.class, runner.getClass()); + runner = (ChainableRunner)runner.getNext(); + assertEquals(FireAllRulesInterceptor.class, runner.getClass()); + runner = (ChainableRunner)runner.getNext(); + assertEquals(LoggingInterceptor.class, runner.getClass()); } diff --git a/drools-persistence-jpa/src/test/java/org/drools/persistence/session/ReloadSessionTest.java b/drools-persistence-jpa/src/test/java/org/drools/persistence/session/ReloadSessionTest.java index 8872b26f358..164752126dc 100644 --- a/drools-persistence-jpa/src/test/java/org/drools/persistence/session/ReloadSessionTest.java +++ b/drools-persistence-jpa/src/test/java/org/drools/persistence/session/ReloadSessionTest.java @@ -135,7 +135,7 @@ public void reloadKnowledgeSessionTest() { commandKSession.insert( integerFact ); // At this point in the code, the fact has been persisted to the database - // (within a transaction via the SingleSessionCommandService) + // (within a transaction via the PersistableRunner) Collection factHandles = commandKSession.getFactHandles(); assertTrue("At least one fact should have been inserted by the ksession.insert() method above.", !factHandles.isEmpty()); FactHandle origFactHandle = factHandles.iterator().next(); diff --git a/drools-persistence-jpa/src/test/java/org/drools/persistence/session/RuleFlowGroupRollbackTest.java b/drools-persistence-jpa/src/test/java/org/drools/persistence/session/RuleFlowGroupRollbackTest.java index 4e5af5217bb..c3214787c54 100644 --- a/drools-persistence-jpa/src/test/java/org/drools/persistence/session/RuleFlowGroupRollbackTest.java +++ b/drools-persistence-jpa/src/test/java/org/drools/persistence/session/RuleFlowGroupRollbackTest.java @@ -35,7 +35,7 @@ import org.kie.internal.KnowledgeBaseFactory; import org.kie.internal.builder.KnowledgeBuilder; import org.kie.internal.builder.KnowledgeBuilderFactory; -import org.kie.internal.command.Context; +import org.kie.api.runtime.Context; import org.kie.internal.persistence.jpa.JPAKnowledgeService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/drools-reteoo/src/test/java/org/drools/reteoo/integrationtests/MultithreadTest.java b/drools-reteoo/src/test/java/org/drools/reteoo/integrationtests/MultithreadTest.java index 43558df2eea..4339d0e2759 100644 --- a/drools-reteoo/src/test/java/org/drools/reteoo/integrationtests/MultithreadTest.java +++ b/drools-reteoo/src/test/java/org/drools/reteoo/integrationtests/MultithreadTest.java @@ -749,14 +749,14 @@ public Boolean call() throws Exception { // } // } // -// class Runner +// class ExecutableRunner // implements // Runnable { // private final long TIME_SPAN; // private final StatelessSession session; // private final AtomicInteger count; // -// public Runner(long BASE_TIME, +// public ExecutableRunner(long BASE_TIME, // StatelessSession session, // final AtomicInteger count) { // this.TIME_SPAN = BASE_TIME; @@ -812,7 +812,7 @@ public Boolean call() throws Exception { // for ( int i = 0; i < THREADS; i++ ) { // RuleBase ruleBase = createRuleBase( pkgs ); // StatelessSession session = createSession( ruleBase ); -// new Thread( new Runner( BASE_TIME, +// new Thread( new ExecutableRunner( BASE_TIME, // session, // count ) ).start(); // } diff --git a/drools-templates/src/test/java/org/drools/template/parser/ExternalSheetListenerTest.java b/drools-templates/src/test/java/org/drools/template/parser/ExternalSheetListenerTest.java index ffe5fbb7955..8a7c871ab21 100644 --- a/drools-templates/src/test/java/org/drools/template/parser/ExternalSheetListenerTest.java +++ b/drools-templates/src/test/java/org/drools/template/parser/ExternalSheetListenerTest.java @@ -150,7 +150,7 @@ public void destroy() { public void submit( AtomicAction action ) { } @Override - public T getKieRuntime(Class cls) { + public T getKieRuntime( Class cls ) { return null; }