ServantProxyFactory.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/RemoteLogger.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, bool rootServant)
  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. return it->second.get();
  34. ServantPrx sp = new ServantProxy(_comm, name, setName);
  35. //需要主动初始化一次
  36. sp->tars_initialize(rootServant);
  37. int syncTimeout = TC_Common::strto<int>(_comm->getProperty("sync-invoke-timeout", "3000"));
  38. int asyncTimeout = TC_Common::strto<int>(_comm->getProperty("async-invoke-timeout", "5000"));
  39. int conTimeout = TC_Common::strto<int>(_comm->getProperty("connect-timeout", "1500"));
  40. sp->tars_timeout(syncTimeout);
  41. sp->tars_async_timeout(asyncTimeout);
  42. sp->tars_connect_timeout(conTimeout);
  43. _servantProxy[tmpObjName] = sp;
  44. return sp.get();
  45. }
  46. ///////////////////////////////////////////////////////////////////////////////
  47. }