[rules-users] unmarshal global variable
Wolfgang Laun
wolfgang.laun at gmail.com
Mon Jan 7 13:00:53 EST 2013
I suppose you might use the classic Singleton design pattern, insert
the object as a fact (so it'll get marshalled) but access its fields
via classname.staticmethod, which is not much different from a
globalname.staticmethod.
-W
On 07/01/2013, Ormond, Alex C. (GDLP) <ACOrmond at greatdanetrailers.com> wrote:
> Many thanks to all who responded.
>
> Wolfgang, I assume you provided the answer. Thank you, I'll give it a
> shot.
>
> Yes, the rule works separate of marshalling. I can believe there's a
> better way to get constants into the session from a spreadsheet, but
> this is the only way I could get to work.
>
> Yes, I did declare "variables" in the spreadsheet.
>
> Cheers to all,
>
> Alex
>
>
> -----Original Message-----
> From: rules-users-bounces at lists.jboss.org
> [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Wolfgang Laun
> Sent: Monday, January 07, 2013 12:44 PM
> To: Rules Users List
> Subject: Re: [rules-users] unmarshal global variable
>
> A DRL global is not marshalled /unmarshalled along with the session.
> You'll have to marshal/unmarshal this object separately, and setGlobal
> it again in the restored session.
> -W
>
> On 07/01/2013, Ormond, Alex C. (GDLP) <ACOrmond at greatdanetrailers.com>
> wrote:
>> Thanks for the response. The first rule table in the spreadsheet
>> (kinda) looks like this:
>>
>> RuleTable Constants
>> NAME CONDITION ACTION ACTION
>>
>> eval(! productPricer.isConstantsSet($1) )
>> productPricer.setConstant($1, $2);
>> productPricer.setConstantsSet($1);
>> Rule Name Set?
>> ProductName TRUE "NAME", "Champion CL"
>> DefaultCost TRUE "COST", "80000"
>> DefaultPrice TRUE "PRICE", "100000"
>> DefaultLength TRUE "LENGTH", "53"
>> Done TRUE TRUE
>>
>>
>> The first rule generated looks like this:
>>
>> rule "ProductName"
>> when
>> eval(! productPricer.isConstantsSet() )
>> then
>> productPricer.setConstant("NAME", "Champion CL");
>> end
>>
>>
>> Alex
>>
>>
>> -----Original Message-----
>> From: rules-users-bounces at lists.jboss.org
>> [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Wolfgang
> Laun
>> Sent: Monday, January 07, 2013 11:22 AM
>> To: Rules Users List
>> Subject: Re: [rules-users] unmarshal global variable
>>
>> The crucial info is: what is in the first table, how do you insert
> this
>> data?
>> Is it a DRL global? A fact? How does the (generated) rule look like?
>> -W
>>
>> On 07/01/2013, acormond <acormond at greatdanetrailers.com> wrote:
>>> Gentlepeople,
>>>
>>> I am fairly new to Drools and have what I hope is a simple question.
>> I am
>>> attempting to marshal (serialize) a Drools knowledge session and then
>>> unmarshall it. The marshalling works but the unmarshalling fails
> with
>> a
>>> null pointer exception. The error is apparently with unmarshalling a
>>> global
>>> variable in the session.
>>>
>>> The session is created from a spreadsheet (decision table). This
>>> spreadsheet
>>> has two RuleTables. The first of these exists solely so that I can
>> enter
>>> some
>>> constants into the session, specifically the name and price of the
>> product
>>> the
>>> spreadsheet is dealing with. The second ruletable is where the rules
>> are
>>> specified. The exception occurs when unmarshalling the first rule in
>> the
>>> first
>>> rule table. If, as a test, I eliminate the first rule table, then I
>> can
>>> successfully marshal and unmarshall the session.
>>>
>>> The marshalling is done using the following, simplified, code:
>>>
>>> Marshaller marshaller = MarshallerFactory.newMarshaller(kbase);
>>> File droolsSessionFile = new File(MARSHAL_FILE);
>>> foStream = new FileOutputStream(droolsSessionFile);
>>> baos = new ByteArrayOutputStream();
>>> marshaller.marshall(baos, ksession);
>>> baos.writeTo(foStream);
>>>
>>> and the unmarshalling is done like this:
>>>
>>> Marshaller marshaller =
>>> MarshallerFactory.newMarshaller(pricingProcessor.getKnowledgeBase());
>>> FileInputStream fis = new FileInputStream(MARSHAL_FILE);
>>> StatefulKnowledgeSession ksession = marshaller.unmarshall(fis);
>>>
>>>
>>> So, where did I go wrong? Perhaps I need to deal with the global
>> variable
>>> differently, perhaps by putting it in the knowledgeBase before I
>> unmarshall
>>> the session?
>>>
>>> Thank you for any help.
>>>
>>> Alex Ormond
>>>
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>>
>>
> http://drools.46999.n3.nabble.com/unmarshal-global-variable-tp4021375.ht
>> ml
>>> Sent from the Drools: User forum mailing list archive at Nabble.com.
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
More information about the rules-users
mailing list