You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2012/07/11 02:20:23 UTC
svn commit: r1359961 [1/2] - in /incubator/mesos/trunk: src/master/
src/slave/ third_party/libprocess/ third_party/libprocess/examples/
third_party/libprocess/include/process/ third_party/libprocess/src/
Author: benh
Date: Wed Jul 11 00:20:22 2012
New Revision: 1359961
URL: http://svn.apache.org/viewvc?rev=1359961&view=rev
Log:
Updates from libprocess (and associated changes).
Added:
incubator/mesos/trunk/third_party/libprocess/LICENSE
incubator/mesos/trunk/third_party/libprocess/TODO
- copied, changed from r1359937, incubator/mesos/trunk/third_party/libprocess/todo
incubator/mesos/trunk/third_party/libprocess/bootstrap (with props)
incubator/mesos/trunk/third_party/libprocess/include/process/thread.hpp
- copied, changed from r1359937, incubator/mesos/trunk/third_party/libprocess/src/thread.hpp
Removed:
incubator/mesos/trunk/third_party/libprocess/src/thread.hpp
incubator/mesos/trunk/third_party/libprocess/todo
Modified:
incubator/mesos/trunk/src/master/http.cpp
incubator/mesos/trunk/src/master/http.hpp
incubator/mesos/trunk/src/master/master.hpp
incubator/mesos/trunk/src/master/slaves_manager.cpp
incubator/mesos/trunk/src/master/slaves_manager.hpp
incubator/mesos/trunk/src/slave/http.cpp
incubator/mesos/trunk/src/slave/http.hpp
incubator/mesos/trunk/src/slave/slave.hpp
incubator/mesos/trunk/third_party/libprocess/Makefile.am
incubator/mesos/trunk/third_party/libprocess/README
incubator/mesos/trunk/third_party/libprocess/examples/example.cpp
incubator/mesos/trunk/third_party/libprocess/include/process/defer.hpp
incubator/mesos/trunk/third_party/libprocess/include/process/deferred.hpp
incubator/mesos/trunk/third_party/libprocess/include/process/event.hpp
incubator/mesos/trunk/third_party/libprocess/include/process/executor.hpp
incubator/mesos/trunk/third_party/libprocess/include/process/future.hpp
incubator/mesos/trunk/third_party/libprocess/include/process/http.hpp
incubator/mesos/trunk/third_party/libprocess/include/process/option.hpp
incubator/mesos/trunk/third_party/libprocess/include/process/process.hpp
incubator/mesos/trunk/third_party/libprocess/src/decoder.hpp
incubator/mesos/trunk/third_party/libprocess/src/encoder.hpp
incubator/mesos/trunk/third_party/libprocess/src/foreach.hpp
incubator/mesos/trunk/third_party/libprocess/src/process.cpp
incubator/mesos/trunk/third_party/libprocess/src/tests.cpp
Modified: incubator/mesos/trunk/src/master/http.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/http.cpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/http.cpp (original)
+++ incubator/mesos/trunk/src/master/http.cpp Wed Jul 11 00:20:22 2012
@@ -35,18 +35,22 @@
#include "master/http.hpp"
#include "master/master.hpp"
+namespace mesos {
+namespace internal {
+namespace master {
+
using process::Future;
-using process::HttpResponse;
-using process::HttpRequest;
+
+using process::http::InternalServerError;
+using process::http::NotFound;
+using process::http::OK;
+using process::http::Response;
+using process::http::Request;
using std::map;
using std::string;
using std::vector;
-namespace mesos {
-namespace internal {
-namespace master {
-
// TODO(benh): Consider moving the modeling code some place else so
// that it can be shared between slave/http.cpp and master/http.cpp.
@@ -160,9 +164,9 @@ JSON::Object model(const Slave& slave)
namespace http {
-Future<HttpResponse> vars(
+Future<Response> vars(
const Master& master,
- const HttpRequest& request)
+ const Request& request)
{
VLOG(1) << "HTTP request for '" << request.path << "'";
@@ -183,7 +187,7 @@ Future<HttpResponse> vars(
out << key << " " << value << "\n";
}
- HttpOKResponse response;
+ OK response;
response.headers["Content-Type"] = "text/plain";
response.headers["Content-Length"] = stringify(out.str().size());
response.body = out.str().data();
@@ -193,9 +197,9 @@ Future<HttpResponse> vars(
namespace json {
-Future<HttpResponse> stats(
+Future<Response> stats(
const Master& master,
- const HttpRequest& request)
+ const Request& request)
{
VLOG(1) << "HTTP request for '" << request.path << "'";
@@ -242,7 +246,7 @@ Future<HttpResponse> stats(
JSON::render(out, object);
- HttpOKResponse response;
+ OK response;
response.headers["Content-Type"] = "application/json";
response.headers["Content-Length"] = stringify(out.str().size());
response.body = out.str().data();
@@ -250,9 +254,9 @@ Future<HttpResponse> stats(
}
-Future<HttpResponse> state(
+Future<Response> state(
const Master& master,
- const HttpRequest& request)
+ const Request& request)
{
VLOG(1) << "HTTP request for '" << request.path << "'";
@@ -305,7 +309,7 @@ Future<HttpResponse> state(
JSON::render(out, object);
- HttpOKResponse response;
+ OK response;
response.headers["Content-Type"] = "application/json";
response.headers["Content-Length"] = stringify(out.str().size());
response.body = out.str().data();
@@ -313,9 +317,9 @@ Future<HttpResponse> state(
}
-Future<HttpResponse> log(
+Future<Response> log(
const Master& master,
- const HttpRequest& request)
+ const Request& request)
{
VLOG(1) << "HTTP request for '" << request.path << "'";
@@ -332,7 +336,7 @@ Future<HttpResponse> log(
LOG(WARNING) << "Failed to \"numify\" the 'offset' ("
<< pairs["offset"].back() << "): "
<< result.error();
- return HttpInternalServerErrorResponse();
+ return InternalServerError();
}
offset = result.get();
}
@@ -344,7 +348,7 @@ Future<HttpResponse> log(
LOG(WARNING) << "Failed to \"numify\" the 'length' ("
<< pairs["length"].back() << "): "
<< result.error();
- return HttpInternalServerErrorResponse();
+ return InternalServerError();
}
length = result.get();
}
@@ -352,7 +356,7 @@ Future<HttpResponse> log(
Option<string> directory = master.conf.get<string>("log_dir");
if (directory.isNone()) {
- return HttpNotFoundResponse();
+ return NotFound();
}
string path = directory.get() + "/mesos-master." + level;
@@ -362,7 +366,7 @@ Future<HttpResponse> log(
if (fd.isError()) {
LOG(WARNING) << "Failed to open log file at "
<< path << ": " << fd.error();
- return HttpInternalServerErrorResponse();
+ return InternalServerError();
}
off_t size = lseek(fd.get(), 0, SEEK_END);
@@ -370,7 +374,7 @@ Future<HttpResponse> log(
if (size == -1) {
PLOG(WARNING) << "Failed to seek in the log";
close(fd.get());
- return HttpInternalServerErrorResponse();
+ return InternalServerError();
}
if (offset == -1) {
@@ -388,7 +392,7 @@ Future<HttpResponse> log(
if (lseek(fd.get(), offset, SEEK_SET) == -1) {
PLOG(WARNING) << "Failed to seek in the log";
close(fd.get());
- return HttpInternalServerErrorResponse();
+ return InternalServerError();
}
// Read length bytes (or to EOF).
@@ -404,7 +408,7 @@ Future<HttpResponse> log(
PLOG(WARNING) << "Failed to read from the log";
delete[] temp;
close(fd.get());
- return HttpInternalServerErrorResponse();
+ return InternalServerError();
} else {
object.values["offset"] = offset;
object.values["length"] = length;
@@ -422,7 +426,7 @@ Future<HttpResponse> log(
JSON::render(out, object);
- HttpOKResponse response;
+ OK response;
response.headers["Content-Type"] = "application/json";
response.headers["Content-Length"] = stringify(out.str().size());
response.body = out.str().data();
Modified: incubator/mesos/trunk/src/master/http.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/http.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/http.hpp (original)
+++ incubator/mesos/trunk/src/master/http.hpp Wed Jul 11 00:20:22 2012
@@ -33,28 +33,28 @@ namespace http {
// Returns current vars in "key value\n" format (keys do not contain
// spaces, values may contain spaces but are ended by a newline).
-process::Future<process::HttpResponse> vars(
+process::Future<process::http::Response> vars(
const Master& master,
- const process::HttpRequest& request);
+ const process::http::Request& request);
namespace json {
// Returns current statistics of the master.
-process::Future<process::HttpResponse> stats(
+process::Future<process::http::Response> stats(
const Master& master,
- const process::HttpRequest& request);
+ const process::http::Request& request);
// Returns current state of the cluster that the master knows about.
-process::Future<process::HttpResponse> state(
+process::Future<process::http::Response> state(
const Master& master,
- const process::HttpRequest& request);
+ const process::http::Request& request);
// Returns data from the log.
-process::Future<process::HttpResponse> log(
+process::Future<process::http::Response> log(
const Master& master,
- const process::HttpRequest& request);
+ const process::http::Request& request);
} // namespace json {
} // namespace http {
Modified: incubator/mesos/trunk/src/master/master.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/master.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/master.hpp (original)
+++ incubator/mesos/trunk/src/master/master.hpp Wed Jul 11 00:20:22 2012
@@ -22,6 +22,7 @@
#include <string>
#include <vector>
+#include <process/http.hpp>
#include <process/process.hpp>
#include <process/protobuf.hpp>
@@ -174,24 +175,24 @@ private:
friend struct SlaveRegistrar;
friend struct SlaveReregistrar;
- // Http handlers, friends of the master in order to access state,
+ // HTTP handlers, friends of the master in order to access state,
// they get invoked from within the master so there is no need to
// use synchronization mechanisms to protect state.
- friend Future<HttpResponse> http::vars(
+ friend Future<process::http::Response> http::vars(
const Master& master,
- const HttpRequest& request);
+ const process::http::Request& request);
- friend Future<HttpResponse> http::json::stats(
+ friend Future<process::http::Response> http::json::stats(
const Master& master,
- const HttpRequest& request);
+ const process::http::Request& request);
- friend Future<HttpResponse> http::json::state(
+ friend Future<process::http::Response> http::json::state(
const Master& master,
- const HttpRequest& request);
+ const process::http::Request& request);
- friend Future<HttpResponse> http::json::log(
+ friend Future<process::http::Response> http::json::log(
const Master& master,
- const HttpRequest& request);
+ const process::http::Request& request);
const Configuration conf;
Modified: incubator/mesos/trunk/src/master/slaves_manager.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/slaves_manager.cpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/slaves_manager.cpp (original)
+++ incubator/mesos/trunk/src/master/slaves_manager.cpp Wed Jul 11 00:20:22 2012
@@ -23,6 +23,7 @@
#include <boost/lexical_cast.hpp>
+#include <process/http.hpp>
#include <process/dispatch.hpp>
#include "common/fatal.hpp"
@@ -33,23 +34,24 @@
#include "master.hpp"
#include "slaves_manager.hpp"
-using namespace mesos;
-using namespace mesos::internal;
-using namespace mesos::internal::master;
+namespace mesos {
+namespace internal {
+namespace master {
using boost::bad_lexical_cast;
using boost::lexical_cast;
using process::Future;
-using process::HttpInternalServerErrorResponse;
-using process::HttpNotFoundResponse;
-using process::HttpOKResponse;
-using process::HttpResponse;
-using process::HttpRequest;
using process::PID;
using process::Process;
using process::UPID;
+using process::http::InternalServerError;
+using process::http::NotFound;
+using process::http::OK;
+using process::http::Response;
+using process::http::Request;
+
using std::ostringstream;
using std::map;
using std::string;
@@ -813,7 +815,7 @@ void SlavesManager::updateInactive(
}
-Future<HttpResponse> SlavesManager::add(const HttpRequest& request)
+Future<Response> SlavesManager::add(const Request& request)
{
// Parse the query to get out the slave hostname and port.
string hostname = "";
@@ -826,11 +828,11 @@ Future<HttpResponse> SlavesManager::add(
if (pairs.count("hostname") == 0) {
LOG(WARNING) << "Slaves manager expecting 'hostname' in query string"
<< " when trying to add a slave";
- return HttpNotFoundResponse();
+ return NotFound();
} else if (pairs.count("port") == 0) {
LOG(WARNING) << "Slaves manager expecting 'port' in query string"
<< " when trying to add a slave";
- return HttpNotFoundResponse();
+ return NotFound();
}
hostname = pairs["hostname"].front();
@@ -842,21 +844,21 @@ Future<HttpResponse> SlavesManager::add(
LOG(WARNING) << "Slaves manager failed to parse 'port = "
<< pairs["port"].front()
<< "' when trying to add a slave";
- return HttpNotFoundResponse();
+ return NotFound();
}
LOG(INFO) << "Slaves manager received HTTP request to add slave at "
<< hostname << ":" << port;
if (add(hostname, port)) {
- return HttpOKResponse();
+ return OK();
} else {
- return HttpInternalServerErrorResponse();
+ return InternalServerError();
}
}
-Future<HttpResponse> SlavesManager::remove(const HttpRequest& request)
+Future<Response> SlavesManager::remove(const Request& request)
{
// Parse the query to get out the slave hostname and port.
string hostname = "";
@@ -869,11 +871,11 @@ Future<HttpResponse> SlavesManager::remo
if (pairs.count("hostname") == 0) {
LOG(WARNING) << "Slaves manager expecting 'hostname' in query string"
<< " when trying to remove a slave";
- return HttpNotFoundResponse();
+ return NotFound();
} else if (pairs.count("port") == 0) {
LOG(WARNING) << "Slaves manager expecting 'port' in query string"
<< " when trying to remove a slave";
- return HttpNotFoundResponse();
+ return NotFound();
}
hostname = pairs["hostname"].front();
@@ -885,21 +887,21 @@ Future<HttpResponse> SlavesManager::remo
LOG(WARNING) << "Slaves manager failed to parse 'port = "
<< pairs["port"].front()
<< "' when trying to remove a slave";
- return HttpNotFoundResponse();
+ return NotFound();
}
LOG(INFO) << "Slaves manager received HTTP request to remove slave at "
<< hostname << ":" << port;
if (remove(hostname, port)) {
- return HttpOKResponse();
+ return OK();
} else {
- return HttpInternalServerErrorResponse();
+ return InternalServerError();
}
}
-Future<HttpResponse> SlavesManager::activate(const HttpRequest& request)
+Future<Response> SlavesManager::activate(const Request& request)
{
// Parse the query to get out the slave hostname and port.
string hostname = "";
@@ -912,11 +914,11 @@ Future<HttpResponse> SlavesManager::acti
if (pairs.count("hostname") == 0) {
LOG(WARNING) << "Slaves manager expecting 'hostname' in query string"
<< " when trying to activate a slave";
- return HttpNotFoundResponse();
+ return NotFound();
} else if (pairs.count("port") == 0) {
LOG(WARNING) << "Slaves manager expecting 'port' in query string"
<< " when trying to activate a slave";
- return HttpNotFoundResponse();
+ return NotFound();
}
hostname = pairs["hostname"].front();
@@ -928,21 +930,21 @@ Future<HttpResponse> SlavesManager::acti
LOG(WARNING) << "Slaves manager failed to parse 'port = "
<< pairs["port"].front()
<< "' when trying to activate a slave";
- return HttpNotFoundResponse();
+ return NotFound();
}
LOG(INFO) << "Slaves manager received HTTP request to activate slave at "
<< hostname << ":" << port;
if (activate(hostname, port)) {
- return HttpOKResponse();
+ return OK();
} else {
- return HttpInternalServerErrorResponse();
+ return InternalServerError();
}
}
-Future<HttpResponse> SlavesManager::deactivate(const HttpRequest& request)
+Future<Response> SlavesManager::deactivate(const Request& request)
{
// Parse the query to get out the slave hostname and port.
string hostname = "";
@@ -955,11 +957,11 @@ Future<HttpResponse> SlavesManager::deac
if (pairs.count("hostname") == 0) {
LOG(WARNING) << "Slaves manager expecting 'hostname' in query string"
<< " when trying to deactivate a slave";
- return HttpNotFoundResponse();
+ return NotFound();
} else if (pairs.count("port") == 0) {
LOG(WARNING) << "Slaves manager expecting 'port' in query string"
<< " when trying to deactivate a slave";
- return HttpNotFoundResponse();
+ return NotFound();
}
hostname = pairs["hostname"].front();
@@ -971,21 +973,21 @@ Future<HttpResponse> SlavesManager::deac
LOG(WARNING) << "Slaves manager failed to parse 'port = "
<< pairs["port"].front()
<< "' when trying to deactivate a slave";
- return HttpNotFoundResponse();
+ return NotFound();
}
LOG(INFO) << "Slaves manager received HTTP request to deactivate slave at "
<< hostname << ":" << port;
if (deactivate(hostname, port)) {
- return HttpOKResponse();
+ return OK();
} else {
- return HttpInternalServerErrorResponse();
+ return InternalServerError();
}
}
-Future<HttpResponse> SlavesManager::activated(const HttpRequest& request)
+Future<Response> SlavesManager::activated(const Request& request)
{
LOG(INFO) << "Slaves manager received HTTP request for activated slaves";
@@ -995,7 +997,7 @@ Future<HttpResponse> SlavesManager::acti
out << hostname << ":" << port << "\n";
}
- HttpOKResponse response;
+ OK response;
response.headers["Content-Type"] = "text/plain";
response.headers["Content-Length"] = lexical_cast<string>(out.str().size());
response.body = out.str().data();
@@ -1003,7 +1005,7 @@ Future<HttpResponse> SlavesManager::acti
}
-Future<HttpResponse> SlavesManager::deactivated(const HttpRequest& request)
+Future<Response> SlavesManager::deactivated(const Request& request)
{
LOG(INFO) << "Slaves manager received HTTP request for deactivated slaves";
@@ -1013,9 +1015,13 @@ Future<HttpResponse> SlavesManager::deac
out << hostname << ":" << port << "\n";
}
- HttpOKResponse response;
+ OK response;
response.headers["Content-Type"] = "text/plain";
response.headers["Content-Length"] = lexical_cast<string>(out.str().size());
response.body = out.str().data();
return response;
}
+
+} // namespace master {
+} // namespace internal {
+} // namespace mesos {
Modified: incubator/mesos/trunk/src/master/slaves_manager.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/slaves_manager.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/slaves_manager.hpp (original)
+++ incubator/mesos/trunk/src/master/slaves_manager.hpp Wed Jul 11 00:20:22 2012
@@ -19,6 +19,7 @@
#ifndef __SLAVES_MANAGER_HPP__
#define __SLAVES_MANAGER_HPP__
+#include <process/http.hpp>
#include <process/process.hpp>
#include "configurator/configurator.hpp"
@@ -36,17 +37,41 @@ class Master;
class SlavesManagerStorage : public process::Process<SlavesManagerStorage>
{
public:
- virtual process::Future<bool> add(const std::string& hostname, uint16_t port) { return true; }
- virtual process::Future<bool> remove(const std::string& hostname, uint16_t port) { return true; }
- virtual process::Future<bool> activate(const std::string& hostname, uint16_t port) { return true; }
- virtual process::Future<bool> deactivate(const std::string& hostname, uint16_t port) { return true; }
+ virtual process::Future<bool> add(
+ const std::string& hostname,
+ uint16_t port)
+ {
+ return true;
+ }
+
+ virtual process::Future<bool> remove(
+ const std::string& hostname,
+ uint16_t port)
+ {
+ return true;
+ }
+
+ virtual process::Future<bool> activate(
+ const std::string& hostname,
+ uint16_t port)
+ {
+ return true;
+ }
+
+ virtual process::Future<bool> deactivate(
+ const std::string& hostname,
+ uint16_t port)
+ {
+ return true;
+ }
};
class SlavesManager : public process::Process<SlavesManager>
{
public:
- SlavesManager(const Configuration& conf, const process::PID<Master>& _master);
+ SlavesManager(const Configuration& conf,
+ const process::PID<Master>& _master);
virtual ~SlavesManager();
@@ -61,12 +86,18 @@ public:
void updateInactive(const multihashmap<std::string, uint16_t>& updated);
private:
- process::Future<process::HttpResponse> add(const process::HttpRequest& request);
- process::Future<process::HttpResponse> remove(const process::HttpRequest& request);
- process::Future<process::HttpResponse> activate(const process::HttpRequest& request);
- process::Future<process::HttpResponse> deactivate(const process::HttpRequest& request);
- process::Future<process::HttpResponse> activated(const process::HttpRequest& request);
- process::Future<process::HttpResponse> deactivated(const process::HttpRequest& request);
+ process::Future<process::http::Response> add(
+ const process::http::Request& request);
+ process::Future<process::http::Response> remove(
+ const process::http::Request& request);
+ process::Future<process::http::Response> activate(
+ const process::http::Request& request);
+ process::Future<process::http::Response> deactivate(
+ const process::http::Request& request);
+ process::Future<process::http::Response> activated(
+ const process::http::Request& request);
+ process::Future<process::http::Response> deactivated(
+ const process::http::Request& request);
const process::PID<Master> master;
Modified: incubator/mesos/trunk/src/slave/http.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/http.cpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/http.cpp (original)
+++ incubator/mesos/trunk/src/slave/http.cpp Wed Jul 11 00:20:22 2012
@@ -30,17 +30,18 @@
#include "slave/http.hpp"
#include "slave/slave.hpp"
-using process::Future;
-using process::HttpResponse;
-using process::HttpRequest;
-
-using std::string;
-
-
namespace mesos {
namespace internal {
namespace slave {
+using process::Future;
+
+using process::http::OK;
+using process::http::Response;
+using process::http::Request;
+
+using std::string;
+
// TODO(benh): Consider moving the modeling code some place else so
// that it can be shared between slave/http.cpp and master/http.cpp.
@@ -112,9 +113,9 @@ JSON::Object model(const Framework& fram
namespace http {
-Future<HttpResponse> vars(
+Future<Response> vars(
const Slave& slave,
- const HttpRequest& request)
+ const Request& request)
{
LOG(INFO) << "HTTP request for '" << request.path << "'";
@@ -135,7 +136,7 @@ Future<HttpResponse> vars(
out << key << " " << value << "\n";
}
- HttpOKResponse response;
+ OK response;
response.headers["Content-Type"] = "text/plain";
response.headers["Content-Length"] = stringify(out.str().size());
response.body = out.str().data();
@@ -145,9 +146,9 @@ Future<HttpResponse> vars(
namespace json {
-Future<HttpResponse> stats(
+Future<Response> stats(
const Slave& slave,
- const HttpRequest& request)
+ const Request& request)
{
LOG(INFO) << "HTTP request for '" << request.path << "'";
@@ -167,7 +168,7 @@ Future<HttpResponse> stats(
JSON::render(out, object);
- HttpOKResponse response;
+ OK response;
response.headers["Content-Type"] = "application/json";
response.headers["Content-Length"] = stringify(out.str().size());
response.body = out.str().data();
@@ -175,9 +176,9 @@ Future<HttpResponse> stats(
}
-Future<HttpResponse> state(
+Future<Response> state(
const Slave& slave,
- const HttpRequest& request)
+ const Request& request)
{
LOG(INFO) << "HTTP request for '" << request.path << "'";
@@ -202,7 +203,7 @@ Future<HttpResponse> state(
JSON::render(out, object);
- HttpOKResponse response;
+ OK response;
response.headers["Content-Type"] = "application/json";
response.headers["Content-Length"] = stringify(out.str().size());
response.body = out.str().data();
Modified: incubator/mesos/trunk/src/slave/http.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/http.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/http.hpp (original)
+++ incubator/mesos/trunk/src/slave/http.hpp Wed Jul 11 00:20:22 2012
@@ -34,23 +34,23 @@ namespace http {
// Returns current vars in "key value\n" format (keys do not contain
// spaces, values may contain spaces but are ended by a newline).
-process::Future<process::HttpResponse> vars(
+process::Future<process::http::Response> vars(
const Slave& slave,
- const process::HttpRequest& request);
+ const process::http::Request& request);
namespace json {
// Returns current statistics of the slave.
-process::Future<process::HttpResponse> stats(
+process::Future<process::http::Response> stats(
const Slave& slave,
- const process::HttpRequest& request);
+ const process::http::Request& request);
// Returns current state of the cluster that the slave knows about.
-process::Future<process::HttpResponse> state(
+process::Future<process::http::Response> state(
const Slave& slave,
- const process::HttpRequest& request);
+ const process::http::Request& request);
} // namespace json {
} // namespace http {
Modified: incubator/mesos/trunk/src/slave/slave.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/slave.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/slave.hpp (original)
+++ incubator/mesos/trunk/src/slave/slave.hpp Wed Jul 11 00:20:22 2012
@@ -19,6 +19,7 @@
#ifndef __SLAVE_HPP__
#define __SLAVE_HPP__
+#include <process/http.hpp>
#include <process/process.hpp>
#include <process/protobuf.hpp>
@@ -161,20 +162,20 @@ protected:
const ExecutorID& executorId);
private:
- // Http handlers, friends of the slave in order to access state,
+ // HTTP handlers, friends of the slave in order to access state,
// they get invoked from within the slave so there is no need to
// use synchronization mechanisms to protect state.
- friend Future<HttpResponse> http::vars(
+ friend Future<process::http::Response> http::vars(
const Slave& slave,
- const HttpRequest& request);
+ const process::http::Request& request);
- friend Future<HttpResponse> http::json::stats(
+ friend Future<process::http::Response> http::json::stats(
const Slave& slave,
- const HttpRequest& request);
+ const process::http::Request& request);
- friend Future<HttpResponse> http::json::state(
+ friend Future<process::http::Response> http::json::state(
const Slave& slave,
- const HttpRequest& request);
+ const process::http::Request& request);
const Configuration conf;
Added: incubator/mesos/trunk/third_party/libprocess/LICENSE
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/LICENSE?rev=1359961&view=auto
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/LICENSE (added)
+++ incubator/mesos/trunk/third_party/libprocess/LICENSE Wed Jul 11 00:20:22 2012
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
Modified: incubator/mesos/trunk/third_party/libprocess/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/Makefile.am?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/Makefile.am (original)
+++ incubator/mesos/trunk/third_party/libprocess/Makefile.am Wed Jul 11 00:20:22 2012
@@ -27,7 +27,7 @@ noinst_LTLIBRARIES = libprocess.la
libprocess_la_SOURCES = src/process.cpp src/pid.cpp src/latch.cpp \
src/tokenize.cpp src/config.hpp src/decoder.hpp \
src/encoder.hpp src/foreach.hpp src/gate.hpp \
- src/synchronized.hpp src/thread.hpp src/tokenize.hpp
+ src/synchronized.hpp src/tokenize.hpp
libprocess_la_CPPFLAGS = -I$(srcdir)/include -I$(BOOST) -I$(GLOG)/src \
-I$(RY_HTTP_PARSER) -I$(LIBEV) $(AM_CPPFLAGS)
@@ -63,6 +63,7 @@ libprocess_la_SOURCES += $(top_srcdir)/i
$(top_srcdir)/include/process/protobuf.hpp \
$(top_srcdir)/include/process/run.hpp \
$(top_srcdir)/include/process/socket.hpp \
+ $(top_srcdir)/include/process/thread.hpp \
$(top_srcdir)/include/process/timeout.hpp \
$(top_srcdir)/include/process/timer.hpp
@@ -71,5 +72,8 @@ libprocess_la_SOURCES += $(top_srcdir)/i
check_PROGRAMS = tests
tests_SOURCES = src/tests.cpp
-tests_CPPFLAGS = -I$(GTEST)/include -I$(GMOCK)/include $(libprocess_la_CPPFLAGS)
+tests_CPPFLAGS = -I$(GTEST)/include -I$(GMOCK)/include \
+ $(libprocess_la_CPPFLAGS)
tests_LDADD = third_party/libgmock.la libprocess.la
+
+# TODO(benh): Fix shared builds (tests need libglog, libev, etc).
\ No newline at end of file
Modified: incubator/mesos/trunk/third_party/libprocess/README
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/README?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/README (original)
+++ incubator/mesos/trunk/third_party/libprocess/README Wed Jul 11 00:20:22 2012
@@ -3,24 +3,9 @@ README for libprocess
Most importantly, if you run into an issue, please send me an email:
benh@berkeley.edu.
-Instructions:
-
-(1) Configure (in a seperate build directory if you prefer).
-
-path/to/configure
-
-(2) Build.
-
-make
-
-(3) Optional: Build some examples.
-
-cd examples && make
-
-(4) Optional: Build the Python library (assuming you have the Python
-headers installed in /usr/include/python2.5, otherwise you can update
-swig/Makefile).
-
-cd swig && make python
-
-
+$ ./bootstrap # Unless you already have a distribution.
+$ mkdir build && cd build # Optional.
+$ path/to/configure
+$ make
+$ make check
+$ ./tests
Copied: incubator/mesos/trunk/third_party/libprocess/TODO (from r1359937, incubator/mesos/trunk/third_party/libprocess/todo)
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/TODO?p2=incubator/mesos/trunk/third_party/libprocess/TODO&p1=incubator/mesos/trunk/third_party/libprocess/todo&r1=1359937&r2=1359961&rev=1359961&view=diff
==============================================================================
(empty)
Added: incubator/mesos/trunk/third_party/libprocess/bootstrap
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/bootstrap?rev=1359961&view=auto
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/bootstrap (added)
+++ incubator/mesos/trunk/third_party/libprocess/bootstrap Wed Jul 11 00:20:22 2012
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# Make sure that we are in the right directory.
+if test ! -f configure.ac; then
+ cat >&2 <<__EOF__
+You must run bootstrap from the root of the distribution.
+__EOF__
+ exit 1
+fi
+
+autoreconf --install -Wall --verbose "${@}"
Propchange: incubator/mesos/trunk/third_party/libprocess/bootstrap
------------------------------------------------------------------------------
svn:executable = *
Modified: incubator/mesos/trunk/third_party/libprocess/examples/example.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/examples/example.cpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/examples/example.cpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/examples/example.cpp Wed Jul 11 00:20:22 2012
@@ -1,54 +1,42 @@
#include <iostream>
#include <sstream>
-#include <process.hpp>
+#include <process/defer.hpp>
+#include <process/dispatch.hpp>
+#include <process/future.hpp>
+#include <process/http.hpp>
+#include <process/process.hpp>
+using namespace process;
-using process::Future;
-using process::HttpOKResponse;
-using process::HttpRequest;
-using process::HttpResponse;
-using process::PID;
-using process::Process;
-using process::Promise;
+using namespace process::http;
+using std::string;
class MyProcess : public Process<MyProcess>
{
public:
- MyProcess()
- {
- std::cout << "MyProcess at " << self() << std::endl;
-
- install("ehlo", &MyProcess::ehlo);
- install("vars", &MyProcess::vars);
- }
+ MyProcess() {}
+ virtual ~MyProcess() {}
- Promise<int> func1()
+ Future<int> func1()
{
- std::cout << "MyProcess::func1 (this = " << this << ")" << std::endl;
- return promise;
+ promise.future().onAny(
+ defer([=] () {
+ terminate(self());
+ }));
+ return promise.future();
}
void func2(int i)
{
- std::cout << "MyProcess::func2 (this = " << this << ")" << std::endl;
promise.set(i);
}
- void ehlo()
- {
- std::cout << "MyProcess::ehlo (this = " << this << ")" << std::endl;
- std::cout << "from(): " << from() << std::endl;
- std::cout << "name(): " << name() << std::endl;
- std::cout << "body(): " << body() << std::endl;
- }
-
- Promise<HttpResponse> vars(const HttpRequest& request)
+ Future<Response> vars(const Request& request)
{
- std::cout << "MyProcess::vars (this = " << this << ")" << std::endl;
- std::string body = "... vars here ...";
- HttpOKResponse response;
+ string body = "... vars here ...";
+ OK response;
response.headers["Content-Type"] = "text/plain";
std::ostringstream out;
out << body.size();
@@ -57,26 +45,77 @@ public:
return response;
}
+ void stop(const UPID& from, const string& body)
+ {
+ terminate(self());
+ }
+
+protected:
+ virtual void initialize()
+ {
+// route("/vars", &MyProcess::vars);
+ route("/vars", [=] (const Request& request) {
+ string body = "... vars here ...";
+ OK response;
+ response.headers["Content-Type"] = "text/plain";
+ std::ostringstream out;
+ out << body.size();
+ response.headers["Content-Length"] = out.str();
+ response.body = body;
+ return response;
+ });
+
+// install("stop", &MyProcess::stop);
+ install("stop", [=] (const UPID& from, const string& body) {
+ terminate(self());
+ });
+ }
+
private:
Promise<int> promise;
};
-class Foo : public Process<Foo> {};
-
-
int main(int argc, char** argv)
{
MyProcess process;
- PID<MyProcess> pid = process::spawn(&process);
+ PID<MyProcess> pid = spawn(&process);
+
+ PID<> pid2 = pid;
+
+// --------------------------------------
+
+// Future<int> future = dispatch(pid, &MyProcess::func1);
+// dispatch(pid, &MyProcess::func2, 42);
+
+// std::cout << future.get() << std::endl;
+
+// post(pid, "stop");
+
+// --------------------------------------
+
+// Promise<bool> p;
+
+// dispatch(pid, &MyProcess::func1)
+// .then([=, &p] (int i) {
+// p.set(i == 42);
+// return p.future();
+// })
+// .then([=] (bool b) {
+// if (b) {
+// post(pid, "stop");
+// }
+// return true; // No Future<void>.
+// });
+
+// dispatch(pid, &MyProcess::func2, 42);
- Future<int> future = process::dispatch(pid, &MyProcess::func1);
- process::dispatch(pid, &MyProcess::func2, 42);
+// --------------------------------------
- std::cout << future.get() << std::endl;
+ dispatch(pid, &MyProcess::func1);
+ dispatch(pid, &MyProcess::func2, 42);
- process::post(pid, "ehlo");
- process::wait(pid);
+ wait(pid);
return 0;
}
Modified: incubator/mesos/trunk/third_party/libprocess/include/process/defer.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/defer.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/process/defer.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/defer.hpp Wed Jul 11 00:20:22 2012
@@ -5,6 +5,8 @@
#include <process/deferred.hpp>
#include <process/dispatch.hpp>
+#include <process/executor.hpp>
+#include <process/preprocessor.hpp>
namespace process {
@@ -16,94 +18,6 @@ namespace process {
// Boost preprocessor macros to provide the actual definitions.
-// The result of invoking 'defer' is actually an internal type,
-// effectively just a wrapper around the result of invoking
-// 'std::tr1::bind'. However, we want the result of bind to be
-// castable to a 'deferred' but we don't want anyone to be able to
-// create a 'deferred' so we use a level-of-indirection via this type.
-template <typename F>
-struct _Defer : std::tr1::_Bind<F>
-{
- template <typename _F>
- operator deferred<_F> ()
- {
- return deferred<_F>(std::tr1::function<_F>(*this));
- }
-
-private:
- template <typename T>
- friend _Defer<void(*(PID<T>, void (T::*)(void)))(
- const PID<T>&, void (T::*)(void))>
- defer(const PID<T>& pid, void (T::*method)(void));
-
-#define TEMPLATE(Z, N, DATA) \
- template <typename T, \
- ENUM_PARAMS(N, typename P), \
- ENUM_PARAMS(N, typename A)> \
- friend _Defer<void(*(PID<T>, \
- void (T::*)(ENUM_PARAMS(N, P)), \
- ENUM_PARAMS(N, A))) \
- (const PID<T>&, \
- void (T::*)(ENUM_PARAMS(N, P)), \
- ENUM_PARAMS(N, P))> \
- defer(const PID<T>& pid, \
- void (T::*method)(ENUM_PARAMS(N, P)), \
- ENUM_BINARY_PARAMS(N, A, a));
-
- REPEAT_FROM_TO(1, 11, TEMPLATE, _) // Args A0 -> A9.
-#undef TEMPLATE
-
- template <typename R, typename T>
- friend _Defer<Future<R>(*(PID<T>, Future<R> (T::*)(void)))(
- const PID<T>&, Future<R> (T::*)(void))>
- defer(const PID<T>& pid, Future<R> (T::*method)(void));
-
-#define TEMPLATE(Z, N, DATA) \
- template <typename R, \
- typename T, \
- ENUM_PARAMS(N, typename P), \
- ENUM_PARAMS(N, typename A)> \
- friend _Defer<Future<R>(*(PID<T>, \
- Future<R> (T::*)(ENUM_PARAMS(N, P)), \
- ENUM_PARAMS(N, A))) \
- (const PID<T>&, \
- Future<R> (T::*)(ENUM_PARAMS(N, P)), \
- ENUM_PARAMS(N, P))> \
- defer(const PID<T>& pid, \
- Future<R> (T::*method)(ENUM_PARAMS(N, P)), \
- ENUM_BINARY_PARAMS(N, A, a));
-
- REPEAT_FROM_TO(1, 11, TEMPLATE, _) // Args A0 -> A9.
-#undef TEMPLATE
-
- template <typename R, typename T>
- friend _Defer<Future<R>(*(PID<T>, R (T::*)(void)))(
- const PID<T>&, R (T::*)(void))>
- defer(const PID<T>& pid, R (T::*method)(void));
-
-#define TEMPLATE(Z, N, DATA) \
- template <typename R, \
- typename T, \
- ENUM_PARAMS(N, typename P), \
- ENUM_PARAMS(N, typename A)> \
- friend _Defer<Future<R>(*(PID<T>, \
- R (T::*)(ENUM_PARAMS(N, P)), \
- ENUM_PARAMS(N, A))) \
- (const PID<T>&, \
- R (T::*)(ENUM_PARAMS(N, P)), \
- ENUM_PARAMS(N, P))> \
- defer(const PID<T>& pid, \
- R (T::*method)(ENUM_PARAMS(N, P)), \
- ENUM_BINARY_PARAMS(N, A, a));
-
- REPEAT_FROM_TO(1, 11, TEMPLATE, _) // Args A0 -> A9.
-#undef TEMPLATE
-
- _Defer(const std::tr1::_Bind<F>& b)
- : std::tr1::_Bind<F>(b) {}
-};
-
-
// First, definitions of defer for methods returning void:
//
// template <typename T, typename ...P>
@@ -119,8 +33,8 @@ private:
// }
template <typename T>
-_Defer<void(*(PID<T>, void (T::*)(void)))(
- const PID<T>&, void (T::*)(void))>
+_Defer<void(*(PID<T>, void (T::*)(void)))
+ (const PID<T>&, void (T::*)(void))>
defer(const PID<T>& pid, void (T::*method)(void))
{
void (*dispatch)(const PID<T>&, void (T::*)(void)) =
@@ -129,16 +43,16 @@ defer(const PID<T>& pid, void (T::*metho
}
template <typename T>
-_Defer<void(*(PID<T>, void (T::*)(void)))(
- const PID<T>&, void (T::*)(void))>
+_Defer<void(*(PID<T>, void (T::*)(void)))
+ (const PID<T>&, void (T::*)(void))>
defer(const Process<T>& process, void (T::*method)(void))
{
return defer(process.self(), method);
}
template <typename T>
-_Defer<void(*(PID<T>, void (T::*)(void)))(
- const PID<T>&, void (T::*)(void))>
+_Defer<void(*(PID<T>, void (T::*)(void)))
+ (const PID<T>&, void (T::*)(void))>
defer(const Process<T>* process, void (T::*method)(void))
{
return defer(process->self(), method);
@@ -155,8 +69,8 @@ defer(const Process<T>* process, void (T
void (T::*)(ENUM_PARAMS(N, P)), \
ENUM_PARAMS(N, P))> \
defer(const PID<T>& pid, \
- void (T::*method)(ENUM_PARAMS(N, P)), \
- ENUM_BINARY_PARAMS(N, A, a)) \
+ void (T::*method)(ENUM_PARAMS(N, P)), \
+ ENUM_BINARY_PARAMS(N, A, a)) \
{ \
void (*dispatch)(const PID<T>&, \
void (T::*)(ENUM_PARAMS(N, P)), \
@@ -175,8 +89,8 @@ defer(const Process<T>* process, void (T
void (T::*)(ENUM_PARAMS(N, P)), \
ENUM_PARAMS(N, P))> \
defer(const Process<T>& process, \
- void (T::*method)(ENUM_PARAMS(N, P)), \
- ENUM_BINARY_PARAMS(N, A, a)) \
+ void (T::*method)(ENUM_PARAMS(N, P)), \
+ ENUM_BINARY_PARAMS(N, A, a)) \
{ \
return defer(process.self(), method, ENUM_PARAMS(N, a)); \
} \
@@ -191,8 +105,8 @@ defer(const Process<T>* process, void (T
void (T::*)(ENUM_PARAMS(N, P)), \
ENUM_PARAMS(N, P))> \
defer(const Process<T>* process, \
- void (T::*method)(ENUM_PARAMS(N, P)), \
- ENUM_BINARY_PARAMS(N, A, a)) \
+ void (T::*method)(ENUM_PARAMS(N, P)), \
+ ENUM_BINARY_PARAMS(N, A, a)) \
{ \
return defer(process->self(), method, ENUM_PARAMS(N, a)); \
}
@@ -216,8 +130,8 @@ defer(const Process<T>* process, void (T
// }
template <typename R, typename T>
-_Defer<Future<R>(*(PID<T>, Future<R> (T::*)(void)))(
- const PID<T>&, Future<R> (T::*)(void))>
+_Defer<Future<R>(*(PID<T>, Future<R> (T::*)(void)))
+ (const PID<T>&, Future<R> (T::*)(void))>
defer(const PID<T>& pid, Future<R> (T::*method)(void))
{
Future<R> (*dispatch)(const PID<T>&, Future<R> (T::*)(void)) =
@@ -234,8 +148,8 @@ defer(const Process<T>& process, Future<
}
template <typename R, typename T>
-_Defer<Future<R>(*(PID<T>, Future<R> (T::*)(void)))(
- const PID<T>&, Future<R> (T::*)(void))>
+_Defer<Future<R>(*(PID<T>, Future<R> (T::*)(void)))
+ (const PID<T>&, Future<R> (T::*)(void))>
defer(const Process<T>* process, Future<R> (T::*method)(void))
{
return defer(process->self(), method);
@@ -253,8 +167,8 @@ defer(const Process<T>* process, Future<
Future<R> (T::*)(ENUM_PARAMS(N, P)), \
ENUM_PARAMS(N, P))> \
defer(const PID<T>& pid, \
- Future<R> (T::*method)(ENUM_PARAMS(N, P)), \
- ENUM_BINARY_PARAMS(N, A, a)) \
+ Future<R> (T::*method)(ENUM_PARAMS(N, P)), \
+ ENUM_BINARY_PARAMS(N, A, a)) \
{ \
Future<R> (*dispatch)(const PID<T>&, \
Future<R> (T::*)(ENUM_PARAMS(N, P)), \
@@ -274,8 +188,8 @@ defer(const Process<T>* process, Future<
Future<R> (T::*)(ENUM_PARAMS(N, P)), \
ENUM_PARAMS(N, P))> \
defer(const Process<T>& process, \
- Future<R> (T::*method)(ENUM_PARAMS(N, P)), \
- ENUM_BINARY_PARAMS(N, A, a)) \
+ Future<R> (T::*method)(ENUM_PARAMS(N, P)), \
+ ENUM_BINARY_PARAMS(N, A, a)) \
{ \
return defer(process.self(), method, ENUM_PARAMS(N, a)); \
} \
@@ -291,8 +205,8 @@ defer(const Process<T>* process, Future<
Future<R> (T::*)(ENUM_PARAMS(N, P)), \
ENUM_PARAMS(N, P))> \
defer(const Process<T>* process, \
- Future<R> (T::*method)(ENUM_PARAMS(N, P)), \
- ENUM_BINARY_PARAMS(N, A, a)) \
+ Future<R> (T::*method)(ENUM_PARAMS(N, P)), \
+ ENUM_BINARY_PARAMS(N, A, a)) \
{ \
return defer(process->self(), method, ENUM_PARAMS(N, a)); \
}
@@ -316,8 +230,8 @@ defer(const Process<T>* process, Future<
// }
template <typename R, typename T>
-_Defer<Future<R>(*(PID<T>, R (T::*)(void)))(
- const PID<T>&, R (T::*)(void))>
+_Defer<Future<R>(*(PID<T>, R (T::*)(void)))
+ (const PID<T>&, R (T::*)(void))>
defer(const PID<T>& pid, R (T::*method)(void))
{
Future<R> (*dispatch)(const PID<T>&, R (T::*)(void)) =
@@ -326,16 +240,16 @@ defer(const PID<T>& pid, R (T::*method)(
}
template <typename R, typename T>
-_Defer<Future<R>(*(PID<T>, R (T::*)(void)))(
- const PID<T>&, R (T::*)(void))>
+_Defer<Future<R>(*(PID<T>, R (T::*)(void)))
+ (const PID<T>&, R (T::*)(void))>
defer(const Process<T>& process, R (T::*method)(void))
{
return defer(process.self(), method);
}
template <typename R, typename T>
-_Defer<Future<R>(*(PID<T>, R (T::*)(void)))(
- const PID<T>&, R (T::*)(void))>
+_Defer<Future<R>(*(PID<T>, R (T::*)(void)))
+ (const PID<T>&, R (T::*)(void))>
defer(const Process<T>* process, R (T::*method)(void))
{
return defer(process->self(), method);
@@ -353,8 +267,8 @@ defer(const Process<T>* process, R (T::*
R (T::*)(ENUM_PARAMS(N, P)), \
ENUM_PARAMS(N, P))> \
defer(const PID<T>& pid, \
- R (T::*method)(ENUM_PARAMS(N, P)), \
- ENUM_BINARY_PARAMS(N, A, a)) \
+ R (T::*method)(ENUM_PARAMS(N, P)), \
+ ENUM_BINARY_PARAMS(N, A, a)) \
{ \
Future<R> (*dispatch)(const PID<T>&, \
R (T::*)(ENUM_PARAMS(N, P)), \
@@ -374,8 +288,8 @@ defer(const Process<T>* process, R (T::*
R (T::*)(ENUM_PARAMS(N, P)), \
ENUM_PARAMS(N, P))> \
defer(const Process<T>& process, \
- R (T::*method)(ENUM_PARAMS(N, P)), \
- ENUM_BINARY_PARAMS(N, A, a)) \
+ R (T::*method)(ENUM_PARAMS(N, P)), \
+ ENUM_BINARY_PARAMS(N, A, a)) \
{ \
return defer(process.self(), method, ENUM_PARAMS(N, a)); \
} \
@@ -391,8 +305,8 @@ defer(const Process<T>* process, R (T::*
R (T::*)(ENUM_PARAMS(N, P)), \
ENUM_PARAMS(N, P))> \
defer(const Process<T>* process, \
- R (T::*method)(ENUM_PARAMS(N, P)), \
- ENUM_BINARY_PARAMS(N, A, a)) \
+ R (T::*method)(ENUM_PARAMS(N, P)), \
+ ENUM_BINARY_PARAMS(N, A, a)) \
{ \
return defer(process->self(), method, ENUM_PARAMS(N, a)); \
}
@@ -400,6 +314,124 @@ defer(const Process<T>* process, R (T::*
REPEAT_FROM_TO(1, 11, TEMPLATE, _) // Args A0 -> A9.
#undef TEMPLATE
+
+namespace internal {
+
+inline void invoker(
+ ProcessBase* _,
+ const std::tr1::function<void(void)>& f)
+{
+ f();
+}
+
+inline void dispatcher(
+ const UPID& pid,
+ const std::tr1::function<void(void)>& f)
+{
+ std::tr1::shared_ptr<std::tr1::function<void(ProcessBase*)> > invoker(
+ new std::tr1::function<void(ProcessBase*)>(
+ std::tr1::bind(&internal::invoker,
+ std::tr1::placeholders::_1,
+ f)));
+
+ internal::dispatch(pid, invoker);
+}
+
+#define TEMPLATE(Z, N, DATA) \
+ template <ENUM_PARAMS(N, typename A)> \
+ void CAT(invoker, N)( \
+ ProcessBase* _, \
+ const std::tr1::function<void(ENUM_PARAMS(N, A))>& f, \
+ ENUM_BINARY_PARAMS(N, A, a)) \
+ { \
+ f(ENUM_PARAMS(N, a)); \
+ } \
+ \
+ template <ENUM_PARAMS(N, typename A)> \
+ void CAT(dispatcher, N)( \
+ const UPID& pid, \
+ const std::tr1::function<void(ENUM_PARAMS(N, A))>& f, \
+ ENUM_BINARY_PARAMS(N, A, a)) \
+ { \
+ std::tr1::shared_ptr<std::tr1::function<void(ProcessBase*)> > invoker( \
+ new std::tr1::function<void(ProcessBase*)>( \
+ std::tr1::bind(&internal::CAT(invoker, N)<ENUM_PARAMS(N, A)>, \
+ std::tr1::placeholders::_1, \
+ f, \
+ ENUM_PARAMS(N, a)))); \
+ \
+ internal::dispatch(pid, invoker); \
+ }
+
+ REPEAT_FROM_TO(1, 11, TEMPLATE, _) // Args A0 -> A9.
+#undef TEMPLATE
+
+
+ // We can't easily use 'std::tr1::_Placeholder<X>' when doing macro
+ // expansion via ENUM_BINARY_PARAMS because compilers don't like it
+ // when you try and concatenate '<' 'N' '>'. Thus, we typedef them.
+#define TEMPLATE(Z, N, DATA) \
+ typedef std::tr1::_Placeholder<INC(N)> _ ## N;
+
+ REPEAT(10, TEMPLATE, _)
+#undef TEMPLATE
+
+} // namespace internal {
+
+
+// Now we define defer calls for functions and bind statements.
+inline deferred<void(void)> defer(const std::tr1::function<void(void)>& f)
+{
+ if (__process__ != NULL) {
+ // In C++11:
+ // const UPID pid = __process__->self();
+ // return []() {
+ // internal::dispatch(pid, [](ProcessBase* _) { f(); });
+ // }
+ return std::tr1::function<void(void)>(
+ std::tr1::bind(&internal::dispatcher,
+ __process__->self(),
+ f));
+ }
+
+ return __executor__->defer(f);
+}
+
+
+#define TEMPLATE(Z, N, DATA) \
+ template <ENUM_PARAMS(N, typename A)> \
+ deferred<void(ENUM_PARAMS(N, A))> defer( \
+ const std::tr1::function<void(ENUM_PARAMS(N, A))>& f) \
+ { \
+ if (__process__ != NULL) { \
+ return std::tr1::function<void(ENUM_PARAMS(N, A))>( \
+ std::tr1::bind(&internal::CAT(dispatcher, N)<ENUM_PARAMS(N, A)>, \
+ __process__->self(), \
+ f, \
+ ENUM_BINARY_PARAMS(N, internal::_, () INTERCEPT))); \
+ } \
+ \
+ return __executor__->defer(f); \
+ } \
+ \
+ template <typename R, ENUM_PARAMS(N, typename A)> \
+ deferred<Future<R>(ENUM_PARAMS(N, A))> defer( \
+ const std::tr1::function<Future<R>(ENUM_PARAMS(N, A))>& f) \
+ { \
+ if (__process__ != NULL) { \
+ return std::tr1::function<Future<R>(ENUM_PARAMS(N, A))>( \
+ std::tr1::bind(&internal::CAT(dispatcher, N)<ENUM_PARAMS(N, A)>, \
+ __process__->self(), \
+ f, \
+ ENUM_BINARY_PARAMS(N, internal::_, () INTERCEPT))); \
+ } \
+ \
+ return __executor__->defer(f); \
+ }
+
+ REPEAT_FROM_TO(1, 11, TEMPLATE, _) // Args A0 -> A9.
+#undef TEMPLATE
+
} // namespace process {
#endif // __PROCESS_DEFER_HPP__
Modified: incubator/mesos/trunk/third_party/libprocess/include/process/deferred.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/deferred.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/process/deferred.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/deferred.hpp Wed Jul 11 00:20:22 2012
@@ -3,15 +3,21 @@
#include <tr1/functional>
-#include <process/dispatch.hpp>
#include <process/future.hpp>
+#include <process/pid.hpp>
#include <process/preprocessor.hpp>
namespace process {
+// Forward declarations (removing these produces cryptic compiler
+// errors even though we are just using them to declare friends).
+class Executor;
+template <typename _F> struct _Defer;
+
+
// Acts like a function call but runs within an asynchronous execution
-// context such as an Executor or a ProcessBase (since only an
-// executor or the 'defer' routines are allowed to create them).
+// context such as an Executor or a ProcessBase (enforced because only
+// an executor or the 'defer' routines are allowed to create them).
template <typename F>
struct deferred : std::tr1::function<F>
{
@@ -19,12 +25,111 @@ private:
// Only an Executor and the 'defer' routines can create these.
friend class Executor;
- template <typename _F>
- friend struct _Defer;
+ template <typename _F> friend struct _Defer;
+
+ friend deferred<void(void)> defer(const std::tr1::function<void(void)>& f);
+
+#define TEMPLATE(Z, N, DATA) \
+ template <ENUM_PARAMS(N, typename A)> \
+ friend deferred<void(ENUM_PARAMS(N, A))> defer( \
+ const std::tr1::function<void(ENUM_PARAMS(N, A))>& f);
+
+ REPEAT_FROM_TO(1, 11, TEMPLATE, _) // Args A0 -> A9.
+#undef TEMPLATE
deferred(const std::tr1::function<F>& f) : std::tr1::function<F>(f) {}
};
+
+// The result of invoking the 'defer' routines is actually an internal
+// type, effectively just a wrapper around the result of invoking
+// 'std::tr1::bind'. However, we want the result of bind to be
+// castable to a 'deferred' but we don't want anyone to be able to
+// create a 'deferred' so we use a level-of-indirection via this type.
+template <typename F>
+struct _Defer : std::tr1::_Bind<F>
+{
+ template <typename _F>
+ operator deferred<_F> ()
+ {
+ return deferred<_F>(std::tr1::function<_F>(*this));
+ }
+
+private:
+ friend class Executor;
+
+ template <typename T>
+ friend _Defer<void(*(PID<T>, void (T::*)(void)))
+ (const PID<T>&, void (T::*)(void))>
+ defer(const PID<T>& pid, void (T::*method)(void));
+
+#define TEMPLATE(Z, N, DATA) \
+ template <typename T, \
+ ENUM_PARAMS(N, typename P), \
+ ENUM_PARAMS(N, typename A)> \
+ friend _Defer<void(*(PID<T>, \
+ void (T::*)(ENUM_PARAMS(N, P)), \
+ ENUM_PARAMS(N, A))) \
+ (const PID<T>&, \
+ void (T::*)(ENUM_PARAMS(N, P)), \
+ ENUM_PARAMS(N, P))> \
+ defer(const PID<T>& pid, \
+ void (T::*method)(ENUM_PARAMS(N, P)), \
+ ENUM_BINARY_PARAMS(N, A, a));
+
+ REPEAT_FROM_TO(1, 11, TEMPLATE, _) // Args A0 -> A9.
+#undef TEMPLATE
+
+ template <typename R, typename T>
+ friend _Defer<Future<R>(*(PID<T>, Future<R> (T::*)(void)))(
+ const PID<T>&, Future<R> (T::*)(void))>
+ defer(const PID<T>& pid, Future<R> (T::*method)(void));
+
+#define TEMPLATE(Z, N, DATA) \
+ template <typename R, \
+ typename T, \
+ ENUM_PARAMS(N, typename P), \
+ ENUM_PARAMS(N, typename A)> \
+ friend _Defer<Future<R>(*(PID<T>, \
+ Future<R> (T::*)(ENUM_PARAMS(N, P)), \
+ ENUM_PARAMS(N, A))) \
+ (const PID<T>&, \
+ Future<R> (T::*)(ENUM_PARAMS(N, P)), \
+ ENUM_PARAMS(N, P))> \
+ defer(const PID<T>& pid, \
+ Future<R> (T::*method)(ENUM_PARAMS(N, P)), \
+ ENUM_BINARY_PARAMS(N, A, a));
+
+ REPEAT_FROM_TO(1, 11, TEMPLATE, _) // Args A0 -> A9.
+#undef TEMPLATE
+
+ template <typename R, typename T>
+ friend _Defer<Future<R>(*(PID<T>, R (T::*)(void)))(
+ const PID<T>&, R (T::*)(void))>
+ defer(const PID<T>& pid, R (T::*method)(void));
+
+#define TEMPLATE(Z, N, DATA) \
+ template <typename R, \
+ typename T, \
+ ENUM_PARAMS(N, typename P), \
+ ENUM_PARAMS(N, typename A)> \
+ friend _Defer<Future<R>(*(PID<T>, \
+ R (T::*)(ENUM_PARAMS(N, P)), \
+ ENUM_PARAMS(N, A))) \
+ (const PID<T>&, \
+ R (T::*)(ENUM_PARAMS(N, P)), \
+ ENUM_PARAMS(N, P))> \
+ defer(const PID<T>& pid, \
+ R (T::*method)(ENUM_PARAMS(N, P)), \
+ ENUM_BINARY_PARAMS(N, A, a));
+
+ REPEAT_FROM_TO(1, 11, TEMPLATE, _) // Args A0 -> A9.
+#undef TEMPLATE
+
+ _Defer(const std::tr1::_Bind<F>& b)
+ : std::tr1::_Bind<F>(b) {}
+};
+
} // namespace process {
#endif // __PROCESS_DEFERRED_HPP__
Modified: incubator/mesos/trunk/third_party/libprocess/include/process/event.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/event.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/process/event.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/event.hpp Wed Jul 11 00:20:22 2012
@@ -96,7 +96,7 @@ private:
struct HttpEvent : Event
{
- HttpEvent(const Socket& _socket, HttpRequest* _request)
+ HttpEvent(const Socket& _socket, http::Request* _request)
: socket(_socket), request(_request) {}
virtual ~HttpEvent()
@@ -110,7 +110,7 @@ struct HttpEvent : Event
}
const Socket socket;
- HttpRequest* const request;
+ http::Request* const request;
private:
// Not copyable, not assignable.
Modified: incubator/mesos/trunk/third_party/libprocess/include/process/executor.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/executor.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/process/executor.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/executor.hpp Wed Jul 11 00:20:22 2012
@@ -5,18 +5,19 @@
#include <process/dispatch.hpp>
#include <process/id.hpp>
#include <process/preprocessor.hpp>
+#include <process/thread.hpp>
namespace process {
// Underlying "process" which handles invoking actual callbacks
// created through an Executor.
-class ExecutorProcess : public process::Process<ExecutorProcess>
+class ExecutorProcess : public Process<ExecutorProcess>
{
private:
friend class Executor;
ExecutorProcess() : ProcessBase(ID::generate("__executor__")) {}
- ~ExecutorProcess() {}
+ virtual ~ExecutorProcess() {}
// Not copyable, not assignable.
ExecutorProcess(const ExecutorProcess&);
@@ -26,8 +27,8 @@ private:
void invoke(const std::tr1::function<void(void)>& f) { f(); }
// Args invoke.
-#define TEMPLATE(Z, N, DATA) \
- template <ENUM_PARAMS(N, typename A)> \
+#define TEMPLATE(Z, N, DATA) \
+ template <ENUM_PARAMS(N, typename A)> \
void CAT(invoke, N)( \
const std::tr1::function<void(ENUM_PARAMS(N, A))>& f, \
ENUM_BINARY_PARAMS(N, A, a)) \
@@ -46,19 +47,20 @@ private:
class Executor
{
public:
- Executor() {
- process::spawn(process);
+ Executor()
+ {
+ spawn(process);
}
~Executor()
{
- process::terminate(process);
- process::wait(process);
+ terminate(process);
+ wait(process);
}
void stop()
{
- process::terminate(process);
+ terminate(process);
// TODO(benh): Note that this doesn't wait because that could
// cause a deadlock ... thus, the semantics here are that no more
@@ -107,9 +109,9 @@ public:
// define wrappers for all std::tr1::bind results. First we start
// with the non-member std::tr1::bind results.
deferred<void(void)> defer(
- const std::tr1::_Bind<void(*())()>& b)
+ const std::tr1::_Bind<void(*(void))(void)>& b)
{
- return defer(std::tr1::function<void()>(b));
+ return defer(std::tr1::function<void(void)>(b));
}
#define TEMPLATE(Z, N, DATA) \
@@ -216,20 +218,21 @@ private:
Executor& operator = (const Executor&);
static void dispatcher(
- const process::PID<ExecutorProcess>& pid,
+ const PID<ExecutorProcess>& pid,
const std::tr1::function<void(void)>& f)
{
- process::dispatch(pid, &ExecutorProcess::invoke, f);
+ // TODO(benh): Why not just use internal::dispatch?
+ dispatch(pid, &ExecutorProcess::invoke, f);
}
#define TEMPLATE(Z, N, DATA) \
template <ENUM_PARAMS(N, typename A)> \
static void CAT(dispatcher, N)( \
- const process::PID<ExecutorProcess>& pid, \
+ const PID<ExecutorProcess>& pid, \
const std::tr1::function<void(ENUM_PARAMS(N, A))>& f, \
ENUM_BINARY_PARAMS(N, A, a)) \
{ \
- process::dispatch( \
+ dispatch( \
pid, \
&ExecutorProcess::CAT(invoke, N)<ENUM_PARAMS(N, A)>, \
f, ENUM_PARAMS(N, a)); \
@@ -241,6 +244,16 @@ private:
ExecutorProcess process;
};
+
+// Per thread executor pointer. The extra level of indirection from
+// _executor_ to __executor__ is used in order to take advantage of
+// the ThreadLocal operators without needing the extra dereference as
+// well as lazily construct the actual executor.
+extern ThreadLocal<Executor>* _executor_;
+
+#define __executor__ \
+ (*_executor_ == NULL ? *_executor_ = new Executor() : *_executor_)
+
} // namespace process {
#endif // __PROCESS_EXECUTOR_HPP__
Modified: incubator/mesos/trunk/third_party/libprocess/include/process/future.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/future.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/process/future.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/future.hpp Wed Jul 11 00:20:22 2012
@@ -15,6 +15,17 @@
namespace process {
+namespace internal {
+
+template <typename T>
+struct wrap;
+
+template <typename T>
+struct unwrap;
+
+} // namespace internal {
+
+
// Forward declaration of Promise.
template <typename T>
class Promise;
@@ -99,6 +110,12 @@ public:
template <typename X>
Future<X> then(const std::tr1::function<X(const T&)>& f) const;
+#if __cplusplus >= 201103L
+ template <typename F>
+ auto then(F f) const
+ -> typename internal::wrap<decltype(f(T()))>::Type;
+#endif
+
private:
friend class Promise<T>;
@@ -143,22 +160,10 @@ public:
~Promise();
bool set(const T& _t);
+ bool set(const Future<T>& future); // Alias for associate.
+ bool associate(const Future<T>& future);
bool fail(const std::string& message);
- bool associate(const Future<T>& future)
- {
- if (!f.isPending()) {
- return false;
- }
-
- future
- .onReady(std::tr1::bind(&Future<T>::set, f, std::tr1::placeholders::_1))
- .onFailed(std::tr1::bind(&Future<T>::fail, f, std::tr1::placeholders::_1))
- .onDiscarded(std::tr1::bind(&Future<T>::discard, f));
-
- return true;
- }
-
// Returns a copy of the future associated with this promise.
Future<T> future() const;
@@ -200,6 +205,29 @@ bool Promise<T>::set(const T& t)
template <typename T>
+bool Promise<T>::set(const Future<T>& future)
+{
+ return associate(future);
+}
+
+
+template <typename T>
+bool Promise<T>::associate(const Future<T>& future)
+{
+ if (!f.isPending()) {
+ return false;
+ }
+
+ future
+ .onReady(std::tr1::bind(&Future<T>::set, f, std::tr1::placeholders::_1))
+ .onFailed(std::tr1::bind(&Future<T>::fail, f, std::tr1::placeholders::_1))
+ .onDiscarded(std::tr1::bind(&Future<T>::discard, f));
+
+ return true;
+}
+
+
+template <typename T>
bool Promise<T>::fail(const std::string& message)
{
return f.fail(message);
@@ -216,6 +244,34 @@ Future<T> Promise<T>::future() const
// Internal helper utilities.
namespace internal {
+template <typename T>
+struct wrap
+{
+ typedef Future<T> Type;
+};
+
+
+template <typename X>
+struct wrap<Future<X> >
+{
+ typedef Future<X> Type;
+};
+
+
+template <typename T>
+struct unwrap
+{
+ typedef T Type;
+};
+
+
+template <typename X>
+struct unwrap<Future<X> >
+{
+ typedef X Type;
+};
+
+
inline void acquire(int* lock)
{
while (!__sync_bool_compare_and_swap(lock, 0, 1)) {
@@ -699,6 +755,31 @@ Future<X> Future<T>::then(
}
+#if __cplusplus >= 201103L
+template <typename T>
+template <typename F>
+auto Future<T>::then(F f) const
+ -> typename internal::wrap<decltype(f(T()))>::Type
+{
+ typedef typename internal::unwrap<decltype(f(T()))>::Type X;
+
+ std::tr1::shared_ptr<Promise<X>> promise(new Promise<X>());
+
+ onAny([=] () {
+ if (this->isReady()) {
+ promise->set(f(this->get()));
+ } else if (this->isFailed()) {
+ promise->fail(this->failure());
+ } else if (this->isDiscarded()) {
+ promise->future().discard();
+ }
+ });
+
+ return promise->future();
+}
+#endif
+
+
template <typename T>
bool Future<T>::set(const T& _t)
{
Modified: incubator/mesos/trunk/third_party/libprocess/include/process/http.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/http.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/process/http.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/http.hpp Wed Jul 11 00:20:22 2012
@@ -1,11 +1,13 @@
#ifndef __PROCESS_HTTP_HPP__
#define __PROCESS_HTTP_HPP__
+#include <map>
#include <string>
namespace process {
+namespace http {
-struct HttpRequest
+struct Request
{
// TODO(benh): Add major/minor version.
std::map<std::string, std::string> headers;
@@ -19,9 +21,9 @@ struct HttpRequest
};
-struct HttpResponse
+struct Response
{
- HttpResponse() : type(BODY) {}
+ Response() : type(BODY) {}
// TODO(benh): Add major/minor version.
std::string status;
@@ -47,51 +49,51 @@ struct HttpResponse
};
-struct HttpOKResponse : HttpResponse
+struct OK : Response
{
- HttpOKResponse() : HttpResponse()
+ OK() : Response()
{
status = "200 OK";
}
};
-struct HttpBadRequestResponse : HttpResponse
+struct BadRequest : Response
{
- HttpBadRequestResponse() : HttpResponse()
+ BadRequest() : Response()
{
status = "400 Bad Request";
}
};
-struct HttpNotFoundResponse : HttpResponse
+struct NotFound : Response
{
- HttpNotFoundResponse() : HttpResponse()
+ NotFound() : Response()
{
status = "404 Not Found";
}
};
-struct HttpInternalServerErrorResponse : HttpResponse
+struct InternalServerError : Response
{
- HttpInternalServerErrorResponse() : HttpResponse()
+ InternalServerError() : Response()
{
status = "500 Internal Server Error";
}
};
-struct HttpServiceUnavailableResponse : HttpResponse
+struct ServiceUnavailable : Response
{
- HttpServiceUnavailableResponse() : HttpResponse()
+ ServiceUnavailable() : Response()
{
status = "503 Service Unavailable";
}
};
-
+} // namespace http {
} // namespace process {
-#endif // __PROCESS_HTTP_HPP
+#endif // __PROCESS_HTTP_HPP__
Modified: incubator/mesos/trunk/third_party/libprocess/include/process/option.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/option.hpp?rev=1359961&r1=1359960&r2=1359961&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/process/option.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/option.hpp Wed Jul 11 00:20:22 2012
@@ -51,7 +51,7 @@ public:
bool operator == (const Option<T>& that) const
{
return (state == NONE && that.state == NONE) ||
- (state == SOME && that.state == SOME && *t == *that.t);
+ (state == SOME && that.state == SOME && *t == *that.t);
}
bool operator != (const Option<T>& that) const