Apache Mesos
Classes | Public Member Functions | Protected Types | Protected Member Functions | Friends | List of all members
process::ProcessBase Class Reference

#include <process.hpp>

Inheritance diagram for process::ProcessBase:
process::EventConsumer process::Process< T > process::Process< AwaitProcess< T > > process::Process< CheckerProcess > process::Process< CollectProcess< T > > process::Process< ContainerDaemonProcess > process::Process< DockerContainerizerProcess > process::Process< FetcherProcess > process::Process< GarbageCollectorProcess > process::Process< GroupProcess > process::Process< Help > process::Process< HttpConnectionProcess< Call, Event > > process::Process< HttpProxy > process::Process< JobObjectManager > process::Process< Logging > process::Process< LogProcess > process::Process< LogReaderProcess > process::Process< LogWriterProcess > process::Process< Master > process::Process< MemoryProfiler > process::Process< MesosAllocatorProcess > process::Process< MesosContainerizerProcess > process::Process< MesosIsolatorProcess > process::Process< MetricsProcess > process::Process< NetworkProcess > process::Process< PendingFutureTrackerProcess > process::Process< Profiler > process::Process< ProvisionerProcess > process::Process< RateLimiterProcess > process::Process< ReaderProcess< T > > process::Process< ReaperProcess > process::Process< ReqResProcess< Req, Res > > process::Process< ResponseHeartbeaterProcess< Message, Event > > process::Process< RuntimeProcess > process::Process< SequenceProcess > process::Process< Slave > process::Process< StatusUpdateManagerProcess< IDType, CheckpointType, UpdateType > > process::Process< SubsystemProcess > process::Process< System > process::Process< TestDiskProfileServerProcess > process::Process< TestResourceProviderProcess< Event, Call, Driver, ResourceProviderInfo, ResourceProviderID, Resource, Resources, OperationState, Operation > > process::Process< ThunkProcess< R > > process::Process< UriDiskProfileAdaptorProcess > process::Process< VersionProcess > process::Process< VolumeManagerProcess > process::Process< WhitelistWatcher >

Classes

struct  RouteOptions
 

Public Member Functions

 ProcessBase (const std::string &id="")
 
 ~ProcessBase () override
 
const UPIDself () const
 
- Public Member Functions inherited from process::EventConsumer
virtual ~EventConsumer ()
 

Protected Types

enum  RemoteConnection { RemoteConnection::REUSE, RemoteConnection::RECONNECT }
 Describes the behavior of the link call when the target pid points to a remote process. More...
 
typedef lambda::function< void(const UPID &, const std::string &)> MessageHandler
 Any function which takes a "from" UPID and a message body as arguments. More...
 
typedef lambda::function< Future< http::Response >const http::Request &)> HttpRequestHandler
 Any function which takes a process::http::Request and returns a process::http::Response. More...
 
typedef 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::http::Response. More...
 

Protected Member Functions

virtual void serve (Event &&event)
 Invoked when an event is serviced. More...
 
void consume (MessageEvent &&event) override
 
void consume (DispatchEvent &&event) override
 
void consume (HttpEvent &&event) override
 
void consume (ExitedEvent &&event) override
 
void consume (TerminateEvent &&event) override
 
virtual void initialize ()
 Invoked when a process gets spawned. More...
 
virtual void finalize ()
 Invoked when a process is terminated. More...
 
virtual void exited (const UPID &)
 Invoked when a linked process has exited. More...
 
virtual void lost (const UPID &)
 Invoked when a linked process can no longer be monitored. More...
 
void send (const UPID &to, const std::string &name, const char *data=nullptr, size_t length=0)
 Sends the message to the specified UPID. More...
 
void send (const UPID &to, std::string &&name)
 
void send (const UPID &to, std::string &&name, std::string &&data)
 
UPID link (const UPID &pid, const RemoteConnection remote=RemoteConnection::REUSE)
 Links with the specified UPID. More...
 
void install (const std::string &name, const MessageHandler &handler)
 Sets up a handler for messages with the specified name. More...
 
template<typename T >
void install (const std::string &name, void(T::*method)(const UPID &, const std::string &))
 Sets up a handler for messages with the specified name. More...
 
void delegate (const std::string &name, const UPID &pid)
 Delegates incoming messages, with the specified name, to the UPID. More...
 
void route (const std::string &name, const Option< std::string > &help, const HttpRequestHandler &handler, const RouteOptions &options=RouteOptions())
 Sets up a handler for HTTP requests with the specified name. More...
 
template<typename T >
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. More...
 
void route (const std::string &name, const std::string &realm, const Option< std::string > &help, const AuthenticatedHttpRequestHandler &handler, const RouteOptions &options=RouteOptions())
 
template<typename T >
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 authentication realm realm is present. More...
 
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 path for the specified name. More...
 
template<typename T >
size_t eventCount ()
 Returns the number of events of the given type currently on the event queue. More...
 

Friends

class SocketManager
 
class ProcessManager
 
void * schedule (void *)
 

Member Typedef Documentation

Any function which takes a process::http::Request and an Option<Principal> and returns a process::http::Response.

This type is meant to be used for the endpoint handlers of authenticated HTTP endpoints.

If the handler is called and the principal is set, this implies two things: 1) The realm that the handler's endpoint is installed into requires authentication. 2) The HTTP request has been successfully authenticated.

If the principal is not set, then the endpoint's realm does not require authentication.

The default consume implementation for HTTP events invokes installed HTTP handlers.

See also
process::ProcessBase::route
typedef lambda::function<Future<http::Response>const http::Request&)> process::ProcessBase::HttpRequestHandler
protected

Any function which takes a process::http::Request and returns a process::http::Response.

The default consume implementation for HTTP events invokes installed HTTP handlers.

See also
process::ProcessBase::route
typedef lambda::function<void(const UPID&, const std::string&)> process::ProcessBase::MessageHandler
protected

Any function which takes a "from" UPID and a message body as arguments.

The default consume implementation for message events invokes installed message handlers, or delegates the message to another process. A message handler always takes precedence over delegating.

See also
process::ProcessBase::install
process::ProcessBase::delegate

Member Enumeration Documentation

Describes the behavior of the link call when the target pid points to a remote process.

This enum has no effect if the target pid points to a local process.

Enumerator
REUSE 

If a persistent socket to the target pid does not exist, a new link is created.

If a persistent socket already exists, link will subscribe this process to the existing link.

This is the default behavior.

RECONNECT 

If a persistent socket to the target pid does not exist, a new link is created.

If a persistent socket already exists, link create a new socket connection with the target pid and atomically swap the existing link with the new link.

Existing linkers will remain linked, albeit via the new socket.

Constructor & Destructor Documentation

process::ProcessBase::ProcessBase ( const std::string &  id = "")
explicit
process::ProcessBase::~ProcessBase ( )
override

Member Function Documentation

void process::ProcessBase::consume ( MessageEvent &&  event)
overrideprotectedvirtual
void process::ProcessBase::consume ( DispatchEvent &&  event)
overrideprotectedvirtual

Reimplemented from process::EventConsumer.

void process::ProcessBase::consume ( HttpEvent &&  event)
overrideprotectedvirtual

Reimplemented from process::EventConsumer.

void process::ProcessBase::consume ( ExitedEvent &&  event)
overrideprotectedvirtual

Reimplemented from process::EventConsumer.

void process::ProcessBase::consume ( TerminateEvent &&  event)
overrideprotectedvirtual

Reimplemented from process::EventConsumer.

void process::ProcessBase::delegate ( const std::string &  name,
const UPID pid 
)
inlineprotected

Delegates incoming messages, with the specified name, to the UPID.

template<typename T >
size_t process::ProcessBase::eventCount ( )
protected

Returns the number of events of the given type currently on the event queue.

MUST be invoked from within the process itself in order to safely examine events.

virtual void process::ProcessBase::exited ( const UPID )
inlineprotectedvirtual

Invoked when a linked process has exited.

For local linked processes (i.e., when the linker and linkee are part of the same OS process), this can be used to reliably detect when the linked process has exited.

For remote linked processes, this indicates that the persistent TCP connection between the linker and the linkee has failed (e.g., linkee process died, a network error occurred). In this situation, the remote linkee process might still be running.

See also
process::ProcessBase::link

Reimplemented in mesos::internal::master::Master, and mesos::internal::slave::Slave.

virtual void process::ProcessBase::finalize ( )
inlineprotectedvirtual
virtual void process::ProcessBase::initialize ( )
inlineprotectedvirtual
void process::ProcessBase::install ( const std::string &  name,
const MessageHandler handler 
)
inlineprotected

Sets up a handler for messages with the specified name.

template<typename T >
void process::ProcessBase::install ( const std::string &  name,
void(T::*)(const UPID &, const std::string &)  method 
)
inlineprotected

Sets up a handler for messages with the specified name.

UPID process::ProcessBase::link ( const UPID pid,
const RemoteConnection  remote = RemoteConnection::REUSE 
)
protected

Links with the specified UPID.

Linking with a process from within the same OS process is guaranteed to give you perfect monitoring of that process.

Linking to a remote process establishes a persistent TCP connection to the remote libprocess instance that hosts that process. If the TCP connection fails, the true state of the remote linked process cannot be determined; we handle this situation by generating an ExitedEvent.

virtual void process::ProcessBase::lost ( const UPID )
inlineprotectedvirtual

Invoked when a linked process can no longer be monitored.

TODO(neilc): This is not implemented.

See also
process::ProcessBase::link
void process::ProcessBase::provide ( const std::string &  name,
const std::string &  path,
const std::map< std::string, std::string > &  types = mime::types 
)
inlineprotected

Sets up the default HTTP request handler to provide the static asset(s) at the specified absolute path for the specified name.

For example, assuming the process named "server" invoked provide("name", "path"), then an HTTP request for /server/name would return the asset found at "path". If the specified path is a directory then an HTTP request for /server/name/file would return the asset found at /path/file.

The Content-Type header of the HTTP response will be set to the specified type given the file extension, which can be changed via the optional types parameter.

void process::ProcessBase::route ( const std::string &  name,
const Option< std::string > &  help,
const HttpRequestHandler handler,
const RouteOptions options = RouteOptions() 
)
protected

Sets up a handler for HTTP requests with the specified name.

Parameters
nameThe endpoint or URL to route. Must begin with a / and must not end with a '/'.
template<typename T >
void process::ProcessBase::route ( const std::string &  name,
const Option< std::string > &  help,
Future< http::Response >(T::*)(const http::Request &)  method,
const RouteOptions options = RouteOptions() 
)
inlineprotected

Sets up a handler for HTTP requests with the specified name.

Parameters
nameThe endpoint or URL to route. Must begin with a / and must not end with a '/'.
void process::ProcessBase::route ( const std::string &  name,
const std::string &  realm,
const Option< std::string > &  help,
const AuthenticatedHttpRequestHandler handler,
const RouteOptions options = RouteOptions() 
)
protected
template<typename T >
void process::ProcessBase::route ( const std::string &  name,
const Option< std::string > &  realm,
const Option< std::string > &  help,
Future< http::Response >(T::*)(const http::Request &, const Option< http::authentication::Principal > &)  method,
const RouteOptions options = RouteOptions() 
)
inlineprotected

Forwards to the correct overload of process::ProcessBase::route(), depending on whether the authentication realm realm is present.

const UPID& process::ProcessBase::self ( ) const
inline
void process::ProcessBase::send ( const UPID to,
const std::string &  name,
const char *  data = nullptr,
size_t  length = 0 
)
protected

Sends the message to the specified UPID.

Prefer the rvalue reference overloads if the data can be moved in.

See also
process::Message
void process::ProcessBase::send ( const UPID to,
std::string &&  name 
)
protected
void process::ProcessBase::send ( const UPID to,
std::string &&  name,
std::string &&  data 
)
protected
virtual void process::ProcessBase::serve ( Event &&  event)
inlineprotectedvirtual

Invoked when an event is serviced.

Reimplemented in process::internal::ThunkProcess< R >.

Friends And Related Function Documentation

friend class ProcessManager
friend
void* schedule ( void *  )
friend
friend class SocketManager
friend

Member Data Documentation

hashmap<std::string, HttpEndpoint> process::ProcessBase::http
Owned<Sequence> process::ProcessBase::httpSequence
hashmap<std::string, MessageHandler> process::ProcessBase::message

The documentation for this class was generated from the following file: