| 1 | package net.spy.memcached.protocol.binary; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | |
| 5 | import net.spy.memcached.ops.OperationState; |
| 6 | import net.spy.memcached.ops.StatsOperation; |
| 7 | |
| 8 | public class StatsOperationImpl extends OperationImpl |
| 9 | implements StatsOperation { |
| 10 | |
| 11 | private static final int CMD = 0x10; |
| 12 | private final String key; |
| 13 | |
| 14 | public StatsOperationImpl(String arg, StatsOperation.Callback c) { |
| 15 | super(CMD, generateOpaque(), c); |
| 16 | key=(arg == null) ? "" : arg; |
| 17 | } |
| 18 | |
| 19 | @Override |
| 20 | public void initialize() { |
| 21 | prepareBuffer(key, 0, EMPTY_BYTES); |
| 22 | } |
| 23 | |
| 24 | @Override |
| 25 | protected void finishedPayload(byte[] pl) throws IOException { |
| 26 | if(keyLen > 0) { |
| 27 | final byte[] keyBytes=new byte[keyLen]; |
| 28 | final byte[] data=new byte[pl.length - keyLen]; |
| 29 | System.arraycopy(pl, 0, keyBytes, 0, keyLen); |
| 30 | System.arraycopy(pl, keyLen, data, 0, pl.length-keyLen); |
| 31 | Callback cb=(Callback)getCallback(); |
| 32 | cb.gotStat(new String(keyBytes, "UTF-8"), |
| 33 | new String(data, "UTF-8")); |
| 34 | } else { |
| 35 | getCallback().receivedStatus(STATUS_OK); |
| 36 | transitionState(OperationState.COMPLETE); |
| 37 | } |
| 38 | resetInput(); |
| 39 | } |
| 40 | |
| 41 | } |