Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
central_controller_rpc_client.h
Go to the documentation of this file.
1 // Copyright 2016 Google Inc.
16 
17 #ifndef PAGESPEED_CONTROLLER_CENTRAL_CONTROLLER_RPC_CLIENT_H_
18 #define PAGESPEED_CONTROLLER_CENTRAL_CONTROLLER_RPC_CLIENT_H_
19 
20 #include <memory>
21 #include <unordered_set>
22 
23 #include "base/macros.h"
24 #include "pagespeed/controller/controller.grpc.pb.h"
35 #include "pagespeed/kernel/base/thread_annotations.h"
37 
38 namespace net_instaweb {
39 
49 
51  public:
52  static const char kControllerReconnectTimeStatistic[];
53  static const int kControllerReconnectDelayMs;
54 
55  CentralControllerRpcClient(const GoogleString& server_address,
56  int panic_threshold, ThreadSystem* thread_system,
57  Timer* timer, Statistics* statistics,
58  MessageHandler* handler);
59  virtual ~CentralControllerRpcClient();
60 
63  ExpensiveOperationCallback* callback) override;
64  void ScheduleRewrite(ScheduleRewriteCallback* callback) override;
65 
66  void ShutDown() override LOCKS_EXCLUDED(mutex_);
67 
68  static void InitStats(Statistics* stats);
69 
70  private:
71  enum State {
72  DISCONNECTED,
73  RUNNING,
74  SHUTDOWN,
75  };
76 
77  class GrpcClientThread;
78  class ClientRegistry;
79 
81  template <typename ContextT, typename CallbackT>
82  void StartContext(CallbackT* callback) LOCKS_EXCLUDED(mutex_);
83 
86  void ConsiderConnecting(int64 now_ms) EXCLUSIVE_LOCKS_REQUIRED(mutex_);
87 
89  bool TimestampsAllowConnection(int64 now) EXCLUSIVE_LOCKS_REQUIRED(mutex_);
90 
91  ThreadSystem* thread_system_;
92  Timer* timer_;
93  std::unique_ptr<AbstractMutex> mutex_;
98  std::unique_ptr<ClientRegistry> clients_;
99  MessageHandler* handler_;
100 
101  State state_ GUARDED_BY(mutex_);
102  const int controller_panic_threshold_;
103  int64 reconnect_time_ms_ GUARDED_BY(mutex_);
104  UpDownCounter* reconnect_time_ms_statistic_;
105 
106  std::unique_ptr<::grpc::CompletionQueue> queue_;
107  std::shared_ptr<::grpc::ChannelInterface> channel_;
108  std::unique_ptr<grpc::CentralControllerRpcService::Stub> stub_;
109 
111  std::unique_ptr<GrpcClientThread> client_thread_ GUARDED_BY(mutex_);
112 
113 
114 };
115 
116 }
117 
118 #endif
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
Implementor interface to rewrite scheduling features in CentralController.
Definition: schedule_rewrite_callback.h:48
void ScheduleExpensiveOperation(ExpensiveOperationCallback *callback) override
CentralController implementation.
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
void ScheduleRewrite(ScheduleRewriteCallback *callback) override
Definition: central_controller.h:29
Definition: central_controller_rpc_client.h:50
Implementor interface to ExpensiveOperation features in CentralController.
Definition: expensive_operation_callback.h:46
void ShutDown() override LOCKS_EXCLUDED(mutex_)
Definition: thread_system.h:40
Definition: statistics.h:73
Definition: message_handler.h:39
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27