1 | // Copyright (c) 2006 Dustin Sallings <dustin@spy.net> |
2 | |
3 | package net.spy.memcached.protocol.ascii; |
4 | |
5 | import java.nio.ByteBuffer; |
6 | |
7 | import net.spy.memcached.ops.NoopOperation; |
8 | import net.spy.memcached.ops.OperationCallback; |
9 | import net.spy.memcached.ops.OperationState; |
10 | import net.spy.memcached.ops.OperationStatus; |
11 | import net.spy.memcached.ops.VersionOperation; |
12 | |
13 | /** |
14 | * Operation to request the version of a memcached server. |
15 | */ |
16 | final class VersionOperationImpl extends OperationImpl |
17 | implements VersionOperation, NoopOperation { |
18 | |
19 | private static final byte[] REQUEST="version\r\n".getBytes(); |
20 | |
21 | public VersionOperationImpl(OperationCallback c) { |
22 | super(c); |
23 | } |
24 | |
25 | @Override |
26 | public void handleLine(String line) { |
27 | assert line.startsWith("VERSION "); |
28 | getCallback().receivedStatus( |
29 | new OperationStatus(true, line.substring("VERSION ".length()))); |
30 | transitionState(OperationState.COMPLETE); |
31 | } |
32 | |
33 | @Override |
34 | public void initialize() { |
35 | setBuffer(ByteBuffer.wrap(REQUEST)); |
36 | } |
37 | |
38 | } |