Permalink
Browse files

added a hole node type for testing

  • Loading branch information...
Rafael H. Schloming
Rafael H. Schloming committed Feb 9, 2011
1 parent 5248899 commit 0f242dbad7f243418bd62a1cc1b840efb36a2aea
Showing with 100 additions and 16 deletions.
  1. +16 −15 connection.py
  2. +5 −0 example-nodes
  3. +77 −0 hole.py
  4. +2 −1 messaging.py
View
@@ -35,6 +35,22 @@ class ConnectionError(Exception):
class Connection:
+ # XXX: these should go someplace more central
+ type_decoder = TypeDecoder()
+ type_encoder = TypeEncoder()
+
+ for cls in CLASSES:
+ # XXX: should index some of this stuff and move it elsewhere
+ type_encoder.deconstructors[cls] = lambda v: (v.DESCRIPTORS[0],
+ v.deconstruct())
+ for d in cls.DESCRIPTORS:
+ if cls.SOURCE == "map":
+ const = lambda d, m, c=cls: c(**dict([(pythonize(k.name), v)
+ for (k, v) in m.iteritems()]))
+ else:
+ const = lambda d, l, c=cls: c(*l)
+ type_decoder.constructors[d] = const
+
def __init__(self, factory):
self.id = "%X" % id(self)
self.factory = factory
@@ -49,21 +65,6 @@ def __init__(self, factory):
self.frame_decoder = FrameDecoder()
self.frame_encoder = FrameEncoder()
- self.type_decoder = TypeDecoder()
- self.type_encoder = TypeEncoder()
-
- for cls in CLASSES:
- # XXX: should index some of this stuff and move it elsewhere
- self.type_encoder.deconstructors[cls] = lambda v: (v.DESCRIPTORS[0],
- v.deconstruct())
- for d in cls.DESCRIPTORS:
- if cls.SOURCE == "map":
- const = lambda d, m, c=cls: c(**dict([(pythonize(k.name), v)
- for (k, v) in m.iteritems()]))
- else:
- const = lambda d, l, c=cls: c(*l)
- self.type_decoder.constructors[d] = const
-
self.open_rcvd = False
self.open_sent = False
self.close_rcvd = False
View
@@ -1,3 +1,6 @@
+from queue import Queue
+from hole import Hole
+
queue = Queue()
topic = Queue(ring=0, acquire=False, dequeue=False)
@@ -6,3 +9,5 @@ ring_topic = Queue(ring=10, acquire=False, dequeue=False)
bounded_queue = Queue(threshold=100)
bounded_topic = Queue(threshold=100, ring=0, acquire=False, dequeue=False)
+
+hole = Hole()
View
77 hole.py
@@ -0,0 +1,77 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+from messaging import Message, encode
+from protocol import ACCEPTED, Transfer
+
+class Hole:
+
+ def __init__(self):
+ self.next_id = 0
+
+ def identify(self):
+ id = self.next_id
+ self.next_id += 1
+ return id
+
+ def capacity(self):
+ return True
+
+ def source(self):
+ return Source(self)
+
+ def target(self):
+ return Target(self)
+
+class Source:
+
+ def __init__(self, hole):
+ self.hole = hole
+
+ def get(self):
+ return str(self.hole.identify()), Transfer(fragments=encode(Message()))
+
+ def resume(self, unsettled):
+ pass
+
+ def settle(self, tag, state):
+ pass
+
+ def close(self):
+ pass
+
+class Target:
+
+ def __init__(self, hole):
+ self.hole = hole
+
+ def capacity(self):
+ return self.hole.capacity()
+
+ def put(self, tag, message):
+ pass
+
+ def resume(self, unsettled):
+ pass
+
+ def settle(self, tag):
+ return ACCEPTED
+
+ def close(self):
+ pass
View
@@ -19,6 +19,7 @@
#
from protocol import Fragment, Header, Properties, Footer
+from connection import Connection
class Message:
@@ -48,7 +49,7 @@ def __repr__(self):
# XXX: encode(message) -> fragments, decode(transfer) -> message
# XXX: frag + defrag
-def encode(message, encoder):
+def encode(message, encoder=Connection.type_encoder):
# XXX: constants
head = Fragment(True, True, 0, 0, 0, encoder.encode(message.header))
prop = Fragment(True, True, 1, 1, 0, encoder.encode(message.properties))

0 comments on commit 0f242db

Please sign in to comment.