There are two distinct ways of passing parameters: call by value and call by reference. Passing Java objects blurs this distinction: the reference to the object is passed by value, but the called method can modify the referred object arbitrarily. The called method can not change the reference itself, i.e., the object remains the same.
But what happens during a RMI? The stub on the client's side behaves as you expect. But then the passed object is serialized, the data (not the object) is sent away, and, eventually, some data comes back and is deserialized into another object. And so this is, ultimately, a call by value, copying in to and out from the remotely called method.
Each setJobName RMI creates a clone of Step - so at the end of this little session you have 4 Step objects, the originals (still around as unchanged facts) and the clones in your "results" list.
-W
Method
Step rmiService.setJobName( Step step,...)
could preserve object identity by copying all attributes of the deserialized object into the "in" object.
(Alternatively, the service could pass the entire object hierarchy to maintain integrity, but with parent and children being facts this would complicate matters considerably.)
I now have a more complex problem to solve involving this RMI issue and would
like some advice. I will state this as a simplified example to help explain
the problem.
Assume an object hierarchy:
there is a Job, which has two attributes, a name and a list of Step objects.
Each Step also has a name.
before rules execute, create an instance of Job with no name.
Add two Steps to the Job's step list: one step is named "one" and the other
is named "two"
the knowledge session has a global named "rmiService" that is a remote
application service.
knowledge session also has a global named "results" that is a List (this is
my Box)
there are two rules:
rule1
when
$step : Step(name="one")
then
$step = rmiService.setJobName($step, "i belong to step one"); // sets the
name of the step's job
results.add($step);
end
rule2
when
$step : Step(name="two")
then
$step = rmiService.setJobName($step, "i belong to step two");
results.add($step);
end
call execute() on the session, passing in the Step objects.
assume that both rules fire. after execution, the results global contains
two objects: the step named "one" has a parent job with name "I belong to
step one" and step named "two" has a parent job with name "i belong to step
two" - in other words, they no longer have the same parent Job.
I can't figure out how I can keep a hierarchy of objects updated when there
are multiple RMI calls in the same session.
--
View this message in context: http://drools.46999.n3.nabble.com/how-to-update-object-modified-by-call-to-remote-web-service-tp3204887p3227109.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users