Search in sources :

Example 1 with KeyA

use of com.salaboy.model.KeyA in project jBPM5-Developer-Guide by Salaboy.

the class EventsTesterJFrame method onKeyAjButtonKeyPressed.

//GEN-LAST:event_keySjButtonActionPerformed
private void onKeyAjButtonKeyPressed(java.awt.event.KeyEvent evt) {
    if (evt.getKeyCode() == KeyEvent.VK_A) {
        ksession.insert(new KeyA());
        ksession.fireAllRules();
        outjTextPane.setText(outjTextPane.getText() + " >>> Key A Pressed!\n");
        keyAjButton.setBackground(new java.awt.Color(51, 255, 0));
        keyAjButton.setForeground(new java.awt.Color(51, 204, 0));
        keyAjButton.setText("[ Key A ]");
        keyAjButton.setOpaque(true);
        evt.consume();
    }
}
Also used : KeyA(com.salaboy.model.KeyA)

Example 2 with KeyA

use of com.salaboy.model.KeyA in project jBPM5-Developer-Guide by Salaboy.

the class MyFirstDrools5FusionRulesTest method testPatternDetectionEvents.

@Test
public void testPatternDetectionEvents() {
    StatefulKnowledgeSession ksession = createKnowledgeSession();
    SessionPseudoClock clock = ksession.getSessionClock();
    int fired = 0;
    // Initial time 0s -> t0
    ksession.insert(new KeyA());
    fired = ksession.fireAllRules();
    clock.advanceTime(15, TimeUnit.MILLISECONDS);
    assertEquals(0, fired);
    ksession.insert(new KeyS());
    fired = ksession.fireAllRules();
    clock.advanceTime(15, TimeUnit.MILLISECONDS);
    assertEquals(0, fired);
    ksession.insert(new KeyD());
    fired = ksession.fireAllRules();
    clock.advanceTime(15, TimeUnit.MILLISECONDS);
    assertEquals(1, fired);
    ksession.dispose();
}
Also used : KeyA(com.salaboy.model.KeyA) SessionPseudoClock(org.drools.time.SessionPseudoClock) KeyD(com.salaboy.model.KeyD) StatefulKnowledgeSession(org.drools.runtime.StatefulKnowledgeSession) KeyS(com.salaboy.model.KeyS) Test(org.junit.Test)

Example 3 with KeyA

use of com.salaboy.model.KeyA in project jBPM5-Developer-Guide by Salaboy.

the class MyFirstDrools5FusionRulesTest method testSimpleEvents.

@Test
public void testSimpleEvents() {
    StatefulKnowledgeSession ksession = createKnowledgeSession();
    // Uncomment to see all the logs
    // KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
    // We have our Session, now let's play with our Events
    SessionPseudoClock clock = ksession.getSessionClock();
    int fired = 0;
    // Initial time 0s -> t0
    ksession.insert(new KeyA());
    fired = ksession.fireAllRules();
    clock.advanceTime(2, TimeUnit.SECONDS);
    assertEquals(0, fired);
    // t1 -> 2s 
    ksession.insert(new KeyA());
    fired = ksession.fireAllRules();
    clock.advanceTime(2, TimeUnit.SECONDS);
    assertEquals(0, fired);
    // t2 -> 4s 
    ksession.insert(new KeyA());
    fired = ksession.fireAllRules();
    clock.advanceTime(2, TimeUnit.SECONDS);
    assertEquals(0, fired);
    // t3 -> 6s 
    ksession.insert(new KeyA());
    fired = ksession.fireAllRules();
    clock.advanceTime(2, TimeUnit.SECONDS);
    assertEquals(1, fired);
    // t4 -> 8s
    ksession.insert(new KeyA());
    fired = ksession.fireAllRules();
    assertEquals(1, fired);
    ksession.dispose();
}
Also used : KeyA(com.salaboy.model.KeyA) SessionPseudoClock(org.drools.time.SessionPseudoClock) StatefulKnowledgeSession(org.drools.runtime.StatefulKnowledgeSession) Test(org.junit.Test)

Aggregations

KeyA (com.salaboy.model.KeyA)3 StatefulKnowledgeSession (org.drools.runtime.StatefulKnowledgeSession)2 SessionPseudoClock (org.drools.time.SessionPseudoClock)2 Test (org.junit.Test)2 KeyD (com.salaboy.model.KeyD)1 KeyS (com.salaboy.model.KeyS)1