Skip to content

Commit

Permalink
Encapsulated configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
pibizza committed Jun 30, 2023
1 parent 147cdee commit 4f9bae0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void setWorkingMemory(final InternalWorkingMemory workingMemory) {
this.workingMemory = workingMemory;
this.agendaGroupsManager.setReteEvaluator( workingMemory );

if (!workingMemory.getRuleSessionConfiguration().getOption(ThreadSafeOption.KEY).isThreadSafe()) {
if (!workingMemory.isThreadSafe()) {
executionStateMachine = new UnsafeExecutionStateMachine();
}

Expand All @@ -219,7 +219,7 @@ public void setWorkingMemory(final InternalWorkingMemory workingMemory) {
}

protected PropagationList createPropagationList() {
if (!workingMemory.getRuleSessionConfiguration().getOption(ThreadSafeOption.KEY).isThreadSafe()) {
if (!workingMemory.isThreadSafe()) {
return new ThreadUnsafePropagationList( workingMemory );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.drools.core.util.bitmask.AllSetBitMask;
import org.drools.core.util.bitmask.BitMask;
import org.kie.api.conf.KieBaseMutabilityOption;
import org.kie.api.runtime.conf.ThreadSafeOption;
import org.kie.api.runtime.rule.FactHandle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -108,7 +107,7 @@ public NamedEntryPoint(EntryPointId entryPoint,
this.entryPointNode = entryPointNode;
this.reteEvaluator = reteEvaluator;
this.ruleBase = this.reteEvaluator.getKnowledgeBase();
this.lock = reteEvaluator.getRuleSessionConfiguration().getOption(ThreadSafeOption.KEY).isThreadSafe() ? new ReentrantLock() : null;
this.lock = reteEvaluator.isThreadSafe() ? new ReentrantLock() : null;
this.handleFactory = this.reteEvaluator.getFactHandleFactory();

RuleBaseConfiguration conf = this.ruleBase.getRuleBaseConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ private StatefulKnowledgeSessionImpl(final long id,
this.propagationIdCounter = new AtomicLong(propagationContext);
this.config = config;
this.ruleSessionConfig = config.as(RuleSessionConfiguration.KEY);

isThreadSafe = ruleSessionConfig.getOption(ThreadSafeOption.KEY).isThreadSafe();

this.environment = environment;

this.propagationIdCounter = new AtomicLong( propagationContext);
Expand Down Expand Up @@ -352,7 +355,6 @@ private StatefulKnowledgeSessionImpl(final long id,
this.initialFactHandle = initInitialFact(null);
}

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

public StatefulKnowledgeSessionImpl setStateless( boolean stateless ) {
Expand Down Expand Up @@ -1517,7 +1519,7 @@ public long getTotalFactCount() {
*/
@Override
public void startOperation(InternalOperationType operationType) {
if (getRuleSessionConfiguration().getOption(ThreadSafeOption.KEY).isThreadSafe() && this.opCounter.getAndIncrement() == 0 ) {
if (isThreadSafe() && this.opCounter.getAndIncrement() == 0 ) {
// means the engine was idle, reset the timestamp
this.lastIdleTimestamp.set(-1);
}
Expand All @@ -1539,7 +1541,7 @@ public void setEndOperationListener(EndOperationListener listener) {
*/
@Override
public void endOperation(InternalOperationType operationType) {
if (getRuleSessionConfiguration().getOption(ThreadSafeOption.KEY).isThreadSafe() && this.opCounter.decrementAndGet() == 0 ) {
if (isThreadSafe() && this.opCounter.decrementAndGet() == 0 ) {
// means the engine is idle, so, set the timestamp
if (this.timerService != null) {
this.lastIdleTimestamp.set(this.timerService.getCurrentTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private Object[] fetchFacts( KnowledgeHelper knowledgeHelper, ValueResolver valu

Object[] facts;
FactHandleLookup fhLookup = null;
if (reteEvaluator.getRuleSessionConfiguration().getOption(ThreadSafeOption.KEY).isThreadSafe()) {
if (reteEvaluator.isThreadSafe()) {
if ( consequence.isUsingDrools() ) {
facts = new Object[consequence.getVariables().length + 1];
fhLookup = FactHandleLookup.create( factSuppliers.length );
Expand Down Expand Up @@ -217,7 +217,7 @@ private Object[] initConsequence( KnowledgeHelper knowledgeHelper, ReteEvaluator
this.globalSuppliers = globalSuppliers.isEmpty() ? null : globalSuppliers.toArray( new GlobalSupplier[globalSuppliers.size()] );
this.factSuppliers = factSuppliers.toArray( new TupleFactSupplier[factSuppliers.size()] );

if (!reteEvaluator.getRuleSessionConfiguration().getOption(ThreadSafeOption.KEY).isThreadSafe()) {
if (!reteEvaluator.isThreadSafe()) {
this.facts = facts;
this.fhLookup = fhLookup;
}
Expand Down

0 comments on commit 4f9bae0

Please sign in to comment.