Re: Is a set state called multiple times?

2017-07-28 Thread fengxia
Very helpful indeed! Thank you for the insight Alex. The concern of "doing too much" is exactly what started conversation when we are expecrimenting with charm, because in our design we are using charm as a state-driven framework that interacts with external resources. So it's the sanity of

Re: Is a set state called multiple times?

2017-07-28 Thread Alex Kavanagh
Hi fengxia As Cory says, it's much better to think of the set_state() and remove_state() as binary flags; in fact in the upcoming version, set_state becomes set_flag() and remove_state() becomes remove_flag() -- although the existing functions will still exist for backwards compatibility. So a

Re: Is a set state called multiple times?

2017-07-27 Thread fengxia
Now thinking of it, I just realized that this concept of True state executing repeatedly is actually a good thing. In many cases, there is a need to query external resource for its status. This is often implemented as a polling loop. So in charm, I can implement it as @when("prep") def

Re: Is a set state called multiple times?

2017-07-27 Thread Cory Johns
fengxia, It's probably more enlightening to think of them as "flags" rather than states. (Indeed, the next release of charms.reactive will deprecate calling them states and will provide set_flag, remove_flag, etc. functions instead.) On Thu, Jul 27, 2017 at 3:29 PM, fengxia

Re: Is a set state called multiple times?

2017-07-27 Thread Cory Johns
On Thu, Jul 27, 2017 at 12:29 PM, Tilman Baumann < tilman.baum...@canonical.com> wrote: > Problems with interfaces: > - *.connected state gets dropped when one unit leaves. Not when the > last one leaves. > If this is happening, then it's because the particular interface layer is doing

Re: Is a set state called multiple times?

2017-07-27 Thread fengxia
Alex, Thank you for the detailed explanations and examples. After reading Tilman's and Cory's replies, I think the confusion is at continuous evaluation (thus execution) of a True state. So a pair of @when and @when_not will result in one of them being executed over and over despite adding a

Re: Is a set state called multiple times?

2017-07-27 Thread fengxia
Tilman, This is quite interesting, and I think that's exactly what confused me -- I took @when as event handler, and expected to be executed only on False->True transition, but not being continuously executed if I don't "remove_state" inside itself. On 07/27/2017 12:29 PM, Tilman Baumann

Re: Is a set state called multiple times?

2017-07-27 Thread Tilman Baumann
The confusion comes from the expectations that states are somehow events and @when decorators are event handlers. @when are predicates on states. When predicates are true the decorated code is executed at every hook invocation. If you want to trigger on edges (state changes) you need to build

Re: Is a set state called multiple times?

2017-07-27 Thread Cory Johns
It does seem that the current behavior of re-evaluating handlers despite none of their flags (states) having changed is confusing, particularly for new users, and we are planning on changing this behavior. Unfortunately, there are some charms that have come to rely on the current behavior, so we

Re: Is a set state called multiple times?

2017-07-27 Thread Alex Kavanagh
Hi On Thu, Jul 27, 2017 at 2:37 AM, fengxia wrote: > Hi Juju, > > Once I set a state, set_state("here"), I want to make sure its @when will > only be executed ONCE (when "here" from False->True). > > So my thought is to remove_state("here") in its @when("here") code block. >

Is a set state called multiple times?

2017-07-26 Thread fengxia
Hi Juju, Once I set a state, set_state("here"), I want to make sure its @when will only be executed ONCE (when "here" from False->True). So my thought is to remove_state("here") in its @when("here") code block. If I don't, will this @when be called multiple times if I don't reset this