/
TransactionClientChannel.java
550 lines (525 loc) · 26.7 KB
/
TransactionClientChannel.java
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.transaction.client.provider.remoting;
import static org.xnio.IoUtils.safeClose;
import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.ThreadLocalRandom;
import javax.transaction.SystemException;
import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import org.jboss.remoting3.Channel;
import org.jboss.remoting3.ClientServiceHandle;
import org.jboss.remoting3.Connection;
import org.jboss.remoting3.ConnectionPeerIdentity;
import org.jboss.remoting3.MessageInputStream;
import org.jboss.remoting3.MessageOutputStream;
import org.jboss.remoting3._private.IntIndexHashMap;
import org.jboss.remoting3._private.IntIndexMap;
import org.jboss.remoting3.util.BlockingInvocation;
import org.jboss.remoting3.util.InvocationTracker;
import org.jboss.remoting3.util.StreamUtils;
import org.wildfly.common.annotation.NotNull;
import org.wildfly.common.rpc.RemoteExceptionCause;
import org.wildfly.transaction.client.SimpleXid;
import org.wildfly.transaction.client._private.Log;
import org.wildfly.transaction.client.spi.SimpleTransactionControl;
import org.xnio.FinishedIoFuture;
import org.xnio.IoFuture;
import org.xnio.OptionMap;
/**
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
*/
final class TransactionClientChannel implements RemotingOperations {
private final Channel channel;
private final InvocationTracker invocationTracker;
private final IntIndexMap<RemotingRemoteTransactionHandle> peerTransactionMap = new IntIndexHashMap<RemotingRemoteTransactionHandle>(RemotingRemoteTransactionHandle::getId);
private final Channel.Receiver receiver = new ReceiverImpl();
private static final ClientServiceHandle<TransactionClientChannel> CLIENT_SERVICE_HANDLE = new ClientServiceHandle<>("txn", TransactionClientChannel::construct);
TransactionClientChannel(final Channel channel) {
this.channel = channel;
invocationTracker = new InvocationTracker(channel);
}
private static IoFuture<TransactionClientChannel> construct(final Channel channel) {
// future protocol versions might have to negotiate a version or capabilities before proceeding
final TransactionClientChannel clientChannel = new TransactionClientChannel(channel);
channel.receiveMessage(clientChannel.getReceiver());
return new FinishedIoFuture<>(clientChannel);
}
@NotNull
public SimpleTransactionControl begin(final ConnectionPeerIdentity peerIdentity) throws SystemException {
int id;
final ThreadLocalRandom random = ThreadLocalRandom.current();
final IntIndexMap<RemotingRemoteTransactionHandle> map = this.peerTransactionMap;
RemotingRemoteTransactionHandle handle;
do {
id = random.nextInt();
} while (map.containsKey(id) || map.putIfAbsent(handle = new RemotingRemoteTransactionHandle(id, this)) != null);
return handle;
}
public void rollback(final Xid xid, final ConnectionPeerIdentity peerIdentity) throws XAException {
final InvocationTracker invocationTracker = getInvocationTracker();
final BlockingInvocation invocation = invocationTracker.addInvocation(BlockingInvocation::new);
// write request
try (MessageOutputStream os = invocationTracker.allocateMessage(invocation)) {
os.writeShort(invocation.getIndex());
os.writeByte(Protocol.M_XA_ROLLBACK);
Protocol.writeParam(Protocol.P_XID, os, xid);
final int peerIdentityId = peerIdentity.getId();
if (peerIdentityId != 0) Protocol.writeParam(Protocol.P_SEC_CONTEXT, os, peerIdentityId, Protocol.UNSIGNED);
} catch (IOException e) {
throw Log.log.failedToSendXA(e, XAException.XAER_RMFAIL);
}
try (BlockingInvocation.Response response = invocation.getResponse()) {
try (MessageInputStream is = response.getInputStream()) {
if (is.readUnsignedByte() != Protocol.M_RESP_XA_ROLLBACK) {
throw Log.log.unknownResponseXa(XAException.XAER_RMERR);
}
int id = is.read();
if (id == Protocol.P_XA_ERROR) {
int len = StreamUtils.readPackedSignedInt32(is);
int error = is.readInt();
final XAException xa = Log.log.peerXaException(error);
xa.initCause(RemoteExceptionCause.readFromStream(is));
if ((id = is.read()) != -1) {
XAException ex = Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
ex.addSuppressed(Log.log.peerXaException(error));
throw ex;
} else {
throw xa;
}
} else if (id == Protocol.P_SEC_EXC) {
int len = StreamUtils.readPackedSignedInt32(is);
final SecurityException sx = Log.log.peerSecurityException();
sx.initCause(RemoteExceptionCause.readFromStream(is));
if ((id = is.read()) != -1) {
XAException ex = Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
ex.addSuppressed(Log.log.peerSecurityException());
throw ex;
} else {
throw sx;
}
} else if (id != -1) {
throw Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
}
} catch (IOException e) {
throw Log.log.responseFailedXa(e, XAException.XAER_RMFAIL);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw Log.log.interruptedXA(XAException.XAER_RMERR);
} catch (IOException e) {
// failed to close the response, but we don't care too much
Log.log.inboundException(e);
}
}
public void setRollbackOnly(final Xid xid, final ConnectionPeerIdentity peerIdentity) throws XAException {
// write rollback-only request
final InvocationTracker invocationTracker = getInvocationTracker();
final BlockingInvocation invocation = invocationTracker.addInvocation(BlockingInvocation::new);
// write request
try (MessageOutputStream os = invocationTracker.allocateMessage(invocation)) {
os.writeShort(invocation.getIndex());
os.writeByte(Protocol.M_XA_RB_ONLY);
Protocol.writeParam(Protocol.P_XID, os, xid);
final int peerIdentityId = peerIdentity.getId();
if (peerIdentityId != 0) Protocol.writeParam(Protocol.P_SEC_CONTEXT, os, peerIdentityId, Protocol.UNSIGNED);
} catch (IOException e) {
throw Log.log.failedToSendXA(e, XAException.XAER_RMFAIL);
}
try (BlockingInvocation.Response response = invocation.getResponse()) {
try (MessageInputStream is = response.getInputStream()) {
if (is.readUnsignedByte() != Protocol.M_RESP_XA_RB_ONLY) {
throw Log.log.unknownResponseXa(XAException.XAER_RMERR);
}
int id = is.read();
if (id == Protocol.P_XA_ERROR) {
int len = StreamUtils.readPackedSignedInt32(is);
int error = is.readInt();
final XAException xa = Log.log.peerXaException(error);
xa.initCause(RemoteExceptionCause.readFromStream(is));
if ((id = is.read()) != -1) {
XAException ex = Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
ex.addSuppressed(xa);
throw ex;
} else {
throw xa;
}
} else if (id == Protocol.P_SEC_EXC) {
int len = StreamUtils.readPackedSignedInt32(is);
final SecurityException sx = Log.log.peerSecurityException();
sx.initCause(RemoteExceptionCause.readFromStream(is));
if ((id = is.read()) != -1) {
XAException ex = Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
ex.addSuppressed(sx);
throw ex;
} else {
throw sx;
}
} else if (id != -1) {
throw Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
}
} catch (IOException e) {
throw Log.log.responseFailedXa(e, XAException.XAER_RMFAIL);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw Log.log.interruptedXA(XAException.XAER_RMERR);
} catch (IOException e) {
// failed to close the response, but we don't care too much
Log.log.inboundException(e);
}
}
public void beforeCompletion(final Xid xid, final ConnectionPeerIdentity peerIdentity) throws XAException {
final InvocationTracker invocationTracker = getInvocationTracker();
final BlockingInvocation invocation = invocationTracker.addInvocation(BlockingInvocation::new);
// write request
try (MessageOutputStream os = invocationTracker.allocateMessage(invocation)) {
os.writeShort(invocation.getIndex());
os.writeByte(Protocol.M_XA_BEFORE);
Protocol.writeParam(Protocol.P_XID, os, xid);
final int peerIdentityId = peerIdentity.getId();
if (peerIdentityId != 0) Protocol.writeParam(Protocol.P_SEC_CONTEXT, os, peerIdentityId, Protocol.UNSIGNED);
} catch (IOException e) {
throw Log.log.failedToSendXA(e, XAException.XAER_RMFAIL);
}
try (BlockingInvocation.Response response = invocation.getResponse()) {
try (MessageInputStream is = response.getInputStream()) {
if (is.readUnsignedByte() != Protocol.M_RESP_XA_BEFORE) {
throw Log.log.unknownResponseXa(XAException.XAER_RMERR);
}
int id = is.read();
if (id == Protocol.P_XA_ERROR) {
int len = StreamUtils.readPackedSignedInt32(is);
int error = is.readInt();
final XAException xa = Log.log.peerXaException(error);
xa.initCause(RemoteExceptionCause.readFromStream(is));
if ((id = is.read()) != -1) {
XAException ex = Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
ex.addSuppressed(xa);
throw ex;
} else {
throw xa;
}
} else if (id == Protocol.P_SEC_EXC) {
int len = StreamUtils.readPackedSignedInt32(is);
final SecurityException sx = Log.log.peerSecurityException();
sx.initCause(RemoteExceptionCause.readFromStream(is));
if ((id = is.read()) != -1) {
XAException ex = Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
ex.addSuppressed(sx);
throw ex;
} else {
throw sx;
}
} else if (id != -1) {
throw Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
}
} catch (IOException e) {
throw Log.log.responseFailedXa(e, XAException.XAER_RMFAIL);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw Log.log.interruptedXA(XAException.XAER_RMERR);
} catch (IOException e) {
// failed to close the response, but we don't care too much
Log.log.inboundException(e);
}
}
public int prepare(final Xid xid, final ConnectionPeerIdentity peerIdentity) throws XAException {
boolean readOnly = false;
final InvocationTracker invocationTracker = getInvocationTracker();
final BlockingInvocation invocation = invocationTracker.addInvocation(BlockingInvocation::new);
// write request
try (MessageOutputStream os = invocationTracker.allocateMessage(invocation)) {
os.writeShort(invocation.getIndex());
os.writeByte(Protocol.M_XA_PREPARE);
Protocol.writeParam(Protocol.P_XID, os, xid);
final int peerIdentityId = peerIdentity.getId();
if (peerIdentityId != 0) Protocol.writeParam(Protocol.P_SEC_CONTEXT, os, peerIdentityId, Protocol.UNSIGNED);
} catch (IOException e) {
throw Log.log.failedToSendXA(e, XAException.XAER_RMFAIL);
}
try (BlockingInvocation.Response response = invocation.getResponse()) {
try (MessageInputStream is = response.getInputStream()) {
if (is.readUnsignedByte() != Protocol.M_RESP_XA_PREPARE) {
throw Log.log.unknownResponseXa(XAException.XAER_RMERR);
}
int id = is.read();
if (id == Protocol.P_XA_ERROR) {
int len = StreamUtils.readPackedSignedInt32(is);
int error = is.readInt();
final XAException xa = Log.log.peerXaException(error);
xa.initCause(RemoteExceptionCause.readFromStream(is));
if ((id = is.read()) != -1) {
XAException ex = Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
ex.addSuppressed(xa);
throw ex;
} else {
throw xa;
}
} else if (id == Protocol.P_SEC_EXC) {
int len = StreamUtils.readPackedSignedInt32(is);
final SecurityException sx = Log.log.peerSecurityException();
sx.initCause(RemoteExceptionCause.readFromStream(is));
if ((id = is.read()) != -1) {
XAException ex = Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
ex.addSuppressed(sx);
throw ex;
} else {
throw sx;
}
} else if (id == Protocol.P_XA_RDONLY) {
readOnly = true;
} else if (id != -1) {
throw Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
}
} catch (IOException e) {
throw Log.log.responseFailedXa(e, XAException.XAER_RMFAIL);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw Log.log.interruptedXA(XAException.XAER_RMERR);
} catch (IOException e) {
// failed to close the response, but we don't care too much
Log.log.inboundException(e);
}
return readOnly ? XAResource.XA_RDONLY : XAResource.XA_OK;
}
public void forget(final Xid xid, final ConnectionPeerIdentity peerIdentity) throws XAException {
final InvocationTracker invocationTracker = getInvocationTracker();
final BlockingInvocation invocation = invocationTracker.addInvocation(BlockingInvocation::new);
// write request
try (MessageOutputStream os = invocationTracker.allocateMessage(invocation)) {
os.writeShort(invocation.getIndex());
os.writeByte(Protocol.M_XA_FORGET);
Protocol.writeParam(Protocol.P_XID, os, xid);
final int peerIdentityId = peerIdentity.getId();
if (peerIdentityId != 0) Protocol.writeParam(Protocol.P_SEC_CONTEXT, os, peerIdentityId, Protocol.UNSIGNED);
} catch (IOException e) {
throw Log.log.failedToSendXA(e, XAException.XAER_RMFAIL);
}
try (BlockingInvocation.Response response = invocation.getResponse()) {
try (MessageInputStream is = response.getInputStream()) {
if (is.readUnsignedByte() != Protocol.M_RESP_XA_FORGET) {
throw Log.log.unknownResponseXa(XAException.XAER_RMERR);
}
int id = is.read();
if (id == Protocol.P_XA_ERROR) {
int len = StreamUtils.readPackedSignedInt32(is);
int error = is.readInt();
final XAException xa = Log.log.peerXaException(error);
xa.initCause(RemoteExceptionCause.readFromStream(is));
if ((id = is.read()) != -1) {
XAException ex = Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
ex.addSuppressed(xa);
throw ex;
} else {
throw xa;
}
} else if (id == Protocol.P_SEC_EXC) {
int len = StreamUtils.readPackedSignedInt32(is);
final SecurityException sx = Log.log.peerSecurityException();
sx.initCause(RemoteExceptionCause.readFromStream(is));
if ((id = is.read()) != -1) {
XAException ex = Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
ex.addSuppressed(sx);
throw ex;
} else {
throw sx;
}
} else if (id != -1) {
throw Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
}
} catch (IOException e) {
throw Log.log.responseFailedXa(e, XAException.XAER_RMFAIL);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw Log.log.interruptedXA(XAException.XAER_RMERR);
} catch (IOException e) {
// failed to close the response, but we don't care too much
Log.log.inboundException(e);
}
}
public void commit(final Xid xid, final boolean onePhase, final ConnectionPeerIdentity peerIdentity) throws XAException {
final InvocationTracker invocationTracker = getInvocationTracker();
final BlockingInvocation invocation = invocationTracker.addInvocation(BlockingInvocation::new);
// write request
try (MessageOutputStream os = invocationTracker.allocateMessage(invocation)) {
os.writeShort(invocation.getIndex());
os.writeByte(Protocol.M_XA_COMMIT);
Protocol.writeParam(Protocol.P_XID, os, xid);
final int peerIdentityId = peerIdentity.getId();
if (peerIdentityId != 0) Protocol.writeParam(Protocol.P_SEC_CONTEXT, os, peerIdentityId, Protocol.UNSIGNED);
if (onePhase) Protocol.writeParam(Protocol.P_ONE_PHASE, os);
} catch (IOException e) {
throw Log.log.failedToSendXA(e, XAException.XAER_RMFAIL);
}
try (BlockingInvocation.Response response = invocation.getResponse()) {
try (MessageInputStream is = response.getInputStream()) {
if (is.readUnsignedByte() != Protocol.M_RESP_XA_COMMIT) {
throw Log.log.unknownResponseXa(XAException.XAER_RMERR);
}
int id = is.read();
if (id == Protocol.P_XA_ERROR) {
int len = StreamUtils.readPackedSignedInt32(is);
int error = is.readInt();
final XAException xa = Log.log.peerXaException(error);
xa.initCause(RemoteExceptionCause.readFromStream(is));
if ((id = is.read()) != -1) {
XAException ex = Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
ex.addSuppressed(xa);
throw ex;
} else {
throw xa;
}
} else if (id == Protocol.P_SEC_EXC) {
int len = StreamUtils.readPackedSignedInt32(is);
final SecurityException sx = Log.log.peerSecurityException();
sx.initCause(RemoteExceptionCause.readFromStream(is));
if ((id = is.read()) != -1) {
XAException ex = Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
ex.addSuppressed(sx);
throw ex;
} else {
throw sx;
}
} else if (id != -1) {
throw Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
}
} catch (IOException e) {
throw Log.log.responseFailedXa(e, XAException.XAER_RMFAIL);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw Log.log.interruptedXA(XAException.XAER_RMERR);
} catch (IOException e) {
// failed to close the response, but we don't care too much
Log.log.inboundException(e);
}
}
@NotNull
public Xid[] recover(final int flag, final String parentName, final ConnectionPeerIdentity peerIdentity) throws XAException {
if ((flag & XAResource.TMSTARTRSCAN) != XAResource.TMSTARTRSCAN) {
return SimpleXid.NO_XIDS;
}
final InvocationTracker invocationTracker = getInvocationTracker();
final BlockingInvocation invocation = invocationTracker.addInvocation(BlockingInvocation::new);
// write request
try (MessageOutputStream os = invocationTracker.allocateMessage(invocation)) {
os.writeShort(invocation.getIndex());
os.writeByte(Protocol.M_XA_RECOVER);
final int peerIdentityId = peerIdentity.getId();
if (peerIdentityId != 0) Protocol.writeParam(Protocol.P_SEC_CONTEXT, os, peerIdentityId, Protocol.UNSIGNED);
Protocol.writeParam(Protocol.P_PARENT_NAME, os, parentName);
} catch (IOException e) {
throw Log.log.failedToSendXA(e, XAException.XAER_RMFAIL);
}
final ArrayList<Xid> recoveryList = new ArrayList<>();
try (BlockingInvocation.Response response = invocation.getResponse()) {
try (MessageInputStream is = response.getInputStream()) {
if (is.readUnsignedByte() != Protocol.M_RESP_XA_RECOVER) {
throw Log.log.unknownResponseXa(XAException.XAER_RMERR);
}
int id = is.read();
for (;;) {
if (id == Protocol.P_XID) {
recoveryList.add(Protocol.readXid(is, StreamUtils.readPackedUnsignedInt32(is)));
} else if (id == Protocol.P_XA_ERROR) {
int len = StreamUtils.readPackedSignedInt32(is);
int error = is.readInt();
final XAException xa = Log.log.peerXaException(error);
xa.initCause(RemoteExceptionCause.readFromStream(is));
if ((id = is.read()) != -1) {
XAException ex = Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
ex.addSuppressed(xa);
throw ex;
} else {
throw xa;
}
} else if (id == Protocol.P_SEC_EXC) {
int len = StreamUtils.readPackedSignedInt32(is);
final SecurityException sx = Log.log.peerSecurityException();
sx.initCause(RemoteExceptionCause.readFromStream(is));
if ((id = is.read()) != -1) {
XAException ex = Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
ex.addSuppressed(sx);
throw ex;
} else {
throw sx;
}
} else if (id != -1) {
throw Log.log.unrecognizedParameter(XAException.XAER_RMFAIL, id);
} else {
break;
}
id = is.read();
}
}
return recoveryList.toArray(SimpleXid.NO_XIDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw Log.log.interruptedXA(XAException.XAER_RMERR);
} catch (IOException e) {
throw Log.log.responseFailedXa(e, XAException.XAER_RMFAIL);
}
}
InvocationTracker getInvocationTracker() {
return invocationTracker;
}
static TransactionClientChannel forConnection(final Connection connection) throws IOException {
return CLIENT_SERVICE_HANDLE.getClientService(connection, OptionMap.EMPTY).get();
}
Channel.Receiver getReceiver() {
return receiver;
}
Connection getConnection() {
return channel.getConnection();
}
void notifyTransactionEnd(final int id){
peerTransactionMap.removeKey(id);
}
class ReceiverImpl implements Channel.Receiver {
public void handleError(final Channel channel, final IOException error) {
handleEnd(channel);
}
public void handleEnd(final Channel channel) {
for (RemotingRemoteTransactionHandle transaction : peerTransactionMap) {
transaction.disconnect();
}
}
public void handleMessage(final Channel channel, final MessageInputStream message) {
try {
channel.receiveMessage(this);
final int invId;
try {
invId = message.readUnsignedShort();
} catch (IOException e) {
// can't do much about this, but it's really unlikely anyway
Log.log.inboundException(e);
return;
}
invocationTracker.signalResponse(invId, 0, message, true);
} finally {
safeClose(message);
}
}
}
}