ObjectProxyFactory.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #ifndef __TARS_OBJECT_PROXY_FACTORY_H_
  17. #define __TARS_OBJECT_PROXY_FACTORY_H_
  18. #include "servant/Communicator.h"
  19. #include "servant/ObjectProxy.h"
  20. #include <vector>
  21. namespace tars
  22. {
  23. /////////////////////////////////////////////////////////////////////////////////////////
  24. /**
  25. * 获取ObjectProxy对象
  26. * 每个objectname在每个客户端网络线程中有唯一一个objectproxy
  27. *
  28. */
  29. class ObjectProxyFactory : public TC_HandleBase, public TC_ThreadRecMutex
  30. {
  31. public:
  32. /**
  33. * 构造函数
  34. * @param pCommunicatorEpoll
  35. */
  36. ObjectProxyFactory(CommunicatorEpoll * pCommunicatorEpoll);
  37. /**
  38. * 获取对象代理
  39. * @param sObjectProxyName
  40. * @param setName 指定set调用的setid
  41. *
  42. * @return ObjectPrx
  43. */
  44. ObjectProxy * getObjectProxy(const string& sObjectProxyName,const string& setName = "");
  45. /**
  46. * 析构函数
  47. */
  48. ~ObjectProxyFactory();
  49. /**
  50. * 所有对象代理加载locator信息
  51. */
  52. int loadObjectLocator();
  53. /**
  54. * 获取所有对象的个数,为了不加锁不用map
  55. */
  56. inline size_t getObjNum()
  57. {
  58. return _objNum;
  59. }
  60. /**
  61. * 根据序号 获取所有obj对象,为了不加锁不用map
  62. */
  63. inline ObjectProxy * getObjectProxy(size_t iNum)
  64. {
  65. assert(iNum < _objNum);
  66. return _vObjectProxys[iNum];
  67. }
  68. private:
  69. /**
  70. * 客户端网络线程
  71. */
  72. CommunicatorEpoll * _communicatorEpoll;
  73. /**
  74. * 保存已创建的objectproxy
  75. */
  76. map<string,ObjectProxy*> _objectProxys;
  77. /**
  78. * 保存已经创建的obj 取的时候可以不用加锁
  79. */
  80. vector<ObjectProxy *> _vObjectProxys;
  81. /*
  82. *保存已经创建obj的数量
  83. */
  84. size_t _objNum;
  85. };
  86. /////////////////////////////////////////////////////////////////////////////////////////
  87. }
  88. #endif