org.kie.api.event.rule.MatchCreatedEvent Java Examples

The following examples show how to use org.kie.api.event.rule.MatchCreatedEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StateBasedNodeInstance.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Override
public void signalEvent(String type, Object event) {
    if ("timerTriggered".equals(type)) {
        TimerInstance timerInstance = (TimerInstance) event;
        if (timerInstances != null && timerInstances.contains(timerInstance.getId())) {
            triggerTimer(timerInstance);
        } else if (timerInstance.getId().equals(slaTimerId)) {
            handleSLAViolation();
        }
    } else if (("slaViolation:" + getId()).equals(type)) {

        handleSLAViolation();
    } else if (type.equals(getActivationType()) && event instanceof MatchCreatedEvent) {
        String name = ((MatchCreatedEvent) event).getMatch().getRule().getName();
        if (checkProcessInstance((Activation) ((MatchCreatedEvent) event).getMatch())) {
            ((MatchCreatedEvent) event).getKieRuntime().signalEvent(name, null);
        }
    }
}
 
Example #2
Source File: StateNodeInstance.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public void activationCreated(MatchCreatedEvent event) {
    Connection selected = null;
    for (Connection connection: getNode().getOutgoingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE)) {
        Constraint constraint = getStateNode().getConstraint(connection);
        if (constraint != null) {
         String constraintName =  getActivationEventType() + "-"
         	+ connection.getTo().getId() + "-" + connection.getToType();
         if (constraintName.equals(event.getMatch().getRule().getName())
         		&& checkProcessInstance((Activation) event.getMatch())) {
         	selected = connection;
         }
        }
    }
    if (selected != null) {
    	removeEventListeners();
    	((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
        triggerConnection(selected);
    }
}
 
Example #3
Source File: DynamicRulesTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testJBRULES_2206() {
    KieBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    ((RuleBaseConfiguration) config).setRuleBaseUpdateHandler( null );
    InternalKnowledgeBase kbase = (InternalKnowledgeBase) getKnowledgeBase( config );
    KieSession session = createKnowledgeSession( kbase );

    AgendaEventListener ael = mock( AgendaEventListener.class );
    session.addEventListener( ael );

    for ( int i = 0; i < 5; i++ ) {
        session.insert( new Cheese() );
    }

    kbase.addPackages( loadKnowledgePackages( "test_JBRULES_2206_1.drl" ));
    ((InternalAgenda) session.getAgenda()).evaluateEagerList();

    // two matching rules were added, so 2 activations should have been created 
    verify( ael, times( 2 ) ).matchCreated(any(MatchCreatedEvent.class));
    int fireCount = session.fireAllRules();
    // both should have fired
    assertEquals( 2, fireCount );

    kbase.addPackages( loadKnowledgePackages( "test_JBRULES_2206_2.drl" ));
    ((InternalAgenda) session.getAgenda()).evaluateEagerList();

    // one rule was overridden and should activate 
    verify( ael, times( 3 ) ).matchCreated(any(MatchCreatedEvent.class));
    fireCount = session.fireAllRules();
    // that rule should fire again
    assertEquals( 1, fireCount );

    session.dispose();
}
 
Example #4
Source File: WorkingMemoryLogger.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.kie.api.event.rule.AgendaEventListener
 */
public void matchCreated(MatchCreatedEvent event) {
    filterLogEvent( new ActivationLogEvent( LogEvent.ACTIVATION_CREATED,
                                            getActivationId( event.getMatch() ),
                                            event.getMatch().getRule().getName(),
                                            extractDeclarations( event.getMatch() ),
                                            ((RuleImpl)event.getMatch().getRule()).getRuleFlowGroup(),
                                            extractFactHandleIds( (Activation) event.getMatch() ) ) );
}
 
Example #5
Source File: AgendaEventSupport.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public void fireActivationCreated(final Activation activation,
                                  final WorkingMemory workingMemory) {
    Iterator<AgendaEventListener> iter = getEventListenersIterator();

    MatchCreatedEvent event = new ActivationCreatedEventImpl(activation, getKRuntime(workingMemory));
    if (iter.hasNext()) {

        do{
            iter.next().matchCreated(event);
        }  while (iter.hasNext());
    }
}
 
Example #6
Source File: StateNodeInstance.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public void signalEvent(String type, Object event) {
	if ("signal".equals(type)) {
		if (event instanceof String) {
			for (Connection connection: getStateNode().getOutgoingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE)) {
				boolean selected = false;
				Constraint constraint = getStateNode().getConstraint(connection);
				if (constraint == null) {
					if (((String) event).equals(connection.getTo().getName())) {
						selected = true;
					}
				} else if (((String) event).equals(constraint.getName())) {
					selected = true;
				}
				if (selected) {
					triggerEvent(ExtendedNodeImpl.EVENT_NODE_EXIT);
					removeEventListeners();
					((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer())
	            		.removeNodeInstance(this);
					triggerConnection(connection);
					return;
				}
			}
		}
	} else if (getActivationEventType().equals(type)) {
		if (event instanceof MatchCreatedEvent) {
			activationCreated((MatchCreatedEvent) event);
		}
	} else {
		super.signalEvent(type, event);
	}
}
 
Example #7
Source File: DebugAgendaEventListener.java    From servicemix with Apache License 2.0 4 votes vote down vote up
/**
 * @see AgendaEventListener#matchCreated(org.kie.api.event.rule.MatchCreatedEvent)
 */
@Override
public void matchCreated(MatchCreatedEvent event) {
    log.info("{}", event);

}
 
Example #8
Source File: RuleCoverageListener.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public void matchCreated(MatchCreatedEvent event) {
}
 
Example #9
Source File: DebugAgendaEventListener.java    From servicemix with Apache License 2.0 4 votes vote down vote up
/**
 * @see AgendaEventListener#matchCreated(org.kie.api.event.rule.MatchCreatedEvent)
 */
@Override
public void matchCreated(MatchCreatedEvent event) {
    log.info("{}", event);

}
 
Example #10
Source File: DebugAgendaEventListener.java    From servicemix with Apache License 2.0 4 votes vote down vote up
/**
 * @see AgendaEventListener#matchCreated(org.kie.api.event.rule.MatchCreatedEvent)
 */
@Override
public void matchCreated(MatchCreatedEvent event) {
    log.info("{}", event);

}
 
Example #11
Source File: CepEngineImpl.java    From hawkular-alerts with Apache License 2.0 4 votes vote down vote up
@Override
public void matchCreated(MatchCreatedEvent event) {
    log.debug(event);
}
 
Example #12
Source File: TriggerRulesEventListener.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public void matchCreated(MatchCreatedEvent event) {
}
 
Example #13
Source File: DebugAgendaEventListener.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public void matchCreated(MatchCreatedEvent event) {
    logger.info( event.toString() );
}
 
Example #14
Source File: DefaultAgendaEventListener.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public void matchCreated(MatchCreatedEvent event) {
    // intentionally left blank
}
 
Example #15
Source File: GenericKieSessionMonitoringImpl.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public void matchCreated(MatchCreatedEvent event) {
    this.consolidated.matchesCreated.incrementAndGet();
    AgendaStatsData data = getRuleStatsInstance( event.getMatch().getRule().getName() );
    data.matchesCreated.incrementAndGet();
}
 
Example #16
Source File: DynamicRulesTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testDynamicRuleRemovalsSubNetworkAndNot() throws Exception {
    InternalKnowledgeBase kbase = (InternalKnowledgeBase) loadKnowledgeBase("test_DynamicRulesWithNotSubnetwork.drl");
    KieSession ksession = createKnowledgeSession( kbase );


    final AgendaEventListener alistener = mock( AgendaEventListener.class );
    ksession.addEventListener( alistener );

    // pattern does not match, so do not activate
    ksession.insert( new Person( "toni" ) );
    ksession.fireAllRules();
    verify( alistener,
            never() ).matchCreated(any(org.kie.api.event.rule.MatchCreatedEvent.class));

    // pattern matches, so create activation
    ksession.insert( new Person( "bob" ) );
    ksession.fireAllRules();
    verify( alistener,
            times( 1 ) ).matchCreated(any(org.kie.api.event.rule.MatchCreatedEvent.class));

    // already active, so no new activation should be created
    ksession.insert( new Person( "mark" ) );
    ksession.fireAllRules();
    verify( alistener,
            times( 1 ) ).matchCreated(any(org.kie.api.event.rule.MatchCreatedEvent.class));

    kbase.removeKiePackage( "org.drools.compiler" );

    assertEquals( 0,
                  kbase.getKiePackages().size() );

    // lets re-compile and add it again
    Collection<KiePackage> kpkgs = loadKnowledgePackages("test_DynamicRulesWithNotSubnetwork.drl");
    kbase.addPackages( kpkgs );
    ksession.fireAllRules();

            // rule should be reactivated, since data is still in the session
    verify( alistener,
            times( 2 ) ).matchCreated(any(org.kie.api.event.rule.MatchCreatedEvent.class));

}
 
Example #17
Source File: TestingEventListener.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public void matchCreated(MatchCreatedEvent event) {
}