GRPC C++  1.0.0
Data Structures | Public Member Functions | Static Public Member Functions | Friends
grpc::ServerBuilder Class Reference

A builder class for the creation and startup of grpc::Server instances. More...

#include <server_builder.h>

Public Member Functions

 ServerBuilder ()
 
ServerBuilderRegisterService (Service *service)
 Register a service. More...
 
ServerBuilderRegisterAsyncGenericService (AsyncGenericService *service)
 Register a generic service. More...
 
ServerBuilderRegisterService (const grpc::string &host, Service *service)
 Register a service. More...
 
ServerBuilderSetMaxMessageSize (int max_message_size)
 Set max message size in bytes. More...
 
ServerBuilderSetCompressionAlgorithmSupportStatus (grpc_compression_algorithm algorithm, bool enabled)
 Set the support status for compression algorithms. More...
 
ServerBuilderSetDefaultCompressionLevel (grpc_compression_level level)
 The default compression level to use for all channel calls in the absence of a call-specific level. More...
 
ServerBuilderSetDefaultCompressionAlgorithm (grpc_compression_algorithm algorithm)
 The default compression algorithm to use for all channel calls in the absence of a call-specific level. More...
 
ServerBuilderSetOption (std::unique_ptr< ServerBuilderOption > option)
 
ServerBuilderAddListeningPort (const grpc::string &addr, std::shared_ptr< ServerCredentials > creds, int *selected_port=nullptr)
 Tries to bind server to the given addr. More...
 
std::unique_ptr< ServerCompletionQueueAddCompletionQueue (bool is_frequently_polled=true)
 Add a completion queue for handling asynchronous services. More...
 
std::unique_ptr< ServerBuildAndStart ()
 Return a running server which is ready for processing calls. More...
 

Static Public Member Functions

static void InternalAddPluginFactory (std::unique_ptr< ServerBuilderPlugin >(*CreatePlugin)())
 For internal use only: Register a ServerBuilderPlugin factory function. More...
 

Friends

class ::grpc::testing::ServerBuilderPluginTest
 

Detailed Description

A builder class for the creation and startup of grpc::Server instances.

Constructor & Destructor Documentation

grpc::ServerBuilder::ServerBuilder ( )

Member Function Documentation

std::unique_ptr<ServerCompletionQueue> grpc::ServerBuilder::AddCompletionQueue ( bool  is_frequently_polled = true)

Add a completion queue for handling asynchronous services.

Caller is required to shutdown the server prior to shutting down the returned completion queue. A typical usage scenario:

// While building the server: ServerBuilder builder; ... cq_ = builder.AddCompletionQueue(); server_ = builder.BuildAndStart();

// While shutting down the server; server_->Shutdown(); cq_->Shutdown(); // Always after the associated server's Shutdown()!

Parameters
is_frequently_polledThis is an optional parameter to inform GRPC library about whether this completion queue would be frequently polled (i.e by calling Next() or AsyncNext()). The default value is 'true' and is the recommended setting. Setting this to 'false' (i.e not polling the completion queue frequently) will have a significantly negative performance impact and hence should not be used in production use cases.
ServerBuilder& grpc::ServerBuilder::AddListeningPort ( const grpc::string addr,
std::shared_ptr< ServerCredentials creds,
int *  selected_port = nullptr 
)

Tries to bind server to the given addr.

It can be invoked multiple times.

Parameters
addrThe address to try to bind to the server (eg, localhost:1234, 192.168.1.1:31416, [::1]:27182, etc.). creds The credentials associated with the server.
selected_port[out]Upon success, updated to contain the port number. nullptr otherwise.
std::unique_ptr<Server> grpc::ServerBuilder::BuildAndStart ( )

Return a running server which is ready for processing calls.

static void grpc::ServerBuilder::InternalAddPluginFactory ( std::unique_ptr< ServerBuilderPlugin >(*)()  CreatePlugin)
static

For internal use only: Register a ServerBuilderPlugin factory function.

ServerBuilder& grpc::ServerBuilder::RegisterAsyncGenericService ( AsyncGenericService service)

Register a generic service.

Matches requests with any :authority

ServerBuilder& grpc::ServerBuilder::RegisterService ( Service service)

Register a service.

This call does not take ownership of the service. The service must exist for the lifetime of the Server instance returned by BuildAndStart(). Matches requests with any :authority

ServerBuilder& grpc::ServerBuilder::RegisterService ( const grpc::string host,
Service service 
)

Register a service.

This call does not take ownership of the service. The service must exist for the lifetime of the Server instance returned by BuildAndStart(). Only matches requests with :authority host

ServerBuilder& grpc::ServerBuilder::SetCompressionAlgorithmSupportStatus ( grpc_compression_algorithm  algorithm,
bool  enabled 
)

Set the support status for compression algorithms.

All algorithms are enabled by default.

Incoming calls compressed with an unsupported algorithm will fail with GRPC_STATUS_UNIMPLEMENTED.

ServerBuilder& grpc::ServerBuilder::SetDefaultCompressionAlgorithm ( grpc_compression_algorithm  algorithm)

The default compression algorithm to use for all channel calls in the absence of a call-specific level.

Note that it overrides any compression level set by SetDefaultCompressionLevel.

ServerBuilder& grpc::ServerBuilder::SetDefaultCompressionLevel ( grpc_compression_level  level)

The default compression level to use for all channel calls in the absence of a call-specific level.

ServerBuilder& grpc::ServerBuilder::SetMaxMessageSize ( int  max_message_size)
inline

Set max message size in bytes.

ServerBuilder& grpc::ServerBuilder::SetOption ( std::unique_ptr< ServerBuilderOption option)

Friends And Related Function Documentation

friend class ::grpc::testing::ServerBuilderPluginTest
friend

Field Documentation

grpc_compression_algorithm grpc::ServerBuilder::algorithm
bool grpc::ServerBuilder::is_set
grpc_compression_level grpc::ServerBuilder::level

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