xref: /aosp_15_r20/external/tensorflow/tensorflow/core/data/service/grpc_dispatcher_impl.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
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 
16 #ifndef TENSORFLOW_CORE_DATA_SERVICE_GRPC_DISPATCHER_IMPL_H_
17 #define TENSORFLOW_CORE_DATA_SERVICE_GRPC_DISPATCHER_IMPL_H_
18 
19 #include "grpcpp/server_builder.h"
20 #include "tensorflow/core/data/service/dispatcher.grpc.pb.h"
21 #include "tensorflow/core/data/service/dispatcher_impl.h"
22 #include "tensorflow/core/data/service/export.pb.h"
23 #include "tensorflow/core/protobuf/service_config.pb.h"
24 
25 namespace tensorflow {
26 namespace data {
27 
28 // This class is a wrapper that handles communication for gRPC.
29 class GrpcDispatcherImpl : public DispatcherService::Service {
30  public:
31   // Constructs a GrpcDispatcherImpl with the given config, and registers it
32   // with `server_builder`.
33   explicit GrpcDispatcherImpl(const experimental::DispatcherConfig& config,
34                               ::grpc::ServerBuilder& server_builder);
~GrpcDispatcherImpl()35   ~GrpcDispatcherImpl() override {}
36 
37   Status Start();
38 
39   size_t NumActiveIterations();
40 
41   DispatcherStateExport ExportState() const;
42 
43 #define HANDLER(method)                                 \
44   ::grpc::Status method(::grpc::ServerContext* context, \
45                         const method##Request* request, \
46                         method##Response* response) override;
47   HANDLER(WorkerHeartbeat);
48   HANDLER(WorkerUpdate);
49   HANDLER(GetDatasetDef);
50   HANDLER(GetSplit);
51   HANDLER(GetVersion);
52   HANDLER(GetOrRegisterDataset);
53   HANDLER(ReleaseIterationClient);
54   HANDLER(MaybeRemoveTask);
55   HANDLER(GetOrCreateJob);
56   HANDLER(GetOrCreateIteration);
57   HANDLER(ClientHeartbeat);
58   HANDLER(GetWorkers);
59   HANDLER(GetDataServiceMetadata);
60   HANDLER(GetDataServiceConfig);
61 #undef HANDLER
62 
63  private:
64   DataServiceDispatcherImpl impl_;
65 
66   TF_DISALLOW_COPY_AND_ASSIGN(GrpcDispatcherImpl);
67 };
68 
69 }  // namespace data
70 }  // namespace tensorflow
71 
72 #endif  // TENSORFLOW_CORE_DATA_SERVICE_GRPC_DISPATCHER_IMPL_H_
73