public EventDrivenTransformationRule<Match, Matcher> build() { Preconditions.checkState(!stateActions.isEmpty(), "The rule has no actions added."); if (lifeCycle == null) { lifeCycle = Lifecycles.getDefault(isUpdateJobAdded, isDeleteJobAdded); } return createRule(name, precondition, stateActions, lifeCycle, filter); } }
/** * 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); }
/** * 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); }
/** * 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); }