Class ChangeMonitor


  • public class ChangeMonitor
    extends IChangeMonitor
    Class responsible for monitoring changes in a specified model. It uses IQuerySpecification objects or EMV Rules defined by the user to achieve this. Based on the instance model to be monitored, a VIATRA Query Engine should be initialized and handed over to this class. An ExecutionSchema is initialized based on the VIATRA Query Engine, then the rules defined by the user are registered in it. By default the monitor accumulates the changes of the defined QuerySpecifications, this behavior, however can be overridden via inheritance.
    • Constructor Detail

      • ChangeMonitor

        public ChangeMonitor​(ViatraQueryEngine engine)
        Constructor that creates a new ChangeMonitor instance based on the specified ViatraQuery engine. Note that to monitor changes of a specific model instance, a VIATRA Query should be initialized on said model instance.
        Parameters:
        engine - The ViatraQueryEngine the monitor is based on.
    • Method Detail

      • addRule

        public void addRule​(RuleSpecification<IPatternMatch> rule)
        Public method used for adding new rules to the monitor. This method can be used both before and after monitoring has been started.
        Parameters:
        rule - The rule to be added to the monitor
      • addRule

        public void addRule​(IQuerySpecification<?> spec)
        Public method used for adding new rules to the monitor. Based on the QuerySpecification provided here, a new Rule will be added to the monitor. This method can be used both before and after monitoring has been started.
        Parameters:
        spec - QuerySpecification to be added to the Monitor
      • removeRule

        public void removeRule​(RuleSpecification<IPatternMatch> rule)
        Public method used for removing rules from the Monitor. This method can be used both before and after monitoring has been started.
        Parameters:
        rule - Rule to be removed
      • removeRule

        public void removeRule​(IQuerySpecification<?> spec)
        Public method used for removing rules from the Monitor. This method can be used both before and after monitoring has been started.
        Parameters:
        spec - The rules based on this QuerySpecification will be removed
      • createCheckpoint

        public ChangeDelta createCheckpoint()
        Creates a new checkpoint and returns the changes in the model so far. The ChangeDelta object returned contains objects that have CREATED, DELETED or have been UPDATED. If this method is used, the history accumulated is erased, as a new checkpoint is created.
        Specified by:
        createCheckpoint in class IChangeMonitor
        Returns:
        the DTO containing the changed elements since the last checkpoint
      • getDeltaSinceLastCheckpoint

        public ChangeDelta getDeltaSinceLastCheckpoint()
        Returns the changes in the model since the last checkpoint. The accumulated data is not erased.
        Specified by:
        getDeltaSinceLastCheckpoint in class IChangeMonitor
        Returns:
        the DTO containing the changed elements
      • startMonitoring

        public void startMonitoring()
        Adds the defined rules to the ExecutionSchema and enables them. Call this method after the rules have been added, and the model instance to be monitored is initialized.
        Specified by:
        startMonitoring in class IChangeMonitor
        Throws:
        ViatraQueryRuntimeException
      • dispose

        public void dispose()
        Disposes the Change monitor's execution schema
      • createDefaultProcessorJobs

        protected java.util.Set<Job<IPatternMatch>> createDefaultProcessorJobs()
        Creates the default EVM Jobs which are executed as a new match appears, disappears or is updated. Can be overridden to specify domain specific functionality
        Returns:
      • registerUpdate

        protected void registerUpdate​(IPatternMatch match)
        Extracts updated elements from the given match
        Parameters:
        match -
      • registerAppear

        protected void registerAppear​(IPatternMatch match)
        Extracts appeared elements from the given match
        Parameters:
        match -
      • registerDisappear

        protected void registerDisappear​(IPatternMatch match)
        Extracts disappeared elements from the given match
        Parameters:
        match -