forked from infinispan/infinispan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ExceptionAckCommand.java
93 lines (78 loc) · 2.5 KB
/
ExceptionAckCommand.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
package org.infinispan.commands.write;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.infinispan.commands.remote.BaseRpcCommand;
import org.infinispan.commons.CacheException;
import org.infinispan.remoting.transport.ResponseCollectors;
import org.infinispan.util.ByteString;
import org.infinispan.util.concurrent.CommandAckCollector;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
/**
* A command that represents an exception acknowledge sent by any owner.
* <p>
* The acknowledge represents an unsuccessful execution of the operation.
*
* @author Pedro Ruivo
* @since 9.0
*/
public class ExceptionAckCommand extends BaseRpcCommand {
private static final Log log = LogFactory.getLog(ExceptionAckCommand.class);
public static final byte COMMAND_ID = 42;
private CommandAckCollector commandAckCollector;
private Throwable throwable;
private long id;
private int topologyId;
public ExceptionAckCommand() {
super(null);
}
public ExceptionAckCommand(ByteString cacheName) {
super(cacheName);
}
public ExceptionAckCommand(ByteString cacheName, long id, Throwable throwable, int topologyId) {
super(cacheName);
this.id = id;
this.throwable = throwable;
this.topologyId = topologyId;
}
public void ack() {
CacheException remoteException = ResponseCollectors.wrapRemoteException(getOrigin(), this.throwable);
commandAckCollector.completeExceptionally(id, remoteException, topologyId);
}
@Override
public byte getCommandId() {
return COMMAND_ID;
}
@Override
public boolean isReturnValueExpected() {
return false;
}
@Override
public boolean canBlock() {
return false;
}
@Override
public void writeTo(ObjectOutput output) throws IOException {
output.writeLong(id);
output.writeObject(throwable);
output.writeInt(topologyId);
}
@Override
public void readFrom(ObjectInput input) throws IOException, ClassNotFoundException {
id = input.readLong();
throwable = (Throwable) input.readObject();
topologyId = input.readInt();
}
public void setCommandAckCollector(CommandAckCollector commandAckCollector) {
this.commandAckCollector = commandAckCollector;
}
@Override
public String toString() {
return "ExceptionAckCommand{" +
"id=" + id +
", throwable=" + throwable +
", topologyId=" + topologyId +
'}';
}
}