| 1 | package net.spy.memcached.protocol.ascii; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | |
| 6 | import net.spy.memcached.ops.BaseOperationFactory; |
| 7 | import net.spy.memcached.ops.CASOperation; |
| 8 | import net.spy.memcached.ops.ConcatenationOperation; |
| 9 | import net.spy.memcached.ops.ConcatenationType; |
| 10 | import net.spy.memcached.ops.DeleteOperation; |
| 11 | import net.spy.memcached.ops.FlushOperation; |
| 12 | import net.spy.memcached.ops.GetOperation; |
| 13 | import net.spy.memcached.ops.GetsOperation; |
| 14 | import net.spy.memcached.ops.KeyedOperation; |
| 15 | import net.spy.memcached.ops.MultiGetOperationCallback; |
| 16 | import net.spy.memcached.ops.Mutator; |
| 17 | import net.spy.memcached.ops.MutatorOperation; |
| 18 | import net.spy.memcached.ops.NoopOperation; |
| 19 | import net.spy.memcached.ops.Operation; |
| 20 | import net.spy.memcached.ops.OperationCallback; |
| 21 | import net.spy.memcached.ops.StatsOperation; |
| 22 | import net.spy.memcached.ops.StoreOperation; |
| 23 | import net.spy.memcached.ops.StoreType; |
| 24 | import net.spy.memcached.ops.VersionOperation; |
| 25 | |
| 26 | /** |
| 27 | * Operation factory for the ascii protocol. |
| 28 | */ |
| 29 | public class AsciiOperationFactory extends BaseOperationFactory { |
| 30 | |
| 31 | public DeleteOperation delete(String key, OperationCallback cb) { |
| 32 | return new DeleteOperationImpl(key, cb); |
| 33 | } |
| 34 | |
| 35 | public FlushOperation flush(int delay, OperationCallback cb) { |
| 36 | return new FlushOperationImpl(delay, cb); |
| 37 | } |
| 38 | |
| 39 | public GetOperation get(String key, GetOperation.Callback cb) { |
| 40 | return new GetOperationImpl(key, cb); |
| 41 | } |
| 42 | |
| 43 | public GetOperation get(Collection<String> keys, GetOperation.Callback cb) { |
| 44 | return new GetOperationImpl(keys, cb); |
| 45 | } |
| 46 | |
| 47 | public GetsOperation gets(String key, GetsOperation.Callback cb) { |
| 48 | return new GetsOperationImpl(key, cb); |
| 49 | } |
| 50 | |
| 51 | public MutatorOperation mutate(Mutator m, String key, int by, |
| 52 | long exp, int def, OperationCallback cb) { |
| 53 | return new MutatorOperationImpl(m, key, by, cb); |
| 54 | } |
| 55 | |
| 56 | public StatsOperation stats(String arg, StatsOperation.Callback cb) { |
| 57 | return new StatsOperationImpl(arg, cb); |
| 58 | } |
| 59 | |
| 60 | public StoreOperation store(StoreType storeType, String key, int flags, |
| 61 | int exp, byte[] data, OperationCallback cb) { |
| 62 | return new StoreOperationImpl(storeType, key, flags, exp, data, cb); |
| 63 | } |
| 64 | |
| 65 | public VersionOperation version(OperationCallback cb) { |
| 66 | return new VersionOperationImpl(cb); |
| 67 | } |
| 68 | |
| 69 | public NoopOperation noop(OperationCallback cb) { |
| 70 | return new VersionOperationImpl(cb); |
| 71 | } |
| 72 | |
| 73 | public CASOperation cas(StoreType type, String key, long casId, int flags, |
| 74 | int exp, byte[] data, OperationCallback cb) { |
| 75 | return new CASOperationImpl(key, casId, flags, exp, data, cb); |
| 76 | } |
| 77 | |
| 78 | public ConcatenationOperation cat(ConcatenationType catType, |
| 79 | long casId, |
| 80 | String key, byte[] data, OperationCallback cb) { |
| 81 | return new ConcatenationOperationImpl(catType, key, data, cb); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | protected Collection<? extends Operation> cloneGet(KeyedOperation op) { |
| 86 | Collection<Operation> rv=new ArrayList<Operation>(); |
| 87 | GetOperation.Callback callback = new MultiGetOperationCallback( |
| 88 | op.getCallback(), op.getKeys().size()); |
| 89 | for(String k : op.getKeys()) { |
| 90 | rv.add(get(k, callback)); |
| 91 | } |
| 92 | return rv; |
| 93 | } |
| 94 | |
| 95 | } |