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/protobuf/service_config.pb.h"
23 
24 namespace tensorflow {
25 namespace data {
26 
27 // This class is a wrapper that handles communication for gRPC.
28 class GrpcDispatcherImpl : public DispatcherService::Service {
29  public:
30   // Constructs a GrpcDispatcherImpl with the given config, and registers it
31   // with `server_builder`.
32   explicit GrpcDispatcherImpl(const experimental::DispatcherConfig& config,
33                               ::grpc::ServerBuilder& server_builder);
~GrpcDispatcherImpl()34   ~GrpcDispatcherImpl() override {}
35 
36   Status Start();
37 
38 #define HANDLER(method)                                 \
39   ::grpc::Status method(::grpc::ServerContext* context, \
40                         const method##Request* request, \
41                         method##Response* response) override;
42   HANDLER(WorkerHeartbeat);
43   HANDLER(WorkerUpdate);
44   HANDLER(GetDatasetDef);
45   HANDLER(GetSplit);
46   HANDLER(GetVersion);
47   HANDLER(GetOrRegisterDataset);
48   HANDLER(ReleaseJobClient);
49   HANDLER(GetOrCreateJob);
50   HANDLER(ClientHeartbeat);
51   HANDLER(GetWorkers);
52 #undef HANDLER
53 
54  private:
55   DataServiceDispatcherImpl impl_;
56 
57   TF_DISALLOW_COPY_AND_ASSIGN(GrpcDispatcherImpl);
58 };
59 
60 }  // namespace data
61 }  // namespace tensorflow
62 
63 #endif  // TENSORFLOW_CORE_DATA_SERVICE_GRPC_DISPATCHER_IMPL_H_
64