[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl - IServerControl.py:1.2.28.1 ServerControl.py:1.2.28.1 configure.zcml:1.2.22.1 meta.zcml:1.1.26.1 metaConfigure.py:1.2.28.1

Ulrich Eck ueck@net-labs.de
Wed, 11 Dec 2002 06:18:32 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl
In directory cvs.zope.org:/tmp/cvs-serv20269/ServerControl

Modified Files:
      Tag: jack-e_scheduler_branch
	IServerControl.py ServerControl.py configure.zcml meta.zcml 
	metaConfigure.py 
Log Message:
added startup_hook for ServerControl


=== Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl/IServerControl.py 1.2 => 1.2.28.1 ===
--- Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl/IServerControl.py:1.2	Mon Jun 10 19:27:51 2002
+++ Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl/IServerControl.py	Wed Dec 11 06:18:32 2002
@@ -36,6 +36,12 @@
        zope. You can register using this interface or the zcml on the global
        ServerController instance."""
 
+    def startup():
+        """Startup the server gracefully
+
+                Returns: Nothing
+        """
+
     def shutdown():
         """Shutdown the server gracefully
 
@@ -47,6 +53,10 @@
 
                 Returns: Nothing
         """
+
+    def registerStartupHook(call, priority, name):
+        """Register a function that will be callen on server startup.
+           The function needs to takes no argument at all."""
 
     def registerShutdownHook(call, priority, name):
         """Register a function that will be callen on server shutdown.


=== Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl/ServerControl.py 1.2 => 1.2.28.1 ===
--- Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl/ServerControl.py:1.2	Mon Jun 10 19:27:51 2002
+++ Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl/ServerControl.py	Wed Dec 11 06:18:32 2002
@@ -27,17 +27,30 @@
     __implements__ = IServerControl
 
     def __init__(self):
+        self._startup_reg = {}     # This is the actual startup registry.
         self._shutdown_reg = {}    # This is the actual shutdown registry.
                                    # It will hold the hooks accessible by their
                                    # priority. The priority actually needs to be
                                    # a floating point value, to allow most fine
                                    # grained control on the priority.
-
+                                   
     ############################################################
     # Implementation methods for interface
     # Zope.App.OFS.ApplicationControl.ServerControl.IServerControl.
 
-    def shutdown(self):
+    # XXX We need app/zodb for Startup/Shutdown probably !!!
+
+    def startup(self, _zodb=None):
+        'See Zope.App.OFS.ApplicationControl.ServerControl.IServerControl.IServerControl'
+        text = ""
+        order = self._startup_reg.keys()
+        order.sort()
+
+        for hook_ in order:
+            hook = self._startup_reg[hook_]
+            hook[0](_zodb)
+
+    def shutdown(self, _zodb=None):
         'See Zope.App.OFS.ApplicationControl.ServerControl.IServerControl.IServerControl'
         text = ""
         order = self._shutdown_reg.keys()
@@ -45,11 +58,23 @@
 
         for hook_ in order:
                 hook = self._shutdown_reg[hook_]
-                hook[0]()
+                hook[0](_zodb)
 
     def restart(self):
         'See Zope.App.OFS.ApplicationControl.ServerControl.IServerControl.IServerControl'
 
+    def registerStartupHook(self, call, priority, name):
+        'See Zope.App.OFS.ApplicationControl.ServerControl.IServerControl.IServerControl'
+
+        priority = float(priority)
+        if priority in self._startup_reg:
+            raise DoublePriorityError, (call, priority, name)
+
+        if not callable(call):
+            raise NotCallableError, (call, priority, name)
+
+        self._startup_reg.update({priority: (call, name)})
+
     def registerShutdownHook(self, call, priority, name):
         'See Zope.App.OFS.ApplicationControl.ServerControl.IServerControl.IServerControl'
 
@@ -66,9 +91,12 @@
     #
     ############################################################
 
-
+## simple log notification for startup
+def startupLogger(_zodb=None):
+    """simple startup logger"""
+    zLOG.LOG("ServerControl", zLOG.INFO, "Server is starting up.")
 
 ## simple log notification for shutdown
-def shutdownLogger():
+def shutdownLogger(_zodb=None):
     """simple shutdown logger"""
     zLOG.LOG("ServerControl", zLOG.INFO, "Server is going to be shut down.")


=== Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl/configure.zcml 1.2 => 1.2.22.1 ===
--- Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl/configure.zcml:1.2	Thu Jun 20 11:54:48 2002
+++ Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl/configure.zcml	Wed Dec 11 06:18:32 2002
@@ -7,6 +7,13 @@
            permission="Zope.ManageApplication"
            provides=".IServerControl." />
 
+  <!-- Hint: Here you see how to register something on Zope startup -->
+  <server-control:registerStartupHook
+       name="Startup logger"
+       priority="0"
+       call=".ServerControl.startupLogger"
+       />
+
   <!-- Hint: Here you see how to register something on Zope shutdown -->
   <server-control:registerShutdownHook
        name="Shutdown logger"


=== Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl/meta.zcml 1.1 => 1.1.26.1 ===
--- Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl/meta.zcml:1.1	Mon Jun 17 14:31:25 2002
+++ Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl/meta.zcml	Wed Dec 11 06:18:32 2002
@@ -1,6 +1,11 @@
 <zopeConfigure xmlns='http://namespaces.zope.org/zope'>
 
   <directives namespace="http://namespaces.zope.org/server-control">
+
+    <directive name="registerStartupHook"
+               attributes="call priority name"
+               handler=".metaConfigure.registerStartupHook" />
+
     <directive name="registerShutdownHook"
                attributes="call priority name"
                handler=".metaConfigure.registerShutdownHook" />


=== Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl/metaConfigure.py 1.2 => 1.2.28.1 ===
--- Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl/metaConfigure.py:1.2	Mon Jun 10 19:27:51 2002
+++ Zope3/lib/python/Zope/App/OFS/ApplicationControl/ServerControl/metaConfigure.py	Wed Dec 11 06:18:32 2002
@@ -20,6 +20,15 @@
 from IServerControl import IServerControl
 from Zope.Configuration.Action import Action
 
+def registerStartupHook(_context, call, name, priority):
+    """Register a startup hook with the current server control utility"""
+    return [
+        Action(
+            discriminator = ('server-control:registerStartupHook', name),
+            callable = doRegisterStartupHook,
+            args = (_context, call, priority, name),
+            )
+        ]
 
 def registerShutdownHook(_context, call, name, priority):
     """Register a shutdown hook with the current server control utility"""
@@ -31,7 +40,13 @@
             )
         ]
 
+
+def doRegisterStartupHook(_context, call, priority, name):
+    server_control = getUtility(_context, IServerControl)
+    server_control.registerStartupHook(_context.resolve(call), priority, name)
+
 def doRegisterShutdownHook(_context, call, priority, name):
     server_control = getUtility(_context, IServerControl)
     server_control.registerShutdownHook(_context.resolve(call), priority, name)
+