mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r1132340 - in /incubator/mesos/trunk/third_party/libprocess: include/process/process.hpp src/process.cpp src/tests.cpp
Date Sun, 05 Jun 2011 09:28:03 GMT
Author: benh
Date: Sun Jun  5 09:28:02 2011
New Revision: 1132340

URL: http://svn.apache.org/viewvc?rev=1132340&view=rev
Log:
Updates to libprocess to support better 'closures' for handling HTTP requests.

Modified:
    incubator/mesos/trunk/third_party/libprocess/include/process/process.hpp
    incubator/mesos/trunk/third_party/libprocess/src/process.cpp
    incubator/mesos/trunk/third_party/libprocess/src/tests.cpp

Modified: incubator/mesos/trunk/third_party/libprocess/include/process/process.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/process.hpp?rev=1132340&r1=1132339&r2=1132340&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/process/process.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/process.hpp Sun Jun  5 09:28:02
2011
@@ -103,23 +103,30 @@ protected:
   bool ready(int fd, int op);
 
   /* Returns sub-second elapsed time (according to this process). */
-  double elapsed();
+  double elapsedTime();
 
   /* Install a handler for a message. */
+  void installMessageHandler(const std::string& name, const std::tr1::function<void()>&
handler)
+  {
+    messageHandlers[name] = handler;
+  }
+
   template <typename T>
-  void install(const std::string& name, void (T::*method)())
+  void installMessageHandler(const std::string& name, void (T::*method)())
   {
-    message_handlers[name] =
-      std::tr1::bind(method, static_cast<T*>(this));
+    installMessageHandler(name, std::tr1::bind(method, static_cast<T*>(this)));
   }
 
   /* Install a handler for an HTTP request. */
+  void installHttpHandler(const std::string& name, const std::tr1::function<Promise<HttpResponse>(const
HttpRequest&)>& handler)
+  {
+    httpHandlers[name] = handler;
+  }
+
   template <typename T>
-  void install(const std::string& name,
-               Promise<HttpResponse> (T::*method)(const HttpRequest&))
+  void installHttpHandler(const std::string& name, Promise<HttpResponse> (T::*method)(const
HttpRequest&))
   {
-    http_handlers[name] =
-      std::tr1::bind(method, static_cast<T*>(this), std::tr1::placeholders::_1);
+    installHttpHandler(name, std::tr1::bind(method, static_cast<T*>(this), std::tr1::placeholders::_1));
   }
 
 private:
@@ -166,10 +173,10 @@ private:
   std::deque<std::tr1::function<void(ProcessBase*)>*> delegators;
 
   /* Handlers for messages. */
-  std::map<std::string, std::tr1::function<void(void)> > message_handlers;
+  std::map<std::string, std::tr1::function<void(void)> > messageHandlers;
 
   /* Handlers for HTTP requests. */
-  std::map<std::string, std::tr1::function<Promise<HttpResponse>(const HttpRequest&)>
> http_handlers;
+  std::map<std::string, std::tr1::function<Promise<HttpResponse>(const HttpRequest&)>
> httpHandlers;
 
   /* Current message. */
   Message* current;

Modified: incubator/mesos/trunk/third_party/libprocess/src/process.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/src/process.cpp?rev=1132340&r1=1132339&r2=1132340&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/src/process.cpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/src/process.cpp Sun Jun  5 09:28:02 2011
@@ -2855,8 +2855,8 @@ string ProcessBase::serve(double secs, b
       size_t index = request->first->path.find('/', 1);
       index = index != string::npos ? index + 1 : request->first->path.size();
       const string& name = request->first->path.substr(index);
-      if (http_handlers.count(name) > 0) {
-        http_handlers[name](*request->first).associate(*request->second);
+      if (httpHandlers.count(name) > 0) {
+        httpHandlers[name](*request->first).associate(*request->second);
       } else {
         VLOG(1) << "Returning '404 Not Found' for HTTP request for '"
                 << request->first->path << "'";
@@ -2871,8 +2871,8 @@ string ProcessBase::serve(double secs, b
       delete delegator;
       continue;
     } else if ((current = dequeue<Message>()) != NULL) {
-      if (message_handlers.count(name()) > 0) {
-        message_handlers[name()]();
+      if (messageHandlers.count(name()) > 0) {
+        messageHandlers[name()]();
 	continue;
       } else {
         return name();
@@ -3013,7 +3013,7 @@ bool ProcessBase::ready(int fd, int op)
 }
 
 
-double ProcessBase::elapsed()
+double ProcessBase::elapsedTime()
 {
   double now = 0;
 

Modified: incubator/mesos/trunk/third_party/libprocess/src/tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/src/tests.cpp?rev=1132340&r1=1132339&r2=1132340&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/src/tests.cpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/src/tests.cpp Sun Jun  5 09:28:02 2011
@@ -116,24 +116,28 @@ TEST(libprocess, call)
 }
 
 
-class InstallMockProcess : public Process<InstallMockProcess>
+class HandlersMockProcess : public Process<HandlersMockProcess>
 {
 public:
-  InstallMockProcess() { install("func", &InstallMockProcess::func); }
+  HandlersMockProcess()
+  {
+    installMessageHandler("func", &HandlersMockProcess::func);
+  }
+
   MOCK_METHOD0(func, void());
 };
 
 
-TEST(libprocess, install)
+TEST(libprocess, handlers)
 {
   ASSERT_TRUE(GTEST_IS_THREADSAFE);
 
-  InstallMockProcess process;
+  HandlersMockProcess process;
 
   EXPECT_CALL(process, func())
     .Times(1);
 
-  PID<InstallMockProcess> pid = process::spawn(&process);
+  PID<HandlersMockProcess> pid = process::spawn(&process);
 
   ASSERT_FALSE(!pid);
 



Mime
View raw message