endpoint_binder_pool.h
Go to the documentation of this file.
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GRPC_CORE_EXT_TRANSPORT_BINDER_CLIENT_ENDPOINT_BINDER_POOL_H
16 #define GRPC_CORE_EXT_TRANSPORT_BINDER_CLIENT_ENDPOINT_BINDER_POOL_H
17 
19 
20 #include <functional>
21 #include <string>
22 
23 #include "absl/container/flat_hash_map.h"
24 
27 
28 namespace grpc_binder {
29 
30 // This class serves as a buffer of endpoint binders between C++ and
31 // Java. `AddEndpointBinder` will be indirectly invoked by Java code, and
32 // `GetEndpointBinder` is for C++ code to register callback to get endpoint
33 // binder when become available. This simplifies JNI related threading issues
34 // since both side only need to interact with this buffer in non-blocking
35 // manner and avoids cross-language callbacks.
37  public:
38  // Invokes the callback when the binder corresponding to the conn_id become
39  // available. If the binder is already available, invokes the callback
40  // immediately.
41  // Ownership of the endpoint binder will be transferred to the callback
42  // function and it will be removed from the pool
43  void GetEndpointBinder(
44  std::string conn_id,
45  std::function<void(std::unique_ptr<grpc_binder::Binder>)> cb);
46 
47  // Add an endpoint binder to the pool
48  void AddEndpointBinder(std::string conn_id,
49  std::unique_ptr<grpc_binder::Binder> b);
50 
51  private:
54  binder_map_ ABSL_GUARDED_BY(m_);
56  std::function<void(std::unique_ptr<grpc_binder::Binder>)>>
57  pending_requests_ ABSL_GUARDED_BY(m_);
58 };
59 
60 // Returns the singleton
62 
63 } // namespace grpc_binder
64 
65 #endif // GRPC_CORE_EXT_TRANSPORT_BINDER_CLIENT_ENDPOINT_BINDER_POOL_H
grpc_binder::EndpointBinderPool::m_
grpc_core::Mutex m_
Definition: endpoint_binder_pool.h:52
binder.h
grpc_binder::EndpointBinderPool::GetEndpointBinder
void GetEndpointBinder(std::string conn_id, std::function< void(std::unique_ptr< grpc_binder::Binder >)> cb)
Definition: endpoint_binder_pool.cc:56
grpc_binder
Definition: connection_id_generator.cc:45
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_binder::GetEndpointBinderPool
EndpointBinderPool * GetEndpointBinderPool()
Definition: endpoint_binder_pool.cc:108
grpc_binder::EndpointBinderPool::ABSL_GUARDED_BY
absl::flat_hash_map< std::string, std::unique_ptr< grpc_binder::Binder > > binder_map_ ABSL_GUARDED_BY(m_)
grpc_binder::EndpointBinderPool::AddEndpointBinder
void AddEndpointBinder(std::string conn_id, std::unique_ptr< grpc_binder::Binder > b)
Definition: endpoint_binder_pool.cc:82
b
uint64_t b
Definition: abseil-cpp/absl/container/internal/layout_test.cc:53
grpc_core::Mutex
Definition: src/core/lib/gprpp/sync.h:61
absl::flat_hash_map
Definition: abseil-cpp/absl/container/flat_hash_map.h:113
grpc_binder::EndpointBinderPool
Definition: endpoint_binder_pool.h:36
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250
sync.h
cb
OPENSSL_EXPORT pem_password_cb * cb
Definition: pem.h:351
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:15