Repository: incubator-unomi Updated Branches: refs/heads/feature-UNOMI-117 de1ae00ad -> b30d3286f (forced update)
UNOMI-93 Add rule execution count to rule service endpoint - Add an endpoint to reset the statistics - Statistics are now stored in a concurrent hash map to avoid concurrency issues. Signed-off-by: Serge Huber <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/5f15a269 Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/5f15a269 Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/5f15a269 Branch: refs/heads/feature-UNOMI-117 Commit: 5f15a269221ac46b46e8f1c30f6f47e57ffccd9e Parents: 1d075ec Author: Serge Huber <[email protected]> Authored: Mon Sep 11 10:56:19 2017 +0200 Committer: Serge Huber <[email protected]> Committed: Mon Sep 11 10:56:19 2017 +0200 ---------------------------------------------------------------------- .../org/apache/unomi/api/services/RulesService.java | 5 +++++ .../org/apache/unomi/rest/RulesServiceEndPoint.java | 13 +++++++++++-- .../unomi/services/services/RulesServiceImpl.java | 10 +++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/5f15a269/api/src/main/java/org/apache/unomi/api/services/RulesService.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/services/RulesService.java b/api/src/main/java/org/apache/unomi/api/services/RulesService.java index acfd9b4..f7de0e2 100644 --- a/api/src/main/java/org/apache/unomi/api/services/RulesService.java +++ b/api/src/main/java/org/apache/unomi/api/services/RulesService.java @@ -70,6 +70,11 @@ public interface RulesService { Map<String,RuleStatistics> getAllRuleStatistics(); /** + * Resets all the rule statistics to zero, useful when testing or if you want to set a point in time. + */ + void resetAllRuleStatistics(); + + /** * Persists the specified rule to the context server. * * @param rule the rule to be persisted http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/5f15a269/rest/src/main/java/org/apache/unomi/rest/RulesServiceEndPoint.java ---------------------------------------------------------------------- diff --git a/rest/src/main/java/org/apache/unomi/rest/RulesServiceEndPoint.java b/rest/src/main/java/org/apache/unomi/rest/RulesServiceEndPoint.java index 1327731..56940cb 100644 --- a/rest/src/main/java/org/apache/unomi/rest/RulesServiceEndPoint.java +++ b/rest/src/main/java/org/apache/unomi/rest/RulesServiceEndPoint.java @@ -82,9 +82,9 @@ public class RulesServiceEndPoint { } /** - * Retrieves the metadata for all known rules. + * Retrieves the rule statistics for all known rules. * - * @return the Set of known metadata + * @return a map that contains the rule key as a key and as the value a @RuleStatistics object. */ @GET @Path("/statistics") @@ -93,6 +93,15 @@ public class RulesServiceEndPoint { } /** + * Deletes all the rule statistics, which basically resets them to 0. + */ + @DELETE + @Path("/statistics") + public void resetAllRuleStatistics() { + rulesService.resetAllRuleStatistics(); + } + + /** * Retrieves rule metadatas for rules matching the specified {@link Query}. * * @param query the query the rules which metadata we want to retrieve must match http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/5f15a269/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java index 973a4a1..6c0ea0f 100644 --- a/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java +++ b/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java @@ -41,6 +41,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.net.URL; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; public class RulesServiceImpl implements RulesService, EventListenerService, SynchronousBundleListener { @@ -60,7 +61,7 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn private Timer rulesTimer; private Timer ruleStatisticsTimer; - private Map<String,RuleStatistics> allRuleStatistics = new HashMap<String,RuleStatistics>(); + private Map<String,RuleStatistics> allRuleStatistics = new ConcurrentHashMap<>(); public void setBundleContext(BundleContext bundleContext) { this.bundleContext = bundleContext; @@ -288,6 +289,13 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn return allRuleStatistics; } + @Override + public void resetAllRuleStatistics() { + Condition matchAllCondition = new Condition(definitionsService.getConditionType("matchAllCondition")); + persistenceService.removeByQuery(matchAllCondition,RuleStatistics.class); + allRuleStatistics.clear(); + } + public Set<Metadata> getRuleMetadatas() { Set<Metadata> metadatas = new HashSet<Metadata>(); for (Rule rule : persistenceService.getAllItems(Rule.class, 0, 50, null).getList()) {
