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
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
*/
package org.jeasy.rules.api;

import java.io.Serializable;

/**
* This interface represents a rule's action.
*
* @author Mahmoud Ben Hassine ([email protected])
*/
@FunctionalInterface
public interface Action {
public interface Action extends Serializable {

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

import java.io.Serializable;

/**
* This interface represents a rule's condition.
*
* @author Mahmoud Ben Hassine ([email protected])
*/
@FunctionalInterface
public interface Condition {
public interface Condition extends Serializable {

/**
* Evaluate the condition according to the known facts.
Expand Down
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
Expand Up @@ -23,6 +23,7 @@
*/
package org.jeasy.rules.api;

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

/**
Expand All @@ -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;
Expand Down
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
Expand Up @@ -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;
Expand All @@ -36,7 +37,7 @@
*
* @author Mahmoud Ben Hassine ([email protected])
*/
public class Facts implements Iterable<Fact<?>> {
public class Facts implements Iterable<Fact<?>>, Serializable {

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

Expand Down
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
Expand Up @@ -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.
*
Expand All @@ -31,7 +33,7 @@
*
* @author Mahmoud Ben Hassine ([email protected])
*/
public interface Rule extends Comparable<Rule> {
public interface Rule extends Comparable<Rule>, Serializable {

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

import java.io.Serializable;

/**
* A listener for rule execution events.
*
* @author Mahmoud Ben Hassine ([email protected])
*/
public interface RuleListener {
public interface RuleListener extends Serializable {

/**
* Triggered before the evaluation of a rule.
Expand Down
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
Expand Up @@ -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;
Expand All @@ -41,7 +42,7 @@
*
* @author Mahmoud Ben Hassine ([email protected])
*/
public class Rules implements Iterable<Rule> {
public class Rules implements Iterable<Rule>, Serializable {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([email protected])
*/
public interface RulesEngineListener {
public interface RulesEngineListener extends Serializable {

/**
* Triggered before evaluating the rule set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -36,13 +38,13 @@
*
* @author Mahmoud Ben Hassine ([email protected])
*/
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.
*/
Expand Down Expand Up @@ -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;
Expand Down