Re: [rules-users] Initialize Global

2007-10-31 Thread Joshua Undesser

I am doing something similar and having some issues.   I am physically
calling setGlobal, but it doesn't seem to be getting setexample

global String USER_NAME;

rule Initialize Globals
salience 100
when
eval(USRE_NAME == null )
then
String name = Josh;
drools.getWorkingMemory().setGlobal(USER_NAME, name);
System.out.println(Local Name :  + name);
System.out.println(Global Name :  + USER_NAME);
end


This produces

Josh
Null

Not sure I fully follow what is happening.I am calling setGlobal, but
the value does not appear to get set, thus the null in the last output
statement.

Also any other rule I have set up that utilizes the USER_NAME global won't
fire, ie


rule Second Rule to Fire

when
eval(USER_NAME != null)
then
System.out.println(Fired Second Rule);
end

This rule never fires.

Can anyone explain this?  And just to clarify, yes, USER_NAME is going to be
immutable once set.

Thanks in advance!

Joshua





Kris Verlaenen wrote:
 
 You can create a rule that initializes your global, preferrably with a
 high 
 salience so it gets executed first:
 
 rule InitializeGlobal salience 100
   when
   then
 ArrayList objectList = new ArrayList();
 objectList.add(1);
 objectList.add(2);
 drools.getWorkingMemory().setGlobal(objectList, objectList);
 end
 
 Kris
 
 - Original Message - 
 From: drools_user [EMAIL PROTECTED]
 To: rules-users@lists.jboss.org
 Sent: Wednesday, October 24, 2007 7:35 PM
 Subject: [rules-users] Initialize Global
 
 

 How do I initialize a global fact in the drl file?  I want use the JSR94 
 API
 and avoid using the Drools API inside the Java code.  I would like to 
 access
 the same variable every execution of a stateful session without having to
 reinstantiate the variable after each execution?

 Basically I want to define a global like this:
 # Define global variable
 global List objectList ;

 # Part that does not work
 objectList = new ArrayList() ;
 objectList.add(1);
 objectList.add(2);


 Thanks
 -- 
 View this message in context: 
 http://www.nabble.com/Initialize-Global-tf4685186.html#a13388685
 Sent from the drools - user mailing list archive at Nabble.com.

 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users 
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 

-- 
View this message in context: 
http://www.nabble.com/Initialize-Global-tf4685186.html#a13517718
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Initialize Global

2007-10-30 Thread Waruzjan Shahbazian
I have the same problem, but eval(objectList == null) doesn't work. If 
I don't execute drools.getWorkingMemory().setGlobal() it works fine, 
as if the rule activates and the object is null.


global List objectList;

rule Start
   salience 101
   when
   #conditions
   then
   objectList = new ArrayList() ;
   objectList.add(1);
   objectList.add(2);   
   System.out.println(Start objectList:+objectList); 
   //drools.getWorkingMemory().setGlobal(objectList, objectList);

end

rule end
   salience 97
   when
   eval (objectList == null)
   then
   System.out.println(End objectList: +objectList);
end
  
gives:
  
   Start objectList:[1, 2]

   End objectList: null

Next I uncomment the drools.getWorkingMemory().setGlobal(objectList, 
objectList); and run the rule again an get:


   Start objectList:[1, 2]
   End objectList: [1, 2]

so the objectList isn't null, but the rule still activates...

Kris Verlaenen schreef:
That initialized my global but the rule still runs every execution.  
Can I

disable the rule after the first execution?
What do you mean by every execution.  A rule should only be executed 
once, unless it gets reactivated (which should not be the case in this 
situation).


I would like to use (if (objectList==null)).  My list is not 
immutable. Can

I make a similar rule for the LHS?
You can test whether the global is null using eval( objectList == null 
)  in the LHS of the rule.


Kris
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Initialize Global

2007-10-30 Thread vdelbart

If your List is not immutable, you can't use global. You have to use WM
facts.

V.


java_user_ wrote:
 
 Thanks.
 
 That initialized my global but the rule still runs every execution.  Can I
 disable the rule after the first execution?  
 
 I would like to use (if (objectList==null)).  My list is not immutable. 
 Can I make a similar rule for the LHS?
 
 
 
 Kris Verlaenen wrote:
 
 You can create a rule that initializes your global, preferrably with a
 high 
 salience so it gets executed first:
 
 rule InitializeGlobal salience 100
   when
   then
 ArrayList objectList = new ArrayList();
 objectList.add(1);
 objectList.add(2);
 drools.getWorkingMemory().setGlobal(objectList, objectList);
 end
 
 Kris
 
 - Original Message - 
 From: drools_user [EMAIL PROTECTED]
 To: rules-users@lists.jboss.org
 Sent: Wednesday, October 24, 2007 7:35 PM
 Subject: [rules-users] Initialize Global
 
 

 How do I initialize a global fact in the drl file?  I want use the JSR94 
 API
 and avoid using the Drools API inside the Java code.  I would like to 
 access
 the same variable every execution of a stateful session without having
 to
 reinstantiate the variable after each execution?

 Basically I want to define a global like this:
 # Define global variable
 global List objectList ;

 # Part that does not work
 objectList = new ArrayList() ;
 objectList.add(1);
 objectList.add(2);


 Thanks
 -- 
 View this message in context: 
 http://www.nabble.com/Initialize-Global-tf4685186.html#a13388685
 Sent from the drools - user mailing list archive at Nabble.com.

 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users 
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 
 
 

-- 
View this message in context: 
http://www.nabble.com/Initialize-Global-tf4685186.html#a13484636
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Initialize Global

2007-10-30 Thread vdelbart

It's normal.

Globally, the rule engine works in two steps :
 - first : the activation (the when statement)
 - second : the execution (the then statement) with salience, ruleflow ...

In your test, you have in the first step objectList = null and in the second
step objectList = [1, 2].

If you want to re-activate your rule, you have to do an update/insert/remove
action... But you can't do that with globals. So you need to use the WM
facts.



Waruzjan Shahbazian-2 wrote:
 
 I have the same problem, but eval(objectList == null) doesn't work. If 
 I don't execute drools.getWorkingMemory().setGlobal() it works fine, 
 as if the rule activates and the object is null.
 
 global List objectList;
 
 rule Start
 salience 101
 when
 #conditions
 then
 objectList = new ArrayList() ;
 objectList.add(1);
 objectList.add(2);   
 System.out.println(Start objectList:+objectList); 
 //drools.getWorkingMemory().setGlobal(objectList, objectList);
 end
 
 rule end
 salience 97
 when
 eval (objectList == null)
 then
 System.out.println(End objectList: +objectList);
 end

 gives:

 Start objectList:[1, 2]
 End objectList: null
 
 Next I uncomment the drools.getWorkingMemory().setGlobal(objectList, 
 objectList); and run the rule again an get:
 
 Start objectList:[1, 2]
 End objectList: [1, 2]
 
 so the objectList isn't null, but the rule still activates...
 
 Kris Verlaenen schreef:
 That initialized my global but the rule still runs every execution.  
 Can I
 disable the rule after the first execution?
 What do you mean by every execution.  A rule should only be executed 
 once, unless it gets reactivated (which should not be the case in this 
 situation).

 I would like to use (if (objectList==null)).  My list is not 
 immutable. Can
 I make a similar rule for the LHS?
 You can test whether the global is null using eval( objectList == null 
 )  in the LHS of the rule.

 Kris
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 

-- 
View this message in context: 
http://www.nabble.com/Initialize-Global-tf4685186.html#a13484734
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Initialize Global

2007-10-30 Thread Waruzjan Shahbazian
Thanks, that sounds logical to me. I guess I just have to trust that 
the rule where the array gets initialised activates earlier than the 
rule where I need the array. That shouldn't be a problem since I use 
salience and to avoid nullpoint exceptions I can use the if(objectList 
!= null)  in the Then part of the rule where I need the array.


Maybe an idea for the drools developers to create an update function 
for the globals so we can eval on them too...in the future.


vdelbart schreef:

It's normal.

Globally, the rule engine works in two steps :
 - first : the activation (the when statement)
 - second : the execution (the then statement) with salience, ruleflow ...

In your test, you have in the first step objectList = null and in the second
step objectList = [1, 2].

If you want to re-activate your rule, you have to do an update/insert/remove
action... But you can't do that with globals. So you need to use the WM
facts.



Waruzjan Shahbazian-2 wrote:
  
I have the same problem, but eval(objectList == null) doesn't work. If 
I don't execute drools.getWorkingMemory().setGlobal() it works fine, 
as if the rule activates and the object is null.


global List objectList;

rule Start
salience 101
when
#conditions
then
objectList = new ArrayList() ;
objectList.add(1);
objectList.add(2);   
System.out.println(Start objectList:+objectList); 
//drools.getWorkingMemory().setGlobal(objectList, objectList);

end

rule end
salience 97
when
eval (objectList == null)
then
System.out.println(End objectList: +objectList);
end
   
gives:
   
Start objectList:[1, 2]

End objectList: null

Next I uncomment the drools.getWorkingMemory().setGlobal(objectList, 
objectList); and run the rule again an get:


Start objectList:[1, 2]
End objectList: [1, 2]

so the objectList isn't null, but the rule still activates...

Kris Verlaenen schreef:

That initialized my global but the rule still runs every execution.  
Can I

disable the rule after the first execution?

What do you mean by every execution.  A rule should only be executed 
once, unless it gets reactivated (which should not be the case in this 
situation).


  
I would like to use (if (objectList==null)).  My list is not 
immutable. Can

I make a similar rule for the LHS?

You can test whether the global is null using eval( objectList == null 
)  in the LHS of the rule.


Kris
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
  

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users





  


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


RE: [rules-users] Initialize Global

2007-10-30 Thread Anstis, Michael (M.)
This is in essence already catered for - you need a LHS fact.

A global is just a holder for some (immutable) set of values\functions to
make life easier for common (immutable) values\functions your rule may need.

If you want to start making the global mutable for RETE to use the changes
they become facts.

 rule Start
 salience 101
 when
 then
 MyGlobalObject myGlobal = new MyGlobalObject();
 ArrayList objectList = new ArrayList() ;
 objectList.add(1);
 objectList.add(2);   
 myGlobal.setList(objectList);
 System.out.println(Start objectList: + objectList); 
 insert(myGlobal);
 end

 rule end
 salience 97
 when
 $g : MyGlobalObject( list != null )
 then
 System.out.println(End objectList:  + $g.getList());
 end


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Waruzjan
Shahbazian
Sent: 30 October 2007 09:31
To: Rules Users List
Subject: Re: [rules-users] Initialize Global

Thanks, that sounds logical to me. I guess I just have to trust that 
the rule where the array gets initialised activates earlier than the 
rule where I need the array. That shouldn't be a problem since I use 
salience and to avoid nullpoint exceptions I can use the if(objectList 
!= null)  in the Then part of the rule where I need the array.

Maybe an idea for the drools developers to create an update function 
for the globals so we can eval on them too...in the future.

vdelbart schreef:
 It's normal.

 Globally, the rule engine works in two steps :
  - first : the activation (the when statement)
  - second : the execution (the then statement) with salience, ruleflow
...

 In your test, you have in the first step objectList = null and in the
second
 step objectList = [1, 2].

 If you want to re-activate your rule, you have to do an
update/insert/remove
 action... But you can't do that with globals. So you need to use the WM
 facts.



 Waruzjan Shahbazian-2 wrote:
   
 I have the same problem, but eval(objectList == null) doesn't work. If 
 I don't execute drools.getWorkingMemory().setGlobal() it works fine, 
 as if the rule activates and the object is null.

 global List objectList;

 rule Start
 salience 101
 when
 #conditions
 then
 objectList = new ArrayList() ;
 objectList.add(1);
 objectList.add(2);   
 System.out.println(Start objectList:+objectList); 
 //drools.getWorkingMemory().setGlobal(objectList, objectList);
 end

 rule end
 salience 97
 when
 eval (objectList == null)
 then
 System.out.println(End objectList: +objectList);
 end

 gives:

 Start objectList:[1, 2]
 End objectList: null

 Next I uncomment the drools.getWorkingMemory().setGlobal(objectList, 
 objectList); and run the rule again an get:

 Start objectList:[1, 2]
 End objectList: [1, 2]

 so the objectList isn't null, but the rule still activates...

 Kris Verlaenen schreef:
 
 That initialized my global but the rule still runs every execution.  
 Can I
 disable the rule after the first execution?
 
 What do you mean by every execution.  A rule should only be executed 
 once, unless it gets reactivated (which should not be the case in this 
 situation).

   
 I would like to use (if (objectList==null)).  My list is not 
 immutable. Can
 I make a similar rule for the LHS?
 
 You can test whether the global is null using eval( objectList == null 
 )  in the LHS of the rule.

 Kris
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
   
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users


 

   

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


smime.p7s
Description: S/MIME cryptographic signature
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Initialize Global

2007-10-30 Thread java_user_

Hi Kris,

I am using a JSR94 stateful session.  My design is to initialize the global
list once and reuse it within the same session.  

The init-global rule is being executed each execution because there is no
conditional statement.  Can I disable the rule for future executions?

Thanks



Kris Verlaenen wrote:
 
 That initialized my global but the rule still runs every execution.  Can
 I
 disable the rule after the first execution?
 What do you mean by every execution.  A rule should only be executed
 once, 
 unless it gets reactivated (which should not be the case in this
 situation).
 
 I would like to use (if (objectList==null)).  My list is not immutable. 
 Can
 I make a similar rule for the LHS?
 You can test whether the global is null using eval( objectList == null ) 
 in 
 the LHS of the rule.
 
 Kris 
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 

-- 
View this message in context: 
http://www.nabble.com/Initialize-Global-tf4685186.html#a13491481
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


RE: [rules-users] Initialize Global

2007-10-30 Thread Anstis, Michael (M.)
Did you try Kris's suggested LHS?

 You can test whether the global is null using eval( objectList == null ) 
 in the LHS of the rule.

This should provide the condition you request and prevent the rule from
firing after the global has been initialised.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of java_user_
Sent: 30 October 2007 16:06
To: rules-users@lists.jboss.org
Subject: Re: [rules-users] Initialize Global


Hi Kris,

I am using a JSR94 stateful session.  My design is to initialize the global
list once and reuse it within the same session.  

The init-global rule is being executed each execution because there is no
conditional statement.  Can I disable the rule for future executions?

Thanks



Kris Verlaenen wrote:
 
 That initialized my global but the rule still runs every execution.  Can
 I
 disable the rule after the first execution?
 What do you mean by every execution.  A rule should only be executed
 once, 
 unless it gets reactivated (which should not be the case in this
 situation).
 
 I would like to use (if (objectList==null)).  My list is not immutable. 
 Can
 I make a similar rule for the LHS?
 You can test whether the global is null using eval( objectList == null ) 
 in 
 the LHS of the rule.
 
 Kris 
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 

-- 
View this message in context:
http://www.nabble.com/Initialize-Global-tf4685186.html#a13491481
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


smime.p7s
Description: S/MIME cryptographic signature
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


RE: [rules-users] Initialize Global

2007-10-30 Thread java_user_

Yes, I used the conditional eval(objectList == null)
The global keeps getting destroyed after each execution.  I am using a
stateful rule session.  I was hoping the global could be reused for each
execution without having to re-init.

I was able to do this in Jess by instantiating the global without having to
use a rule.  Then I was able to use the same list each execution of my
stateful session without having to recreate the list.  The Jess list is an
internal Jess object and not a Java ArrayList.
Jess Code to declare and initialize a global list:
(defglobal ?*objectList* = 
(create$
  (new String  s0) 
  (new String  s1) 
)
)



Anstis, Michael (M.) wrote:
 
 Did you try Kris's suggested LHS?
 
 You can test whether the global is null using eval( objectList == null ) 
 in the LHS of the rule.
 
 This should provide the condition you request and prevent the rule from
 firing after the global has been initialised.
 
 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of java_user_
 Sent: 30 October 2007 16:06
 To: rules-users@lists.jboss.org
 Subject: Re: [rules-users] Initialize Global
 
 
 Hi Kris,
 
 I am using a JSR94 stateful session.  My design is to initialize the
 global
 list once and reuse it within the same session.  
 
 The init-global rule is being executed each execution because there is no
 conditional statement.  Can I disable the rule for future executions?
 
 Thanks
 
 
 
 Kris Verlaenen wrote:
 
 That initialized my global but the rule still runs every execution.  Can
 I
 disable the rule after the first execution?
 What do you mean by every execution.  A rule should only be executed
 once, 
 unless it gets reactivated (which should not be the case in this
 situation).
 
 I would like to use (if (objectList==null)).  My list is not immutable. 
 Can
 I make a similar rule for the LHS?
 You can test whether the global is null using eval( objectList == null ) 
 in 
 the LHS of the rule.
 
 Kris 
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 
 
 -- 
 View this message in context:
 http://www.nabble.com/Initialize-Global-tf4685186.html#a13491481
 Sent from the drools - user mailing list archive at Nabble.com.
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
  
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 

-- 
View this message in context: 
http://www.nabble.com/Initialize-Global-tf4685186.html#a13493442
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Initialize Global

2007-10-29 Thread java_user_

Thanks.

That initialized my global but the rule still runs every execution.  Can I
disable the rule after the first execution?  

I would like to use (if (objectList==null)).  My list is not immutable.  Can
I make a similar rule for the LHS?



Kris Verlaenen wrote:
 
 You can create a rule that initializes your global, preferrably with a
 high 
 salience so it gets executed first:
 
 rule InitializeGlobal salience 100
   when
   then
 ArrayList objectList = new ArrayList();
 objectList.add(1);
 objectList.add(2);
 drools.getWorkingMemory().setGlobal(objectList, objectList);
 end
 
 Kris
 
 - Original Message - 
 From: drools_user [EMAIL PROTECTED]
 To: rules-users@lists.jboss.org
 Sent: Wednesday, October 24, 2007 7:35 PM
 Subject: [rules-users] Initialize Global
 
 

 How do I initialize a global fact in the drl file?  I want use the JSR94 
 API
 and avoid using the Drools API inside the Java code.  I would like to 
 access
 the same variable every execution of a stateful session without having to
 reinstantiate the variable after each execution?

 Basically I want to define a global like this:
 # Define global variable
 global List objectList ;

 # Part that does not work
 objectList = new ArrayList() ;
 objectList.add(1);
 objectList.add(2);


 Thanks
 -- 
 View this message in context: 
 http://www.nabble.com/Initialize-Global-tf4685186.html#a13388685
 Sent from the drools - user mailing list archive at Nabble.com.

 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users 
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 

-- 
View this message in context: 
http://www.nabble.com/Initialize-Global-tf4685186.html#a13471016
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Initialize Global

2007-10-29 Thread Kris Verlaenen

That initialized my global but the rule still runs every execution.  Can I
disable the rule after the first execution?
What do you mean by every execution.  A rule should only be executed once, 
unless it gets reactivated (which should not be the case in this situation).


I would like to use (if (objectList==null)).  My list is not immutable. 
Can

I make a similar rule for the LHS?
You can test whether the global is null using eval( objectList == null )  in 
the LHS of the rule.


Kris 


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


RE: [rules-users] Initialize Global

2007-10-25 Thread Anstis, Michael (M.)
Do you want a true global variable or a fact available to all rules?

Either way, you could have a rule to set it up...

Rule init-global
When
Then
myGlobal.doSomethingToInitialiseIt();
End

Rule init-fact
When
$f : MyFact()
Then
$f.doSomethingToInitialiseIt();
End


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of drools_user
Sent: 24 October 2007 18:35
To: rules-users@lists.jboss.org
Subject: [rules-users] Initialize Global


How do I initialize a global fact in the drl file?  I want use the JSR94 API
and avoid using the Drools API inside the Java code.  I would like to access
the same variable every execution of a stateful session without having to
reinstantiate the variable after each execution?

Basically I want to define a global like this:
# Define global variable
global List objectList ;

# Part that does not work
objectList = new ArrayList() ;
objectList.add(1);
objectList.add(2); 


Thanks
-- 
View this message in context:
http://www.nabble.com/Initialize-Global-tf4685186.html#a13388685
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


smime.p7s
Description: S/MIME cryptographic signature
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Initialize Global

2007-10-25 Thread Kris Verlaenen
You can create a rule that initializes your global, preferrably with a high 
salience so it gets executed first:


rule InitializeGlobal salience 100
 when
 then
   ArrayList objectList = new ArrayList();
   objectList.add(1);
   objectList.add(2);
   drools.getWorkingMemory().setGlobal(objectList, objectList);
end

Kris

- Original Message - 
From: drools_user [EMAIL PROTECTED]

To: rules-users@lists.jboss.org
Sent: Wednesday, October 24, 2007 7:35 PM
Subject: [rules-users] Initialize Global




How do I initialize a global fact in the drl file?  I want use the JSR94 
API
and avoid using the Drools API inside the Java code.  I would like to 
access

the same variable every execution of a stateful session without having to
reinstantiate the variable after each execution?

Basically I want to define a global like this:
# Define global variable
global List objectList ;

# Part that does not work
objectList = new ArrayList() ;
objectList.add(1);
objectList.add(2);


Thanks
--
View this message in context: 
http://www.nabble.com/Initialize-Global-tf4685186.html#a13388685

Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users 


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Initialize Global

2007-10-25 Thread vdelbart

Beware,

2.5.4.5. Globals
If you use a global on the LHS of a rule, make sure it is immutable.

regards,

V.


java_user_ wrote:
 
 How do I initialize a global fact in the drl file?  I want use the JSR94
 API and avoid using the Drools API inside the Java code.  I would like to
 access the same variable every execution of a stateful session without
 having to reinstantiate the variable after each execution?
 
 Basically I want to define a global like this:
 # Define global variable
 global List objectList ;
 
 # Part that does not work
 objectList = new ArrayList() ;
 objectList.add(1);
 objectList.add(2); 
 
 
 Thanks
 

-- 
View this message in context: 
http://www.nabble.com/Initialize-Global-tf4685186.html#a13406827
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users