main.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * Tencent is pleased to support the open source community by making Tars available.
  3. *
  4. * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
  5. *
  6. * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  7. * in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * https://opensource.org/licenses/BSD-3-Clause
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. */
  16. #include "AdminReg.h"
  17. #include "servant/Communicator.h"
  18. #include <iostream>
  19. using namespace std;
  20. using namespace tars;
  21. class Test1
  22. {
  23. public:
  24. Test1(const string &sStr);
  25. ~Test1();
  26. void th_dohandle(int excut_num);
  27. private:
  28. Communicator _comm;
  29. AdminRegPrx _prx;
  30. };
  31. Test1::Test1(const string &sStr)
  32. {
  33. _comm.stringToProxy("tars.tarsAdminRegistry.AdminRegObj@tcp -h 10.208.139.242 -p 12000 -t 60000", _prx);
  34. }
  35. Test1::~Test1()
  36. {
  37. }
  38. void Test1::th_dohandle(int excut_num)
  39. {
  40. for(int i=0; i<excut_num; i++)
  41. {
  42. try
  43. {
  44. string application("tars");
  45. string serverName("tarsconfig");
  46. string nodeName("10.208.139.242");
  47. ServerStateDesc state;
  48. string result;
  49. int iRet = _prx->tars_set_timeout(15000)->getServerState(application, serverName, nodeName, state, result);
  50. if(iRet == 0)
  51. {
  52. cout << "succ." << state.presentStateInReg << endl;
  53. }
  54. else
  55. {
  56. cout << "fail." << endl;
  57. }
  58. }
  59. catch(TC_Exception &e)
  60. {
  61. cout << "pthread id: " << std::this_thread::get_id() << "id: " << i << "exception: " << e.what() << endl;
  62. }
  63. catch(...)
  64. {
  65. cout << "pthread id: " << std::this_thread::get_id() << "id: " << i << "unknown exception." << endl;
  66. }
  67. }
  68. }
  69. int main(int argc,char ** argv)
  70. {
  71. if(argc != 4)
  72. {
  73. cout << "usage: " << argv[0] << " ThreadNum CallTimes sObj" << endl;
  74. return -1;
  75. }
  76. string s = string(argv[3]);
  77. Test1 test1(s);
  78. try
  79. {
  80. tars::Int32 times = TC_Common::strto<tars::Int32>(string(argv[3]));
  81. test1.th_dohandle(times);
  82. }
  83. catch(exception &e)
  84. {
  85. cout<<e.what()<<endl;
  86. }
  87. catch(...)
  88. {
  89. }
  90. cout << "end" << endl;
  91. return 0;
  92. }