GRPC C++  1.24.0
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Friends
grpc_impl::ServerBuilder Class Reference

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

#include <server_builder_impl.h>

Data Structures

class  experimental_type
 NOTE: class experimental_type is not part of the public API of this class. More...
 
struct  NamedService
 
struct  Port
 Experimental, to be deprecated. More...
 

Public Types

enum  SyncServerOption { NUM_CQS, MIN_POLLERS, MAX_POLLERS, CQ_TIMEOUT_MSEC }
 Options for synchronous servers. More...
 

Public Member Functions

 ServerBuilder ()
 
virtual ~ServerBuilder ()
 
virtual std::unique_ptr< grpc::ServerBuildAndStart ()
 Return a running server which is ready for processing calls. More...
 
ServerBuilderRegisterService (grpc::Service *service)
 Register a service. More...
 
ServerBuilderAddListeningPort (const grpc::string &addr_uri, std::shared_ptr< grpc_impl::ServerCredentials > creds, int *selected_port=nullptr)
 Enlists an endpoint addr (port with an optional IP address) to bind the grpc::Server object to be created to. More...
 
std::unique_ptr< grpc_impl::ServerCompletionQueueAddCompletionQueue (bool is_frequently_polled=true)
 Add a completion queue for handling asynchronous services. More...
 
ServerBuilderRegisterService (const grpc::string &host, grpc::Service *service)
 Register a service. More...
 
ServerBuilderRegisterAsyncGenericService (grpc::AsyncGenericService *service)
 Register a generic service. More...
 
ServerBuilderSetMaxReceiveMessageSize (int max_receive_message_size)
 Set max receive message size in bytes. More...
 
ServerBuilderSetMaxSendMessageSize (int max_send_message_size)
 Set max send message size in bytes. More...
 
ServerBuilderSetMaxMessageSize (int max_message_size)
 
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...
 
ServerBuilderSetResourceQuota (const grpc_impl::ResourceQuota &resource_quota)
 Set the attached buffer pool for this server. More...
 
ServerBuilderSetOption (std::unique_ptr< grpc::ServerBuilderOption > option)
 
ServerBuilderSetSyncServerOption (SyncServerOption option, int value)
 Only useful if this is a Synchronous server. More...
 
template<class T >
ServerBuilderAddChannelArgument (const grpc::string &arg, const T &value)
 Add a channel argument (an escape hatch to tuning core library parameters directly) More...
 
ServerBuilderEnableWorkaround (grpc_workaround_list id)
 Enable a server workaround. More...
 
experimental_type experimental ()
 NOTE: The function experimental() is not stable public API. More...
 

Static Public Member Functions

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

Protected Types

typedef std::unique_ptr< grpc::stringHostString
 Experimental, to be deprecated. More...
 

Protected Member Functions

std::vector< Portports ()
 Experimental, to be deprecated. More...
 
std::vector< NamedService * > services ()
 Experimental, to be deprecated. More...
 
std::vector< grpc::ServerBuilderOption * > options ()
 Experimental, to be deprecated. More...
 

Friends

class ::grpc::testing::ServerBuilderPluginTest
 

Detailed Description

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

Member Typedef Documentation

◆ HostString

typedef std::unique_ptr<grpc::string> grpc_impl::ServerBuilder::HostString
protected

Experimental, to be deprecated.

Member Enumeration Documentation

◆ SyncServerOption

Options for synchronous servers.

Enumerator
NUM_CQS 

Number of completion queues.

MIN_POLLERS 

Minimum number of polling threads.

MAX_POLLERS 

Maximum number of polling threads.

CQ_TIMEOUT_MSEC 

Completion queue timeout in milliseconds.

Constructor & Destructor Documentation

◆ ServerBuilder()

grpc_impl::ServerBuilder::ServerBuilder ( )

◆ ~ServerBuilder()

virtual grpc_impl::ServerBuilder::~ServerBuilder ( )
virtual

Member Function Documentation

◆ AddChannelArgument()

template<class T >
ServerBuilder& grpc_impl::ServerBuilder::AddChannelArgument ( const grpc::string arg,
const T &  value 
)
inline

Add a channel argument (an escape hatch to tuning core library parameters directly)

◆ AddCompletionQueue()

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

Add a completion queue for handling asynchronous services.

Best performance is typically obtained by using one thread per polling completion queue.

Caller is required to shutdown the server prior to shutting down the returned completion queue. Caller is also required to drain the completion queue after shutting it down. 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()! // Drain the cq_ that was created void* ignored_tag; bool ignored_ok; while (cq_->Next(&ignored_tag, &ignored_ok)) { }

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.

◆ AddListeningPort()

ServerBuilder& grpc_impl::ServerBuilder::AddListeningPort ( const grpc::string addr_uri,
std::shared_ptr< grpc_impl::ServerCredentials creds,
int *  selected_port = nullptr 
)

Enlists an endpoint addr (port with an optional IP address) to bind the grpc::Server object to be created to.

It can be invoked multiple times.

Parameters
addr_uriThe address to try to bind to the server in URI form. If the scheme name is omitted, "dns:///" is assumed. To bind to any address, please use IPv6 any, i.e., [::]:<port>, which also accepts IPv4 connections. Valid values include dns:///localhost:1234, / 192.168.1.1:31416, dns:///[::1]:27182, etc.).
credsThe credentials associated with the server.
selected_port[out]If not nullptr, gets populated with the port number bound to the grpc::Server for the corresponding endpoint after it is successfully bound by BuildAndStart(), 0 otherwise. AddListeningPort does not modify this pointer.

◆ BuildAndStart()

virtual std::unique_ptr<grpc::Server> grpc_impl::ServerBuilder::BuildAndStart ( )
virtual

Return a running server which is ready for processing calls.

Before calling, one typically needs to ensure that:

  1. a service is registered - so that the server knows what to serve (via RegisterService, or RegisterAsyncGenericService)
  2. a listening port has been added - so the server knows where to receive traffic (via AddListeningPort)
  3. [for async api only] completion queues have been added via AddCompletionQueue

◆ EnableWorkaround()

ServerBuilder& grpc_impl::ServerBuilder::EnableWorkaround ( grpc_workaround_list  id)

Enable a server workaround.

Do not use unless you know what the workaround does. For explanation and detailed descriptions of workarounds, see doc/workarounds.md.

◆ experimental()

experimental_type grpc_impl::ServerBuilder::experimental ( )
inline

NOTE: The function experimental() is not stable public API.

It is a view to the experimental components of this class. It may be changed or removed at any time.

◆ InternalAddPluginFactory()

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

For internal use only: Register a ServerBuilderPlugin factory function.

◆ options()

std::vector<grpc::ServerBuilderOption*> grpc_impl::ServerBuilder::options ( )
inlineprotected

Experimental, to be deprecated.

◆ ports()

std::vector<Port> grpc_impl::ServerBuilder::ports ( )
inlineprotected

Experimental, to be deprecated.

◆ RegisterAsyncGenericService()

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

Register a generic service.

Matches requests with any :authority This is mostly useful for writing generic gRPC Proxies where the exact serialization format is unknown

◆ RegisterService() [1/2]

ServerBuilder& grpc_impl::ServerBuilder::RegisterService ( grpc::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

◆ RegisterService() [2/2]

ServerBuilder& grpc_impl::ServerBuilder::RegisterService ( const grpc::string host,
grpc::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

◆ services()

std::vector<NamedService*> grpc_impl::ServerBuilder::services ( )
inlineprotected

Experimental, to be deprecated.

◆ SetCompressionAlgorithmSupportStatus()

ServerBuilder& grpc_impl::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.

◆ SetDefaultCompressionAlgorithm()

ServerBuilder& grpc_impl::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.

◆ SetDefaultCompressionLevel()

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

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

◆ SetMaxMessageSize()

ServerBuilder& grpc_impl::ServerBuilder::SetMaxMessageSize ( int  max_message_size)
inline
Deprecated:
For backward compatibility.

◆ SetMaxReceiveMessageSize()

ServerBuilder& grpc_impl::ServerBuilder::SetMaxReceiveMessageSize ( int  max_receive_message_size)
inline

Set max receive message size in bytes.

The default is GRPC_DEFAULT_MAX_RECV_MESSAGE_LENGTH.

◆ SetMaxSendMessageSize()

ServerBuilder& grpc_impl::ServerBuilder::SetMaxSendMessageSize ( int  max_send_message_size)
inline

Set max send message size in bytes.

The default is GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH.

◆ SetOption()

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

◆ SetResourceQuota()

ServerBuilder& grpc_impl::ServerBuilder::SetResourceQuota ( const grpc_impl::ResourceQuota resource_quota)

Set the attached buffer pool for this server.

◆ SetSyncServerOption()

ServerBuilder& grpc_impl::ServerBuilder::SetSyncServerOption ( SyncServerOption  option,
int  value 
)

Only useful if this is a Synchronous server.

Friends And Related Function Documentation

◆ ::grpc::testing::ServerBuilderPluginTest

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

Field Documentation

◆ algorithm

grpc_compression_algorithm grpc_impl::ServerBuilder::algorithm

◆ is_set

bool grpc_impl::ServerBuilder::is_set

◆ level

grpc_compression_level grpc_impl::ServerBuilder::level

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