3 Replies Latest reply on Aug 23, 2011 9:40 AM by salaboy21

    Is WorkingMemoryLogger working?

    lukasz.kozerski

      Hi,

       

      it seems that WorkingMemoryLogger (WorkingMemoryConsoleLogger for example) is not working after session loading.

       

      Example:

       

      StatefulKnowledgeSession session = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, config,

                      environment);

      new WorkingMemoryConsoleLogger(ksession);

      WorkItemManager mgr = ksession.getWorkItemManager();

      mgr.completeWorkItem(workItemId, null);

       

      In this example logger logs nothing.

       

      Thanks,

      Lukasz

        • 1. Re: Is WorkingMemoryLogger working?
          salaboy21

          did you try with

          KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession); ?

          • 2. Re: Is WorkingMemoryLogger working?
            lukasz.kozerski

            Yes.

             

            I have simple method:

             

                private Environment environment(EntityManagerFactory emf) {

                    Environment env = KnowledgeBaseFactory.newEnvironment();

                    env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);

                    env.set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES,

                            new ObjectMarshallingStrategy[] {MarshallerFactory.newSerializeMarshallingStrategy()});

                    return env;

                }

             

            In this example logger works fine:

             

                    environment = environment(emf);

                    StatefulKnowledgeSession ksession = newSession();

                    int sessionId = ksession.getId();

                    Map<String, Object> parameters = new HashMap<String, Object>();

                    Object object = createObject();

                    parameters.put("object", object);

                    ksession.insert(object);

                    ksession.startProcess("process", parameters);

                    ksession.fireAllRules();

                    environment = environment(emf);

                    ksession = loadSession(sessionId);

                    KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);

                    WorkItemManager mgr = ksession.getWorkItemManager();

                    mgr.completeWorkItem(workItemId, null);

                    ksession.dispose();

             

            and when I will comment this line:

             

                    //environment = environment(emf); <- commented

                    ksession = loadSession(sessionId);

                    KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);

             

            it is not.

            • 3. Re: Is WorkingMemoryLogger working?
              salaboy21

              Yes I saw that behavior before. That's probably because the you are persisting the session and the Environment keeps a reference to the old entity manager that has some value cached. When you reinitialize the environment to load once again the session you clean that object and the session is restored completely fromt the BD and works again without an inconsistent state.

              If you think about the purpose of loading a session, is that you will load the session in a different thread where you need to initialize the environment once again. Cheers