[CalendarServer-changes] [12546] CalendarServer/trunk/txdav/dps
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:23:03 PDT 2014
Revision: 12546
http://trac.calendarserver.org//changeset/12546
Author: sagen at apple.com
Date: 2014-02-03 16:55:57 -0800 (Mon, 03 Feb 2014)
Log Message:
-----------
Reuse AMP connection
Modified Paths:
--------------
CalendarServer/trunk/txdav/dps/client.py
CalendarServer/trunk/txdav/dps/protocol.py
CalendarServer/trunk/txdav/dps/service.py
Modified: CalendarServer/trunk/txdav/dps/client.py
===================================================================
--- CalendarServer/trunk/txdav/dps/client.py 2014-02-03 22:00:02 UTC (rev 12545)
+++ CalendarServer/trunk/txdav/dps/client.py 2014-02-04 00:55:57 UTC (rev 12546)
@@ -18,29 +18,34 @@
from twext.who.idirectory import RecordType
from twext.python.log import Logger
from twisted.internet import reactor
+from twisted.internet.defer import inlineCallbacks
+
import sys
log = Logger()
-
-def makeBetterRequest():
-
+ at inlineCallbacks
+def makeEvenBetterRequest():
shortName = sys.argv[1]
ds = DirectoryService(None)
- d = ds.recordWithShortName(RecordType.user, shortName)
+ record = (yield ds.recordWithShortName(RecordType.user, shortName))
+ print("A: {r}".format(r=record))
+ record = (yield ds.recordWithShortName(RecordType.user, shortName))
+ print("B: {r}".format(r=record))
- def gotResults(record):
- print('Done: %s' % (record,))
- reactor.stop()
- def gotError(failure):
- print("Failure: %s" % (failure,))
- reactor.stop()
+def succeeded(result):
+ print("yay")
+ reactor.stop()
- d.addCallbacks(gotResults, gotError)
- reactor.run()
+def failed(failure):
+ print("boo: {f}".format(f=failure))
+ reactor.stop()
+
if __name__ == '__main__':
- makeBetterRequest()
+ d = makeEvenBetterRequest()
+ d.addCallbacks(succeeded, failed)
+ reactor.run()
Modified: CalendarServer/trunk/txdav/dps/protocol.py
===================================================================
--- CalendarServer/trunk/txdav/dps/protocol.py 2014-02-03 22:00:02 UTC (rev 12545)
+++ CalendarServer/trunk/txdav/dps/protocol.py 2014-02-04 00:55:57 UTC (rev 12546)
@@ -18,6 +18,7 @@
from twisted.protocols import amp
from twisted.internet.defer import inlineCallbacks, returnValue
from twext.python.log import Logger
+
import cPickle as pickle
log = Logger()
@@ -36,6 +37,7 @@
class DirectoryProxyAMPProtocol(amp.AMP):
"""
+ Server side of directory proxy
"""
def __init__(self, directory):
Modified: CalendarServer/trunk/txdav/dps/service.py
===================================================================
--- CalendarServer/trunk/txdav/dps/service.py 2014-02-03 22:00:02 UTC (rev 12545)
+++ CalendarServer/trunk/txdav/dps/service.py 2014-02-04 00:55:57 UTC (rev 12546)
@@ -14,11 +14,15 @@
# limitations under the License.
##
-from twext.who.xml import DirectoryService as XMLDirectoryService
-from twext.who.index import DirectoryService as BaseDirectoryService
+# Temporary:
+from txdav.who.xml import DirectoryService as XMLDirectoryService
+
+
+from twext.who.directory import DirectoryService as BaseDirectoryService
from twext.who.directory import DirectoryRecord as BaseDirectoryRecord
from twext.who.util import ConstantsContainer
-from twext.who.idirectory import RecordType
+import twext.who.idirectory
+import txdav.who.idirectory
from twisted.python.usage import Options, UsageError
from twisted.plugin import IPlugin
@@ -34,6 +38,7 @@
from .protocol import DirectoryProxyAMPProtocol, RecordWithShortNameCommand
from twisted.internet import reactor
+from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet.protocol import ClientCreator
from twisted.protocols import amp
import cPickle as pickle
@@ -42,16 +47,29 @@
class DirectoryService(BaseDirectoryService):
+ """
+ Client side of directory proxy
+ """
recordType = ConstantsContainer(
- (RecordType.user, RecordType.group)
+ (twext.who.idirectory.RecordType,
+ txdav.who.idirectory.RecordType)
)
+
+ @inlineCallbacks
def _getConnection(self):
# path = config.DirectoryProxy.SocketPath
path = "data/Logs/state/directory-proxy.sock"
- return ClientCreator(reactor, amp.AMP).connectUNIX(path)
+ if getattr(self, "_connection", None) is None:
+ log.debug("Creating connection")
+ connection = (yield ClientCreator(reactor, amp.AMP).connectUNIX(path))
+ self._connection = connection
+ else:
+ log.debug("Already have connection")
+ returnValue(self._connection)
+
def recordWithShortName(self, recordType, shortName):
def deserialize(result):
@@ -78,6 +96,8 @@
pass
+
+
class DirectoryProxyAMPFactory(Factory):
"""
"""
@@ -92,6 +112,8 @@
+
+
class DirectoryProxyOptions(Options):
optParameters = [[
"config", "f", DEFAULT_CONFIG_FILE, "Path to configuration file."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/77c37743/attachment.html>
More information about the calendarserver-changes
mailing list