You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2016/05/13 18:05:44 UTC

mesos git commit: Used `collect` for waiting on establishing connection.

Repository: mesos
Updated Branches:
  refs/heads/master 20f77092f -> 238d8cedb


Used `collect` for waiting on establishing connection.

This trivial change replaces the previous nested lambda logic
with `process::collect`.

Review: https://reviews.apache.org/r/47219/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/238d8ced
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/238d8ced
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/238d8ced

Branch: refs/heads/master
Commit: 238d8cedb68d5c5019b1e85851e7c29a0fb602e4
Parents: 20f7709
Author: Anand Mazumdar <ma...@gmail.com>
Authored: Fri May 13 11:05:31 2016 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Fri May 13 11:05:31 2016 -0700

----------------------------------------------------------------------
 src/scheduler/scheduler.cpp | 47 +++++++++++++++-------------------------
 1 file changed, 17 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/238d8ced/src/scheduler/scheduler.cpp
----------------------------------------------------------------------
diff --git a/src/scheduler/scheduler.cpp b/src/scheduler/scheduler.cpp
index 255454d..b66661b 100644
--- a/src/scheduler/scheduler.cpp
+++ b/src/scheduler/scheduler.cpp
@@ -28,6 +28,7 @@
 #include <queue>
 #include <string>
 #include <sstream>
+#include <tuple>
 
 #include <mesos/v1/mesos.hpp>
 #include <mesos/v1/scheduler.hpp>
@@ -35,6 +36,7 @@
 #include <mesos/master/detector.hpp>
 
 #include <process/async.hpp>
+#include <process/collect.hpp>
 #include <process/defer.hpp>
 #include <process/delay.hpp>
 #include <process/dispatch.hpp>
@@ -81,16 +83,19 @@ using namespace mesos::internal::master;
 
 using namespace process;
 
+using std::get;
 using std::ostream;
 using std::queue;
 using std::shared_ptr;
 using std::string;
+using std::tuple;
 using std::vector;
 
 using mesos::internal::recordio::Reader;
 
 using mesos::master::detector::MasterDetector;
 
+using process::collect;
 using process::Owned;
 using process::wait; // Necessary on some OS's to disambiguate.
 
@@ -319,30 +324,19 @@ protected:
 
     state = CONNECTING;
 
-    // These automatic variables are needed for lambda capture. We need to
-    // create a copy here because `master` or `connectionId` values might change
-    // by the time the second `http::connect` gets called.
-    ::URL master_ = master.get();
-    UUID connectionId_ = connectionId.get();
+    auto connector = [this]() -> Future<Connection> {
+      return process::http::connect(master.get());
+    };
 
     // We create two persistent connections here, one for subscribe
     // call/streaming response and another for non-subscribe calls/responses.
-    process::http::connect(master_)
-      .onAny(defer(self(), [this, master_, connectionId_](
-                               const Future<Connection>& connection) {
-        process::http::connect(master_)
-          .onAny(defer(self(),
-                       &Self::connected,
-                       connectionId_,
-                       connection,
-                       lambda::_1));
-      }));
+    collect(connector(), connector())
+      .onAny(defer(self(), &Self::connected, connectionId.get(), lambda::_1));
   }
 
   void connected(
       const UUID& _connectionId,
-      const Future<Connection>& connection1,
-      const Future<Connection>& connection2)
+      const Future<tuple<Connection, Connection>>& _connections)
   {
     // It is possible that a new master was detected while we had an ongoing
     // (re-)connection attempt with the old master.
@@ -354,19 +348,11 @@ protected:
     CHECK_EQ(CONNECTING, state);
     CHECK_SOME(connectionId);
 
-    if (!connection1.isReady()) {
+    if (!_connections.isReady()) {
       disconnected(connectionId.get(),
-                   connection1.isFailed()
-                     ? connection1.failure()
-                     : "Subscribe future discarded");
-      return;
-    }
-
-    if (!connection2.isReady()) {
-      disconnected(connectionId.get(),
-                   connection2.isFailed()
-                     ? connection2.failure()
-                     : "Non-subscribe future discarded");
+                   _connections.isFailed()
+                     ? _connections.failure()
+                     : "Connection future discarded");
       return;
     }
 
@@ -374,7 +360,8 @@ protected:
 
     state = CONNECTED;
 
-    connections = Connections {connection1.get(), connection2.get()};
+    connections =
+      Connections {get<0>(_connections.get()), get<1>(_connections.get())};
 
     connections->subscribe.disconnected()
       .onAny(defer(self(),