KeepAliveNodeF.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * Tencent is pleased to support the open source community by making Tars available.
  3. *
  4. * Copyright (C) 2016THL 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 "util/tc_platform.h"
  17. #include "util/tc_port.h"
  18. #include "servant/KeepAliveNodeF.h"
  19. #include "servant/RemoteLogger.h"
  20. #include "servant/Communicator.h"
  21. namespace tars
  22. {
  23. void KeepAliveNodeFHelper::setNodeInfo(const CommunicatorPtr &comm, const string &obj, const string &app, const string &server)
  24. {
  25. _comm = comm;
  26. if(!obj.empty())
  27. {
  28. _nodePrx = _comm->stringToProxy<ServerFPrx>(obj);
  29. }
  30. _si.application = app;
  31. _si.serverName = server;
  32. _si.pid = TC_Port::getpid();
  33. }
  34. void KeepAliveNodeFHelper::keepAlive(const string &adapter)
  35. {
  36. try
  37. {
  38. if(_nodePrx)
  39. {
  40. ServerInfo si = _si;
  41. si.adapter = adapter;
  42. _nodePrx->async_keepAlive(NULL,si);
  43. }
  44. }
  45. catch(exception &ex)
  46. {
  47. TLOGERROR("KeepAliveNodeFHelper::keepAlive error:" << ex.what() << endl);
  48. }
  49. catch(...)
  50. {
  51. TLOGERROR("KeepAliveNodeFHelper::keepAlive unknown error" << endl);
  52. }
  53. }
  54. void KeepAliveNodeFHelper::keepActiving()
  55. {
  56. try
  57. {
  58. if(_nodePrx)
  59. {
  60. _nodePrx->async_keepActiving(NULL, _si);
  61. }
  62. }
  63. catch(exception &ex)
  64. {
  65. TLOGERROR("[KeepAliveNodeFHelper::keepAlive error:" << ex.what() << "]" << endl);
  66. }
  67. catch(...)
  68. {
  69. TLOGERROR("[KeepAliveNodeFHelper::keepAlive unknown error]" << endl);
  70. }
  71. }
  72. void KeepAliveNodeFHelper::reportVersion(const string &version)
  73. {
  74. try
  75. {
  76. if(_nodePrx)
  77. {
  78. _nodePrx->async_reportVersion(NULL, _si.application, _si.serverName, version);
  79. }
  80. }
  81. catch(exception &ex)
  82. {
  83. TLOGERROR("[KeepAliveNodeFHelper::reportVersion error:" << ex.what() << "]" << endl);
  84. }
  85. catch(...)
  86. {
  87. TLOGERROR("[KeepAliveNodeFHelper::reportVersion unknown error" << "]" << endl);
  88. }
  89. }
  90. }