qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject svn commit: r1630895 - in /qpid/proton/branches/examples: proton-c/bindings/python/proton.py tutorial/helloworld.py tutorial/proton_events.py tutorial/proton_server.py
Date Fri, 10 Oct 2014 14:00:03 GMT
Author: gsim
Date: Fri Oct 10 14:00:02 2014
New Revision: 1630895

URL: http://svn.apache.org/r1630895
Log:
Updated to work with latest event class from trunk

Modified:
    qpid/proton/branches/examples/proton-c/bindings/python/proton.py
    qpid/proton/branches/examples/tutorial/helloworld.py
    qpid/proton/branches/examples/tutorial/proton_events.py
    qpid/proton/branches/examples/tutorial/proton_server.py

Modified: qpid/proton/branches/examples/proton-c/bindings/python/proton.py
URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/proton-c/bindings/python/proton.py?rev=1630895&r1=1630894&r2=1630895&view=diff
==============================================================================
--- qpid/proton/branches/examples/proton-c/bindings/python/proton.py (original)
+++ qpid/proton/branches/examples/proton-c/bindings/python/proton.py Fri Oct 10 14:00:02 2014
@@ -2911,6 +2911,10 @@ class Delivery(object):
       self._dlv = None
 
   @property
+  def released(self):
+    return self._dlv is None
+
+  @property
   def tag(self):
     return pn_delivery_tag(self._dlv)
 
@@ -3422,6 +3426,62 @@ class Event:
       collector._contexts.remove(self.context)
       self.context._released()
 
+  @property
+  def connection(self):
+    if self.clazz == "pn_connection":
+      return self.context
+    elif self.clazz == "pn_session":
+      return self.context.connection
+    elif self.clazz == "pn_link":
+      return self.context.connection
+    elif self.clazz == "pn_delivery" and not self.context.released:
+      return self.context.link.connection
+    else:
+      return None
+
+  @property
+  def session(self):
+    if self.clazz == "pn_session":
+      return self.context
+    elif self.clazz == "pn_link":
+      return self.context.session
+    elif self.clazz == "pn_delivery" and not self.context.released:
+      return self.context.link.session
+    else:
+      return None
+
+  @property
+  def link(self):
+    if self.clazz == "pn_link":
+      return self.context
+    elif self.clazz == "pn_delivery" and not self.context.released:
+      return self.context.link
+    else:
+      return None
+
+  @property
+  def sender(self):
+    l = self.link
+    if l and l.is_sender:
+      return l
+    else:
+      return None
+
+  @property
+  def receiver(self):
+    l = self.link
+    if l and l.is_receiver:
+      return l
+    else:
+      return None
+
+  @property
+  def delivery(self):
+    if self.clazz == "pn_delivery":
+      return self.context
+    else:
+      return None
+
   def __repr__(self):
     return "%s(%s)" % (pn_event_type_name(self.type), self.context)
 

Modified: qpid/proton/branches/examples/tutorial/helloworld.py
URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/tutorial/helloworld.py?rev=1630895&r1=1630894&r2=1630895&view=diff
==============================================================================
--- qpid/proton/branches/examples/tutorial/helloworld.py (original)
+++ qpid/proton/branches/examples/tutorial/helloworld.py Fri Oct 10 14:00:02 2014
@@ -31,8 +31,8 @@ class HelloWorld(proton_events.BaseHandl
         self.conn.create_sender(self.address)
 
     def on_credit(self, event):
-        event.link.send_msg(Message(body=u"Hello World!"))
-        event.link.close()
+        event.sender.send_msg(Message(body=u"Hello World!"))
+        event.sender.close()
 
     def on_message(self, event):
         print event.message.body

Modified: qpid/proton/branches/examples/tutorial/proton_events.py
URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/tutorial/proton_events.py?rev=1630895&r1=1630894&r2=1630895&view=diff
==============================================================================
--- qpid/proton/branches/examples/tutorial/proton_events.py (original)
+++ qpid/proton/branches/examples/tutorial/proton_events.py Fri Oct 10 14:00:02 2014
@@ -281,45 +281,27 @@ class Events(object):
         return self.collector.peek() == None
 
 class ApplicationEvent(Event):
-    CATEGORY_GENERAL = "general"
-
     def __init__(self, type, connection=None, session=None, link=None, delivery=None, subject=None):
         self.type = type
-        self.transport = None
         self.subject = subject
         if delivery:
-            self.delivery = delivery
-            self.link = delivery.link
-            self.session = self.link.session
-            self.connection = self.session.connection
-            self.category = Event.CATEGORY_DELIVERY
+            self.context = delivery
+            self.clazz = "pn_delivery"
         elif link:
-            self.delivery = None
-            self.link = link
-            self.session = self.link.session
-            self.connection = self.session.connection
-            self.category = Event.CATEGORY_LINK
+            self.context = link
+            self.clazz = "pn_link"
         elif session:
-            self.delivery = None
-            self.link = None
-            self.session = session
-            self.connection = self.session.connection
-            category = Event.CATEGORY_SESSION
+            self.context = session
+            self.clazz = "pn_session"
         elif connection:
-            self.delivery = None
-            self.link = None
-            self.session = None
-            self.connection = connection
-            self.category = Event.CATEGORY_CONNECTION
-        else:
-            self.delivery = None
-            self.link = None
-            self.session = None
-            self.connection = None
-            self.category = ApplicationEvent.CATEGORY_GENERAL
+            self.context = connection
+            self.clazz = "pn_connection"
+        else:
+            self.context = None
+            self.clazz = "none"
 
     def __repr__(self):
-        objects = [self.connection, self.session, self.link, self.delivery, self.subject]
+        objects = [self.context, self.subject]
         return "%s(%s)" % (self.type,
                            ", ".join([str(o) for o in objects if o is not None]))
 
@@ -473,21 +455,23 @@ class FlowController(EventDispatcher):
             self.top_up(event.link)
 
     def on_delivery(self, event):
-        if event.delivery.link.is_receiver:
+        if not event.delivery.released and event.delivery.link.is_receiver:
             self.top_up(event.delivery.link)
 
 class ScopedDispatcher(EventDispatcher):
 
     scopes = {
-        Event.CATEGORY_CONNECTION: ["connection"],
-        Event.CATEGORY_SESSION: ["session", "connection"],
-        Event.CATEGORY_LINK: ["link", "session", "connection"],
-        Event.CATEGORY_DELIVERY: ["delivery", "link", "session", "connection"]
+        "pn_connection": ["connection"],
+        "pn_session": ["session", "connection"],
+        "pn_link": ["link", "session", "connection"],
+        "pn_delivery": ["delivery", "link", "session", "connection"]
     }
 
     def dispatch(self, event):
+        if event.type in [Event.CONNECTION_FINAL, Event.SESSION_FINAL, Event.LINK_FINAL]:
+            return
         method = self.methods.get(event.type, "on_%s" % str(event.type))
-        objects = [getattr(event, attr) for attr in self.scopes.get(event.category, [])]
+        objects = [getattr(event, attr) for attr in self.scopes.get(event.clazz, [])]
         targets = [getattr(o, "context") for o in objects if hasattr(o, "context")]
         handlers = [getattr(t, method) for t in targets if hasattr(t, method)]
         for h in handlers:
@@ -542,8 +526,8 @@ class OutgoingMessageHandler(EventDispat
 
     def on_delivery(self, event):
         dlv = event.delivery
-        link = dlv.link
-        if link.is_sender and dlv.updated and not hasattr(dlv, "_been_settled"):
+        if dlv.released: return
+        if dlv.link.is_sender and dlv.updated:
             if dlv.remote_state == Delivery.ACCEPTED:
                 self.on_accepted(event)
             elif dlv.remote_state == Delivery.REJECTED:
@@ -555,7 +539,6 @@ class OutgoingMessageHandler(EventDispat
             if dlv.settled:
                 self.on_settled(event)
             if self.auto_settle():
-                dlv._been_settled = True
                 dlv.settle()
 
     def on_credit(self, event): pass
@@ -581,7 +564,7 @@ class Reject(ProtonException):
 class IncomingMessageHandler(EventDispatcher):
     def on_delivery(self, event):
         dlv = event.delivery
-        link = dlv.link
+        if dlv.released or not dlv.link.is_receiver: return
         if dlv.readable and not dlv.partial:
             event.message = recv_msg(dlv)
             try:

Modified: qpid/proton/branches/examples/tutorial/proton_server.py
URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/tutorial/proton_server.py?rev=1630895&r1=1630894&r2=1630895&view=diff
==============================================================================
--- qpid/proton/branches/examples/tutorial/proton_server.py (original)
+++ qpid/proton/branches/examples/tutorial/proton_server.py Fri Oct 10 14:00:02 2014
@@ -32,7 +32,7 @@ class Server(IncomingMessageHandler):
         self.on_request(event.message.body, event.message.reply_to)
 
     def on_connection_open(self, event):
-        if "ANONYMOUS-RELAY" in event.connection.remote_offered_capabilities:
+        if event.connection.remote_offered_capabilities and "ANONYMOUS-RELAY" in event.connection.remote_offered_capabilities:
             self.relay = self.conn.create_sender(None)
 
     def on_connection_close(self, endpoint, error):



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message