-
Notifications
You must be signed in to change notification settings - Fork 615
/
AbstractDataCommand.java
112 lines (93 loc) · 2.47 KB
/
AbstractDataCommand.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
package org.infinispan.commands.read;
import static org.infinispan.commons.util.EnumUtil.prettyPrintBitSet;
import static org.infinispan.commons.util.Util.toStr;
import java.util.Objects;
import org.infinispan.commands.DataCommand;
import org.infinispan.commands.SegmentSpecificCommand;
import org.infinispan.context.Flag;
/**
* @author Mircea.Markus@jboss.com
* @author Sanne Grinovero <sanne@hibernate.org> (C) 2011 Red Hat Inc.
* @since 4.0
*/
public abstract class AbstractDataCommand implements DataCommand, SegmentSpecificCommand {
protected Object key;
protected long flags;
// These 2 ints have to stay next to each other to ensure they are aligned together
private int topologyId = -1;
protected int segment;
protected AbstractDataCommand(Object key, int segment, long flagsBitSet) {
this.key = key;
if (segment < 0) {
throw new IllegalArgumentException("Segment must be 0 or greater");
}
this.segment = segment;
this.flags = flagsBitSet;
}
protected AbstractDataCommand() {
this.segment = -1;
}
@Override
public int getSegment() {
return segment;
}
@Override
public int getTopologyId() {
return topologyId;
}
@Override
public void setTopologyId(int topologyId) {
this.topologyId = topologyId;
}
@Override
public long getFlagsBitSet() {
return flags;
}
@Override
public void setFlagsBitSet(long bitSet) {
this.flags = bitSet;
}
@Override
public Object getKey() {
return key;
}
public void setKey(Object key) {
this.key = key;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
AbstractDataCommand other = (AbstractDataCommand) obj;
return flags == other.flags && Objects.equals(key, other.key);
}
@Override
public int hashCode() {
return (key != null ? key.hashCode() : 0);
}
@Override
public String toString() {
return getClass().getSimpleName() +
" {key=" + toStr(key) +
", flags=" + printFlags() +
"}";
}
@Override
public boolean isReturnValueExpected() {
return true;
}
@Override
public boolean canBlock() {
return false;
}
protected final String printFlags() {
return prettyPrintBitSet(flags, Flag.class);
}
}