Mercurial > hg > Database > Alice
view src/alice/datasegment/DataSegmentManager.java @ 39:3155337e754e
add logger
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 27 Jan 2012 16:57:26 +0900 |
parents | 20c67f673224 |
children | 20616fe4d28a |
line wrap: on
line source
package alice.datasegment; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicInteger; import org.apache.log4j.Logger; import org.msgpack.type.Value; import alice.codesegment.CodeSegment; public abstract class DataSegmentManager { protected ConcurrentHashMap<String, DataSegmentKey> dataSegments = new ConcurrentHashMap<String, DataSegmentKey>(); protected ConcurrentHashMap<Integer, Command> seqHash = new ConcurrentHashMap<Integer, Command>(); public LinkedBlockingQueue<Command> replyQueue = new LinkedBlockingQueue<Command>(); protected AtomicInteger seq = new AtomicInteger(1); protected Runnable replyThread = new Runnable() { Logger logger = Logger.getLogger("reply"); @Override public void run() { while (true) { try { Command reply = replyQueue.take(); Command cmd = seqHash.get(reply.seq); cmd.cs.ids.reply(cmd.receiver, new DataSegmentValue(reply.index, reply.val, reply.reverseKey)); logger.debug(reply.getCommandString() + " " + cmd.getCommandString()); } catch (InterruptedException e) { e.printStackTrace(); } } } }; public abstract void put(String key, Value val); public abstract void update(String key, Value val); public void take(Receiver receiver, String key, CodeSegment cs) { take(receiver, key, 0, cs); } public abstract void take(Receiver receiver, String key, int index, CodeSegment cs); public void peek(Receiver receiver, String key, CodeSegment cs) { peek(receiver, key, 0, cs); } public abstract void peek(Receiver receiver, String key, int index, CodeSegment cs); public abstract void remove(String key); public abstract void finish(); }