Liskov'ify feed & merge.

This commit is contained in:
Stephen Diehl
2012-05-16 17:30:10 -04:00
parent b1f8bbd189
commit 7f4c94d4e1
3 changed files with 36 additions and 170 deletions
+19 -10
View File
@@ -2,10 +2,11 @@ from feed import Feed
import zipline.protocol as zp
from zipline.protocol import COMPONENT_TYPE
from zipline.components.aggregator import Aggregate
from collections import Counter
class Merge(Feed):
class Merge(Aggregate):
"""
Merges multiple streams of events into single messages.
"""
@@ -27,14 +28,28 @@ class Merge(Feed):
def get_id(self):
return "MERGE"
@property
def get_type(self):
return COMPONENT_TYPE.CONDUIT
# -------
# Sockets
# -------
def open(self):
self.pull_socket = self.bind_merge()
self.feed_socket = self.bind_result()
# -------
# Framing
# -------
def unframe(self, msg):
return zp.TRANSFORM_UNFRAME(msg)
def frame(self, event):
return zp.MERGE_FRAME(event)
# ---------
# Data Flow
# ---------
def next(self):
"""Get the next merged message from the feed buffer."""
if not (self.is_full() or self.draining):
@@ -53,12 +68,6 @@ class Merge(Feed):
result.merge(cur)
return result
def unframe(self, msg):
return zp.TRANSFORM_UNFRAME(msg)
def frame(self, event):
return zp.MERGE_FRAME(event)
def append(self, event):
"""
:param event: a ndict with one entry. key is the name of the