[CalendarServer-changes] [12032] CalendarServer/trunk/twext/application/masterchild.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:23:32 PDT 2014
Revision: 12032
http://trac.calendarserver.org//changeset/12032
Author: wsanchez at apple.com
Date: 2013-12-04 16:30:14 -0800 (Wed, 04 Dec 2013)
Log Message:
-----------
Make port and protocol options on master.
Modified Paths:
--------------
CalendarServer/trunk/twext/application/masterchild.py
Modified: CalendarServer/trunk/twext/application/masterchild.py
===================================================================
--- CalendarServer/trunk/twext/application/masterchild.py 2013-12-04 18:02:33 UTC (rev 12031)
+++ CalendarServer/trunk/twext/application/masterchild.py 2013-12-05 00:30:14 UTC (rev 12032)
@@ -15,9 +15,19 @@
##
"""
-Application container
+Application container for a service consisting of a master process that
+accepts connections and dispatches them via inherited file descriptors to
+child processes.
"""
+__all__ = [
+ "MasterOptions",
+ "MasterServiceMaker",
+ "ChildOptions",
+ "ChildServiceMaker",
+]
+
+
import sys
from collections import namedtuple
@@ -46,8 +56,46 @@
Options for a master process.
"""
+ def opt_protocol(self, value):
+ """
+ Protocol
+ """
+ try:
+ protocol = namedClass(value)
+ except (ValueError, AttributeError):
+ raise UsageError("Unknown protocol: {0}".format(value))
+ self["protocol"] = protocol
+
+ def opt_port(self, value):
+ """
+ Inherited file descriptor
+ """
+ try:
+ try:
+ port = int(value)
+ except ValueError:
+ raise ValueError("not an integer")
+
+ if port < 0:
+ raise ValueError("must be >=0")
+
+ except ValueError as e:
+ raise UsageError(
+ "Invalid port number {0!r}: {1}".format(value, e)
+ )
+
+ self["port"] = port
+
+
+ def postOptions(self):
+ for parameter in ("protocol", "port"):
+ if parameter not in self:
+ raise UsageError("{0} parameter is required".format(parameter))
+
+
+
class SpawningInheritingProtocolFactory(InheritingProtocolFactory):
def __init__(self, dispatcher, spawningService, description):
super(SpawningInheritingProtocolFactory, self).__init__(
@@ -67,8 +115,8 @@
def makeService(self, options):
service = MultiService()
- port = 8000
- childProtocol = "twext.protocols.echo.EchoProtocol"
+ port = options["port"]
+ childProtocol = options["protocol"]
# Dispatcher
statusWatcher = StatusWatcher()
@@ -234,6 +282,18 @@
Options for a child process.
"""
+ def opt_protocol(self, value):
+ """
+ Protocol
+ """
+ try:
+ protocol = namedClass(value)
+ except (ValueError, AttributeError):
+ raise UsageError("Unknown protocol: {0}".format(value))
+
+ self["protocol"] = protocol
+
+
def opt_inherited_fd(self, value):
"""
Inherited file descriptor
@@ -255,20 +315,8 @@
self["inherited-fd"] = fd
- def opt_protocol(self, value):
- """
- Protocol
- """
- try:
- protocol = namedClass(value)
- except (ValueError, AttributeError):
- raise UsageError("Unknown protocol: {0}".format(value))
-
- self["protocol"] = protocol
-
-
def postOptions(self):
- for parameter in ("inherited-fd", "protocol"):
+ for parameter in ("protocol", "inherited-fd"):
if parameter not in self:
raise UsageError("{0} parameter is required".format(parameter))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/2f018edd/attachment.html>
More information about the calendarserver-changes
mailing list