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
pull/393/head
Devesh Gote 2 years ago
parent d445083153
commit aca17367f7

@ -23,13 +23,15 @@
*/ */
package org.jeasy.rules.api; package org.jeasy.rules.api;
import java.io.Serializable;
/** /**
* This interface represents a rule's action. * This interface represents a rule's action.
* *
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) * @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/ */
@FunctionalInterface @FunctionalInterface
public interface Action { public interface Action extends Serializable {
/** /**
* Execute the action when the rule's condition evaluates to true. * Execute the action when the rule's condition evaluates to true.

@ -23,13 +23,15 @@
*/ */
package org.jeasy.rules.api; package org.jeasy.rules.api;
import java.io.Serializable;
/** /**
* This interface represents a rule's condition. * This interface represents a rule's condition.
* *
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) * @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/ */
@FunctionalInterface @FunctionalInterface
public interface Condition { public interface Condition extends Serializable {
/** /**
* Evaluate the condition according to the known facts. * Evaluate the condition according to the known facts.

@ -23,6 +23,7 @@
*/ */
package org.jeasy.rules.api; package org.jeasy.rules.api;
import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
/** /**
@ -32,7 +33,7 @@ import java.util.Objects;
* @param <T> type of the fact * @param <T> type of the fact
* @author Mahmoud Ben Hassine * @author Mahmoud Ben Hassine
*/ */
public class Fact<T> { public class Fact<T> implements Serializable {
private final String name; private final String name;
private final T value; private final T value;

@ -23,6 +23,7 @@
*/ */
package org.jeasy.rules.api; package org.jeasy.rules.api;
import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -36,7 +37,7 @@ import java.util.Set;
* *
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) * @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<>(); private final Set<Fact<?>> facts = new HashSet<>();

@ -23,6 +23,8 @@
*/ */
package org.jeasy.rules.api; package org.jeasy.rules.api;
import java.io.Serializable;
/** /**
* Abstraction for a rule that can be fired by a rules engine. * Abstraction for a rule that can be fired by a rules engine.
* *
@ -31,7 +33,7 @@ package org.jeasy.rules.api;
* *
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) * @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/ */
public interface Rule extends Comparable<Rule> { public interface Rule extends Comparable<Rule>, Serializable {
/** /**
* Default rule name. * Default rule name.

@ -23,12 +23,14 @@
*/ */
package org.jeasy.rules.api; package org.jeasy.rules.api;
import java.io.Serializable;
/** /**
* A listener for rule execution events. * A listener for rule execution events.
* *
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) * @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/ */
public interface RuleListener { public interface RuleListener extends Serializable {
/** /**
* Triggered before the evaluation of a rule. * Triggered before the evaluation of a rule.

@ -25,6 +25,7 @@ package org.jeasy.rules.api;
import org.jeasy.rules.core.RuleProxy; import org.jeasy.rules.core.RuleProxy;
import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.Objects; import java.util.Objects;
@ -41,7 +42,7 @@ import java.util.TreeSet;
* *
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) * @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<>(); private Set<Rule> rules = new TreeSet<>();

@ -25,12 +25,14 @@ package org.jeasy.rules.api;
import org.jeasy.rules.core.InferenceRulesEngine; import org.jeasy.rules.core.InferenceRulesEngine;
import java.io.Serializable;
/** /**
* A listener for rules engine execution events. * A listener for rules engine execution events.
* *
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) * @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/ */
public interface RulesEngineListener { public interface RulesEngineListener extends Serializable {
/** /**
* Triggered before evaluating the rule set. * Triggered before evaluating the rule set.

@ -26,6 +26,8 @@ package org.jeasy.rules.api;
import org.jeasy.rules.core.DefaultRulesEngine; import org.jeasy.rules.core.DefaultRulesEngine;
import org.jeasy.rules.core.InferenceRulesEngine; import org.jeasy.rules.core.InferenceRulesEngine;
import java.io.Serializable;
/** /**
* Parameters of a rules engine. * Parameters of a rules engine.
* *
@ -36,13 +38,13 @@ import org.jeasy.rules.core.InferenceRulesEngine;
* *
* @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com) * @author Mahmoud Ben Hassine (mahmoud.benhassine@icloud.com)
*/ */
public class RulesEngineParameters { public class RulesEngineParameters implements Serializable {
/** /**
* Default rule priority threshold. * Default rule priority threshold.
*/ */
public static final int DEFAULT_RULE_PRIORITY_THRESHOLD = Integer.MAX_VALUE; public static final int DEFAULT_RULE_PRIORITY_THRESHOLD = Integer.MAX_VALUE;
/** /**
* Parameter to skip next applicable rules when a rule is applied. * Parameter to skip next applicable rules when a rule is applied.
*/ */
@ -73,10 +75,10 @@ public class RulesEngineParameters {
/** /**
* Create a new {@link RulesEngineParameters}. * Create a new {@link RulesEngineParameters}.
* *
* @param skipOnFirstAppliedRule parameter to skip next applicable rules on first applied 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 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 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) { public RulesEngineParameters(final boolean skipOnFirstAppliedRule, final boolean skipOnFirstFailedRule, final boolean skipOnFirstNonTriggeredRule, final int priorityThreshold) {
this.skipOnFirstAppliedRule = skipOnFirstAppliedRule; this.skipOnFirstAppliedRule = skipOnFirstAppliedRule;

Loading…
Cancel
Save