##// END OF EJS Templates
peer: add an iterbatcher interface...
Augie Fackler -
r28436:8d38eab2 default
parent child Browse files
Show More
@@ -41,6 +41,14 b' class batcher(object):'
41 41 def submit(self):
42 42 raise NotImplementedError()
43 43
44 class iterbatcher(batcher):
45
46 def submit(self):
47 raise NotImplementedError()
48
49 def results(self):
50 raise NotImplementedError()
51
44 52 class localbatch(batcher):
45 53 '''performs the queued calls directly'''
46 54 def __init__(self, local):
@@ -50,6 +58,19 b' class localbatch(batcher):'
50 58 for name, args, opts, resref in self.calls:
51 59 resref.set(getattr(self.local, name)(*args, **opts))
52 60
61 class localiterbatcher(iterbatcher):
62 def __init__(self, local):
63 super(iterbatcher, self).__init__()
64 self.local = local
65
66 def submit(self):
67 # submit for a local iter batcher is a noop
68 pass
69
70 def results(self):
71 for name, args, opts, resref in self.calls:
72 yield getattr(self.local, name)(*args, **opts)
73
53 74 def batchable(f):
54 75 '''annotation for batchable methods
55 76
@@ -91,6 +112,14 b' class peerrepository(object):'
91 112 def batch(self):
92 113 return localbatch(self)
93 114
115 def iterbatch(self):
116 """Batch requests but allow iterating over the results.
117
118 This is to allow interleaving responses with things like
119 progress updates for clients.
120 """
121 return localiterbatcher(self)
122
94 123 def capable(self, name):
95 124 '''tell whether repo supports named capability.
96 125 return False if not supported.
@@ -114,6 +114,25 b' class remotebatch(peer.batcher):'
114 114 encresref.set(encres)
115 115 resref.set(batchable.next())
116 116
117 class remoteiterbatcher(peer.iterbatcher):
118 def __init__(self, remote):
119 super(remoteiterbatcher, self).__init__()
120 self._remote = remote
121
122 def submit(self):
123 """Break the batch request into many patch calls and pipeline them.
124
125 This is mostly valuable over http where request sizes can be
126 limited, but can be used in other places as well.
127 """
128 rb = self._remote.batch()
129 rb.calls = self.calls
130 rb.submit()
131
132 def results(self):
133 for name, args, opts, resref in self.calls:
134 yield resref.value
135
117 136 # Forward a couple of names from peer to make wireproto interactions
118 137 # slightly more sensible.
119 138 batchable = peer.batchable
@@ -193,6 +212,9 b' class wirepeer(peer.peerrepository):'
193 212 def _submitone(self, op, args):
194 213 return self._call(op, **args)
195 214
215 def iterbatch(self):
216 return remoteiterbatcher(self)
217
196 218 @batchable
197 219 def lookup(self, key):
198 220 self.requirecap('lookup', _('look up remote revision'))
General Comments 0
You need to be logged in to leave comments. Login now