13 #ifndef __PROCESS_PROCESS_HPP__ 14 #define __PROCESS_PROCESS_HPP__ 68 void install(std::vector<Owned<FirewallRule>>&& rules);
79 const UPID&
self()
const {
return pid; }
87 std::move(event).consume(
this);
143 const std::string&
name,
144 const char* data =
nullptr,
210 typedef lambda::function<void(const UPID&, const std::string&)>
217 const std::string& name,
220 handlers.message[
name] = handler;
226 template <
typename T>
228 const std::string& name,
229 void (T::*method)(
const UPID&,
const std::string&))
235 lambda::bind(method, dynamic_cast<T*>(
this), lambda::_1, lambda::_2);
244 delegates[
name] = pid;
256 typedef lambda::function<Future<http::Response>(
const http::Request&)>
263 : requestStreaming(false) {}
277 const std::string& name,
285 template <
typename T>
287 const std::string& name,
296 lambda::bind(method, dynamic_cast<T*>(
this), lambda::_1);
297 route(name, help, handler, options);
320 typedef lambda::function<Future<http::Response>(
329 const std::string& name,
330 const std::string& realm,
341 const std::string& name,
353 lambda::bind(method, dynamic_cast<T*>(
this), lambda::_1, lambda::_2);
354 route(name, realm.
get(), help, handler, options);
358 route(name, help, handler, options);
377 const std::string& name,
378 const std::string&
path,
386 assets[
name] = asset;
394 template <
typename T>
399 friend class ProcessManager;
415 std::atomic<State> state = ATOMIC_VAR_INIT(State::BOTTOM);
418 std::atomic<bool> termination = ATOMIC_VAR_INIT(
false);
425 bool enqueue(
Event* event);
428 std::map<std::string, UPID> delegates;
468 std::map<std::string, std::string>
types;
473 const HttpEndpoint& endpoint,
474 const std::string& name,
482 std::map<std::string, Asset> assets;
486 std::unique_ptr<EventQueue> events;
490 std::shared_ptr<ProcessBase*> reference;
492 std::shared_ptr<Gate> gate;
504 template <
typename T>
555 void finalize(
bool finalize_wsa =
false);
595 return spawn(&process, manage);
598 template <
typename T>
606 if (!
spawn(static_cast<ProcessBase*>(t), manage)) {
613 template <
typename T>
616 return spawn(&t, manage);
660 const std::string& name,
661 const char* data =
nullptr,
667 const std::string& name,
668 const char* data =
nullptr,
727 #endif // __PROCESS_PROCESS_HPP__
void finalize(bool finalize_wsa=false)
Clean up the library.
lambda::function< void(const UPID &, const std::string &)> MessageHandler
Any function which takes a "from" UPID and a message body as arguments.
Definition: process.hpp:211
Future< Response > request(const Request &request, bool streamedResponse=false)
Asynchronously sends an HTTP request to the process and returns the HTTP response once the entire res...
RemoteConnection
Describes the behavior of the link call when the target pid points to a remote process.
Definition: process.hpp:161
void provide(const std::string &name, const std::string &path, const std::map< std::string, std::string > &types=mime::types)
Sets up the default HTTP request handler to provide the static asset(s) at the specified absolute pat...
Definition: process.hpp:376
bool initialize(const Option< std::string > &delegate=None(), const Option< std::string > &readwriteAuthenticationRealm=None(), const Option< std::string > &readonlyAuthenticationRealm=None())
Initialize the library.
Definition: event.hpp:142
T Self
Definition: process.hpp:518
Owned< Sequence > httpSequence
Definition: process.hpp:461
Definition: event.hpp:178
Definition: process.hpp:72
Definition: socket_manager.hpp:36
UPID spawn(ProcessBase *process, bool manage=false)
Spawn a new process.
Definition: duration.hpp:32
lambda::function< Future< http::Response > const http::Request &, const Option< http::authentication::Principal > &)> AuthenticatedHttpRequestHandler
Any function which takes a process::http::Request and an Option<Principal> and returns a process::htt...
Definition: process.hpp:323
void terminate(const UPID &pid, bool inject=true)
Sends a TerminateEvent to the given process.
RouteOptions()
Definition: process.hpp:262
Definition: event.hpp:233
bool isSome() const
Definition: option.hpp:116
hashmap< std::string, HttpEndpoint > http
Definition: process.hpp:456
Definition: event.hpp:209
std::map< std::string, std::string > types
~Process() override
Definition: process.hpp:507
PID< Logging > logging()
Return the PID associated with the global logging process.
thread_local ProcessBase * __process__
void install(std::vector< Owned< FirewallRule >> &&rules)
Install a list of firewall rules which are used to forbid incoming HTTP requests. ...
void post(const UPID &to, const std::string &name, const char *data=nullptr, size_t length=0)
Sends a message with data without a return address.
hashmap< std::string, MessageHandler > message
Definition: process.hpp:455
An "untyped" PID, used to encapsulate the process ID for lower-layer abstractions (eg...
Definition: pid.hpp:39
Definition: duration.hpp:207
void route(const std::string &name, const Option< std::string > &help, Future< http::Response >(T::*method)(const http::Request &), const RouteOptions &options=RouteOptions())
Sets up a handler for HTTP requests with the specified name.
Definition: process.hpp:286
virtual void initialize()
Invoked when a process gets spawned.
Definition: process.hpp:100
void install(const std::string &name, const MessageHandler &handler)
Sets up a handler for messages with the specified name.
Definition: process.hpp:216
lambda::function< Future< http::Response >const http::Request &)> HttpRequestHandler
Any function which takes a process::http::Request and returns a process::http::Response.
Definition: process.hpp:257
const T & get() const &
Definition: option.hpp:119
bool requestStreaming
Definition: process.hpp:267
virtual void finalize()
Invoked when a process is terminated.
Definition: process.hpp:108
bool wait(const UPID &pid, const Duration &duration=Seconds(-1))
Wait for the process to exit for no more than the specified seconds.
Definition: address.hpp:52
bool exited(const UPID &from, const UPID &to)
Simulates disconnection of the link between 'from' and 'to' by sending an ExitedEvent to 'to'...
virtual void exited(const UPID &)
Invoked when a linked process has exited.
Definition: process.hpp:124
Definition: process.hpp:260
A "process identifier" used to uniquely identify a process when dispatching messages.
Definition: pid.hpp:289
Definition: executor.hpp:48
std::string absolutePath(const std::string &path)
Get the request absolutePath path with delegate prefix.
network::inet::Address address()
Returns the socket address associated with this instance of the library.
Definition: event.hpp:103
virtual void lost(const UPID &)
Invoked when a linked process can no longer be monitored.
Definition: process.hpp:133
void install(const std::string &name, void(T::*method)(const UPID &, const std::string &))
Sets up a handler for messages with the specified name.
Definition: process.hpp:227
Try< Nothing > bind(int_fd s, const Address &address)
Definition: network.hpp:46
void route(const std::string &name, const Option< std::string > &realm, const Option< std::string > &help, Future< http::Response >(T::*method)(const http::Request &, const Option< http::authentication::Principal > &), const RouteOptions &options=RouteOptions())
Forwards to the correct overload of process::ProcessBase::route(), depending on whether the authentic...
Definition: process.hpp:340
Definition: process.hpp:505
virtual void serve(Event &&event)
Invoked when an event is serviced.
Definition: process.hpp:85
const UPID & self() const
Definition: process.hpp:79
void delegate(const std::string &name, const UPID &pid)
Delegates incoming messages, with the specified name, to the UPID.
Definition: process.hpp:242
constexpr const char * name
Definition: shell.hpp:41
long workers()
Returns the number of worker threads the library has created.
T This
Definition: process.hpp:519
Try< Nothing > schedule(const mesos::maintenance::Schedule &schedule, const hashmap< MachineID, Machine > &machines)
Performs the following checks on the new maintenance schedule:
Future< size_t > send(const int_fd &fd, const void *buf, size_t size)