{"size": 1415, "ext": "js", "max_stars_repo_path": "sponge-nashorn/examples/script/js/rules_sync_async.js", "max_stars_repo_name": "mnpas/sponge", "max_stars_repo_stars_event_min_datetime": "2017-12-16T21:48:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T12:22:24.000Z", "max_issues_repo_path": "sponge-nashorn/examples/script/js/rules_sync_async.js", "max_issues_repo_name": "mnpas/sponge", "max_issues_repo_issues_event_min_datetime": "2020-12-18T11:56:46.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T18:37:10.000Z", "max_forks_repo_path": "sponge-nashorn/examples/script/js/rules_sync_async.js", "max_forks_repo_name": "mnpas/sponge", "max_forks_repo_forks_event_min_datetime": "2019-12-29T16:08:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-15T14:05:34.000Z"}
{"max_stars_count": 9, "max_issues_count": 3, "max_forks_count": 2, "avg_line_length": 32.9069767442, "max_line_length": 110, "alphanum_fraction": 0.6141342756}
/**
 * Sponge Knowledge Base
 * Using rules - synchronous and asynchronous
 */

var correlationEventsLog;

function onInit() {
    // Variables for assertions only
    correlationEventsLog = new org.openksavi.sponge.examples.util.CorrelationEventsLog();
    sponge.setVariable("correlationEventsLog", correlationEventsLog);
}

var RuleFFF = Java.extend(Rule, {
    onConfigure: function(self) {
        self.withEvents(["e1", "e2", "e3 :first"]).withSynchronous(true);
    },
    onRun: function(self, event) {
        self.logger.debug("Running rule for event: {}", event.name);
        correlationEventsLog.addEvents("RuleFFF", self);
    }
});

var RuleFFL = Java.extend(Rule, {
    onConfigure: function(self) {
        self.withEvents(["e1", "e2", "e3 :last"]).withDuration(Duration.ofSeconds(2)).withSynchronous(false);
    },
    onRun: function(self, event) {
        self.logger.debug("Running rule for event: {}", event.name);
        correlationEventsLog.addEvents("RuleFFL", self);
    }
});

function onStartup() {
    sponge.event("e1").set("label", "1").send();
    sponge.event("e2").set("label", "2").send();
    sponge.event("e2").set("label", "3").send();
    sponge.event("e2").set("label", "4").send();
    sponge.event("e3").set("label", "5").send();
    sponge.event("e3").set("label", "6").send();
    sponge.event("e3").set("label", "7").send();
}
