1 |
torben |
644 |
import net.spy.memcached.MemcachedClient; |
2 |
|
|
import java.net.InetSocketAddress; |
3 |
|
|
|
4 |
|
|
public class Consumer |
5 |
|
|
{ |
6 |
|
|
static final int SLOT_COUNT = 10; |
7 |
|
|
|
8 |
|
|
public static void main(String args[]) throws Exception |
9 |
|
|
{ |
10 |
|
|
MemcachedClient c = new MemcachedClient( new InetSocketAddress("localhost", 11211) ); |
11 |
|
|
|
12 |
|
|
int current = 0; |
13 |
|
|
while (true) { |
14 |
|
|
|
15 |
|
|
String key = "slot:" + current; |
16 |
|
|
|
17 |
|
|
|
18 |
|
|
String data = (String) c.get(key); |
19 |
|
|
if ( data != null) { |
20 |
|
|
System.out.println("Consuming slot " + current); |
21 |
|
|
|
22 |
|
|
System.out.println("Got >" +data + "<"); |
23 |
|
|
|
24 |
|
|
c.delete(key); |
25 |
|
|
} |
26 |
|
|
|
27 |
|
|
|
28 |
|
|
current = (current+1) % SLOT_COUNT; |
29 |
|
|
|
30 |
|
|
Thread.sleep( 900 ); |
31 |
|
|
} |
32 |
|
|
} |
33 |
|
|
} |