Class RuleBase
- java.lang.Object
-
- org.eclipse.viatra.transformation.evm.api.RuleBase
-
- Direct Known Subclasses:
AdaptableRuleBase
public class RuleBase extends java.lang.Object
An RuleBase is associated to anEventRealm
and it is responsible for creating, managing and disposing rules in the Rule Engine. It provides an unmodifiable view for the collection of applicable activations.
-
-
Field Summary
Fields Modifier and Type Field Description protected Agenda
agenda
protected EventRealm
eventRealm
protected org.apache.log4j.Logger
logger
protected java.util.Map<RuleSpecification<?>,java.util.Map<EventFilter<?>,RuleInstance<?>>>
ruleInstanceTable
-
Constructor Summary
Constructors Modifier Constructor Description protected
RuleBase(EventRealm eventRealm, Agenda agenda)
Instantiates a new RuleBase instance with the givenEventRealm
andAgenda
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ScopedConflictSet
createScopedConflictSet(ConflictResolver conflictResolver, java.util.Map<RuleSpecification<?>,java.util.Set<EventFilter<?>>> specifications)
Creates a scoped conflict set of the enabled activations of the provided rule specifications and filters using the given conflict resolver.protected void
dispose()
Disposes of each rule instance managed by the agenda.protected <EventAtom>
RuleInstance<EventAtom>findInstance(RuleSpecification<EventAtom> specification, EventFilter<? super EventAtom> filter)
Agenda
getAgenda()
EventRealm
getEventRealm()
<EventAtom>
RuleInstance<EventAtom>getInstance(RuleSpecification<EventAtom> specification, EventFilter<? super EventAtom> filter)
Returns the filtered instance managed by the RuleBase for the given specification.org.apache.log4j.Logger
getLogger()
java.util.Set<RuleInstance<?>>
getRuleInstances()
java.util.Map<RuleSpecification<?>,java.util.Set<EventFilter<?>>>
getRuleSpecificationMultimap()
protected <EventAtom>
RuleInstance<EventAtom>instantiateRule(RuleSpecification<EventAtom> specification, EventFilter<? super EventAtom> filter)
Instantiates the given specification over the EventRealm of the RuleBase.protected <EventAtom>
booleanremoveRule(RuleInstance<EventAtom> instance)
Removes and disposes of a rule instance.protected <EventAtom>
booleanremoveRule(RuleSpecification<EventAtom> specification, EventFilter<? super EventAtom> filter)
Removes and disposes of a rule instance with the given specification.
-
-
-
Field Detail
-
eventRealm
protected final EventRealm eventRealm
-
ruleInstanceTable
protected final java.util.Map<RuleSpecification<?>,java.util.Map<EventFilter<?>,RuleInstance<?>>> ruleInstanceTable
-
agenda
protected final Agenda agenda
-
logger
protected final org.apache.log4j.Logger logger
-
-
Constructor Detail
-
RuleBase
protected RuleBase(EventRealm eventRealm, Agenda agenda)
Instantiates a new RuleBase instance with the givenEventRealm
andAgenda
.- Parameters:
eventRealm
- theEventRealm
instanceagenda
- theAgenda
instance
-
-
Method Detail
-
instantiateRule
protected <EventAtom> RuleInstance<EventAtom> instantiateRule(RuleSpecification<EventAtom> specification, EventFilter<? super EventAtom> filter)
Instantiates the given specification over the EventRealm of the RuleBase. If the specification was already instantiated, the existing instance is returned.- Parameters:
specification
- the rule to be instantiated- Returns:
- the created or existing rule instance
-
removeRule
protected <EventAtom> boolean removeRule(RuleInstance<EventAtom> instance)
Removes and disposes of a rule instance.- Parameters:
instance
-- Returns:
- true, if the instance was part of the RuleBase
-
removeRule
protected <EventAtom> boolean removeRule(RuleSpecification<EventAtom> specification, EventFilter<? super EventAtom> filter)
Removes and disposes of a rule instance with the given specification.- Parameters:
specification
-filter
- the partial match used as filter- Returns:
- true, if the specification had an instance in the RuleBase
-
dispose
protected void dispose()
Disposes of each rule instance managed by the agenda.
-
getEventRealm
public EventRealm getEventRealm()
-
getRuleSpecificationMultimap
public java.util.Map<RuleSpecification<?>,java.util.Set<EventFilter<?>>> getRuleSpecificationMultimap()
- Since:
- 2.0
-
getRuleInstances
public java.util.Set<RuleInstance<?>> getRuleInstances()
- Returns:
- an immutable copy of the set of rule instances
-
getInstance
public <EventAtom> RuleInstance<EventAtom> getInstance(RuleSpecification<EventAtom> specification, EventFilter<? super EventAtom> filter)
Returns the filtered instance managed by the RuleBase for the given specification.- Parameters:
specification
-filter
- the partial match to be used as filter- Returns:
- the instance, if it exists, null otherwise
-
findInstance
protected <EventAtom> RuleInstance<EventAtom> findInstance(RuleSpecification<EventAtom> specification, EventFilter<? super EventAtom> filter)
-
createScopedConflictSet
public ScopedConflictSet createScopedConflictSet(ConflictResolver conflictResolver, java.util.Map<RuleSpecification<?>,java.util.Set<EventFilter<?>>> specifications)
Creates a scoped conflict set of the enabled activations of the provided rule specifications and filters using the given conflict resolver. The set will be incrementally updated until disposed.- Parameters:
conflictResolver
-specifications
-- Since:
- 2.0
-
getAgenda
public Agenda getAgenda()
-
getLogger
public org.apache.log4j.Logger getLogger()
-
-