Patchwork [07,of,15] speedy: add interface hiding client/server communication details

login
register
mail settings
Submitter Tomasz Kleczek
Date Dec. 11, 2012, 6:38 p.m.
Message ID <6a86dedaaeefeaebc8ae.1355251102@dev408.prn1.facebook.com>
Download mbox | patch
Permalink /patch/55/
State Superseded
Headers show

Comments

Tomasz Kleczek - Dec. 11, 2012, 6:38 p.m.
# HG changeset patch
# User Tomasz Kleczek <tkleczek at fb.com>
# Date 1354924803 28800
# Branch stable
# Node ID 6a86dedaaeefeaebc8ae1294eac389604e0072a2
# Parent  62febe888e9b12cd5bb711bea2d70b843b8b4251
speedy: add interface hiding client/server communication details

This patch is a step in providing support for forwarding queries
to a remove server.

It introduces a proxyclient interface that is used by metapeer
to send the query to send the server and receive the respond.

Also provides the simple implementation of the interface for
the local communication.

Patch

diff --git a/hgext/speedy/localtransport.py b/hgext/speedy/localtransport.py
new file mode 100644
--- /dev/null
+++ b/hgext/speedy/localtransport.py
@@ -0,0 +1,23 @@ 
+# Copyright 2012 Facebook
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+"""Local client/server communication conforming to the abstract interface
+
+`Local` means client and server are run in the same interpreter instance.
+"""
+
+import transport
+
+class localclient(transport.clientproxy):
+    """Talks directly to the history server.
+
+    Used when server and client are run in the same interpreter instance.
+    """
+
+    def __init__(self, server):
+        self._server = server
+
+    def request(self, queryname, args):
+        return getattr(self._server, queryname)(*args)
diff --git a/hgext/speedy/transport.py b/hgext/speedy/transport.py
new file mode 100644
--- /dev/null
+++ b/hgext/speedy/transport.py
@@ -0,0 +1,12 @@ 
+# Copyright 2012 Facebook
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+"""Abstracting low-level details of the client/server communication."""
+
+class clientproxy(object):
+
+    def request(queryname, args):
+        raise NotImplementedError
+