1 | // Copyright (c) 2006 Dustin Sallings <dustin@spy.net> |
2 | |
3 | package net.spy.memcached.protocol.ascii; |
4 | |
5 | import java.nio.ByteBuffer; |
6 | import java.util.Collection; |
7 | import java.util.Collections; |
8 | |
9 | import net.spy.memcached.KeyUtil; |
10 | import net.spy.memcached.ops.DeleteOperation; |
11 | import net.spy.memcached.ops.OperationCallback; |
12 | import net.spy.memcached.ops.OperationState; |
13 | import net.spy.memcached.ops.OperationStatus; |
14 | |
15 | /** |
16 | * Operation to delete an item from the cache. |
17 | */ |
18 | final class DeleteOperationImpl extends OperationImpl |
19 | implements DeleteOperation { |
20 | |
21 | private static final int OVERHEAD=32; |
22 | |
23 | private static final OperationStatus DELETED= |
24 | new OperationStatus(true, "DELETED"); |
25 | private static final OperationStatus NOT_FOUND= |
26 | new OperationStatus(false, "NOT_FOUND"); |
27 | |
28 | private final String key; |
29 | |
30 | public DeleteOperationImpl(String k, OperationCallback cb) { |
31 | super(cb); |
32 | key=k; |
33 | } |
34 | |
35 | @Override |
36 | public void handleLine(String line) { |
37 | getLogger().debug("Delete of %s returned %s", key, line); |
38 | getCallback().receivedStatus(matchStatus(line, DELETED, NOT_FOUND)); |
39 | transitionState(OperationState.COMPLETE); |
40 | } |
41 | |
42 | @Override |
43 | public void initialize() { |
44 | ByteBuffer b=ByteBuffer.allocate( |
45 | KeyUtil.getKeyBytes(key).length + OVERHEAD); |
46 | setArguments(b, "delete", key); |
47 | b.flip(); |
48 | setBuffer(b); |
49 | } |
50 | |
51 | public Collection<String> getKeys() { |
52 | return Collections.singleton(key); |
53 | } |
54 | |
55 | } |