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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
// **********************************************************************
//
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
package IceInternal;
final public class Incoming extends IncomingBase implements Ice.Request
{
public
Incoming(Instance instance, Ice.ConnectionI connection, Ice.ObjectAdapter adapter, boolean response, byte compress,
int requestId)
{
super(instance, connection, adapter, response, compress, requestId);
_is = new BasicStream(instance);
}
//
// Request implementation
//
public boolean
isCollocated()
{
return false;
}
public Ice.Current
getCurrent()
{
return _current;
}
//
// These functions allow this object to be reused, rather than reallocated.
//
public void
reset(Instance instance, Ice.ConnectionI connection, Ice.ObjectAdapter adapter, boolean response, byte compress,
int requestId)
{
_cb = null;
_inParamPos = -1;
if(_is == null)
{
_is = new BasicStream(instance);
}
super.reset(instance, connection, adapter, response, compress, requestId);
}
public void
reclaim()
{
_cb = null;
_inParamPos = -1;
if(_is != null)
{
_is.reset();
}
super.reclaim();
}
public void
invoke(ServantManager servantManager)
{
//
// Read the current.
//
_current.id.__read(_is);
//
// For compatibility with the old FacetPath.
//
String[] facetPath = _is.readStringSeq();
if(facetPath.length > 0)
{
if(facetPath.length > 1)
{
throw new Ice.MarshalException();
}
_current.facet = facetPath[0];
}
else
{
_current.facet = "";
}
_current.operation = _is.readString();
_current.mode = Ice.OperationMode.values()[_is.readByte()];
_current.ctx = new java.util.HashMap<String, String>();
int sz = _is.readSize();
while(sz-- > 0)
{
String first = _is.readString();
String second = _is.readString();
_current.ctx.put(first, second);
}
if(_response)
{
assert(_os.size() == Protocol.headerSize + 4); // Reply status position.
_os.writeByte(ReplyStatus.replyOK);
_os.startWriteEncaps();
}
byte replyStatus = ReplyStatus.replyOK;
Ice.DispatchStatus dispatchStatus = Ice.DispatchStatus.DispatchOK;
//
// 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.
//
if(servantManager != null)
{
_servant = servantManager.findServant(_current.id, _current.facet);
if(_servant == null)
{
_locator = servantManager.findServantLocator(_current.id.category);
if(_locator == null && _current.id.category.length() > 0)
{
_locator = servantManager.findServantLocator("");
}
if(_locator != null)
{
try
{
_servant = _locator.locate(_current, _cookie);
}
catch(Ice.UserException ex)
{
_os.writeUserException(ex);
replyStatus = ReplyStatus.replyUserException;
}
catch(java.lang.Exception ex)
{
__handleException(ex);
return;
}
}
}
}
if(_servant != null)
{
try
{
assert(replyStatus == ReplyStatus.replyOK);
dispatchStatus = _servant.__dispatch(this, _current);
if(dispatchStatus == Ice.DispatchStatus.DispatchUserException)
{
replyStatus = ReplyStatus.replyUserException;
}
if(dispatchStatus != Ice.DispatchStatus.DispatchAsync)
{
if(_locator != null && !__servantLocatorFinished())
{
return;
}
}
}
catch(java.lang.Exception ex)
{
if(_locator != null && !__servantLocatorFinished())
{
return;
}
__handleException(ex);
return;
}
}
else if(replyStatus == ReplyStatus.replyOK)
{
if(servantManager != null && servantManager.hasServant(_current.id))
{
replyStatus = ReplyStatus.replyFacetNotExist;
}
else
{
replyStatus = ReplyStatus.replyObjectNotExist;
}
}
//
// Don't put the code below into the try block above. Exceptions
// in the code below are considered fatal, and must propagate to
// the caller of this operation.
//
//
// DispatchAsync is "pseudo dispatch status", used internally
// only to indicate async dispatch.
//
if(dispatchStatus == Ice.DispatchStatus.DispatchAsync)
{
//
// If this was an asynchronous dispatch, we're done here.
//
return;
}
assert(_connection != null);
if(_response)
{
_os.endWriteEncaps();
if(replyStatus != ReplyStatus.replyOK && replyStatus != ReplyStatus.replyUserException)
{
assert(replyStatus == ReplyStatus.replyObjectNotExist ||
replyStatus == ReplyStatus.replyFacetNotExist);
_os.resize(Protocol.headerSize + 4, false); // Reply status position.
_os.writeByte(replyStatus);
_current.id.__write(_os);
//
// For compatibility with the old FacetPath.
//
if(_current.facet == null || _current.facet.length() == 0)
{
_os.writeStringSeq(null);
}
else
{
String[] facetPath2 = { _current.facet };
_os.writeStringSeq(facetPath2);
}
_os.writeString(_current.operation);
}
else
{
int save = _os.pos();
_os.pos(Protocol.headerSize + 4); // Reply status position.
_os.writeByte(replyStatus);
_os.pos(save);
}
_connection.sendResponse(_os, _compress);
}
else
{
_connection.sendNoResponse();
}
_connection = null;
}
public BasicStream
is()
{
return _is;
}
public BasicStream
os()
{
return _os;
}
public final void
push(Ice.DispatchInterceptorAsyncCallback cb)
{
if(_interceptorAsyncCallbackList == null)
{
_interceptorAsyncCallbackList = new java.util.LinkedList<Ice.DispatchInterceptorAsyncCallback>();
}
_interceptorAsyncCallbackList.addFirst(cb);
}
public final void
pop()
{
assert _interceptorAsyncCallbackList != null;
_interceptorAsyncCallbackList.removeFirst();
}
public final void
startOver()
{
if(_inParamPos == -1)
{
//
// That's the first startOver, so almost nothing to do
//
_inParamPos = _is.pos();
}
else
{
killAsync();
//
// Let's rewind _is and clean-up _os
//
_is.pos(_inParamPos);
if(_response)
{
_os.endWriteEncaps();
_os.resize(Protocol.headerSize + 4, false);
_os.writeByte(ReplyStatus.replyOK);
_os.startWriteEncaps();
}
}
}
public final void
killAsync()
{
//
// Always runs in the dispatch thread
//
if(_cb != null)
{
//
// May raise ResponseSentException
//
_cb.__deactivate(this);
_cb = null;
}
}
final void
setActive(IncomingAsync cb)
{
assert _cb == null;
_cb = cb;
}
final boolean
isRetriable()
{
return _inParamPos != -1;
}
public Incoming next; // For use by ConnectionI.
private BasicStream _is;
private IncomingAsync _cb;
private int _inParamPos = -1;
}
|