Class RulesServiceImpl
java.lang.Object
org.apache.unomi.services.impl.rules.RulesServiceImpl
- All Implemented Interfaces:
EventListener
,EventListenerService
,RulesService
,org.osgi.framework.BundleListener
,org.osgi.framework.SynchronousBundleListener
,org.osgi.service.cm.ManagedService
public class RulesServiceImpl
extends Object
implements RulesService, EventListenerService, org.osgi.framework.SynchronousBundleListener, org.osgi.service.cm.ManagedService
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
bind
(org.osgi.framework.ServiceReference<RuleListenerService> serviceReference) void
bundleChanged
(org.osgi.framework.BundleEvent event) boolean
Whether or not this listener can handle the specified event.void
fireAlreadyRaised
(RuleListenerService.AlreadyRaisedFor alreadyRaisedFor, Rule rule, Event event) void
fireEvaluate
(Rule rule, Event event) void
fireExecuteActions
(Rule rule, Event event) Get all rules available in the system.Retrieves the statistics for all the rulesgetMatchingRules
(Event event) Retrieves all the matching rules for a specific eventRetrieves the rule identified by the specified identifier.getRuleDetails
(Query query) Retrieves rule details for rules matching the specified query.Retrieves the metadata for all known rules.getRuleMetadatas
(Query query) Retrieves rule metadatas for rules matching the specifiedQuery
.getRuleStatistics
(String ruleId) Retrieves the statistics for a rulegetTrackedConditions
(Item source) Retrieves tracked conditions (rules with a condition marked with thetrackedCondition
tag and whichsourceEventCondition
matches the specified item) for the specified item.int
Handles the specified event.void
void
void
Refresh the rules for this instance by reloading them from the persistence backendvoid
removeRule
(String ruleId) Deletes the rule identified by the specified identifier.void
Resets all the rule statistics to zero, useful when testing or if you want to set a point in time.void
setActionExecutorDispatcher
(ActionExecutorDispatcher actionExecutorDispatcher) void
setBundleContext
(org.osgi.framework.BundleContext bundleContext) void
setDefinitionsService
(DefinitionsService definitionsService) void
setEventService
(EventService eventService) void
setOptimizedRulesActivated
(Boolean optimizedRulesActivated) void
setPersistenceService
(PersistenceService persistenceService) void
Persists the specified rule to the context server.void
setRulesRefreshInterval
(Integer rulesRefreshInterval) void
setRulesStatisticsRefreshInterval
(Integer rulesStatisticsRefreshInterval) void
setSchedulerService
(SchedulerService schedulerService) void
unbind
(org.osgi.framework.ServiceReference<RuleListenerService> serviceReference) void
updated
(Dictionary<String, ?> properties)
-
Field Details
-
TRACKED_PARAMETER
- See Also:
-
-
Constructor Details
-
RulesServiceImpl
public RulesServiceImpl()
-
-
Method Details
-
setBundleContext
public void setBundleContext(org.osgi.framework.BundleContext bundleContext) -
setPersistenceService
-
setDefinitionsService
-
setEventService
-
setSchedulerService
-
setActionExecutorDispatcher
-
setRulesRefreshInterval
-
setRulesStatisticsRefreshInterval
-
setOptimizedRulesActivated
-
updated
- Specified by:
updated
in interfaceorg.osgi.service.cm.ManagedService
-
postConstruct
public void postConstruct() -
preDestroy
public void preDestroy() -
getMatchingRules
Description copied from interface:RulesService
Retrieves all the matching rules for a specific event- Specified by:
getMatchingRules
in interfaceRulesService
- Parameters:
event
- the event we want to retrieve all the matching rules for- Returns:
- a set of rules that match the event passed in the parameters
-
refreshRules
public void refreshRules()Description copied from interface:RulesService
Refresh the rules for this instance by reloading them from the persistence backend- Specified by:
refreshRules
in interfaceRulesService
-
getAllRules
Description copied from interface:RulesService
Get all rules available in the system. (This is not doing a persistence query to retrieve the rules, it's using the internal in memory cache that is refreshed every second by default but can vary depending on your own configuration)- Specified by:
getAllRules
in interfaceRulesService
- Returns:
- all rules available.
-
canHandle
Description copied from interface:EventListenerService
Whether or not this listener can handle the specified event.- Specified by:
canHandle
in interfaceEventListenerService
- Parameters:
event
- the event to be handled- Returns:
true
if this listener can handle the specified event,false
otherwise
-
onEvent
Description copied from interface:EventListenerService
Handles the specified event.- Specified by:
onEvent
in interfaceEventListenerService
- Parameters:
event
- the event to be handled- Returns:
- the result of the event handling as combination of
EventService
flags, to be checked using bitwise AND (&) operator - See Also:
-
getRuleStatistics
Description copied from interface:RulesService
Retrieves the statistics for a rule- Specified by:
getRuleStatistics
in interfaceRulesService
- Parameters:
ruleId
- the identifier of the rule- Returns:
- a long representing the number of times the rule was matched and executed.
-
getAllRuleStatistics
Description copied from interface:RulesService
Retrieves the statistics for all the rules- Specified by:
getAllRuleStatistics
in interfaceRulesService
- Returns:
- a map containing rule IDs as key, and the RuleStatistics object as a value
-
resetAllRuleStatistics
public void resetAllRuleStatistics()Description copied from interface:RulesService
Resets all the rule statistics to zero, useful when testing or if you want to set a point in time.- Specified by:
resetAllRuleStatistics
in interfaceRulesService
-
getRuleMetadatas
Description copied from interface:RulesService
Retrieves the metadata for all known rules. Note that it only includes the rules in memory, not those persisted in storage.- Specified by:
getRuleMetadatas
in interfaceRulesService
- Returns:
- the Set of known metadata
-
getRuleMetadatas
Description copied from interface:RulesService
Retrieves rule metadatas for rules matching the specifiedQuery
.- Specified by:
getRuleMetadatas
in interfaceRulesService
- Parameters:
query
- the query the rules which metadata we want to retrieve must match- Returns:
- a
PartialList
of rules metadata for the rules matching the specified query
-
getRuleDetails
Description copied from interface:RulesService
Retrieves rule details for rules matching the specified query.- Specified by:
getRuleDetails
in interfaceRulesService
- Parameters:
query
- the query specifying which rules to retrieve- Returns:
- a
PartialList
of rule details for the rules matching the specified query
-
getRule
Description copied from interface:RulesService
Retrieves the rule identified by the specified identifier.- Specified by:
getRule
in interfaceRulesService
- Parameters:
ruleId
- the identifier of the rule we want to retrieve- Returns:
- the rule identified by the specified identifier or
null
if no such rule exists.
-
setRule
Description copied from interface:RulesService
Persists the specified rule to the context server.- Specified by:
setRule
in interfaceRulesService
- Parameters:
rule
- the rule to be persisted
-
getTrackedConditions
Description copied from interface:RulesService
Retrieves tracked conditions (rules with a condition marked with thetrackedCondition
tag and whichsourceEventCondition
matches the specified item) for the specified item.- Specified by:
getTrackedConditions
in interfaceRulesService
- Parameters:
source
- the item which tracked conditions we want to retrieve- Returns:
- the Set of tracked conditions for the specified item
-
removeRule
Description copied from interface:RulesService
Deletes the rule identified by the specified identifier.- Specified by:
removeRule
in interfaceRulesService
- Parameters:
ruleId
- the identifier of the rule we want to delete
-
bundleChanged
public void bundleChanged(org.osgi.framework.BundleEvent event) - Specified by:
bundleChanged
in interfaceorg.osgi.framework.BundleListener
-
bind
-
unbind
-
fireEvaluate
-
fireAlreadyRaised
public void fireAlreadyRaised(RuleListenerService.AlreadyRaisedFor alreadyRaisedFor, Rule rule, Event event) -
fireExecuteActions
-