Nested Interleaves
Hi!
Is it possible to use nested Interleaves? Consider a scenerio where we have a set of mutually independent receiver-sets that can run concurrently, but individual receivers in each set require to run exclusively within the set.
For example, receivers A, B, C use part S1 of state and hence require running mutually exclusively. Again, receivers D, E, F run mutually exclusively as they modify part S2 of the system state. However, The sets ABC and DEF can run mutually concurrent as they deal with different parts of state. Again, for receivers that work simultaneously with both parts of the state may run exclusively against these sets.
I have found a lot of need for this pattern in complex orchestration programs, but I'm not sure if such a pattern would work.
Piyoosh
[1044 byte] By [
Piyoosh] at [2008-2-12]
YOu can do what you want by using two independent interleaves, then using a special Update message, that is dealt by handler that is in both interleaves. That special Update modifies state that both sets of interleaves need to be exclusive with. This update handler is effectively now running exclusively to both sets of interleaves
this gives you maximum concurrency, and keeps things compositional (the interleaves dont know about each other and just submit a message when they want to update state that affects everyone)
g
This is the right approach, the two side by side interleaves is what you want. Omit brings up one good point about the teardown: When you post a TearDownMessage one of the handlers will fire. But it has an easy workaround. Within your TearDownHandler just post back the TeardownMessage in your teardown post. This way all handlers (it does not matter how many interleaves share this teardown port) will execute and the port will end up with one extra teardown message, which is ok (it will GC anyway)