01: package org.drools.reteoo;
02:
03: import java.util.Collection;
04: import java.util.List;
05:
06: import org.drools.FactHandle;
07: import org.drools.StatefulSession;
08: import org.drools.common.InternalRuleBase;
09: import org.drools.concurrent.AssertObject;
10: import org.drools.concurrent.AssertObjects;
11: import org.drools.concurrent.ExecutorService;
12: import org.drools.concurrent.FireAllRules;
13: import org.drools.concurrent.Future;
14: import org.drools.concurrent.UpdateObject;
15: import org.drools.concurrent.RetractObject;
16: import org.drools.spi.AgendaFilter;
17:
18: public class ReteooStatefulSession extends ReteooWorkingMemory
19: implements StatefulSession {
20: private final ExecutorService executor;
21:
22: public ReteooStatefulSession(final int id,
23: final InternalRuleBase ruleBase,
24: final ExecutorService executorService) {
25: super (id, ruleBase);
26: this .executor = executorService;
27: }
28:
29: public Future asyncInsert(final Object object) {
30: final AssertObject assertObject = new AssertObject(object);
31: this .executor.submit(assertObject);
32: return assertObject;
33: }
34:
35: public Future asyncRetract(final FactHandle factHandle) {
36: return this .executor.submit(new RetractObject(factHandle));
37: }
38:
39: public Future asyncUpdate(final FactHandle factHandle,
40: final Object object) {
41: return this .executor
42: .submit(new UpdateObject(factHandle, object));
43: }
44:
45: public Future asyncInsert(final Object[] array) {
46: final AssertObjects assertObjects = new AssertObjects(array);
47: this .executor.submit(assertObjects);
48: return assertObjects;
49: }
50:
51: public Future asyncInsert(final Collection collection) {
52: final AssertObjects assertObjects = new AssertObjects(
53: collection);
54: this .executor.submit(assertObjects);
55: return assertObjects;
56: }
57:
58: public Future asyncFireAllRules(final AgendaFilter agendaFilter) {
59: final FireAllRules fireAllRules = new FireAllRules(agendaFilter);
60: this .executor.submit(fireAllRules);
61: return fireAllRules;
62: }
63:
64: public Future asyncFireAllRules() {
65: final FireAllRules fireAllRules = new FireAllRules(null);
66: this .executor.submit(fireAllRules);
67: return fireAllRules;
68: }
69:
70: public void dispose() {
71: this.ruleBase.disposeStatefulSession(this);
72: }
73: }
|