org.eclipse.viatra.transformation.evm.api

## 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 and Description
    --- | ---
    `protected` | `RuleInstance(RuleSpecification<EventAtom> specification)` Creates an instance using a RuleSpecification.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `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.
    `boolean` | `addActivationNotificationListener(IActivationNotificationListener listener, boolean fireNow)` Delegate method for `ActivationNotificationProvider.addActivationNotificationListener(org.eclipse.viatra.transformation.evm.notification.IActivationNotificationListener, boolean)`.
    `Activation<EventAtom>` | `createActivation(EventAtom atom)`
    `protected void` | `dispose()` Disposes the rule instance by inactivating all activations and disposing of its activation notification provider and attribute monitor.
    `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().
    `void` | `fire(Activation<EventAtom> activation, Context context)` Fires the given activation using the supplied context.
    `java.util.Collection<Activation<EventAtom>>` | `getActivationsFor(ActivationState state)`
    `java.util.Map<ActivationState,Activation<EventAtom>>` | `getActivationsFor(EventAtom atom)`
    `java.util.Set<Activation<EventAtom>>` | `getAllActivations()`
    `EventFilter<? super EventAtom>` | `getFilter()`
    `ActivationLifeCycle` | `getLifeCycle()`
    `RuleSpecification<EventAtom>` | `getSpecification()`
    `boolean` | `removeActivationNotificationListener(IActivationNotificationListener listener)` Delegate method for `ActivationNotificationProvider.removeActivationNotificationListener(org.eclipse.viatra.transformation.evm.notification.IActivationNotificationListener)`.
    `void` | `setHandler(EventHandler<EventAtom> handler)`
    `java.util.stream.Stream<Activation<EventAtom>>` | `streamAllActivations()`
    `java.lang.String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### 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 for `ActivationNotificationProvider.addActivationNotificationListener(org.eclipse.viatra.transformation.evm.notification.IActivationNotificationListener, boolean)`.
      Specified by:
        `addActivationNotificationListener` in interface `IActivationNotificationProvider`
      Parameters:
        `listener` -
        `fireNow` -

    - #### removeActivationNotificationListener

          public boolean removeActivationNotificationListener(IActivationNotificationListener listener)

      Delegate method for `ActivationNotificationProvider.removeActivationNotificationListener(org.eclipse.viatra.transformation.evm.notification.IActivationNotificationListener)`.
      Specified by:
        `removeActivationNotificationListener` in interface `IActivationNotificationProvider`
      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:
        `toString` in class `java.lang.Object`