hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
main.cpp
Go to the documentation of this file.
1 #include <ReducingHandler.h>
2 #include <ReducingPartsCountersStorage.h>
3 #include <ReducingOutputMessageBuilder.h>
4 #include <ConsoleSupportNotifier.h>
5 #include <ReducingExceptionsTranslator.h>
6 #include <SphinxTaskReducersManagerBuilder.h>
7 #include <PocoJSONReducingInputMessageConvertor.h>
8 #include <PocoJSONReducingOutputMessageConvertor.h>
9 
10 using namespace HCE::reduce;
11 using namespace HCE::reduce_types;
12 using namespace HCE::reduce_convertors;
13 using namespace HCE::sphinx;
14 using namespace HCE::sphinx::reduce_task;
15 using namespace Poco;
16 using namespace std;
17 
18 int main(int argc, char** argv)
19 {
20  SphinxTaskReducersManagerBuilder<> sphinxTaskReducersManagerBuilder;
21  SharedPtr<ReducingPartsCountersStorage> reducingPartsCountersStorage(new ReducingPartsCountersStorage());
22  SharedPtr<SphinxTaskReducersManagerIf<SphinxReduceJobBuilder<> > >sphinxTaskReducersManager = sphinxTaskReducersManagerBuilder.build();
23  SharedPtr<ReducingExceptionsTranslator>reducingExceptionsTranslator(new ReducingExceptionsTranslator());
24  SharedPtr<ReducingOutputMessageBuilder>reducingOutputMessageBuilder(new ReducingOutputMessageBuilder(reducingExceptionsTranslator));
25  SharedPtr<SupportNotifierIf> supportNotifier(new ConsoleSupportNotifier());
26 
27  ReducingHandler<> reducingHandler(reducingPartsCountersStorage, sphinxTaskReducersManager, reducingOutputMessageBuilder, supportNotifier);
28 
29  PocoJSONReducingInputMessageConvertor pocoJSONReducingInputMessageConvertor;
30  PocoJSONReducingOutputMessageConvertor pocoJSONReducingOutputMessageConvertor;
31 
32  string sphinxResultJSON = "";
33  string reducingResponseJSON = "";
34  int itemId = 2;
35  int nodesCount = 1;
36  bool done = false;
37  SharedPtr<ReducingInputMessage>reducingInputMessage;
38  SharedPtr<ReducingOutputMessage> reducingOutputMessage;
39 
40  try{
41  reducingInputMessage = pocoJSONReducingInputMessageConvertor.convertToReducingInputMessageFrom(sphinxResultJSON);
42  }
44  cout << e.what() << endl;
45  return 1;
46  }
47 
48 
49  reducingHandler.accumulateReducingData(itemId, reducingInputMessage);
50 
51  try{
52  if(reducingHandler.getAccumulateReducingPartsNumberBy(itemId) == nodesCount){
53  done = true;
54  }
55  }
56  catch(NotFoundByKeyException& e){
57  cout << e.what() << endl;
58  return 2;
59  }
60 
61  if (done){
62  reducingOutputMessage = reducingHandler.makeReducing(itemId);
63  reducingHandler.deleteReducingTaskBy(itemId);
64  }
65 
66  try{
67  reducingResponseJSON = pocoJSONReducingOutputMessageConvertor.convertToJSONFrom(reducingOutputMessage);
68  }
70  cout << e.what() << endl;
71  return 3;
72  }
73 
74  return 0;
75 }