protected ViatraQueryEventSource(ViatraQueryEventRealm realm, ViatraQueryEventSourceSpecification<Match> sourceDefinition) { super(sourceDefinition, realm); ViatraQueryMatcher<Match> _matcher = sourceDefinition.getMatcher(realm.getEngine()); this.matcher = _matcher; }
public static ViatraQueryEventRealm create(ViatraQueryEngine engine) { return new ViatraQueryEventRealm(engine); }
/** * Creates a new rule engine that is initialized over the given * ViatraQueryEngine and an agenda without rules. * @param engine * @return the prepared rule engine */ public static RuleEngine createViatraQueryRuleEngine(final ViatraQueryEngine engine) { return EventDrivenVM.createRuleEngine(ViatraQueryEventRealm.create(engine)); }
/** * Creates a {@link RuleSpecification} with the given query specification, life-cycle and jobs. * * For default life-cycle implementations, see {@link DefaultActivationLifeCycle}. * * @param querySpecification * @param lifecycle * @param jobs */ public static <Match extends IPatternMatch> RuleSpecification<Match> newMatcherRuleSpecification(IQuerySpecification<? extends ViatraQueryMatcher<Match>> querySpecification, ActivationLifeCycle lifecycle, Set<Job<Match>> jobs){ return new RuleSpecification<Match>(ViatraQueryEventRealm.createSourceSpecification(querySpecification), lifecycle, jobs); }
@Override public void prepareRuleInstance(RuleInstance<Match> ruleInstance, EventFilter<? super Match> filter) { Preconditions.checkArgument(ruleInstance != null, "Cannot prepare null rule instance!"); ViatraQueryEventSource<Match> source = realm.createSource(sourceSpecification); ViatraQueryEventHandler<Match> handler = new ViatraQueryEventHandler<Match>(source, filter, ruleInstance); handler.prepareEventHandler(); }
/** * Creates a {@link RuleSpecification} with the given query specification, life-cycle and jobs and name. * * For default life-cycle implementations, see {@link DefaultActivationLifeCycle}. * * @param querySpecification * @param lifecycle * @param jobs * @param name */ public static <Match extends IPatternMatch> RuleSpecification<Match> newMatcherRuleSpecification(IQuerySpecification<? extends ViatraQueryMatcher<Match>> querySpecification, ActivationLifeCycle lifecycle, Set<Job<Match>> jobs, String name){ return new RuleSpecification<Match>(ViatraQueryEventRealm.createSourceSpecification(querySpecification), lifecycle, jobs, name); }
protected static void disposeRuleEngine(RuleEngine ruleEngine) { Map<ViatraQueryEngine, WeakReference<RuleEngine>> ruleEngineMap = getInstance().getQueryToRuleEngineMap(); EventRealm eventRealm = ruleEngine.getEventRealm(); if(eventRealm instanceof ViatraQueryEventRealm) { ViatraQueryEngine queryEngine = ((ViatraQueryEventRealm) eventRealm).getEngine(); ruleEngineMap.remove(queryEngine); } else { // very unlikely case as we always create such realm throw new IllegalArgumentException("Trying to dispose rule engine on realm different from ViatraQueryEventRealm!"); } ruleEngine.dispose(); }
/** * Creates a new execution schema that is initialized over the given ViatraQueryEngine, creates an executor and * agenda with the given rule specifications and prepares a scheduler using the provided factory. * * @param engine * @param schedulerFactory * @param specifications * @return the prepared execution schema */ public static ExecutionSchema createViatraQueryExecutionSchema(final ViatraQueryEngine engine, final ISchedulerFactory schedulerFactory, final Set<RuleSpecification<?>> specifications) { return EventDrivenVM.createExecutionSchema(ViatraQueryEventRealm.create(engine), schedulerFactory, specifications); }
/** * Creates a new adaptable {@link RuleEngine} based on the input {@link ViatraQueryEngine} */ public RuleEngine createAdaptableRuleEngine(ViatraQueryEngine queryEngine) { AdaptableConflictResolver conflictResolver = new AdaptableConflictResolver(new ArbitraryOrderConflictResolver(), this); Agenda debugAgenda = new Agenda(conflictResolver); debugAgenda.setActivationListener( new AdaptableActivationNotificationListener(debugAgenda.getActivationListener(), this)); RuleBase debugRulebase = new AdaptableRuleBase(ViatraQueryEventRealm.create(queryEngine), debugAgenda, this); return RuleEngine.create(debugRulebase); }
/** * Creates a new adaptable {@link ExecutionSchema} based on the input parameters. */ public ExecutionSchema createAdaptableExecutionSchema(ViatraQueryEngine queryEngine, ISchedulerFactory schedulerFactory, ConflictResolver conflictResolver) { IExecutor executor = new AdaptableExecutor(new Executor(), this); ConflictResolver adaptableConflictResolver = new AdaptableConflictResolver(conflictResolver, this); Agenda debugAgenda = new Agenda(adaptableConflictResolver); debugAgenda.setActivationListener( new AdaptableActivationNotificationListener(debugAgenda.getActivationListener(), this)); RuleBase debugRulebase = new AdaptableRuleBase(ViatraQueryEventRealm.create(queryEngine), debugAgenda, this); ScheduledExecution execution = new ScheduledExecution(debugRulebase, executor); Scheduler scheduler = schedulerFactory.prepareScheduler(execution); final ExecutionSchema schema = ExecutionSchema.create(scheduler); schema.setConflictResolver(adaptableConflictResolver); return schema; }