I have a stateful session which is having objects inserted and updated from
multiple threads. The thread managing the session is using the fireUntilHalt
method as below:
@Override
public void run() {
if (logger.isDebugEnabled()) {
logger.debug("Starting session...");
}
threadName = Thread.currentThread().getName();
session.fireUntilHalt();
}
The code being invoked to insert/modify objects is below:
public synchronized void insertOrUpdate(Object fact) {
Preconditions.checkNotNull(fact);
FactHandle factHandle = session.getFactHandle(fact);
if (factHandle == null) {
session.insert(fact);
} else {
session.update(factHandle, fact);
}
}
The problem I am running into is that I have a control fact which keeps an
internal counter(messages coming in are sequenced and need to be processed
in order) and a list of "deregister messages"(messages that are not going
to be inserted for various reasons). The problem I am having is that 75% of
the time it seems something goes wrong with the counter and messages stop
being processed and build up in the session. If i pass every message in and
don't try and deregister any everything works ok. The rules I have for
working with the message deregister is as follows(this is a an example there
are will be other rules added eventually):
rule "Dereg Message"
salience 10000
when
$controller:MessageControl($pos:currentPosition,excludedPositions[$pos]!=null)
then
modify( $controller ){
moveCurrentPositionForward(1)
}
end
rule "Remove Message"
salience -15000
when
$controller:MessageControl($pos:currentPosition,excludedPositions[$pos]==null)
$tsc:Message(rank==$pos)
then
cdiEvent.fire(new CDIEvent($tsc));
retract($tsc);
modify( $controller ){
moveCurrentPositionForward(1)
}
end
The controller class is:
private BigInteger currentPosition = new BigInteger("0");
private Map<BigInteger, BigInteger> excludedPositions = new
ConcurrentHashMap<BigInteger, BigInteger>();
public synchronized void addPositionToExclusionList(BigInteger position) {
excludedPositions.put(position, position);
}
public synchronized BigInteger getCurrentPosition() {
return currentPosition;
}
public synchronized void moveCurrentPositionForward(Integer value) {
currentPosition = currentPosition.add(new BigInteger(value.toString()));
}
public synchronized Map<BigInteger, BigInteger> getExcludedPositions() {
return excludedPositions;
}
public synchronized Collection<BigInteger> getExclusionList() {
return excludedPositions.values();
}
Any thoughts to why this may be occuring? I have been banging my head on
this problem for a couple days. We are using drools 5.3
--
View this message in context:
http://drools.46999.n3.nabble.com/Multi-Access-to-Stateful-Session-tp3877...
Sent from the Drools: User forum mailing list archive at
Nabble.com.