[CalendarServer-changes] [2654] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Wed Jul 2 12:26:29 PDT 2008


Revision: 2654
          http://trac.macosforge.org/projects/calendarserver/changeset/2654
Author:   wsanchez at apple.com
Date:     2008-07-02 12:26:29 -0700 (Wed, 02 Jul 2008)
Log Message:
-----------
Add a mechanism for registering hooks into the config object.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/config.py
    CalendarServer/trunk/twistedcaldav/tap.py

Modified: CalendarServer/trunk/twistedcaldav/config.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/config.py	2008-07-02 17:20:30 UTC (rev 2653)
+++ CalendarServer/trunk/twistedcaldav/config.py	2008-07-02 19:26:29 UTC (rev 2654)
@@ -243,12 +243,31 @@
         self.setDefaults(defaults)
         self._data = copy.deepcopy(self._defaults)
         self._configFile = None
+        self._hooks = [
+            self.updateDirectoryService,
+            self.updateACLs,
+            self.updateRejectClients,
+            self.updateDropBox,
+            self.updateLogLevels,
+            self.updateThreadPoolSize,
+        ]
 
     def __str__(self):
         return str(self._data)
 
+    def addHook(self, hook):
+        self._hooks.append(hook)
+
     def update(self, items):
         #
+        # Call hooks
+        #
+        for hook in self._hooks:
+            hook(self, items)
+
+    @staticmethod
+    def updateDirectoryService(self, items):
+        #
         # Special handling for directory services configs
         #
         dsType = items.get("DirectoryService", {}).get("type", None)
@@ -275,6 +294,8 @@
             if param not in serviceDefaultParams[self._data["DirectoryService"]["type"]]:
                 del self._data["DirectoryService"]["params"][param]
 
+    @staticmethod
+    def updateACLs(self, items):
         #
         # Base resource ACLs
         #
@@ -347,15 +368,9 @@
 
         log.debug("Nav ACL: %s" % (self.ProvisioningResourceACL.toxml(),))
 
+    @staticmethod
+    def updateRejectClients(self, items):
         #
-        # FIXME: Use the config object instead of doing this here
-        #
-        from twistedcaldav.resource import CalendarPrincipalResource
-        CalendarPrincipalResource.enableDropBox(self.EnableDropBox)
-
-        self.updateLogLevels()
-
-        #
         # Compile RejectClients expressions for speed
         #
         try:
@@ -363,7 +378,16 @@
         except re.error, e:
             raise ConfigurationError("Invalid regular expression in RejectClients: %s" % (e,))
 
-    def updateLogLevels(self):
+    @staticmethod
+    def updateDropBox(self, items):
+        #
+        # FIXME: Use the config object instead of doing this here
+        #
+        from twistedcaldav.resource import CalendarPrincipalResource
+        CalendarPrincipalResource.enableDropBox(self.EnableDropBox)
+
+    @staticmethod
+    def updateLogLevels(self, items):
         clearLogLevels()
 
         try:
@@ -380,6 +404,11 @@
         except InvalidLogLevelError, e:
             raise ConfigurationError("Invalid log level: %s" % (e.level))
 
+    @staticmethod
+    def updateThreadPoolSize(self, items):
+        from twisted.internet import reactor
+        reactor.suggestThreadPoolSize(self.ThreadPoolSize)
+
     def updateDefaults(self, items):
         _mergeData(self._defaults, items)
         self.update(items)
@@ -400,6 +429,7 @@
         raise AttributeError(attr)
 
     def reload(self):
+        log.info("Reloading configuration from file: %s" % (self._configFile,))
         self._data = copy.deepcopy(self._defaults)
         self.loadConfig(self._configFile)
 

Modified: CalendarServer/trunk/twistedcaldav/tap.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/tap.py	2008-07-02 17:20:30 UTC (rev 2653)
+++ CalendarServer/trunk/twistedcaldav/tap.py	2008-07-02 19:26:29 UTC (rev 2654)
@@ -19,7 +19,6 @@
 
 from zope.interface import implements
 
-from twisted.internet import reactor
 from twisted.internet.address import IPv4Address
 
 from twisted.python.log import FileLogObserver
@@ -645,6 +644,11 @@
             maxRequests=config.MaxRequests,
             betweenRequestsTimeOut=config.IdleConnectionTimeOut)
 
+        def updateChannel(config, items):
+            channel.maxRequests = config.MaxRequests
+
+        config.addHook(updateChannel)
+
         if not config.BindAddresses:
             config.BindAddresses = [""]
 
@@ -699,8 +703,6 @@
         # Change log level back to what it was before
         setLogLevelForNamespace(None, oldLogLevel)
 
-        reactor.suggestThreadPoolSize(config.ThreadPoolSize)
-
         return service
 
     makeService_Combined = makeService_Combined
@@ -738,24 +740,19 @@
 
             import signal
             def sighup_handler(num, frame):
-                log.error("SIGHUP recieved at %s" % (location(frame),))
+                log.info("SIGHUP recieved at %s" % (location(frame),))
 
                 # Reload the config file
-                log.info("Reloading configuration file")
                 config.reload()
 
-                log.info("Suggesting size for the reactor threadpool: %r" % (
-                        config.ThreadPoolSize))
-                reactor.suggestThreadPoolSize(config.ThreadPoolSize)
+                # FIXME: There is no memcachepool.getCachePool
+                #   Also, better option is probably to add a hook to
+                #   the config object instead of doing things here.
+                #log.info("Suggesting new max clients for memcache.")
+                #memcachepool.getCachePool().suggestMaxClients(
+                #    config.Memcached["MaxClients"]
+                #)
 
-                log.info("Suggesting new max clients for memcache.")
-                memcachepool.getCachePool().suggestMaxClients(
-                        config.Memcached["MaxClients"])
-
             signal.signal(signal.SIGHUP, sighup_handler)
 
-            #def sigusr1_handler(num, frame):
-            #    log.debug("SIGUSR1 recieved at %s" % (location(frame),))
-            #signal.signal(signal.SIGUSR1, sigusr1_handler)
-
             return service
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080702/f6d84ae2/attachment.html 


More information about the calendarserver-changes mailing list