ServantProxyFactory.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 "servant/ServantProxyFactory.h"
  17. #include "servant/TarsLogger.h"
  18. namespace tars
  19. {
  20. ServantProxyFactory::ServantProxyFactory(Communicator* cm)
  21. : _comm(cm)
  22. {
  23. }
  24. ServantProxyFactory::~ServantProxyFactory()
  25. {
  26. }
  27. ServantPrx::element_type* ServantProxyFactory::getServantProxy(const string& name,const string& setName)
  28. {
  29. TC_LockT<TC_ThreadRecMutex> lock(*this);
  30. string tmpObjName = name + ":" + setName;
  31. map<string, ServantPrx>::iterator it = _servantProxy.find(tmpObjName);
  32. if(it != _servantProxy.end())
  33. {
  34. return it->second.get();
  35. }
  36. ObjectProxy ** ppObjectProxy = new ObjectProxy * [_comm->getClientThreadNum()];
  37. assert(ppObjectProxy != NULL);
  38. for(size_t i = 0; i < _comm->getClientThreadNum(); ++i)
  39. {
  40. ppObjectProxy[i] = _comm->getCommunicatorEpoll(i)->getObjectProxy(name, setName);
  41. }
  42. ServantPrx sp = new ServantProxy(_comm, ppObjectProxy, _comm->getClientThreadNum());
  43. int syncTimeout = TC_Common::strto<int>(_comm->getProperty("sync-invoke-timeout", "3000"));
  44. int asyncTimeout = TC_Common::strto<int>(_comm->getProperty("async-invoke-timeout", "5000"));
  45. int conTimeout = TC_Common::strto<int>(_comm->getProperty("connect-timeout", "1500"));
  46. sp->tars_timeout(syncTimeout);
  47. sp->tars_async_timeout(asyncTimeout);
  48. sp->tars_connect_timeout(conTimeout);
  49. _servantProxy[tmpObjName] = sp;
  50. return sp.get();
  51. }
  52. ///////////////////////////////////////////////////////////////////////////////
  53. }