-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support proxy and generic call of baidu protocol
- Loading branch information
1 parent
bbd88a8
commit 544cb06
Showing
13 changed files
with
666 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
|
||
#include "brpc/baidu_master_service.h" | ||
#include "butil/logging.h" | ||
|
||
namespace brpc { | ||
|
||
BaiduMasterService::BaiduMasterService() | ||
:_status(new(std::nothrow) MethodStatus) { | ||
LOG_IF(FATAL, NULL == _status) << "Fail to new MethodStatus"; | ||
} | ||
|
||
BaiduMasterService::~BaiduMasterService() { | ||
delete _status; | ||
_status = NULL; | ||
} | ||
|
||
void BaiduMasterService::Describe(std::ostream &os, | ||
const DescribeOptions&) const { | ||
os << butil::class_name_str(*this); | ||
} | ||
|
||
void BaiduMasterService::Expose(const butil::StringPiece& prefix) { | ||
if (NULL == _status) { | ||
return; | ||
} | ||
std::string s; | ||
const std::string& cached_name = butil::class_name_str(*this); | ||
s.reserve(prefix.size() + 1 + cached_name.size()); | ||
s.append(prefix.data(), prefix.size()); | ||
s.push_back('_'); | ||
s.append(cached_name); | ||
_status->Expose(s); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
|
||
#ifndef BRPC_BAIDU_MASTER_SERVICE_H | ||
#define BRPC_BAIDU_MASTER_SERVICE_H | ||
|
||
#include <google/protobuf/service.h> | ||
#include <google/protobuf/stubs/callback.h> | ||
#include "brpc/details/method_status.h" | ||
#include "brpc/proto_base.pb.h" | ||
#include "brpc/controller.h" | ||
#include "brpc/serialized_request.h" | ||
#include "brpc/serialized_response.h" | ||
|
||
namespace brpc { | ||
|
||
namespace policy { | ||
void ProcessRpcRequest(InputMessageBase* msg_base); | ||
} | ||
|
||
class BaiduMasterService : public ::google::protobuf::Service | ||
, public Describable { | ||
public: | ||
BaiduMasterService(); | ||
~BaiduMasterService() override; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(BaiduMasterService); | ||
|
||
AdaptiveMaxConcurrency& MaxConcurrency() { | ||
return _max_concurrency; | ||
} | ||
|
||
virtual void ProcessRpcRequest(Controller* cntl, | ||
const SerializedRequest* request, | ||
SerializedResponse* response, | ||
::google::protobuf::Closure* done) = 0; | ||
|
||
|
||
// Put descriptions into the stream. | ||
void Describe(std::ostream &os, const DescribeOptions&) const override; | ||
|
||
// implements Service ---------------------------------------------- | ||
|
||
void CallMethod(const ::google::protobuf::MethodDescriptor*, | ||
::google::protobuf::RpcController* controller, | ||
const ::google::protobuf::Message* request, | ||
::google::protobuf::Message* response, | ||
::google::protobuf::Closure* done) override { | ||
ProcessRpcRequest((Controller*)controller, | ||
(const SerializedRequest*)request, | ||
(SerializedResponse*)response, done); | ||
} | ||
|
||
const ::google::protobuf::ServiceDescriptor* GetDescriptor() override { | ||
return BaiduMasterServiceBase::descriptor(); | ||
} | ||
|
||
const ::google::protobuf::Message& GetRequestPrototype( | ||
const ::google::protobuf::MethodDescriptor*) const override { | ||
return _default_request; | ||
} | ||
|
||
const ::google::protobuf::Message& GetResponsePrototype( | ||
const ::google::protobuf::MethodDescriptor*) const override { | ||
return _default_response; | ||
} | ||
|
||
private: | ||
friend void policy::ProcessRpcRequest(InputMessageBase* msg_base); | ||
friend class StatusService; | ||
friend class Server; | ||
|
||
void Expose(const butil::StringPiece& prefix); | ||
|
||
SerializedRequest _default_request; | ||
SerializedResponse _default_response; | ||
|
||
MethodStatus* _status; | ||
AdaptiveMaxConcurrency _max_concurrency; | ||
}; | ||
|
||
} | ||
|
||
#endif //BRPC_BAIDU_MASTER_SERVICE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.