[Zope3-dev] Zope3 LifeCycle Events
Ulrich Eck
ueck@net-labs.de
10 Dec 2002 00:44:44 +0100
About Implementing LifeCycle Events for Z3
While prototyping a Task Schedule for Zope3 i thought about
LifeCycle Events for Z3. Right now there is no way for any
component to find out when zope starts or stops.
For a Task Schedule there needs to be some Thread that
takes care about executing Tasks when their time is come.
Our first approach was to start a TimeEventProducer that
publishes an ITimeEvent every n sec/min/hour. Guido mentioned
that this would be ineffective for sites that schedule events
only sometimes - i have a new solution for this. To publish the
TimeEvent we need a Path to a local EventService
(we were talking about requiring an EventService in the RootFolder
and therefore create it automatically).
We can then send a TimeEvent to the persistently subscribed
Schedules whose process there effective Tasks then.
The TimeEventProducer runs in a seperate Thread or from
outside Zope3.
This is really a messy implementation i think.
Things would be much easier if there where LifeCycle Events
for Zope3 e.g.:
* ZopeStartupEvent: Is published after all setup is done when
starting a Zope-Instance
* ZopeRefreshEvent: Is publish when the modules should be reloaded
This could help to implement some equivalent to Refresh in Z2
* ZopeShutdownEvent: Is published before any shutdownprocess begins
(probably hooks into shutdown and signals)
When a Zope3-Instance process is started the EventService in the
RootFolder is connected and a ZopeStartupEvent is published.
All persistently subscribed Components are "woken-up" and allowed
to e.g. register themself within a global service or do some
work that is needed at startup (e.g. start a Thread for the Scheduler)
When shutting down Zope via Web or CTRL-C the ZopeShutdownEvent is
published and all "active" components can cleanup before the
process finishes.
This would generalize the approach i needed to work out
for every component that is interested in the LifeCycle of
a Zope-Process.
What do others thing about that ??
Should i go on and try to prototype this one ??
thanks for your comments,
Ulrich Eck