-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOuterProxyFactory.h
More file actions
64 lines (49 loc) · 1.29 KB
/
OuterProxyFactory.h
File metadata and controls
64 lines (49 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef _OUTER_PROXY_FACTORY_H_
#define _OUTER_PROXY_FACTORY_H_
#include <map>
#include <stdexcept>
#include "util/tc_autoptr.h"
#include "util/tc_thread_mutex.h"
#include "servant/Global.h"
#include "servant/Application.h"
using namespace std;
using namespace tars;
/**
* 代理对象工厂
*/
class OuterProxyFactory : public TC_HandleBase
, public TC_ThreadMutex
{
public:
template<class T> T& getChecked(const string& name, T& t)
{
if (_proxy.find(name) == _proxy.end())
{
t = Application::getCommunicator()->stringToProxy<T>(name);
//在Tars下这个判断不会进入,Tars获取对象代理不会执行远端检测
if (!t)
{
ostringstream os;
os << "invalid outer proxy:" << name;
throw TC_Exception(os.str().c_str(), __LINE__);
}
else
{
TC_LockT<TC_ThreadMutex> lock(*this);
_proxy[name] = t;
}
return t;
}
t = (typename T::element_type*)((_proxy[name]).get());
return t;
}
private:
OuterProxyFactory(){}
friend class OuterFactoryImp;
private:
map<string, tars::ServantPrx> _proxy;
};
//
typedef TC_AutoPtr<OuterProxyFactory> OuterProxyFactoryPtr;
/////////////////////////////////////////////////////////////////
#endif