1 Reply Latest reply on Mar 26, 2014 3:50 AM by Andy Taylor

    Unable to Reload Rules for Second time

    Aravind K S Newbie

      I have an application which is using drools 5.5.0 final and i want to remove packages from knowledge base and add it again to reflect new changes. But for the first time i am able to remove and add it. Second time it is stopping at kbase.removeKnowledgePackage(packageName);. it is not giving any error also.

       

      This is my code

      rulelist will have the rules to be fired..

       

                         kbase = allRuleBases1.get("Kbase");

                          Collection<KnowledgePackage> packages = kbase

                              .getKnowledgePackages();

                              Iterator<KnowledgePackage> iter = packages.iterator();

                              while(iter.hasNext()){

                                 

                               KnowledgePackage kbPackage = iter.next();

                                String packageName = kbPackage.getName();

                                System.out.println("packageName = " + packageName);

                                kbase.removeKnowledgePackage(packageName);

                                System.out.println("removed packageName = " + packageName); }

                             

                              //kbase.getKnowledgePackages().removeAll(packages);

                              ksession = allRuleBases.get("DefaultScenario");

                              //System.out.println("ksession=="+ksession);

                              //kbase = ksession.getKnowledgeBase();

                              kbuilder1 = KnowledgeBuilderFactory.newKnowledgeBuilder();

                         

                              istream = new ByteArrayInputStream(ruleslist.getBytes());

                              kbuilder1.add(ResourceFactory.newInputStreamResource(istream), ResourceType.DRL);

                              errors = kbuilder1.getErrors();

                              if (errors.size() > 0) {

                                  for (KnowledgeBuilderError error : errors) {

                                      System.err.println(error);

                                  }

                                  throw new IllegalArgumentException("Could not parse knowledge.");

                              }

                             

                             

                              kbase.addKnowledgePackages(kbuilder1.getKnowledgePackages());   

                         

                          //    while(kbase.getStatefulKnowledgeSessions().iterator()){

                                 

                              while(kbase.getStatefulKnowledgeSessions().iterator().hasNext()){

                                  ksession = kbase.getStatefulKnowledgeSessions().iterator().next();

                                  break;

                                  }

                              allRuleBases.put("DefaultScenario", ksession);

                              allRuleBases1.put("Kbase", kbase);