Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Serializable For Rules #393

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Implement Serializable For Rules
 The objects needs to be serialized so that the data
 can be cached and stored instead of preparing it
 again and running through compilation process
deveshspendlabs committed Sep 6, 2022
commit aca17367f7ed8db5e96f8026d6fc771b0b52e679
Original file line number Diff line number Diff line change
@@ -23,13 +23,15 @@
*/
package org.jeasy.rules.api;

import java.io.Serializable;

/**
* This interface represents a rule's action.
*
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/
@FunctionalInterface
public interface Action {
public interface Action extends Serializable {

/**
* Execute the action when the rule's condition evaluates to true.
Original file line number Diff line number Diff line change
@@ -23,13 +23,15 @@
*/
package org.jeasy.rules.api;

import java.io.Serializable;

/**
* This interface represents a rule's condition.
*
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/
@FunctionalInterface
public interface Condition {
public interface Condition extends Serializable {

/**
* Evaluate the condition according to the known facts.
3 changes: 2 additions & 1 deletion easy-rules-core/src/main/java/org/jeasy/rules/api/Fact.java
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
*/
package org.jeasy.rules.api;

import java.io.Serializable;
import java.util.Objects;

/**
@@ -32,7 +33,7 @@
* @param <T> type of the fact
* @author Mahmoud Ben Hassine
*/
public class Fact<T> {
public class Fact<T> implements Serializable {

private final String name;
private final T value;
3 changes: 2 additions & 1 deletion easy-rules-core/src/main/java/org/jeasy/rules/api/Facts.java
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
*/
package org.jeasy.rules.api;

import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -36,7 +37,7 @@
*
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/
public class Facts implements Iterable<Fact<?>> {
public class Facts implements Iterable<Fact<?>>, Serializable {

private final Set<Fact<?>> facts = new HashSet<>();

4 changes: 3 additions & 1 deletion easy-rules-core/src/main/java/org/jeasy/rules/api/Rule.java
Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@
*/
package org.jeasy.rules.api;

import java.io.Serializable;

/**
* Abstraction for a rule that can be fired by a rules engine.
*
@@ -31,7 +33,7 @@
*
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/
public interface Rule extends Comparable<Rule> {
public interface Rule extends Comparable<Rule>, Serializable {

/**
* Default rule name.
Original file line number Diff line number Diff line change
@@ -23,12 +23,14 @@
*/
package org.jeasy.rules.api;

import java.io.Serializable;

/**
* A listener for rule execution events.
*
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/
public interface RuleListener {
public interface RuleListener extends Serializable {

/**
* Triggered before the evaluation of a rule.
3 changes: 2 additions & 1 deletion easy-rules-core/src/main/java/org/jeasy/rules/api/Rules.java
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@

import org.jeasy.rules.core.RuleProxy;

import java.io.Serializable;
import java.util.Collections;
import java.util.Iterator;
import java.util.Objects;
@@ -41,7 +42,7 @@
*
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/
public class Rules implements Iterable<Rule> {
public class Rules implements Iterable<Rule>, Serializable {

private Set<Rule> rules = new TreeSet<>();

Original file line number Diff line number Diff line change
@@ -25,12 +25,14 @@

import org.jeasy.rules.core.InferenceRulesEngine;

import java.io.Serializable;

/**
* A listener for rules engine execution events.
*
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/
public interface RulesEngineListener {
public interface RulesEngineListener extends Serializable {

/**
* Triggered before evaluating the rule set.
Original file line number Diff line number Diff line change
@@ -26,6 +26,8 @@
import org.jeasy.rules.core.DefaultRulesEngine;
import org.jeasy.rules.core.InferenceRulesEngine;

import java.io.Serializable;

/**
* Parameters of a rules engine.
*
@@ -36,13 +38,13 @@
*
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/
public class RulesEngineParameters {
public class RulesEngineParameters implements Serializable {

/**
* Default rule priority threshold.
*/
public static final int DEFAULT_RULE_PRIORITY_THRESHOLD = Integer.MAX_VALUE;

/**
* Parameter to skip next applicable rules when a rule is applied.
*/
@@ -73,10 +75,10 @@ public RulesEngineParameters() {
/**
* Create a new {@link RulesEngineParameters}.
*
* @param skipOnFirstAppliedRule parameter to skip next applicable rules on first applied rule.
* @param skipOnFirstFailedRule parameter to skip next applicable rules on first failed rule.
* @param skipOnFirstAppliedRule parameter to skip next applicable rules on first applied rule.
* @param skipOnFirstFailedRule parameter to skip next applicable rules on first failed rule.
* @param skipOnFirstNonTriggeredRule parameter to skip next applicable rules on first non triggered rule.
* @param priorityThreshold threshold after which rules should be skipped.
* @param priorityThreshold threshold after which rules should be skipped.
*/
public RulesEngineParameters(final boolean skipOnFirstAppliedRule, final boolean skipOnFirstFailedRule, final boolean skipOnFirstNonTriggeredRule, final int priorityThreshold) {
this.skipOnFirstAppliedRule = skipOnFirstAppliedRule;