LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Member Functions | Private Member Functions | Private Attributes
LogCabin::RPC::Server Class Reference

A Server listens for incoming RPCs over TCP connections and dispatches these to Services. More...

#include <Server.h>

List of all members.

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 &)
Serveroperator= (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.

Detailed Description

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.

Definition at line 38 of file Server.h.


Constructor & Destructor Documentation

LogCabin::RPC::Server::Server ( Event::Loop eventLoop,
uint32_t  maxMessageLength 
)

Constructor.

This object won't actually do anything until bind() is called.

Parameters:
eventLoopEvent::Loop that will be used to find out when the underlying socket may be read from or written to without blocking.
maxMessageLengthThe 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.

Definition at line 60 of file Server.cc.

Destructor.

ServerRPC objects originating from this Server may be kept around after this destructor returns; however, they won't actually send replies anymore.

Definition at line 68 of file Server.cc.

LogCabin::RPC::Server::Server ( const Server ) [private]

Member Function Documentation

std::string LogCabin::RPC::Server::bind ( const Address listenAddress)

See OpaqueServer::bind().

Definition at line 73 of file Server.cc.

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.

Parameters:
serviceIdA unique ID for the service. See Protocol::Common::ServiceId.
serviceThe service to invoke when RPCs arrive with the given serviceId. This service will always be invoked on a thread pool.
maxThreadsThe maximum number of threads to execute RPCs concurrently inside the service.

Definition at line 79 of file Server.cc.

Server& LogCabin::RPC::Server::operator= ( const Server ) [private]

Member Data Documentation

std::mutex LogCabin::RPC::Server::mutex [private]

Protects services from concurrent modification.

Definition at line 102 of file Server.h.

std::unordered_map<uint16_t, std::shared_ptr<Service> > LogCabin::RPC::Server::services [private]

Maps from service IDs to ThreadDispatchService instances.

Protected by mutex.

Definition at line 108 of file Server.h.

Deals with RPCs created by opaqueServer.

Definition at line 113 of file Server.h.

Listens for new RPCs on TCP connections and invokes rpcHandler with them.

Definition at line 119 of file Server.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines