/Users/deen/code/yugabyte-db/src/yb/server/rpc_server.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | #ifndef YB_SERVER_RPC_SERVER_H |
33 | | #define YB_SERVER_RPC_SERVER_H |
34 | | |
35 | | #include <memory> |
36 | | #include <string> |
37 | | #include <vector> |
38 | | |
39 | | #include "yb/gutil/ref_counted.h" |
40 | | |
41 | | #include "yb/rpc/rpc_fwd.h" |
42 | | #include "yb/rpc/service_pool.h" |
43 | | |
44 | | #include "yb/util/status_fwd.h" |
45 | | #include "yb/util/enums.h" |
46 | | #include "yb/util/net/net_fwd.h" |
47 | | |
48 | | namespace yb { |
49 | | namespace server { |
50 | | |
51 | | struct RpcServerOptions { |
52 | | RpcServerOptions(); |
53 | | |
54 | | std::string rpc_bind_addresses; |
55 | | uint16_t default_port = 0; |
56 | | int32_t connection_keepalive_time_ms; |
57 | | }; |
58 | | |
59 | | class RpcServer { |
60 | | public: |
61 | | RpcServer(const std::string& name, RpcServerOptions opts, |
62 | | rpc::ConnectionContextFactoryPtr connection_context_factory); |
63 | | ~RpcServer(); |
64 | | |
65 | | CHECKED_STATUS Init(rpc::Messenger* messenger); |
66 | | // Services need to be registered after Init'ing, but before Start'ing. |
67 | | // The service's ownership will be given to a ServicePool. |
68 | | CHECKED_STATUS RegisterService( |
69 | | size_t queue_limit, rpc::ServiceIfPtr service, |
70 | | rpc::ServicePriority priority = rpc::ServicePriority::kNormal); |
71 | | CHECKED_STATUS Bind(); |
72 | | CHECKED_STATUS Start(); |
73 | | void Shutdown(); |
74 | | |
75 | 216k | const std::vector<Endpoint>& GetBoundAddresses() const { |
76 | 216k | return rpc_bound_addresses_; |
77 | 216k | } |
78 | | |
79 | 71.8k | const std::vector<HostPort>& GetRpcHostPort() const { |
80 | 71.8k | return rpc_host_port_; |
81 | 71.8k | } |
82 | | |
83 | | std::string ToString() const; |
84 | | |
85 | | const rpc::ServicePool* TEST_service_pool(const std::string& service_name) const; |
86 | | |
87 | | private: |
88 | | enum ServerState { |
89 | | // Default state when the rpc server is constructed. |
90 | | UNINITIALIZED, |
91 | | // State after Init() was called. |
92 | | INITIALIZED, |
93 | | // State after Bind(). |
94 | | BOUND, |
95 | | // State after Start() was called. |
96 | | STARTED |
97 | | }; |
98 | | |
99 | | std::string name_; |
100 | | |
101 | | ServerState server_state_; |
102 | | |
103 | | const RpcServerOptions options_; |
104 | | |
105 | | rpc::Messenger* messenger_ = nullptr; |
106 | | |
107 | | // Parsed addresses to bind RPC to. Set by Init(). |
108 | | std::vector<Endpoint> rpc_bind_addresses_; |
109 | | std::vector<Endpoint> rpc_bound_addresses_; |
110 | | |
111 | | // This saves the rpc host port flag's ip and port information (and no dns name lookup is done). |
112 | | std::vector<HostPort> rpc_host_port_; |
113 | | |
114 | | rpc::ConnectionContextFactoryPtr connection_context_factory_; |
115 | | |
116 | | DISALLOW_COPY_AND_ASSIGN(RpcServer); |
117 | | }; |
118 | | |
119 | | } // namespace server |
120 | | } // namespace yb |
121 | | |
122 | | #endif // YB_SERVER_RPC_SERVER_H |