rpgoldman / europa-pso

Automatically exported from code.google.com/p/europa-pso
0 stars 0 forks source link

Make all listeners behave consistently #18

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
If possible, see:

 * [http://babelfish.arc.nasa.gov/trac/europa/changeset/5093] which changes
behavior for one type of listener.
 * [http://babelfish.arc.nasa.gov/trac/europa/changeset/5098] which fixed a
bug in the above change.

Repeat those changes for all listeners.  Here's the email describing the
above changes:

 Repeat for all other listeners.

Here's my email describing why:

Hi all,

Short form: to guarantee that listeners will be notified in the order they
are added (in the reverse order, actually), I am going to change them from
being stored in a set to being stored in a vector, unless people object. We
were already asserting that a listener never gets added twice.

Long form: I was getting non-deterministic behavior because I had two plan
database listeners: one internal to EUROPA and one that I was creating in
my Java application. Because these were added to the set, their order
depended on the pointers involved. The order of events is interesting:

A) If the java listener is first:

1. Java activates X 2. java listener notified that X activated 3. C++
listener notified that X activated 4. C++ activates slave token Y 5. java
listener notified that Y activated 6. C++ listener notified that Y activated

B) If the C++ listener is first:

1. Java activates X 2. C++ listener notified that X activated 3. C++
activates slave token Y 4. C++ listener notified that Y activated 5. Java
listener notified that Y activated 6. Java listener notified that X activated

Notice that the java listener gets the messages 'backward' in the B, hence
the decisision to use a reverse iterator in the vector of listeners (ie,
since the internal listeners are most likely to be the impolite ones with
side-effects, notify the external listeners first).

Tristan

P.S. Thanks to Matt for solving the conundrum! :) 

Some other comments:

There are a few changes that would be nice:

   1. The ability to give listeners priorities so we can order them however
we want. This is orthogonal to other changes.
   2. No matter what order the listeners are in, each listener should get
events in the order they occur.  This probably requires each publisher to
have a list of messages received, and never start publishing a new message
until it completes sending the previous one to all listeners, to avoid the
problem of #207.
   3. Internal listeners to have higher priority than external listeners.
This should not be done until the previous item, to avoid ruining the fix
in [5093].
   4. Can we unify all listeners?  Is there an external listener library
that would be worth using?
   5. All changes should also have relevant tests added to our new cppUnit
framework. 

Original issue reported on code.google.com by tristanb...@gmail.com on 9 Sep 2009 at 11:43