[CalendarServer-changes] [12057] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:24:36 PDT 2014
Revision: 12057
http://trac.calendarserver.org//changeset/12057
Author: wsanchez at apple.com
Date: 2013-12-12 11:27:46 -0800 (Thu, 12 Dec 2013)
Log Message:
-----------
Better plugin-fu.
Modified Paths:
--------------
CalendarServer/trunk/twext/application/masterchild.py
CalendarServer/trunk/twisted/plugins/masterchild.py
Modified: CalendarServer/trunk/twext/application/masterchild.py
===================================================================
--- CalendarServer/trunk/twext/application/masterchild.py 2013-12-12 18:34:30 UTC (rev 12056)
+++ CalendarServer/trunk/twext/application/masterchild.py 2013-12-12 19:27:46 UTC (rev 12057)
@@ -289,6 +289,12 @@
log = Logger()
+ def __init__(self):
+ self.tapname = "master"
+ self.description = self.__class__.__doc__
+ self.options = MasterOptions
+
+
def makeService(self, options):
service = MasterService()
@@ -516,6 +522,12 @@
Child process service maker.
"""
+ def __init__(self):
+ self.tapname = "child"
+ self.description = self.__class__.__doc__
+ self.options = ChildOptions
+
+
def makeService(self, options):
factory = ServerFactory.forProtocol(options["protocol"])
service = ChildService(options["inherited-fd"], factory)
Modified: CalendarServer/trunk/twisted/plugins/masterchild.py
===================================================================
--- CalendarServer/trunk/twisted/plugins/masterchild.py 2013-12-12 18:34:30 UTC (rev 12056)
+++ CalendarServer/trunk/twisted/plugins/masterchild.py 2013-12-12 19:27:46 UTC (rev 12057)
@@ -20,39 +20,66 @@
from twisted.plugin import IPlugin
from twisted.application.service import IServiceMaker
-from twext.application.masterchild import MasterOptions, ChildOptions
@implementer(IPlugin, IServiceMaker)
-class ServiceMaker(object):
- def __init__(self, name, description, options, serviceMakerClass):
- self.tapname = name
- self.description = description
- self.options = options
- self.serviceMakerClass = serviceMakerClass
- self._serviceMaker = None
+class ServiceMakerWrapper(object):
+ """
+ ServiceMaker that instantiates and wraps a ServiceMaker, given a class name
+ and arguments.
+ """
+ def __init__(self, className, *args, **kwargs):
+ """
+ @param className: The fully qualified name of the
+ L{IServiceMaker}-providing class to instiantiate.
+ @type className: L{str}
+ @param args: Sequential arguments to pass to the class's constructor.
+ @type args: arguments L{list}
+
+ @param kwargs: Keyword arguments to pass to the class's constructor.
+ @type args: arguments L{dict}
+ """
+ self.className = className
+ self.args = args
+ self.kwargs = kwargs
+
+
+ @property
+ def wrappedServiceMaker(self):
+ if not hasattr(self, "_wrappedServiceMaker"):
+ makerClass = namedClass(self.className)
+ maker = makerClass(*self.args, **self.kwargs)
+ self._wrappedServiceMaker = maker
+
+ return self._wrappedServiceMaker
+
+
+ @property
+ def tapname(self):
+ return self.wrappedServiceMaker.tapname
+
+
+ @property
+ def description(self):
+ return self.wrappedServiceMaker.description
+
+
+ @property
+ def options(self):
+ return self.wrappedServiceMaker.options
+
+
def makeService(self, options):
- if self._serviceMaker is None:
- self._serviceMaker = namedClass(self.serviceMakerClass)()
+ return self.wrappedServiceMaker.makeService(options)
- return self._serviceMaker.makeService(options)
-
-masterServiceMaker = ServiceMaker(
- "master",
- "Master process application container",
- MasterOptions,
+masterServiceMaker = ServiceMakerWrapper(
"twext.application.masterchild.MasterServiceMaker"
)
-
-
-childServiceMaker = ServiceMaker(
- "child",
- "Child process application container",
- ChildOptions,
+childServiceMaker = ServiceMakerWrapper(
"twext.application.masterchild.ChildServiceMaker"
)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/9cead41a/attachment.html>
More information about the calendarserver-changes
mailing list