Skip to content

Commit

Permalink
Using isThreadSafe at creation time of reteevaluator
Browse files Browse the repository at this point in the history
  • Loading branch information
pibizza committed Jun 30, 2023
1 parent 38405af commit 5847a88
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.drools.core.runtime.process.InternalProcessRuntime;
import org.drools.core.rule.consequence.InternalMatch;
import org.kie.api.runtime.Channel;
import org.kie.api.runtime.conf.ThreadSafeOption;
import org.kie.api.runtime.rule.EntryPoint;

public interface InternalWorkingMemory
Expand Down Expand Up @@ -121,7 +120,4 @@ default FactHandleClassStore getStoreForClass(Class<?> clazz) {

void cancelActivation(InternalMatch internalMatch, boolean declarativeAgenda);

default boolean isThreadSafe() {
return getRuleSessionConfiguration().getOption(ThreadSafeOption.KEY).isThreadSafe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ default Collection<TimerJobInstance> getTimerJobInstances(long id) {

long getNextPropagationIdCounter();

default boolean isThreadSafe() {
return true;
}
boolean isThreadSafe();

default FactHandleClassStore getStoreForClass(Class<?> clazz) {
return getDefaultEntryPoint().getObjectStore().getStoreForClass(clazz);
Expand Down Expand Up @@ -137,6 +135,8 @@ default KnowledgeHelper createKnowledgeHelper() {
int fireAllRules(int max);
int fireAllRules(AgendaFilter agendaFilter);
int fireAllRules(AgendaFilter agendaFilter, int max);



default void setWorkingMemoryActionListener(Consumer<PropagationEntry> listener) {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,4 +735,8 @@ public SessionClock getSessionClock() {
public ProcessInstance startProcessFromNodeIds(String processId, Map<String, Object> params, String... nodeIds) {
return delegate.startProcessFromNodeIds(processId, params, nodeIds);
}

public boolean isThreadSafe() {
return delegate.isThreadSafe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ public class StatefulKnowledgeSessionImpl extends AbstractRuntime

private Consumer<PropagationEntry> workingMemoryActionListener;

private boolean isThreadSafe;

// ------------------------------------------------------------
// Constructors
// ------------------------------------------------------------
Expand Down Expand Up @@ -349,6 +351,8 @@ private StatefulKnowledgeSessionImpl(final long id,
if (initInitFactHandle) {
this.initialFactHandle = initInitialFact(null);
}

isThreadSafe = getRuleSessionConfiguration().getOption(ThreadSafeOption.KEY).isThreadSafe();
}

public StatefulKnowledgeSessionImpl setStateless( boolean stateless ) {
Expand Down Expand Up @@ -518,6 +522,10 @@ public boolean isAlive() {
public void destroy() {
dispose();
}

public boolean isThreadSafe() {
return isThreadSafe;
}

public void update(FactHandle factHandle) {
this.update(factHandle,
Expand Down Expand Up @@ -1755,4 +1763,6 @@ public ProcessInstance startProcessFromNodeIds(String processId, Map<String, Obj
public ProcessInstance startProcessFromNodeIds(String processId, CorrelationKey key, Map<String, Object> params, String... nodeIds) {
return getProcessRuntime().startProcessFromNodeIds(processId, key, params, nodeIds);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
import org.kie.api.definition.rule.Direct;
import org.kie.api.definition.rule.Propagation;
import org.kie.api.definition.type.Role;
import org.kie.api.runtime.conf.ThreadSafeOption;
import org.kie.internal.builder.KnowledgeBuilderConfiguration;
import org.kie.internal.builder.conf.PropertySpecificOption;

Expand Down Expand Up @@ -391,6 +392,7 @@ private void processConsequence( RuleContext ctx, Consequence consequence, Strin
// This is changed, because we must use the Declarations provided by the RTN, otherwise tuple indexes are not set.
Declaration[] requiredDeclarations = getRequiredDeclarationsIfPossible( ctx, consequence, name );
boolean enabledTupleOptimization = requiredDeclarations != null && requiredDeclarations.length > 0;


if ( name.equals( RuleImpl.DEFAULT_CONSEQUENCE_NAME ) ) {
if ("java".equals(consequence.getLanguage())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ public void dispose() {

this.timerService.shutdown();
}

@Override
public boolean isThreadSafe() {
return true;
}

@Override
public QueryResults getQueryResults(String queryName, Object... arguments) {
Expand Down

0 comments on commit 5847a88

Please sign in to comment.