/** * Creates a {@link StatelessJob} for the given state with the given processor. A stateless job simply processes the * match in the activation during execution. * * @param cRUDActivationStateEnum * @param processor * @since 2.0 */ public static <Match extends IPatternMatch> Job<Match> newStatelessJob( final CRUDActivationStateEnum cRUDActivationStateEnum, final Consumer<Match> processor) { return new StatelessJob<Match>(cRUDActivationStateEnum, processor); }
public static <EventAtom> Job<EventAtom> newEnableJob(final Job<EventAtom> job) { return new EnableJob<EventAtom>(job); }
public static <EventAtom> Job<EventAtom> newErrorLoggingJob(final Job<EventAtom> job) { return new ErrorLoggingJob<EventAtom>(job); }
/** * 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. * * @throws ViatraQueryRuntimeException */ @Override public void startMonitoring() { for (RuleSpecification<IPatternMatch> rule : rules) { executionSchema.addRule(rule); } executionSchema.startUnscheduledExecution(); // Enable the jobs to listen to changes for (Job<?> job : allJobs) { EnableJob<?> enableJob = (EnableJob<?>) job; enableJob.setEnabled(true); } started = true; }
/** * Creates the rule used for updating the results including changes in feature values. * * @param observableCollectionUpdate * the observable collection to handle * @param querySpecification * the {@link IQuerySpecification} used to create the rule */ protected static <Match extends IPatternMatch, Matcher extends ViatraQueryMatcher<Match>> RuleSpecification<Match> createUpdatingRuleSpecification( IObservablePatternMatchCollectionUpdate<Match> observableCollectionUpdate, IQuerySpecification<Matcher> querySpecification) { Set<Job<Match>> jobs = getObservableCollectionJobs(observableCollectionUpdate); Job<Match> updateJob = Jobs.newErrorLoggingJob(new SequentialProcessorsJob<Match>( CRUDActivationStateEnum.UPDATED, Arrays.asList( new ObservableCollectionProcessor<Match>(Direction.DELETE, observableCollectionUpdate), new ObservableCollectionProcessor<Match>(Direction.INSERT, observableCollectionUpdate) ))); jobs.add(updateJob); return Rules.newMatcherRuleSpecification(querySpecification, Lifecycles.getDefault(true, true), jobs); }
/** * 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 * * @return */ protected Set<Job<IPatternMatch>> createDefaultProcessorJobs() { // Define default MatchProcessors Consumer<IPatternMatch> appearProcessor = this::registerAppear; Consumer<IPatternMatch> disappearProcessor = this::registerDisappear; Consumer<IPatternMatch> updateProcessor = this::registerUpdate; // Create Jobs Set<Job<IPatternMatch>> jobs = new HashSet<>(); Job<IPatternMatch> appear = new StatelessJob<IPatternMatch>(CRUDActivationStateEnum.CREATED, appearProcessor); Job<IPatternMatch> disappear = new StatelessJob<IPatternMatch>(CRUDActivationStateEnum.DELETED, disappearProcessor); Job<IPatternMatch> update = new StatelessJob<IPatternMatch>(CRUDActivationStateEnum.UPDATED, updateProcessor); jobs.add(Jobs.newEnableJob(appear)); jobs.add(Jobs.newEnableJob(disappear)); jobs.add(Jobs.newEnableJob(update)); allJobs.addAll(jobs); return jobs; }
/** * Public method used for adding new rules to the monitor. This method can be used both before and after monitoring * has been started. * * @param rule * The rule to be added to the monitor */ public void addRule(RuleSpecification<IPatternMatch> rule) { rules.add(rule); Map<ActivationState, Set<Job<IPatternMatch>>> jobs = rule.getJobs(); if (started) { executionSchema.addRule(rule); } for (Set<Job<IPatternMatch>> jobEntries : jobs.values()) { for (Job<?> job : jobEntries) { if (started) { EnableJob<?> enableJob = (EnableJob<?>) job; enableJob.setEnabled(true); } else { allJobs.add(job); } } } }