-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathRule7Main.java
64 lines (51 loc) · 2.14 KB
/
Rule7Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.sample;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.drools.core.time.impl.PseudoClockScheduler;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import com.sample.model.*;
import com.sample.utils.FactsLoader;
public class Rule7Main {
public static void main(String[] args) {
KieServices kieServices = KieServices.Factory.get();
KieContainer kieContainer = kieServices.getKieClasspathContainer();
KieSession kieSession = kieContainer.newKieSession("ksession-rules7");
// kieSession.addEventListener(new LoggingAgendaEventListener());
// kieSession.addEventListener(new LoggingRuleRuntimeEventListener());
//
List<BagScannedEvent> events = FactsLoader.loadEvents("events-extra.csv");
System.out.println("All events:");
events.forEach(e -> System.out.println(" " + e));
events.stream().forEach(event -> { insertAndFire(kieSession, event);});
}
private static void insertAndFire(KieSession kieSession, BagScannedEvent event) {
// System.out.println(event);
PseudoClockScheduler clock = kieSession.getSessionClock();
Location location = event.getLocation();
switch(location) {
case CHECK_IN :
kieSession.getEntryPoint("CheckIn").insert(event);
break;
case SORTING :
kieSession.getEntryPoint("Sorting").insert(event);
break;
case STAGING :
kieSession.getEntryPoint("Staging").insert(event);
break;
case LOADING :
kieSession.getEntryPoint("Loading").insert(event);
break;
default:
throw new IllegalArgumentException("Unexpected location.");
}
kieSession.insert(event);
long deltaTime = event.getTimestamp().getTime() - clock.getCurrentTime();
if (deltaTime > 0) {
// System.out.println("Advancing clock with: " + deltaTime);
clock.advanceTime(deltaTime, TimeUnit.MILLISECONDS);
}
kieSession.fireAllRules();
}
}