Package org.kie.api.runtime

Examples of org.kie.api.runtime.KieContainer


    }

    private static KieBase checkBuildingResources( PMML pmml ) throws IOException {

        KieServices ks = KieServices.Factory.get();
        KieContainer kieContainer = ks.getKieClasspathContainer();

        if ( registry == null ) {
            initRegistry();
        }

        String chosenKieBase = null;

        for ( Object o : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels() ) {

            if ( o instanceof NaiveBayesModel ) {
                if ( ! naiveBayesLoaded ) {
                    for ( String ntempl : NAIVE_BAYES_TEMPLATES ) {
                        prepareTemplate( ntempl );
                    }
                    naiveBayesLoaded = true;
                }
                chosenKieBase = chosenKieBase == null ? "PMML-Bayes" : "PMML";
            }

            if ( o instanceof NeuralNetwork ) {
                if ( ! neuralLoaded ) {
                    for ( String ntempl : NEURAL_TEMPLATES ) {
                        prepareTemplate( ntempl );
                    }
                    neuralLoaded = true;
                }
                chosenKieBase = chosenKieBase == null ? "PMML-Neural" : "PMML";
            }

            if ( o instanceof ClusteringModel ) {
                if ( ! clusteringLoaded  ) {
                    for ( String ntempl : CLUSTERING_TEMPLATES ) {
                        prepareTemplate( ntempl );
                    }
                    clusteringLoaded = true;
                }
                chosenKieBase = chosenKieBase == null ? "PMML-Cluster" : "PMML";
            }

            if ( o instanceof SupportVectorMachineModel ) {
                if ( ! svmLoaded ) {
                    for ( String ntempl : SVM_TEMPLATES ) {
                        prepareTemplate( ntempl );
                    }
                    svmLoaded = true;
                }
                chosenKieBase = chosenKieBase == null ? "PMML-SVM" : "PMML";
            }

            if ( o instanceof TreeModel ) {
                if ( ! treeLoaded ) {
                    for ( String ntempl : TREE_TEMPLATES ) {
                        prepareTemplate( ntempl );
                    }
                    treeLoaded = true;
                }
                chosenKieBase = chosenKieBase == null ? "PMML-Tree" : "PMML";
            }

            if ( o instanceof RegressionModel ) {
                if ( ! simpleRegLoaded ) {
                    for ( String ntempl : SIMPLEREG_TEMPLATES ) {
                        prepareTemplate( ntempl );
                    }
                    simpleRegLoaded = true;
                }
                chosenKieBase = chosenKieBase == null ? "PMML-Regression" : "PMML";
            }

            if ( o instanceof Scorecard ) {
                if ( ! scorecardLoaded ) {
                    for ( String ntempl : SCORECARD_TEMPLATES ) {
                        prepareTemplate( ntempl );
                    }
                    scorecardLoaded = true;
                }
                chosenKieBase = chosenKieBase == null ? "PMML-Scorecard" : "PMML";
            }
        }

        if ( chosenKieBase == null ) {
            chosenKieBase = "PMML-Base";
        }
        return kieContainer.getKieBase( chosenKieBase );
    }
View Full Code Here


        Resource ex1Res = ks.getResources().newFileSystemResource(getFile("kiebase-inclusion"));
        Resource ex2Res = ks.getResources().newFileSystemResource(getFile("named-kiesession"));

        KieModule kModule = kr.addKieModule(ex1Res, ex2Res);
        KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId());

        KieSession kSession = kContainer.newKieSession("ksession2");
        kSession.setGlobal("out", out);

        Object msg1 = createMessage(kContainer, "Dave", "Hello, HAL. Do you read me, HAL?");
        kSession.insert(msg1);
        kSession.fireAllRules();
View Full Code Here

        KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);

        kfs.writeKModuleXML(kieModule.toXML());
        KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();

        KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
        try {
            kieContainer.getKieBase("KBase");
            fail("Should throw a RuntimeException because the CLOUD kbase is trying to use features only available in STREAM mode");
        } catch (Exception e) { }
    }
View Full Code Here

        File file = mfs.getFile( KieBuilderImpl.getCompilationCachePath( releaseId, "KBase1") );
        assertNotNull( file );

        Resource jarRes = ks.getResources().newByteArrayResource( jar );
        KieModule km = ks.getRepository().addKieModule( jarRes );
        KieContainer kc = ks.newKieContainer( km.getReleaseId() );
       
        KieBase kbase = kc.getKieBase();
        FactType type = kbase.getFactType( "org.drools.compiler", "X" );
        FactField foo = type.getField( "foo" );
        Object x = type.newInstance();
        foo.set( x, "Hello World" );
       
        KieSession ksession = kc.newKieSession();
        ksession.insert(x);

        int count = ksession.fireAllRules();
        assertEquals( 1, count );
    }
View Full Code Here

        assertNotNull( ikm.getResource( r1.getSourcePath() ) );
        assertNotNull( ikm.getResource( r2.getSourcePath() ) );
        assertNotNull( ikm.getResource( r3.getSourcePath() ) );

        // Create a session and fire rules
        KieContainer kc = ks.newKieContainer(km.getReleaseId());
        KieSession ksession = kc.newKieSession();
        ksession.insert(new Message("Hello World"));
        assertEquals( 2, ksession.fireAllRules() );
        ksession.dispose();
  }
View Full Code Here

        // Create an in-memory jar for version 1.0.0
        ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
        KieModule km = createAndDeployJar(ks, releaseId1, drl1, drl2_1);

        // Create a session and fire rules
        KieContainer kc = ks.newKieContainer(km.getReleaseId());
        KieSession ksession = kc.newKieSession();
        ksession.insert(new Message("Hello World"));
        assertEquals( 1, ksession.fireAllRules() );
        ksession.dispose();

        // Create a new jar for version 1.1.0
        ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
        km = createAndDeployJar( ks, releaseId2, drl1, drl2_2 );

        // try to update the container to version 1.1.0
        kc.updateToVersion(releaseId2);
       
        // create and use a new session
        ksession = kc.newKieSession();
        ksession.insert(new Message("Hello World"));
        assertEquals( 2, ksession.fireAllRules() );
    }
View Full Code Here

        // Create an in-memory jar for version 1.0.0
        ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
        KieModule km = createAndDeployJar( ks, releaseId1, drl1, drl2_1 );

        // Create a session and fire rules
        KieContainer kc = ks.newKieContainer( km.getReleaseId() );
        KieSession ksession = kc.newKieSession();
        ksession.insert(new Message("Hello World"));
        assertEquals( 1, ksession.fireAllRules() );

        // Create a new jar for version 1.1.0
        ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
        km = createAndDeployJar( ks, releaseId2, drl1, drl2_2 );

        // try to update the container to version 1.1.0
        kc.updateToVersion(releaseId2);
       
        // continue working with the session
        ksession.insert(new Message("Hello World"));
        assertEquals( 3, ksession.fireAllRules() );
    }
View Full Code Here

        // Create an in-memory jar for version 1.0.0
        ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-delete", "1.0.0");
        KieModule km = createAndDeployJar( ks, releaseId1, drl1, drl2 );

        KieContainer kieContainer = ks.newKieContainer(releaseId1);
        KieContainer kieContainer2 = ks.newKieContainer(releaseId1);

        KieSession ksession = kieContainer.newKieSession();
        ksession.insert(new Message("Hello World"));
        assertEquals( 2, ksession.fireAllRules() );

        ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-delete", "1.0.1");
        km = createAndDeployJar( ks, releaseId2, null, drl2 );

        kieContainer.updateToVersion(releaseId2);
       
        // test with the old ksession ...
        ksession.insert(new Message("Hello World"));
        assertEquals( 1, ksession.fireAllRules() );

        // ... and with a brand new one
        ksession = kieContainer.newKieSession();
        ksession.insert(new Message("Hello World"));
        assertEquals( 1, ksession.fireAllRules() );

        // check that the second kieContainer hasn't been affected by the update of the first one
        KieSession ksession2 = kieContainer2.newKieSession();
        ksession2.insert(new Message("Hello World"));
        assertEquals( 2, ksession2.fireAllRules() );
    }
View Full Code Here

        KieFileSystem kfs = ks.newKieFileSystem()
                .write("src/main/resources/r1.drl", drl1)
                .write("src/main/resources/r2.drl", drl2_1);

        KieBuilder kieBuilder = ks.newKieBuilder( kfs ).buildAll();
        KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());

        KieSession ksession = kieContainer.newKieSession();
        ksession.insert(new Message("Hello World"));
        assertEquals( 1, ksession.fireAllRules() );

        kfs.write("src/main/resources/r2.drl", drl2_2);
        IncrementalResults results = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();

        assertEquals(1, results.getAddedMessages().size());
        assertEquals(0, results.getRemovedMessages().size());

        kieContainer.updateToVersion(ks.getRepository().getDefaultReleaseId());
        ksession = kieContainer.newKieSession();
        ksession.insert(new Message("Hello World"));
        assertEquals( 1, ksession.fireAllRules() );
    }
View Full Code Here

        IncrementalResults results = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();

        assertEquals( 0, results.getAddedMessages().size() );
        assertEquals( 1, results.getRemovedMessages().size() );

        KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
        KieSession ksession = kieContainer.newKieSession();
        ksession.insert(new Message("Hello World"));
        assertEquals( 2, ksession.fireAllRules() );
    }
View Full Code Here

TOP

Related Classes of org.kie.api.runtime.KieContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.