/** * Creates a {@link RuleSpecification} with the given query specification and jobs, * using the {@link DefaultActivationLifeCycle#DEFAULT} life-cycle. * * @param querySpecification * @param jobs */ public static <Match extends IPatternMatch> RuleSpecification<Match> newMatcherRuleSpecification(IQuerySpecification<? extends ViatraQueryMatcher<Match>> querySpecification, Set<Job<Match>> jobs){ return newMatcherRuleSpecification(querySpecification, Lifecycles.getDefault(true, true), jobs); }
/** * Returns a RuleSpecification that can be added to a rule engine. */ @Override public RuleSpecification<MATCH> getRuleSpecification() { if (ruleSpec == null) { final Job<MATCH> job = Jobs.newStatelessJob(CRUDActivationStateEnum.CREATED, action); ruleSpec = Rules.newMatcherRuleSpecification(precondition, lifecycle, Collections.singleton(job), getName()); } return ruleSpec; }
/** * Creates the rule used for updating the results. * * @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> createRuleSpecification( IObservablePatternMatchCollectionUpdate<Match> observableCollectionUpdate, IQuerySpecification<Matcher> querySpecification) { Set<Job<Match>> jobs = getObservableCollectionJobs(observableCollectionUpdate); return Rules.newMatcherRuleSpecification(querySpecification, Lifecycles.getDefault(false, true), jobs); }
/** * Creates the rule used for updating the results. * * @param observableCollectionUpdate * the observable collection to handle * @param matcher * the {@link ViatraQueryMatcher} used to create the rule */ protected static <Match extends IPatternMatch, Matcher extends ViatraQueryMatcher<Match>> RuleSpecification<Match> createRuleSpecification( IObservablePatternMatchCollectionUpdate<Match> observableCollectionUpdate, Matcher matcher) { Set<Job<Match>> jobs = getObservableCollectionJobs(observableCollectionUpdate); return Rules.newMatcherRuleSpecification(matcher, Lifecycles.getDefault(false, true), jobs); }
/** * @since 2.0 */ public EventDrivenTransformationRule(String name, IQuerySpecification<Matcher> precondition, Map<CRUDActivationStateEnum, ? extends Consumer<Match>> stateActions, ActivationLifeCycle lifeCycle, EventFilter<? super Match> filter) { this.name = name; Set<Job<Match>> jobs = new HashSet<>(); boolean createdJobAdded = false; for (Entry<CRUDActivationStateEnum, ? extends Consumer<Match>> stateAction : stateActions.entrySet()) { CRUDActivationStateEnum state = stateAction.getKey(); Consumer<Match> action = stateAction.getValue(); jobs.add(Jobs.newStatelessJob(state, action)); if (state == CRUDActivationStateEnum.CREATED) { createdJobAdded = true; } } if (!createdJobAdded) { jobs.add(Jobs.newNopJob(CRUDActivationStateEnum.CREATED)); } this.precondition = precondition; ruleSpecification = Rules.newMatcherRuleSpecification(precondition, lifeCycle, jobs, name); this.filter = filter; }
/** * 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. * * @param spec * QuerySpecification to be added to the Monitor */ public void addRule(IQuerySpecification<?> spec) { RuleSpecification<IPatternMatch> rule = Rules.newMatcherRuleSpecification( (IQuerySpecification<? extends ViatraQueryMatcher<IPatternMatch>>) spec, Lifecycles.getDefault(true, true), createDefaultProcessorJobs()); specs.put(spec, rule); addRule(rule); }
/** * 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); }