DuncanDoyle / jboss-brms-6-workshop

12 stars 7 forks source link

Issue during Unmarshall #1

Open rubenghio opened 8 years ago

rubenghio commented 8 years ago

I was doing some tests to your Class "FileKieSessionLoader.java".....

Saving the KieSession worked perfect. The problem is when I am trying to "Load" the kieSession.

A nullpointerException is throwing during DRL when it tries to read a Map with a globals "elements"

My session uses a Global Map "elements" so I am not sure how to tell to uses when is unmarshalling

rubenghio commented 8 years ago

18:30:34,701 ERROR org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/fms-rules-web].[ar.com.cablevision.fms.web.resource.RulesApplication] JBWEB000236: Servlet.service() for servlet ar.com.cablevision.fms.web.resource.RulesApplication threw exception: org.jboss.resteasy.spi.UnhandledException: [Error: null pointer: elements.get("NO")] [Near : {... networkElement.type == element ....}] ^ In [Rule "Posible Caída Parcial por UsCer Hi en PE" in ar/com/cablevision/fms/fms_rules/ruido_cp_uscer_pe.drl]

DuncanDoyle commented 8 years ago

AFAIK, serialisation of globals is not done automatically by the Drools Marshallers. If you look at the code, I serialize the KieBase, KieConfiguration and KieSession. The KieSession serialisation serialises the state of some nodes (only the state which cannot be recreated during replay on de-serialization), the facts in WorkingMemory (session) and the state of the agenda (rule activations, dormant rule activations, etc.).

So, if you're using globals in your KieSession, you will need to serialize them yourself, and re-set them after KieSession deserialisation.

rubenghio commented 8 years ago

Duncan, first of all, thanks for your quick response. BTW, I could get this working during this, if that helps

//Previous to load KieSession File Environment environment = kServices.newEnvironment(); Map<String, Object> globals = new HashMap<String, Object>(); globals.put(ELEMENTS, elements); globals.put(EVENTS, events); globals.put(NOTIFICATIONS, notifications); globals.put(LOGGER, LOG); MapGlobalResolver resolver = new MapGlobalResolver(globals); environment.set(EnvironmentName.GLOBALS, resolver);

//Load Process FileKieSessionLoader loader = new FileKieSessionLoader(new File("/tmp/kieSession.file")); loader.setEnvironment(environment); loader.load();

//Change in FileKieSessionLoader .... KieSession kieSession = marshaller.unmarshall(fis, kieSessionConfiguration, environment); ....