Java Code Examples for org.kie.api.runtime.KieSession#getObject()

The following examples show how to use org.kie.api.runtime.KieSession#getObject() . 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: StatefulSessionTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetStatefulKnowledgeSessions() throws Exception {
    final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("../empty.drl"));

    final KieSession ksession_1 = createKnowledgeSession(kbase);
    final String expected_1 = "expected_1";
    final String expected_2 = "expected_2";
    final FactHandle handle_1 = ksession_1.insert(expected_1);
    final FactHandle handle_2 = ksession_1.insert(expected_2);
    ksession_1.fireAllRules();
    final Collection<? extends KieSession> coll_1 = kbase.getKieSessions();
    assertTrue(coll_1.size() == 1);

    final KieSession ksession_2 = coll_1.iterator().next();
    final Object actual_1 = ksession_2.getObject(handle_1);
    final Object actual_2 = ksession_2.getObject(handle_2);
    assertEquals(expected_1, actual_1);
    assertEquals(expected_2, actual_2);

    ksession_1.dispose();
    final Collection<? extends KieSession> coll_2 = kbase.getKieSessions();
    assertTrue(coll_2.size() == 0);

    // here to make sure it's safe to call dispose() twice
    ksession_1.dispose();
    final Collection<? extends KieSession> coll_3 = kbase.getKieSessions();
    assertTrue(coll_3.size() == 0);
}
 
Example 2
Source File: GetObjectCommand.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public Object execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup( KieSession.class );

    FactHandle factHandle = this.factHandle;
    if( factHandle == null ) {
        factHandle = this.disconnectedFactHandle;
    }
    Object object = ksession.getObject( factHandle );

    if (this.outIdentifier != null) {
        ((RegistryContext) context).lookup( ExecutionResultImpl.class ).setResult( this.outIdentifier, object );
    }

    return object;
}
 
Example 3
Source File: BusPassService.java    From buspass-ws with Apache License 2.0 5 votes vote down vote up
/**
 * Print out details of all facts in working memory.
 * Handy for debugging.
 */
@SuppressWarnings("unused")
private void printFactsMessage(KieSession kieSession) {
    Collection<FactHandle> allHandles = kieSession.getFactHandles();
    
    String msg = "\nAll facts:\n";
    for (FactHandle handle : allHandles) {
        msg += "    " + kieSession.getObject(handle) + "\n";
    }
    System.out.println(msg);
}
 
Example 4
Source File: DroolsUtil.java    From qzr with Apache License 2.0 5 votes vote down vote up
public static Object getObject(KieSession ksession, FactHandle handle) {
    if (handle == null) {
        return null;
    } else {
        return ksession.getObject(handle);
    }
}