1 | package net.spy.memcached.protocol.ascii; |
2 | |
3 | import java.net.SocketAddress; |
4 | import java.nio.channels.SocketChannel; |
5 | import java.util.concurrent.BlockingQueue; |
6 | |
7 | import net.spy.memcached.ops.GetOperation; |
8 | import net.spy.memcached.ops.Operation; |
9 | import net.spy.memcached.ops.OperationState; |
10 | import net.spy.memcached.protocol.ProxyCallback; |
11 | import net.spy.memcached.protocol.TCPMemcachedNodeImpl; |
12 | |
13 | /** |
14 | * Memcached node for the ASCII protocol. |
15 | */ |
16 | public final class AsciiMemcachedNodeImpl extends TCPMemcachedNodeImpl { |
17 | |
18 | public AsciiMemcachedNodeImpl(SocketAddress sa, SocketChannel c, |
19 | int bufSize, BlockingQueue<Operation> rq, |
20 | BlockingQueue<Operation> wq, BlockingQueue<Operation> iq) { |
21 | super(sa, c, bufSize, rq, wq, iq); |
22 | } |
23 | |
24 | @Override |
25 | protected void optimize() { |
26 | // make sure there are at least two get operations in a row before |
27 | // attempting to optimize them. |
28 | if(writeQ.peek() instanceof GetOperation) { |
29 | optimizedOp=writeQ.remove(); |
30 | if(writeQ.peek() instanceof GetOperation) { |
31 | OptimizedGetImpl og=new OptimizedGetImpl( |
32 | (GetOperation)optimizedOp); |
33 | optimizedOp=og; |
34 | |
35 | while(writeQ.peek() instanceof GetOperation) { |
36 | GetOperationImpl o=(GetOperationImpl) writeQ.remove(); |
37 | if(!o.isCancelled()) { |
38 | og.addOperation(o); |
39 | } |
40 | } |
41 | |
42 | // Initialize the new mega get |
43 | optimizedOp.initialize(); |
44 | assert optimizedOp.getState() == OperationState.WRITING; |
45 | ProxyCallback pcb=(ProxyCallback) og.getCallback(); |
46 | getLogger().debug("Set up %s with %s keys and %s callbacks", |
47 | this, pcb.numKeys(), pcb.numCallbacks()); |
48 | } |
49 | } |
50 | } |
51 | |
52 | } |