Permalink
Browse files

some refactoring

  • Loading branch information...
progrium committed Feb 21, 2012
1 parent e2c6acd commit 710b55235ee9e843df39f96d04702abcec02d08f
Showing with 11 additions and 6 deletions.
  1. +4 −0 stomp4py/frame.py
  2. +7 −6 stomp4py/server/base.py
View
@@ -9,6 +9,7 @@ def __init__(self, command, headers=None, body=None):
if self.headers is None:
self.headers = {}
self.body = body or ''
+ self.conn_id = 0
self.error = None
@property
@@ -51,6 +52,9 @@ def receipt_id(self):
""" RECEIPT, ERROR """
return self.headers.get('receipt-id')
+ def __repr__(self):
+ return "<StompFrame:%s %s \"%s\">" % (self.command, self.headers, self.body)
+
def pack(self):
"""Pack the frame as a string
View
@@ -4,10 +4,10 @@
import socket
class Subscription(object):
- def __init__(self, handler, id, destination):
+ def __init__(self, handler, frame):
self.handler = handler
- self.id = id
- self.destination = destination
+ self.id = frame.id or uuid.uuid4().hex
+ self.destination = frame.destination
self.active = True
def send(self, body, headers=None):
@@ -20,6 +20,7 @@ def cancel(self):
self.active = False
class BaseHandler(object):
+ subscription_class = Subscription
def __init__(self, app=None):
if app:
@@ -65,6 +66,7 @@ def _send_message(self, subscription, body, headers=None):
self._send("MESSAGE", headers, body)
def _dispatch(self, frame):
+ frame.conn_id = id(self)
handler = 'handle_%s' % frame.command.lower()
if hasattr(self, handler):
getattr(self, handler)(frame)
@@ -95,9 +97,8 @@ def handle_send(self, frame):
def handle_subscribe(self, frame):
if frame.ack == 'auto':
- id = frame.id or uuid.uuid4().hex
- subscription = Subscription(self, id, frame.destination)
- self.subscriptions[id] = subscription
+ subscription = self.subscription_class(self, frame)
+ self.subscriptions[subscription.id] = subscription
self.app(frame, subscription)
else:
frame.error = "Ack mode 'auto' is the only supported mode"

0 comments on commit 710b552

Please sign in to comment.