| 93 | } |
| 94 | |
| 95 | int main(int argc, char* argv[]) { |
| 96 | // Parse gflags. We recommend you to use gflags as well. |
| 97 | GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); |
| 98 | |
| 99 | // A Channel represents a communication line to a Server. Notice that |
| 100 | // Channel is thread-safe and can be shared by all threads in your program. |
| 101 | brpc::ParallelChannel channel; |
| 102 | brpc::ParallelChannelOptions pchan_options; |
| 103 | pchan_options.timeout_ms = FLAGS_timeout_ms; |
| 104 | if (channel.Init(&pchan_options) != 0) { |
| 105 | LOG(ERROR) << "Fail to init ParallelChannel"; |
| 106 | return -1; |
| 107 | } |
| 108 | |
| 109 | brpc::ChannelOptions sub_options; |
| 110 | sub_options.protocol = FLAGS_protocol; |
| 111 | sub_options.connection_type = FLAGS_connection_type; |
| 112 | sub_options.max_retry = FLAGS_max_retry; |
| 113 | // Setting sub_options.timeout_ms does not work because timeout of sub |
| 114 | // channels are disabled in ParallelChannel. |
| 115 | |
| 116 | if (FLAGS_same_channel) { |
| 117 | // For brpc >= 1.0.155.31351, a sub channel can be added into |
| 118 | // a ParallelChannel more than once. |
| 119 | brpc::Channel* sub_channel = new brpc::Channel; |
| 120 | // Initialize the channel, NULL means using default options. |
| 121 | // options, see `brpc/channel.h'. |
| 122 | if (sub_channel->Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), &sub_options) != 0) { |
| 123 | LOG(ERROR) << "Fail to initialize sub_channel"; |
| 124 | return -1; |
| 125 | } |
| 126 | for (int i = 0; i < FLAGS_channel_num; ++i) { |
| 127 | if (channel.AddChannel(sub_channel, brpc::OWNS_CHANNEL, |
| 128 | NULL, NULL) != 0) { |
| 129 | LOG(ERROR) << "Fail to AddChannel, i=" << i; |
| 130 | return -1; |
| 131 | } |
| 132 | } |
| 133 | } else { |
| 134 | for (int i = 0; i < FLAGS_channel_num; ++i) { |
| 135 | brpc::Channel* sub_channel = new brpc::Channel; |
| 136 | // Initialize the channel, NULL means using default options. |
| 137 | // options, see `brpc/channel.h'. |
| 138 | if (sub_channel->Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(), &sub_options) != 0) { |
| 139 | LOG(ERROR) << "Fail to initialize sub_channel[" << i << "]"; |
| 140 | return -1; |
| 141 | } |
| 142 | if (channel.AddChannel(sub_channel, brpc::OWNS_CHANNEL, |
| 143 | NULL, NULL) != 0) { |
| 144 | LOG(ERROR) << "Fail to AddChannel, i=" << i; |
| 145 | return -1; |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // Initialize bvar for sub channel |
| 151 | g_sub_channel_latency = new bvar::LatencyRecorder[FLAGS_channel_num]; |
| 152 | for (int i = 0; i < FLAGS_channel_num; ++i) { |
nothing calls this directly
no test coverage detected