You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2014/11/05 20:50:15 UTC

svn commit: r1636946 - in /qpid/proton/branches/examples/tutorial: proton_events.py selected_recv.py

Author: gsim
Date: Wed Nov  5 19:50:14 2014
New Revision: 1636946

URL: http://svn.apache.org/r1636946
Log:
Basic link configuration mechanism and example demonstratign its use

Added:
    qpid/proton/branches/examples/tutorial/selected_recv.py   (with props)
Modified:
    qpid/proton/branches/examples/tutorial/proton_events.py

Modified: qpid/proton/branches/examples/tutorial/proton_events.py
URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/tutorial/proton_events.py?rev=1636946&r1=1636945&r2=1636946&view=diff
==============================================================================
--- qpid/proton/branches/examples/tutorial/proton_events.py (original)
+++ qpid/proton/branches/examples/tutorial/proton_events.py Wed Nov  5 19:50:14 2014
@@ -763,6 +763,47 @@ class Transaction(object):
                     self.handler.on_transaction_committed(event)
 
 
+class LinkOption(object):
+    def apply(self, link): pass
+    def test(self, link): return True
+
+class AtMostOnce(LinkOption):
+    def apply(self, link):
+        link.snd_settle_mode = Link.SND_SETTLED
+
+class AtLeastOnce(LinkOption):
+    def apply(self, link):
+        link.snd_settle_mode = Link.SND_UNSETTLED
+        link.rcv_settle_mode = Link.RCV_FIRST
+
+class SenderOption(LinkOption):
+    def apply(self, sender): pass
+    def test(self, link): return link.is_sender
+
+class ReceiverOption(LinkOption):
+    def apply(self, receiver): pass
+    def test(self, link): return link.is_receiver
+
+class Filter(ReceiverOption):
+    def __init__(self, filter_set={}):
+        self.filter_set = filter_set
+
+    def apply(self, receiver):
+        receiver.source.filter.put_dict(self.filter_set)
+
+class Selector(Filter):
+    def __init__(self, value, name='selector'):
+        super(Selector, self).__init__({symbol(name): Described(symbol('apache.org:selector-filter:string'), value)})
+
+def _apply_link_options(options, link):
+    if options:
+        if isinstance(options, list):
+            for o in options:
+                if o.test(link): o.apply(link)
+        else:
+            if options.test(link): options.apply(link)
+
+
 class MessagingContext(object):
     def __init__(self, conn, handler=None, ssn=None):
         self.conn = conn
@@ -780,9 +821,8 @@ class MessagingContext(object):
 
     handler = property(_get_handler, _set_handler)
 
-    def create_sender(self, target, source=None, name=None, handler=None, tags=None):
+    def create_sender(self, target, source=None, name=None, handler=None, tags=None, options=None):
         snd = self._get_ssn().sender(name or self._get_id(target, source))
-        snd.snd_settle_mode = Link.SND_SETTLED
         if source:
             snd.source.address = source
         if target:
@@ -791,10 +831,11 @@ class MessagingContext(object):
             snd.context = handler
         snd.tags = tags or delivery_tags()
         snd.send_msg = types.MethodType(_send_msg, snd)
+        _apply_link_options(options, snd)
         snd.open()
         return snd
 
-    def create_receiver(self, source, target=None, name=None, dynamic=False, handler=None):
+    def create_receiver(self, source, target=None, name=None, dynamic=False, handler=None, options=None):
         rcv = self._get_ssn().receiver(name or self._get_id(source, target))
         if source:
             rcv.source.address = source
@@ -804,6 +845,7 @@ class MessagingContext(object):
             rcv.target.address = target
         if handler:
             rcv.context = handler
+        _apply_link_options(options, rcv)
         rcv.open()
         return rcv
 

Added: qpid/proton/branches/examples/tutorial/selected_recv.py
URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/tutorial/selected_recv.py?rev=1636946&view=auto
==============================================================================
--- qpid/proton/branches/examples/tutorial/selected_recv.py (added)
+++ qpid/proton/branches/examples/tutorial/selected_recv.py Wed Nov  5 19:50:14 2014
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+
+import proton_events
+
+class Recv(proton_events.ClientHandler):
+    def on_message(self, event):
+        print event.message.body
+
+try:
+    conn = proton_events.connect("localhost:5672", handler=Recv())
+    conn.create_receiver("examples", options=proton_events.Selector(u"colour = 'green'"))
+    proton_events.run()
+except KeyboardInterrupt: pass
+
+
+

Propchange: qpid/proton/branches/examples/tutorial/selected_recv.py
------------------------------------------------------------------------------
    svn:executable = *



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