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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
// **********************************************************************
//
// Copyright (c) 2001
// Mutable Realms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
package IceInternal;
public class Incoming
{
public
Incoming(Instance instance, Ice.ObjectAdapter adapter)
{
_is = new BasicStream(instance);
_os = new BasicStream(instance);
_current = new Ice.Current();
_current.adapter = adapter;
_current.id = new Ice.Identity();
_cookie = new Ice.LocalObjectHolder();
if(_current.adapter != null)
{
((Ice.ObjectAdapterI)(_current.adapter)).incUsageCount();
}
}
//
// This function allows this object to be reused, rather than
// reallocated.
//
public void
reset(Ice.ObjectAdapter adapter)
{
_is.reset();
_os.reset();
if(_current.ctx != null)
{
_current.ctx.clear();
}
if(_current.adapter != adapter)
{
if(_current.adapter != null)
{
((Ice.ObjectAdapterI)(_current.adapter)).decUsageCount();
}
_current.adapter = adapter;
if(_current.adapter != null)
{
((Ice.ObjectAdapterI)(_current.adapter)).incUsageCount();
}
}
}
//
// Reclaim resources.
//
public void
destroy()
{
_is.destroy();
_os.destroy();
if(_current.adapter != null)
{
((Ice.ObjectAdapterI)(_current.adapter)).decUsageCount();
}
}
public void
invoke(boolean response)
{
//
// Read the current.
//
_current.id.__read(_is);
_current.facet = _is.readStringSeq();
_current.operation = _is.readString();
_current.mode = Ice.OperationMode.convert(_is.readByte());
int sz = _is.readSize();
while(sz-- > 0)
{
String first = _is.readString();
String second = _is.readString();
if(_current.ctx == null)
{
_current.ctx = new java.util.HashMap();
}
_current.ctx.put(first, second);
}
_is.startReadEncaps();
int statusPos;
if(response)
{
statusPos = _os.size();
_os.writeByte((byte)0);
_os.startWriteEncaps();
}
else
{
statusPos = 0; // Initialize, to keep the compiler happy.
}
Ice.Object servant = null;
Ice.ServantLocator locator = null;
_cookie.value = null;
DispatchStatus status;
//
// Don't put the code above into the try block below. Exceptions
// in the code above are considered fatal, and must propagate to
// the caller of this operation.
//
try
{
if(_current.adapter != null)
{
servant = _current.adapter.identityToServant(_current.id);
if(servant == null && _current.id.category.length() > 0)
{
locator = _current.adapter.findServantLocator(_current.id.category);
if(locator != null)
{
servant = locator.locate(_current, _cookie);
}
}
if(servant == null)
{
locator = _current.adapter.findServantLocator("");
if(locator != null)
{
servant = locator.locate(_current, _cookie);
}
}
}
if(servant == null)
{
status = DispatchStatus.DispatchObjectNotExist;
}
else
{
if(_current.facet.length > 0)
{
Ice.Object facetServant = servant.ice_findFacetPath(_current.facet, 0);
if(facetServant == null)
{
status = DispatchStatus.DispatchFacetNotExist;
}
else
{
status = facetServant.__dispatch(this, _current);
}
}
else
{
status = servant.__dispatch(this, _current);
}
}
}
catch(Ice.LocationForward ex)
{
if(locator != null && servant != null)
{
locator.finished(_current, servant, _cookie.value);
}
_is.endReadEncaps();
if(response)
{
_os.endWriteEncaps();
_os.resize(statusPos, false);
_os.writeByte((byte)DispatchStatus._DispatchLocationForward);
_os.writeProxy(ex._prx);
}
return;
}
catch(Ice.RequestFailedException ex)
{
if(locator != null && servant != null)
{
locator.finished(_current, servant, _cookie.value);
}
_is.endReadEncaps();
if(response)
{
_os.endWriteEncaps();
_os.resize(statusPos, false);
if(ex instanceof Ice.ObjectNotExistException)
{
_os.writeByte((byte)DispatchStatus._DispatchObjectNotExist);
}
else if(ex instanceof Ice.FacetNotExistException)
{
_os.writeByte((byte)DispatchStatus._DispatchFacetNotExist);
}
else if(ex instanceof Ice.OperationNotExistException)
{
_os.writeByte((byte)DispatchStatus._DispatchOperationNotExist);
}
else
{
assert(false);
}
// Write the data from the exception, not from _current,
// so that a RequestFailedException can override the
// information from _current.
ex.id.__write(_os);
_os.writeStringSeq(ex.facet);
_os.writeString(ex.operation);
}
return;
}
catch(Ice.LocalException ex)
{
if(locator != null && servant != null)
{
locator.finished(_current, servant, _cookie.value);
}
_is.endReadEncaps();
if(response)
{
_os.endWriteEncaps();
_os.resize(statusPos, false);
_os.writeByte((byte)DispatchStatus._DispatchUnknownLocalException);
_os.writeString(ex.toString());
}
return;
}
/* Not possible in Java - UserExceptions are checked exceptions
catch(Ice.UserException ex)
{
// ...
}
*/
catch(RuntimeException ex)
{
if(locator != null && servant != null)
{
locator.finished(_current, servant, _cookie.value);
}
_is.endReadEncaps();
if(response)
{
_os.endWriteEncaps();
_os.resize(statusPos, false);
_os.writeByte((byte)DispatchStatus._DispatchUnknownException);
_os.writeString(ex.toString());
}
return;
}
if(locator != null && servant != null)
{
locator.finished(_current, servant, _cookie.value);
}
_is.endReadEncaps();
if(response)
{
_os.endWriteEncaps();
if(status != DispatchStatus.DispatchOK && status != DispatchStatus.DispatchUserException)
{
assert(status == DispatchStatus.DispatchObjectNotExist ||
status == DispatchStatus.DispatchFacetNotExist ||
status == DispatchStatus.DispatchOperationNotExist);
_os.resize(statusPos, false);
_os.writeByte((byte)status.value());
_current.id.__write(_os);
_os.writeStringSeq(_current.facet);
_os.writeString(_current.operation);
}
else
{
int save = _os.pos();
_os.pos(statusPos);
_os.writeByte((byte)status.value());
_os.pos(save);
}
}
}
public BasicStream
is()
{
return _is;
}
public BasicStream
os()
{
return _os;
}
private BasicStream _is;
private BasicStream _os;
private Ice.Current _current;
private Ice.LocalObjectHolder _cookie;
Incoming next; // For use by Connection
}
|