You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2017/09/01 19:25:34 UTC

qpid-proton git commit: PROTON-1553: c++ add connection::wake and on_connection_wake()

Repository: qpid-proton
Updated Branches:
  refs/heads/master cf38e3d3a -> a8f0c956a


PROTON-1553: c++ add connection::wake and on_connection_wake()

Expose the pn_connection_wake() and PN_CONNECTION_WAKE C features in C++.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/a8f0c956
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/a8f0c956
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/a8f0c956

Branch: refs/heads/master
Commit: a8f0c956af0e2936b3b6f505d2c3c4ac69cd2cdb
Parents: cf38e3d
Author: Alan Conway <ac...@redhat.com>
Authored: Fri Sep 1 15:00:46 2017 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Fri Sep 1 15:00:46 2017 -0400

----------------------------------------------------------------------
 .../bindings/cpp/include/proton/connection.hpp    | 18 ++++++++++++++++++
 .../cpp/include/proton/messaging_handler.hpp      | 18 +++++++++++++++++-
 proton-c/bindings/cpp/src/connection.cpp          |  5 +++++
 proton-c/bindings/cpp/src/handler.cpp             |  1 +
 proton-c/bindings/cpp/src/messaging_adapter.cpp   |  7 +++++++
 .../bindings/cpp/src/proactor_container_impl.cpp  |  6 +-----
 6 files changed, 49 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a8f0c956/proton-c/bindings/cpp/include/proton/connection.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/connection.hpp b/proton-c/bindings/cpp/include/proton/connection.hpp
index 7888508..cac403b 100644
--- a/proton-c/bindings/cpp/include/proton/connection.hpp
+++ b/proton-c/bindings/cpp/include/proton/connection.hpp
@@ -140,6 +140,24 @@ PN_CPP_CLASS_EXTERN connection : public internal::object<pn_connection_t>, publi
     /// @see @ref connection_options::idle_timeout
     PN_CPP_EXTERN uint32_t idle_timeout() const;
 
+    /// **Unsettled API** - trigger an event from another thread
+    ///
+    /// wake() can be called from any thread. The proton library will call
+    /// messaging_handler::on_connection_wake() as soon as possible in the correct
+    /// event handling thread.
+    ///
+    /// @note
+    /// * Thread safe: this is the *only* @ref connection function that can be
+    ///   called from outside the handler thread.
+    /// * Multiple calls to wake() may be coalesced into a single call to
+    ///   messaging_handler::on_connection_wake() that occurs after all of them.
+    /// * Spurious messaging_handler::on_connection_wake() calls can occur even if the application
+    ///   does not call wake()
+    ///
+    /// @see work_queue provides an easier way execute code safely in the
+    /// event handler thread.
+    PN_CPP_EXTERN void wake() const;
+
     /// @cond INTERNAL
   friend class internal::factory<connection>;
   friend class container;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a8f0c956/proton-c/bindings/cpp/include/proton/messaging_handler.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/messaging_handler.hpp b/proton-c/bindings/cpp/include/proton/messaging_handler.hpp
index 9c4d8f8..4b1b920 100644
--- a/proton-c/bindings/cpp/include/proton/messaging_handler.hpp
+++ b/proton-c/bindings/cpp/include/proton/messaging_handler.hpp
@@ -146,11 +146,27 @@ PN_CPP_CLASS_EXTERN messaging_handler {
     /// **Unsettled API** - The receiving peer has requested a drain of
     /// remaining credit.
     PN_CPP_EXTERN virtual void on_sender_drain_start(sender &s);
-    
+
     /// **Unsettled API** - The credit outstanding at the time of the
     /// call to receiver::drain has been consumed or returned.
     PN_CPP_EXTERN virtual void on_receiver_drain_finish(receiver &r);
 
+    /// **Unsettled API** - an event that can be triggered from another thread.
+    ///
+    /// on_connection_wake() can be triggered by any thread calling connection::wake()
+    /// It is used to notify the application's @ref messaging_handler instance
+    /// that something needs attention.
+    ///
+    /// The application handler and the triggering thread must use some form of
+    /// thread-safe state or communication to tell the handler what it needs to do.
+    ///
+    /// @note spurious calls to on_connection_wake() can occur without any
+    /// application call to connection::wake()
+    ///
+    /// @see work_queue provides an easier way execute code safely in the
+    /// handler thread.
+    PN_CPP_EXTERN virtual void on_connection_wake(connection&);
+
     /// Fallback error handling.
     PN_CPP_EXTERN virtual void on_error(const error_condition &c);
 };

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a8f0c956/proton-c/bindings/cpp/src/connection.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/connection.cpp b/proton-c/bindings/cpp/src/connection.cpp
index a37d3b5..1d66c41 100644
--- a/proton-c/bindings/cpp/src/connection.cpp
+++ b/proton-c/bindings/cpp/src/connection.cpp
@@ -40,6 +40,7 @@
 #include <proton/session.h>
 #include <proton/transport.h>
 #include <proton/object.h>
+#include <proton/proactor.h>
 
 namespace proton {
 
@@ -174,4 +175,8 @@ uint32_t connection::idle_timeout() const {
     return pn_transport_get_remote_idle_timeout(pn_connection_transport(pn_object()));
 }
 
+void connection::wake() const {
+    pn_connection_wake(pn_object());
+}
+
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a8f0c956/proton-c/bindings/cpp/src/handler.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/handler.cpp b/proton-c/bindings/cpp/src/handler.cpp
index 84d9e8a..0e693a0 100644
--- a/proton-c/bindings/cpp/src/handler.cpp
+++ b/proton-c/bindings/cpp/src/handler.cpp
@@ -85,6 +85,7 @@ void messaging_handler::on_tracker_settle(tracker &) {}
 void messaging_handler::on_delivery_settle(delivery &) {}
 void messaging_handler::on_sender_drain_start(sender &) {}
 void messaging_handler::on_receiver_drain_finish(receiver &) {}
+void messaging_handler::on_connection_wake(connection&) {}
 
 void messaging_handler::on_error(const error_condition& c) { throw proton::error(c.what()); }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a8f0c956/proton-c/bindings/cpp/src/messaging_adapter.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/messaging_adapter.cpp b/proton-c/bindings/cpp/src/messaging_adapter.cpp
index cb1b776..0fcf6fc 100644
--- a/proton-c/bindings/cpp/src/messaging_adapter.cpp
+++ b/proton-c/bindings/cpp/src/messaging_adapter.cpp
@@ -296,6 +296,11 @@ void on_transport_closed(messaging_handler& handler, pn_event_t* event) {
     handler.on_transport_close(t);
 }
 
+void on_connection_wake(messaging_handler& handler, pn_event_t* event) {
+    connection c(make_wrapper(pn_event_connection(event)));
+    handler.on_connection_wake(c);
+}
+
 }
 
 void messaging_adapter::dispatch(messaging_handler& handler, pn_event_t* event)
@@ -321,6 +326,8 @@ void messaging_adapter::dispatch(messaging_handler& handler, pn_event_t* event)
 
       case PN_TRANSPORT_CLOSED: on_transport_closed(handler, event); break;
 
+      case PN_CONNECTION_WAKE: on_connection_wake(handler, event); break;
+
       // Ignore everything else
       default: break;
     }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a8f0c956/proton-c/bindings/cpp/src/proactor_container_impl.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/proactor_container_impl.cpp b/proton-c/bindings/cpp/src/proactor_container_impl.cpp
index 43460db..4f90c68 100644
--- a/proton-c/bindings/cpp/src/proactor_container_impl.cpp
+++ b/proton-c/bindings/cpp/src/proactor_container_impl.cpp
@@ -482,10 +482,6 @@ bool container::impl::handle(pn_event_t* event) {
         }
         return false;
     }
-    // If the event was just connection wake then there isn't anything more to do
-    case PN_CONNECTION_WAKE:
-        return false;
-
     // Connection driver will bind a new transport to the connection at this point
     case PN_CONNECTION_INIT:
         return false;
@@ -559,7 +555,7 @@ void container::impl::thread() {
           finished = handle(e);
           if (finished) break;
         }
-      } catch (proton::error& e) {
+      } catch (const std::exception& e) {
         // If we caught an exception then shutdown the (other threads of the) container
         disconnect_error_ = error_condition("exception", e.what());
         if (!stopping_) stop(disconnect_error_);


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