HelloImp.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #include "HelloImp.h"
  2. #include "HelloServer.h"
  3. #include "servant/RemoteLogger.h"
  4. #include "Push.h"
  5. using namespace tars;
  6. std::atomic<int> hello_count(0);
  7. std::atomic<int> trans_count(0);
  8. HelloImp::HelloImp()
  9. {
  10. }
  11. ///////////////////////////////////////////////////////////////////////////////
  12. void HelloImp::initialize()
  13. {
  14. Application::getCommunicator()->stringToProxy(g_HelloServerObj, _helloPrx);
  15. _helloPrx->tars_async_timeout(100*1000);
  16. }
  17. void HelloImp::destroy()
  18. {
  19. ++g_handleDestroy;
  20. }
  21. struct HelloCallback : public HelloPrxCallback
  22. {
  23. HelloCallback(tars::CurrentPtr &current, int index, const string &s) : _current(current), _index(index), _s(s)
  24. {
  25. }
  26. //回调函数
  27. virtual void callback_testHello(int ret, const string &r)
  28. {
  29. // LOG_CONSOLE_DEBUG << ret << endl;
  30. assert(ret == 0);
  31. Hello::async_response_testTrans(_current, ret, r);
  32. }
  33. virtual void callback_testHello_exception(tars::Int32 ret)
  34. {
  35. cout << "callback exception:" << ret << endl;
  36. }
  37. tars::CurrentPtr _current;
  38. int _index;
  39. string _s;
  40. };
  41. int HelloImp::testTrans(int index, const string &s, string &r, CurrentPtr current)
  42. {
  43. // LOG_CONSOLE_DEBUG << index << endl;
  44. ++trans_count;
  45. try
  46. {
  47. current->setResponse(false);
  48. HelloPrxCallbackPtr p = new HelloCallback(current, index, s);
  49. _helloPrx->async_testHello(p, index, s);
  50. }
  51. catch (exception &e)
  52. {
  53. cout << "exception:" << e.what() << endl;
  54. }
  55. return 0;
  56. }
  57. int HelloImp::testSyncTrans(int index, const string &s, string &r, CurrentPtr current)
  58. {
  59. try
  60. {
  61. int ret = _helloPrx->testHello(index, s, r);
  62. return ret;
  63. }
  64. catch (exception &e)
  65. {
  66. cout << "exception:" << e.what() << endl;
  67. }
  68. return -1;
  69. }
  70. int HelloImp::testHello(int index, const string& s, string& r, CurrentPtr current)
  71. {
  72. //
  73. // if(index % 10000 == 0)
  74. // {
  75. // LOG_CONSOLE_DEBUG << index << endl;
  76. // }
  77. ++hello_count;
  78. r = s;
  79. return 0;
  80. }
  81. int HelloImp::testPid(string &r, CurrentPtr current)
  82. {
  83. r = TC_Common::tostr(this->getApplication());
  84. return 0;
  85. }
  86. int HelloImp::testTimeout(int timeout, CurrentPtr current)
  87. {
  88. TC_Common::sleep(timeout);
  89. return 0;
  90. }
  91. int HelloImp::testDyeing(const std::string & strIn,std::string &strOut, CurrentPtr current)
  92. {
  93. LOG_CONSOLE_DEBUG << strIn << endl;
  94. strOut="this is a dyeing message";
  95. TLOG_DEBUG(strOut << "1, debug log" << endl);
  96. FDLOG("test") << strOut << "1, day log" << endl;
  97. TLOG_DEBUG(strOut << "2, debug log" << endl);
  98. FDLOG("test") << strOut << "2, day log" << endl;
  99. return _helloPrx->testDyeingTrans();
  100. }
  101. tars::Int32 HelloImp::testDyeingTrans(CurrentPtr current)
  102. {
  103. string strOut = "this is a dyeing trans message";
  104. TLOG_DEBUG(strOut << "1, debug log" << endl);
  105. FDLOG("test") << strOut << "1, day log" << endl;
  106. TLOG_DEBUG(strOut << "2, debug log" << endl);
  107. FDLOG("test") << strOut << "2, day log" << endl;
  108. return 0;
  109. }
  110. bool HelloImp::testCoro(const std::string& sIn, std::string &sOut, CurrentPtr current)
  111. {
  112. return ServantProxyThreadData::getData()->_sched != NULL;
  113. }
  114. int HelloImp::testConHash(std::string &sOut, CurrentPtr current)
  115. {
  116. sOut = _handle->getBindAdapter()->getEndpoint().toString();
  117. return 0;
  118. }
  119. int HelloImp::testPushRegister(const string &msg, CurrentPtr current)
  120. {
  121. Push::async_response_push_testPush(current, 0, msg);
  122. return 0;
  123. }
  124. ///////////////////////////////////////////////////////////////////////////////