HCE project C++ developers source code library  1.1.1
HCE project developer library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxTaskReducersManager.cpp
Go to the documentation of this file.
2 
3 namespace HCE {
4 namespace sphinx {
5 namespace reduce_task {
6 
8  const Poco::SharedPtr<SphinxTaskReducersStorageIf>& sphinxTaskReducersStorage,
9  const Poco::SharedPtr<SphinxTaskReducerFactoryIf>& sphinxTaskReducerFactory,
10  const Poco::SharedPtr<SphinxResultJSONConvertorIf>& sphinxResultJSONConvertor)
11 {
12  _sphinxTaskReducersStorage = sphinxTaskReducersStorage;
13  _sphinxTaskReducerFactory = sphinxTaskReducerFactory;
14  _sphinxResultJSONConvertor = sphinxResultJSONConvertor;
15 }
16 
18 
19 
21 {
22  return types::MessageType::mtSphinx;
23 }
24 
25 bool SphinxTaskReducersManager::isReducerExist(unsigned long long reduceTaskId)
26 {
27  try{
28  _sphinxTaskReducersStorage->findByKey(reduceTaskId);
29  return true;
30  }
32  return false;
33  }
34 }
35 
36 void SphinxTaskReducersManager::createReducer(unsigned long long reduceTaskId)
37 {
38  Poco::SharedPtr<SphinxTaskReducerIf> sphinxTaskReducer =
39  _sphinxTaskReducerFactory->create();
40  _sphinxTaskReducersStorage->addWithKey(reduceTaskId, sphinxTaskReducer);
41 }
42 
43 void SphinxTaskReducersManager::addDataInReducer(unsigned long long reduceTaskId,
44  const std::string& json)
45 {
46  Poco::SharedPtr<SphinxResultData> sphinxResult =
47  _sphinxResultJSONConvertor->convertToSphinxResultDataFrom(json);
48  Poco::SharedPtr<SphinxTaskReducerIf> sphinxTaskReducer =
49  _sphinxTaskReducersStorage->findByKey(reduceTaskId);
50  sphinxTaskReducer->addData(*sphinxResult.get());
51 }
52 
54  reduceTaskId)
55 {
56  Poco::SharedPtr<SphinxTaskReducerIf> sphinxTaskReducer =
57  _sphinxTaskReducersStorage->findByKey(reduceTaskId);
58  sphinxTaskReducer->reduce(_sphinxTaskReducerFactory->getScheduleStrategy());
59  Poco::SharedPtr<SphinxResultData> reduceResult = sphinxTaskReducer->getResult();
60  return _sphinxResultJSONConvertor->convertToJSONFrom(
61  transformSphinxResultData(reduceResult));
62 }
63 
64 void SphinxTaskReducersManager::deleteReducerBy(unsigned long long reduceTaskId)
65 {
66  _sphinxTaskReducersStorage->deleteByKey(reduceTaskId);
67 }
68 
69 Poco::SharedPtr<SphinxResultData> SphinxTaskReducersManager::transformSphinxResultData(
70  Poco::SharedPtr<SphinxResultData>& reduceResult)
71 {
72  SphinxResultTruncaterIf& sphinxResultTrancater = _sphinxTaskReducerFactory->
73  getSphinxResultTrancater();
74  return sphinxResultTrancater.trancate(reduceResult);
75 }
76 
77 }
78 }
79 }