Class RuleInstance<EventAtom>
- java.lang.Object
-
- org.eclipse.viatra.transformation.evm.api.RuleInstance<EventAtom>
-
- All Implemented Interfaces:
IActivationNotificationProvider
public class RuleInstance<EventAtom> extends java.lang.Object implements IActivationNotificationProvider
The rule instance is created in the EVM for a rule specification. The instance manages the set of activations and processes events that affect the instance and its activations. It uses the life-cycle defined in its specification for updating the state of activations and the jobs to execute them, when requested. The instance also provides change notification to the agenda about activation state changes.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedRuleInstance(RuleSpecification<EventAtom> specification)Creates an instance using a RuleSpecification.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ActivationStateactivationStateTransition(Activation<EventAtom> activation, EventType event)Performs the state transition on the given activation in response to the specified event using the life-cycle defined in the rule specification.booleanaddActivationNotificationListener(IActivationNotificationListener listener, boolean fireNow)Activation<EventAtom>createActivation(EventAtom atom)protected voiddispose()Disposes the rule instance by inactivating all activations and disposing of its activation notification provider and attribute monitor.protected voiddoFire(Activation<EventAtom> activation, ActivationState activationState, EventAtom atom, Context context)Checks whether the activation is part of the activation set of the instance, then updates the state by calling activationStateTransition().voidfire(Activation<EventAtom> activation, Context context)Fires the given activation using the supplied context.java.util.Map<ActivationState,Activation<EventAtom>>getActivationsFor(EventAtom atom)java.util.Collection<Activation<EventAtom>>getActivationsFor(ActivationState state)java.util.Set<Activation<EventAtom>>getAllActivations()EventFilter<? super EventAtom>getFilter()ActivationLifeCyclegetLifeCycle()RuleSpecification<EventAtom>getSpecification()booleanremoveActivationNotificationListener(IActivationNotificationListener listener)voidsetHandler(EventHandler<EventAtom> handler)java.util.stream.Stream<Activation<EventAtom>>streamAllActivations()java.lang.StringtoString()
-
-
-
Constructor Detail
-
RuleInstance
protected RuleInstance(RuleSpecification<EventAtom> specification)
Creates an instance using a RuleSpecification.- Parameters:
specification-engine-- Throws:
java.lang.IllegalArgumentException- if filter is mutable
-
-
Method Detail
-
setHandler
public void setHandler(EventHandler<EventAtom> handler)
-
createActivation
public Activation<EventAtom> createActivation(EventAtom atom)
-
fire
public void fire(Activation<EventAtom> activation, Context context)
Fires the given activation using the supplied context. Delegates to the doFire method- Parameters:
activation-context-
-
doFire
protected void doFire(Activation<EventAtom> activation, ActivationState activationState, EventAtom atom, Context context)
Checks whether the activation is part of the activation set of the instance, then updates the state by calling activationStateTransition(). Finally, it executes each job that corresponds to the activation state using the supplied context.- Parameters:
activation-activationState-atom-context-
-
activationStateTransition
public ActivationState activationStateTransition(Activation<EventAtom> activation, EventType event)
Performs the state transition on the given activation in response to the specified event using the life-cycle defined in the rule specification. If there is a transition defined for the current state and the event, the activation state is updated. Finally, an activation change notification is sent to listeners and the new state is returned.- Parameters:
activation-event-- Returns:
- the state of the activation after the transition
-
addActivationNotificationListener
public boolean addActivationNotificationListener(IActivationNotificationListener listener, boolean fireNow)
Delegate method forActivationNotificationProvider.addActivationNotificationListener(org.eclipse.viatra.transformation.evm.notification.IActivationNotificationListener, boolean).- Specified by:
addActivationNotificationListenerin interfaceIActivationNotificationProvider- Parameters:
listener-fireNow-
-
removeActivationNotificationListener
public boolean removeActivationNotificationListener(IActivationNotificationListener listener)
Delegate method forActivationNotificationProvider.removeActivationNotificationListener(org.eclipse.viatra.transformation.evm.notification.IActivationNotificationListener).- Specified by:
removeActivationNotificationListenerin interfaceIActivationNotificationProvider- Parameters:
listener-
-
getSpecification
public RuleSpecification<EventAtom> getSpecification()
- Returns:
- the specification
-
getFilter
public EventFilter<? super EventAtom> getFilter()
-
getLifeCycle
public ActivationLifeCycle getLifeCycle()
-
getActivationsFor
public java.util.Map<ActivationState,Activation<EventAtom>> getActivationsFor(EventAtom atom)
- Returns:
- a possibly live map of activations of a given atom
- Since:
- 2.3
-
streamAllActivations
public java.util.stream.Stream<Activation<EventAtom>> streamAllActivations()
- Returns:
- a stream of the current set of activations (live, do not modify while iterating)
- Since:
- 2.3
-
getAllActivations
public java.util.Set<Activation<EventAtom>> getAllActivations()
- Returns:
- an unmodifiable live view of the set of activations
- Since:
- 2.3
-
getActivationsFor
public java.util.Collection<Activation<EventAtom>> getActivationsFor(ActivationState state)
- Parameters:
state-- Returns:
- the possibly live set of activations in the given state
- Since:
- 2.3
-
dispose
protected void dispose()
Disposes the rule instance by inactivating all activations and disposing of its activation notification provider and attribute monitor. Rule instances are managed by their RuleBase, they should be disposed through that!
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-