> On Oct 10, 2016, at 4:38 PM, Daniel Sutcliffe <dan...@gmail.com> wrote:
>
> Generically, can I somehow bubble up events through the Service
> hierarchy, or should I communicate with external objects to the
> hierarchy that can bubble down actions from higher up?
Following the <https://en.wikipedia.org/wiki/Single_responsibility_principle
<https://en.wikipedia.org/wiki/Single_responsibility_principle>>, the service
hierarchy's job is just to make sure everything gets started up and shut down
together.
It sounds to me like you have a pretty well-defined hierarchy which seems like
it fits into the service hierarchy because it's roughly parallel in terms of
which objects participate; however, you have very application-specific
semantics for this parallel hierarchy. For example, it's pretty unusual to
have a super-service reconfigure a subordinate service in order to recover from
an error condition, in my experience, unless you're talking about stuff like
erlang supervision hierarchies, but that requires runtime support like the code
being recovered running in a subprocess that doesn't share state.
It often feels like abstractions are expensive so you should have as few of
them as possible; but, in reality, *simple* abstractions are cheap, and what
makes abstraction expensive is when you overload them. Make a new, simple
abstraction that contains exactly the semantics you just described, and use
composition to point at the appropriate point in the MultiService hierarchy.
When it's time to "stop" a service, do setServiceParent(None); when it's time
to "start" it, do setServiceParent(appropriateServiceParent). This should take
care of keeping your services in the appropriate state.
BTW, if you have stateful long-running services that have to self-modify based
on changing circumstances, you might want to also check out
https://github.com/glyph/automat <https://github.com/glyph/automat> to see if
it can help you ensure that everything's in a consistent state.
Good luck!
-glyph
_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python