LogCabin
|
A Server listens for incoming RPCs over TCP connections and dispatches these to Services. More...
#include <Server.h>
Classes | |
class | RPCHandler |
Services RPCs. More... | |
Public Member Functions | |
Server (Event::Loop &eventLoop, uint32_t maxMessageLength) | |
Constructor. | |
~Server () | |
Destructor. | |
std::string | bind (const Address &listenAddress) |
See OpaqueServer::bind(). | |
void | registerService (uint16_t serviceId, std::shared_ptr< Service > service, uint32_t maxThreads) |
Register a Service to receive RPCs from clients. | |
Private Member Functions | |
Server (const Server &) | |
Server & | operator= (const Server &) |
Private Attributes | |
std::mutex | mutex |
Protects services from concurrent modification. | |
std::unordered_map< uint16_t, std::shared_ptr< Service > > | services |
Maps from service IDs to ThreadDispatchService instances. | |
RPCHandler | rpcHandler |
Deals with RPCs created by opaqueServer. | |
OpaqueServer | opaqueServer |
Listens for new RPCs on TCP connections and invokes rpcHandler with them. |
A Server listens for incoming RPCs over TCP connections and dispatches these to Services.
Servers can be created from any thread, but they will always run on the thread running the Event::Loop. Services will always run on a thread pool.
LogCabin::RPC::Server::Server | ( | Event::Loop & | eventLoop, |
uint32_t | maxMessageLength | ||
) |
Constructor.
This object won't actually do anything until bind() is called.
eventLoop | Event::Loop that will be used to find out when the underlying socket may be read from or written to without blocking. |
maxMessageLength | The maximum number of bytes to allow per request/response. This exists to limit the amount of buffer space a single RPC can use. Attempting to send longer responses will PANIC; attempting to receive longer requests will disconnect the underlying socket. |
LogCabin::RPC::Server::Server | ( | const Server & | ) | [private] |
std::string LogCabin::RPC::Server::bind | ( | const Address & | listenAddress | ) |
See OpaqueServer::bind().
void LogCabin::RPC::Server::registerService | ( | uint16_t | serviceId, |
std::shared_ptr< Service > | service, | ||
uint32_t | maxThreads | ||
) |
Register a Service to receive RPCs from clients.
If a service has already been registered for this service ID, this will replace it. This may be called from any thread.
serviceId | A unique ID for the service. See Protocol::Common::ServiceId. |
service | The service to invoke when RPCs arrive with the given serviceId. This service will always be invoked on a thread pool. |
maxThreads | The maximum number of threads to execute RPCs concurrently inside the service. |
std::mutex LogCabin::RPC::Server::mutex [private] |
std::unordered_map<uint16_t, std::shared_ptr<Service> > LogCabin::RPC::Server::services [private] |
Maps from service IDs to ThreadDispatchService instances.
Protected by mutex.
RPCHandler LogCabin::RPC::Server::rpcHandler [private] |
Deals with RPCs created by opaqueServer.
Listens for new RPCs on TCP connections and invokes rpcHandler with them.