1 | package net.spy.memcached.protocol.binary; |
2 | |
3 | import java.util.Collection; |
4 | import java.util.Collections; |
5 | |
6 | import net.spy.memcached.ops.ConcatenationOperation; |
7 | import net.spy.memcached.ops.ConcatenationType; |
8 | import net.spy.memcached.ops.OperationCallback; |
9 | import net.spy.memcached.ops.OperationStatus; |
10 | |
11 | class ConcatenationOperationImpl extends OperationImpl |
12 | implements ConcatenationOperation { |
13 | |
14 | private static final int APPEND=0x0e; |
15 | private static final int PREPEND=0x0f; |
16 | |
17 | private final String key; |
18 | private final long cas; |
19 | private final ConcatenationType catType; |
20 | private final byte[] data; |
21 | |
22 | private static int cmdMap(ConcatenationType t) { |
23 | int rv=-1; |
24 | switch(t) { |
25 | case append: rv=APPEND; break; |
26 | case prepend: rv=PREPEND; break; |
27 | } |
28 | // Check fall-through. |
29 | assert rv != -1 : "Unhandled store type: " + t; |
30 | return rv; |
31 | } |
32 | |
33 | public ConcatenationOperationImpl(ConcatenationType t, String k, |
34 | byte[] d, long c, OperationCallback cb) { |
35 | super(cmdMap(t), generateOpaque(), cb); |
36 | key=k; |
37 | data=d; |
38 | cas=c; |
39 | catType=t; |
40 | } |
41 | |
42 | @Override |
43 | public void initialize() { |
44 | prepareBuffer(key, cas, data); |
45 | } |
46 | |
47 | @Override |
48 | protected OperationStatus getStatusForErrorCode(int errCode, byte[] errPl) { |
49 | OperationStatus rv=null; |
50 | switch(errCode) { |
51 | case ERR_EXISTS: |
52 | rv=EXISTS_STATUS; |
53 | break; |
54 | case ERR_NOT_FOUND: |
55 | rv=NOT_FOUND_STATUS; |
56 | break; |
57 | case ERR_NOT_STORED: |
58 | rv=NOT_FOUND_STATUS; |
59 | break; |
60 | } |
61 | return rv; |
62 | } |
63 | |
64 | public Collection<String> getKeys() { |
65 | return Collections.singleton(key); |
66 | } |
67 | |
68 | public long getCasValue() { |
69 | return cas; |
70 | } |
71 | |
72 | public byte[] getData() { |
73 | return data; |
74 | } |
75 | |
76 | public ConcatenationType getStoreType() { |
77 | return catType; |
78 | } |
79 | |
80 | } |