forked from sogou/srpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a18c49c
commit 0b16172
Showing
13 changed files
with
426 additions
and
81 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
Copyright (c) 2021 Sogou, Inc. | ||
Licensed 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 __RPC_FILTER_H__ | ||
#define __RPC_FILTER_H__ | ||
|
||
#include <map> | ||
#include <vector> | ||
#include <string> | ||
#include "workflow/WFTask.h" | ||
#include "workflow/WFTaskFactory.h" | ||
|
||
namespace srpc | ||
{ | ||
|
||
using RPCModuleData = std::map<std::string, std::string>; | ||
using RPCLogVector = std::vector<std::pair<std::string, std::string>>; | ||
|
||
static RPCModuleData global_empty_map; | ||
|
||
class RPCFilter | ||
{ | ||
public: | ||
SubTask *create_filter_task(const RPCModuleData& data) | ||
{ | ||
if (this->filter(const_cast<RPCModuleData&>(data))) | ||
return this->create(const_cast<RPCModuleData&>(data)); | ||
|
||
return WFTaskFactory::create_empty_task(); | ||
} | ||
|
||
private: | ||
virtual SubTask *create(RPCModuleData& data) = 0; | ||
|
||
virtual bool filter(RPCModuleData& data) = 0; | ||
|
||
public: | ||
RPCFilter(int module_type, const std::string name) : | ||
name(std::move(name)) | ||
{ | ||
this->module_type = module_type; | ||
} | ||
|
||
const std::string& get_name() const { return this->name; } | ||
int get_module_type() const { return this->module_type; } | ||
|
||
virtual bool client_begin(SubTask *task, const RPCModuleData& data) | ||
{ | ||
return true; | ||
} | ||
|
||
virtual bool server_begin(SubTask *task, const RPCModuleData& data) | ||
{ | ||
return true; | ||
} | ||
|
||
virtual bool client_end(SubTask *task, const RPCModuleData& data) | ||
{ | ||
return true; | ||
} | ||
|
||
virtual bool server_end(SubTask *task, const RPCModuleData& data) | ||
{ | ||
return true; | ||
} | ||
|
||
private: | ||
std::string name; | ||
int module_type; | ||
}; | ||
|
||
/* | ||
class RPCMonitorPrometheus : public RPCFilter | ||
{ | ||
public: | ||
bool filter_finish() | ||
{ | ||
SRPCGlobal->get_instance()->get_prometheus()->write(); | ||
} | ||
}; | ||
*/ | ||
|
||
} // end namespace srpc | ||
|
||
#endif | ||
|
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.