Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
grpc::Channel Class Referencefinal

Channels represent a connection to an endpoint. Created by CreateChannel. More...

#include <channel.h>

Inheritance diagram for grpc::Channel:
Inheritance graph
[legend]

Public Member Functions

def __enter__ (self)
 
def __exit__ (self, exc_type, exc_val, exc_tb)
 
def close (self)
 
std::string GetLoadBalancingPolicyName () const
 Returns the LB policy name, or the empty string if not yet available. More...
 
std::string GetServiceConfigJSON () const
 
grpc_connectivity_state GetState (bool try_to_connect) override
 
def stream_stream (self, method, request_serializer=None, response_deserializer=None)
 
def stream_unary (self, method, request_serializer=None, response_deserializer=None)
 
def subscribe (self, callback, try_to_connect=False)
 
def unary_stream (self, method, request_serializer=None, response_deserializer=None)
 
def unary_unary (self, method, request_serializer=None, response_deserializer=None)
 
def unsubscribe (self, callback)
 
 ~Channel () override
 
- Public Member Functions inherited from grpc::ChannelInterface
template<typename T >
void NotifyOnStateChange (grpc_connectivity_state last_observed, T deadline, grpc::CompletionQueue *cq, void *tag)
 
template<typename T >
bool WaitForConnected (T deadline)
 Wait for this channel to be connected. More...
 
template<typename T >
bool WaitForStateChange (grpc_connectivity_state last_observed, T deadline)
 
virtual ~ChannelInterface ()
 
- Public Member Functions inherited from grpc::internal::CallHook
virtual ~CallHook ()
 

Private Member Functions

grpc::CompletionQueueCallbackCQ () override
 
 Channel (const std::string &host, grpc_channel *c_channel, std::vector< std::unique_ptr< grpc::experimental::ClientInterceptorFactoryInterface >> interceptor_creators)
 
grpc::internal::Call CreateCall (const grpc::internal::RpcMethod &method, grpc::ClientContext *context, grpc::CompletionQueue *cq) override
 
grpc::internal::Call CreateCallInternal (const grpc::internal::RpcMethod &method, grpc::ClientContext *context, grpc::CompletionQueue *cq, size_t interceptor_pos) override
 
void NotifyOnStateChangeImpl (grpc_connectivity_state last_observed, gpr_timespec deadline, grpc::CompletionQueue *cq, void *tag) override
 
void PerformOpsOnCall (grpc::internal::CallOpSetInterface *ops, grpc::internal::Call *call) override
 
void * RegisterMethod (const char *method) override
 
bool WaitForStateChangeImpl (grpc_connectivity_state last_observed, gpr_timespec deadline) override
 
- Private Member Functions inherited from grpc::GrpcLibraryCodegen
 GrpcLibraryCodegen (bool call_grpc_init=true)
 
virtual ~GrpcLibraryCodegen ()
 

Private Attributes

grpc_channel *const c_channel_
 
std::atomic< CompletionQueue * > callback_cq_ {nullptr}
 
const std::string host_
 
std::vector< std::unique_ptr< grpc::experimental::ClientInterceptorFactoryInterface > > interceptor_creators_
 
grpc::internal::Mutex mu_
 

Friends

void experimental::ChannelResetConnectionBackoff (Channel *channel)
 
std::shared_ptr< Channelgrpc::CreateChannelInternal (const std::string &host, grpc_channel *c_channel, std::vector< std::unique_ptr< grpc::experimental::ClientInterceptorFactoryInterface >> interceptor_creators)
 
template<class InputMessage , class OutputMessage >
class grpc::internal::BlockingUnaryCallImpl
 
class grpc::internal::InterceptedChannel
 
class grpc::testing::ChannelTestPeer
 

Detailed Description

Channels represent a connection to an endpoint. Created by CreateChannel.

Affords RPC invocation via generic methods on client-side.

Channel objects implement the Context Manager type, although they need not
support being entered and exited multiple times.

Definition at line 54 of file include/grpcpp/channel.h.

Constructor & Destructor Documentation

◆ ~Channel()

grpc::Channel::~Channel ( )
override

Definition at line 63 of file channel_cc.cc.

◆ Channel()

grpc::Channel::Channel ( const std::string &  host,
grpc_channel c_channel,
std::vector< std::unique_ptr< grpc::experimental::ClientInterceptorFactoryInterface >>  interceptor_creators 
)
private

Definition at line 53 of file channel_cc.cc.

Member Function Documentation

◆ __enter__()

def grpc.Channel.__enter__ (   self)
Enters the runtime context related to the channel object.

Reimplemented in grpc._channel.Channel, grpc._interceptor._Channel, and grpc_testing._channel._channel.TestingChannel.

Definition at line 1071 of file src/python/grpcio/grpc/__init__.py.

◆ __exit__()

def grpc.Channel.__exit__ (   self,
  exc_type,
  exc_val,
  exc_tb 
)
Exits the runtime context related to the channel object.

Reimplemented in grpc._channel.Channel, grpc._interceptor._Channel, and grpc_testing._channel._channel.TestingChannel.

Definition at line 1075 of file src/python/grpcio/grpc/__init__.py.

◆ CallbackCQ()

grpc::CompletionQueue * grpc::Channel::CallbackCQ ( )
overrideprivatevirtual

Reimplemented from grpc::ChannelInterface.

Definition at line 249 of file channel_cc.cc.

◆ close()

def grpc.Channel.close (   self)
Closes this Channel and releases all resources held by it.

Closing the Channel will immediately terminate all RPCs active with the
Channel and it is not valid to invoke new RPCs with the Channel.

This method is idempotent.

Reimplemented in grpc._channel.Channel, grpc._interceptor._Channel, and grpc_testing._channel._channel.TestingChannel.

Definition at line 1061 of file src/python/grpcio/grpc/__init__.py.

◆ CreateCall()

grpc::internal::Call grpc::Channel::CreateCall ( const grpc::internal::RpcMethod method,
grpc::ClientContext context,
grpc::CompletionQueue cq 
)
overrideprivatevirtual

Implements grpc::ChannelInterface.

Definition at line 163 of file channel_cc.cc.

◆ CreateCallInternal()

grpc::internal::Call grpc::Channel::CreateCallInternal ( const grpc::internal::RpcMethod method,
grpc::ClientContext context,
grpc::CompletionQueue cq,
size_t  interceptor_pos 
)
overrideprivatevirtual

Reimplemented from grpc::ChannelInterface.

Definition at line 117 of file channel_cc.cc.

◆ GetLoadBalancingPolicyName()

std::string grpc::Channel::GetLoadBalancingPolicyName ( ) const

Returns the LB policy name, or the empty string if not yet available.

Definition at line 97 of file channel_cc.cc.

◆ GetServiceConfigJSON()

std::string grpc::Channel::GetServiceConfigJSON ( ) const

Returns the service config in JSON form, or the empty string if not available.

Definition at line 103 of file channel_cc.cc.

◆ GetState()

grpc_connectivity_state grpc::Channel::GetState ( bool  try_to_connect)
overridevirtual

Get the current channel state. If the channel is in IDLE and try_to_connect is set to true, try to connect.

Implements grpc::ChannelInterface.

Definition at line 180 of file channel_cc.cc.

◆ NotifyOnStateChangeImpl()

void grpc::Channel::NotifyOnStateChangeImpl ( grpc_connectivity_state  last_observed,
gpr_timespec  deadline,
grpc::CompletionQueue cq,
void *  tag 
)
overrideprivatevirtual

Implements grpc::ChannelInterface.

Definition at line 202 of file channel_cc.cc.

◆ PerformOpsOnCall()

void grpc::Channel::PerformOpsOnCall ( grpc::internal::CallOpSetInterface ops,
grpc::internal::Call call 
)
overrideprivatevirtual

Implements grpc::internal::CallHook.

Definition at line 169 of file channel_cc.cc.

◆ RegisterMethod()

void * grpc::Channel::RegisterMethod ( const char *  method)
overrideprivatevirtual

Implements grpc::ChannelInterface.

Definition at line 175 of file channel_cc.cc.

◆ stream_stream()

def grpc.Channel.stream_stream (   self,
  method,
  request_serializer = None,
  response_deserializer = None 
)
Creates a StreamStreamMultiCallable for a stream-stream method.

Args:
  method: The name of the RPC method.
  request_serializer: Optional :term:`serializer` for serializing the request
    message. Request goes unserialized in case None is passed.
  response_deserializer: Optional :term:`deserializer` for deserializing the
    response message. Response goes undeserialized in case None
    is passed.

Returns:
  A StreamStreamMultiCallable value for the named stream-stream method.

Reimplemented in grpc._channel.Channel, grpc._interceptor._Channel, and grpc_testing._channel._channel.TestingChannel.

Definition at line 1041 of file src/python/grpcio/grpc/__init__.py.

◆ stream_unary()

def grpc.Channel.stream_unary (   self,
  method,
  request_serializer = None,
  response_deserializer = None 
)
Creates a StreamUnaryMultiCallable for a stream-unary method.

Args:
  method: The name of the RPC method.
  request_serializer: Optional :term:`serializer` for serializing the request
    message. Request goes unserialized in case None is passed.
  response_deserializer: Optional :term:`deserializer` for deserializing the
    response message. Response goes undeserialized in case None is
    passed.

Returns:
  A StreamUnaryMultiCallable value for the named stream-unary method.

Reimplemented in grpc._channel.Channel, grpc._interceptor._Channel, and grpc_testing._channel._channel.TestingChannel.

Definition at line 1021 of file src/python/grpcio/grpc/__init__.py.

◆ subscribe()

def grpc.Channel.subscribe (   self,
  callback,
  try_to_connect = False 
)
Subscribe to this Channel's connectivity state machine.

A Channel may be in any of the states described by ChannelConnectivity.
This method allows application to monitor the state transitions.
The typical use case is to debug or gain better visibility into gRPC
runtime's state.

Args:
  callback: A callable to be invoked with ChannelConnectivity argument.
    ChannelConnectivity describes current state of the channel.
    The callable will be invoked immediately upon subscription
    and again for every change to ChannelConnectivity until it
    is unsubscribed or this Channel object goes out of scope.
  try_to_connect: A boolean indicating whether or not this Channel
    should attempt to connect immediately. If set to False, gRPC
    runtime decides when to connect.

Reimplemented in grpc._channel.Channel, grpc._interceptor._Channel, and grpc_testing._channel._channel.TestingChannel.

Definition at line 950 of file src/python/grpcio/grpc/__init__.py.

◆ unary_stream()

def grpc.Channel.unary_stream (   self,
  method,
  request_serializer = None,
  response_deserializer = None 
)
Creates a UnaryStreamMultiCallable for a unary-stream method.

Args:
  method: The name of the RPC method.
  request_serializer: Optional :term:`serializer` for serializing the request
    message. Request goes unserialized in case None is passed.
  response_deserializer: Optional :term:`deserializer` for deserializing the
    response message. Response goes undeserialized in case None is
    passed.

Returns:
  A UnaryStreamMultiCallable value for the name unary-stream method.

Reimplemented in grpc._channel.Channel, grpc._interceptor._Channel, and grpc_testing._channel._channel.TestingChannel.

Definition at line 1001 of file src/python/grpcio/grpc/__init__.py.

◆ unary_unary()

def grpc.Channel.unary_unary (   self,
  method,
  request_serializer = None,
  response_deserializer = None 
)
Creates a UnaryUnaryMultiCallable for a unary-unary method.

Args:
  method: The name of the RPC method.
  request_serializer: Optional :term:`serializer` for serializing the request
    message. Request goes unserialized in case None is passed.
  response_deserializer: Optional :term:`deserializer` for deserializing the
    response message. Response goes undeserialized in case None
    is passed.

Returns:
  A UnaryUnaryMultiCallable value for the named unary-unary method.

Reimplemented in grpc._channel.Channel, grpc._interceptor._Channel, and grpc_testing._channel._channel.TestingChannel.

Definition at line 981 of file src/python/grpcio/grpc/__init__.py.

◆ unsubscribe()

def grpc.Channel.unsubscribe (   self,
  callback 
)
Unsubscribes a subscribed callback from this Channel's connectivity.

Args:
  callback: A callable previously registered with this Channel from
  having been passed to its "subscribe" method.

Reimplemented in grpc._channel.Channel, grpc._interceptor._Channel, and grpc_testing._channel._channel.TestingChannel.

Definition at line 971 of file src/python/grpcio/grpc/__init__.py.

◆ WaitForStateChangeImpl()

bool grpc::Channel::WaitForStateChangeImpl ( grpc_connectivity_state  last_observed,
gpr_timespec  deadline 
)
overrideprivatevirtual

Implements grpc::ChannelInterface.

Definition at line 210 of file channel_cc.cc.

Friends And Related Function Documentation

◆ experimental::ChannelResetConnectionBackoff

◆ grpc::CreateChannelInternal

std::shared_ptr<Channel> grpc::CreateChannelInternal ( const std::string &  host,
grpc_channel c_channel,
std::vector< std::unique_ptr< grpc::experimental::ClientInterceptorFactoryInterface >>  interceptor_creators 
)
friend

◆ grpc::internal::BlockingUnaryCallImpl

template<class InputMessage , class OutputMessage >
friend class grpc::internal::BlockingUnaryCallImpl
friend

Definition at line 74 of file include/grpcpp/channel.h.

◆ grpc::internal::InterceptedChannel

Definition at line 82 of file include/grpcpp/channel.h.

◆ grpc::testing::ChannelTestPeer

friend class grpc::testing::ChannelTestPeer
friend

Definition at line 75 of file include/grpcpp/channel.h.

Member Data Documentation

◆ c_channel_

grpc_channel* const grpc::Channel::c_channel_
private

Definition at line 108 of file include/grpcpp/channel.h.

◆ callback_cq_

std::atomic<CompletionQueue*> grpc::Channel::callback_cq_ {nullptr}
private

Definition at line 117 of file include/grpcpp/channel.h.

◆ host_

const std::string grpc::Channel::host_
private

Definition at line 107 of file include/grpcpp/channel.h.

◆ interceptor_creators_

std::vector< std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface> > grpc::Channel::interceptor_creators_
private

Definition at line 121 of file include/grpcpp/channel.h.

◆ mu_

grpc::internal::Mutex grpc::Channel::mu_
private

Definition at line 111 of file include/grpcpp/channel.h.


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


grpc
Author(s):
autogenerated on Fri May 16 2025 03:03:30