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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
// **********************************************************************
//
// Copyright (c) 2001
// MutableRealms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
#include <Ice/RoutingTable.h>
#include <Ice/IdentityUtil.h>
#include <Glacier/ClientBlobject.h>
using namespace std;
using namespace Ice;
using namespace Glacier;
Glacier::ClientBlobject::ClientBlobject(const CommunicatorPtr& communicator,
const IceInternal::RoutingTablePtr& routingTable,
const string& allowCategories) :
_communicator(communicator),
_logger(_communicator->getLogger()),
_routingTable(routingTable)
{
PropertiesPtr properties = _communicator->getProperties();
_traceLevel = properties->getPropertyAsInt("Glacier.Router.Trace.Client");
size_t current = 0;
const string ws = " \t";
do
{
size_t pos = allowCategories.find_first_of(ws, current);
size_t len = (pos == string::npos) ? string::npos : pos - current;
_allowCategories.insert(allowCategories.substr(current, len));
current = allowCategories.find_first_not_of(ws, pos);
}
while (current != string::npos);
}
Glacier::ClientBlobject::~ClientBlobject()
{
assert(!_communicator);
}
void
Glacier::ClientBlobject::destroy()
{
//
// No mutex protection necessary, destroy is only called after all
// object adapters have shut down.
//
_communicator = 0;
_logger = 0;
_routingTable = 0;
}
bool
Glacier::ClientBlobject::ice_invoke(const std::vector<Byte>& inParams, std::vector<Byte>& outParams,
const Current& current)
{
assert(_communicator); // Destroyed?
//
// If there is an allowCategories set then enforce it.
//
if (!_allowCategories.empty())
{
if (_allowCategories.find(current.identity.category) == _allowCategories.end())
{
if (_traceLevel > 0)
{
Trace out(_logger, "Glacier");
out << "rejecting request. identity: " << identityToString(current.identity);
}
ObjectNotExistException ex(__FILE__, __LINE__);
ex.identity = current.identity;
throw ex;
}
}
try
{
ObjectPrx proxy = _routingTable->get(current.identity);
if (!proxy)
{
ObjectNotExistException ex(__FILE__, __LINE__);
ex.identity = current.identity;
throw ex;
}
if (!current.facet.empty())
{
proxy = proxy->ice_newFacet(current.facet);
}
Context::const_iterator p = current.context.find("_fwd");
if (p != current.context.end())
{
for (unsigned int i = 0; i < p->second.length(); ++i)
{
char option = p->second[i];
switch (option)
{
case 't':
{
proxy = proxy->ice_twoway();
break;
}
case 'o':
{
proxy = proxy->ice_oneway();
break;
}
case 'd':
{
proxy = proxy->ice_datagram();
break;
}
case 's':
{
proxy = proxy->ice_secure(true);
break;
}
default:
{
Warning out(_logger);
out << "unknown forward option `" << option << "'";
break;
}
}
}
}
if (_traceLevel >= 2)
{
Trace out(_logger, "Glacier");
out << "routing to:\n"
<< "proxy = " << _communicator->proxyToString(proxy) << '\n'
<< "operation = " << current.operation << '\n'
<< "nonmutating = " << (current.nonmutating ? "true" : "false");
}
return proxy->ice_invoke(current.operation, current.nonmutating, inParams, outParams, current.context);
}
catch (const Exception& ex)
{
if (_traceLevel)
{
Trace out(_logger, "Glacier");
out << "routing exception:\n" << ex;
}
ex.ice_throw();
}
assert(false);
return true; // To keep the compiler happy.
}
|