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
public class RulesServiceImpl extends Object implements RulesService, EventListenerService, org.osgi.framework.SynchronousBundleListener
-
-
Field Summary
Fields Modifier and Type Field Description static StringTRACKED_PARAMETER
-
Constructor Summary
Constructors Constructor Description RulesServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbind(org.osgi.framework.ServiceReference<RuleListenerService> serviceReference)voidbundleChanged(org.osgi.framework.BundleEvent event)booleancanHandle(Event event)Whether or not this listener can handle the specified event.voidfireAlreadyRaised(RuleListenerService.AlreadyRaisedFor alreadyRaisedFor, Rule rule, Event event)voidfireEvaluate(Rule rule, Event event)voidfireExecuteActions(Rule rule, Event event)List<Rule>getAllRules()Get all rules available in the system.Map<String,RuleStatistics>getAllRuleStatistics()Retrieves the statistics for all the rulesSet<Rule>getMatchingRules(Event event)Retrieves all the matching rules for a specific eventRulegetRule(String ruleId)Retrieves the rule identified by the specified identifier.PartialList<Rule>getRuleDetails(Query query)Retrieves rule details for rules matching the specified query.Set<Metadata>getRuleMetadatas()Retrieves the metadata for all known rules.PartialList<Metadata>getRuleMetadatas(Query query)Retrieves rule metadatas for rules matching the specifiedQuery.RuleStatisticsgetRuleStatistics(String ruleId)Retrieves the statistics for a ruleSet<Condition>getTrackedConditions(Item source)Retrieves tracked conditions (rules with a condition marked with thetrackedConditiontag and whichsourceEventConditionmatches the specified item) for the specified item.intonEvent(Event event)Handles the specified event.voidpostConstruct()voidpreDestroy()voidrefreshRules()Refresh the rules for this instance by reloading them from the persistence backendvoidremoveRule(String ruleId)Deletes the rule identified by the specified identifier.voidresetAllRuleStatistics()Resets all the rule statistics to zero, useful when testing or if you want to set a point in time.voidsetActionExecutorDispatcher(ActionExecutorDispatcher actionExecutorDispatcher)voidsetBundleContext(org.osgi.framework.BundleContext bundleContext)voidsetDefinitionsService(DefinitionsService definitionsService)voidsetEventService(EventService eventService)voidsetOptimizedRulesActivated(Boolean optimizedRulesActivated)voidsetPersistenceService(PersistenceService persistenceService)voidsetRule(Rule rule)Persists the specified rule to the context server.voidsetRulesRefreshInterval(Integer rulesRefreshInterval)voidsetRulesStatisticsRefreshInterval(Integer rulesStatisticsRefreshInterval)voidsetSchedulerService(SchedulerService schedulerService)voidunbind(org.osgi.framework.ServiceReference<RuleListenerService> serviceReference)
-
-
-
Field Detail
-
TRACKED_PARAMETER
public static final String TRACKED_PARAMETER
- See Also:
- Constant Field Values
-
-
Method Detail
-
setBundleContext
public void setBundleContext(org.osgi.framework.BundleContext bundleContext)
-
setPersistenceService
public void setPersistenceService(PersistenceService persistenceService)
-
setDefinitionsService
public void setDefinitionsService(DefinitionsService definitionsService)
-
setEventService
public void setEventService(EventService eventService)
-
setSchedulerService
public void setSchedulerService(SchedulerService schedulerService)
-
setActionExecutorDispatcher
public void setActionExecutorDispatcher(ActionExecutorDispatcher actionExecutorDispatcher)
-
setRulesRefreshInterval
public void setRulesRefreshInterval(Integer rulesRefreshInterval)
-
setRulesStatisticsRefreshInterval
public void setRulesStatisticsRefreshInterval(Integer rulesStatisticsRefreshInterval)
-
setOptimizedRulesActivated
public void setOptimizedRulesActivated(Boolean optimizedRulesActivated)
-
postConstruct
public void postConstruct()
-
preDestroy
public void preDestroy()
-
getMatchingRules
public Set<Rule> getMatchingRules(Event event)
Description copied from interface:RulesServiceRetrieves all the matching rules for a specific event- Specified by:
getMatchingRulesin 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:RulesServiceRefresh the rules for this instance by reloading them from the persistence backend- Specified by:
refreshRulesin interfaceRulesService
-
getAllRules
public List<Rule> getAllRules()
Description copied from interface:RulesServiceGet 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:
getAllRulesin interfaceRulesService- Returns:
- all rules available.
-
canHandle
public boolean canHandle(Event event)
Description copied from interface:EventListenerServiceWhether or not this listener can handle the specified event.- Specified by:
canHandlein interfaceEventListenerService- Parameters:
event- the event to be handled- Returns:
trueif this listener can handle the specified event,falseotherwise
-
onEvent
public int onEvent(Event event)
Description copied from interface:EventListenerServiceHandles the specified event.- Specified by:
onEventin interfaceEventListenerService- Parameters:
event- the event to be handled- Returns:
- the result of the event handling as combination of
EventServiceflags, to be checked using bitwise AND (&) operator - See Also:
EventService.NO_CHANGE,EventService.PROFILE_UPDATED,EventService.SESSION_UPDATED
-
getRuleStatistics
public RuleStatistics getRuleStatistics(String ruleId)
Description copied from interface:RulesServiceRetrieves the statistics for a rule- Specified by:
getRuleStatisticsin interfaceRulesService- Parameters:
ruleId- the identifier of the rule- Returns:
- a long representing the number of times the rule was matched and executed.
-
getAllRuleStatistics
public Map<String,RuleStatistics> getAllRuleStatistics()
Description copied from interface:RulesServiceRetrieves the statistics for all the rules- Specified by:
getAllRuleStatisticsin interfaceRulesService- Returns:
- a map containing rule IDs as key, and the RuleStatistics object as a value
-
resetAllRuleStatistics
public void resetAllRuleStatistics()
Description copied from interface:RulesServiceResets all the rule statistics to zero, useful when testing or if you want to set a point in time.- Specified by:
resetAllRuleStatisticsin interfaceRulesService
-
getRuleMetadatas
public Set<Metadata> getRuleMetadatas()
Description copied from interface:RulesServiceRetrieves the metadata for all known rules. Note that it only includes the rules in memory, not those persisted in storage.- Specified by:
getRuleMetadatasin interfaceRulesService- Returns:
- the Set of known metadata
-
getRuleMetadatas
public PartialList<Metadata> getRuleMetadatas(Query query)
Description copied from interface:RulesServiceRetrieves rule metadatas for rules matching the specifiedQuery.- Specified by:
getRuleMetadatasin interfaceRulesService- Parameters:
query- the query the rules which metadata we want to retrieve must match- Returns:
- a
PartialListof rules metadata for the rules matching the specified query
-
getRuleDetails
public PartialList<Rule> getRuleDetails(Query query)
Description copied from interface:RulesServiceRetrieves rule details for rules matching the specified query.- Specified by:
getRuleDetailsin interfaceRulesService- Parameters:
query- the query specifying which rules to retrieve- Returns:
- a
PartialListof rule details for the rules matching the specified query
-
getRule
public Rule getRule(String ruleId)
Description copied from interface:RulesServiceRetrieves the rule identified by the specified identifier.- Specified by:
getRulein interfaceRulesService- Parameters:
ruleId- the identifier of the rule we want to retrieve- Returns:
- the rule identified by the specified identifier or
nullif no such rule exists.
-
setRule
public void setRule(Rule rule)
Description copied from interface:RulesServicePersists the specified rule to the context server.- Specified by:
setRulein interfaceRulesService- Parameters:
rule- the rule to be persisted
-
getTrackedConditions
public Set<Condition> getTrackedConditions(Item source)
Description copied from interface:RulesServiceRetrieves tracked conditions (rules with a condition marked with thetrackedConditiontag and whichsourceEventConditionmatches the specified item) for the specified item.- Specified by:
getTrackedConditionsin interfaceRulesService- Parameters:
source- the item which tracked conditions we want to retrieve- Returns:
- the Set of tracked conditions for the specified item
-
removeRule
public void removeRule(String ruleId)
Description copied from interface:RulesServiceDeletes the rule identified by the specified identifier.- Specified by:
removeRulein interfaceRulesService- Parameters:
ruleId- the identifier of the rule we want to delete
-
bundleChanged
public void bundleChanged(org.osgi.framework.BundleEvent event)
- Specified by:
bundleChangedin interfaceorg.osgi.framework.BundleListener
-
bind
public void bind(org.osgi.framework.ServiceReference<RuleListenerService> serviceReference)
-
unbind
public void unbind(org.osgi.framework.ServiceReference<RuleListenerService> serviceReference)
-
fireAlreadyRaised
public void fireAlreadyRaised(RuleListenerService.AlreadyRaisedFor alreadyRaisedFor, Rule rule, Event event)
-
-