Mercurial > hg > Members > tatsuki > Alice
changeset 364:1494d44392a2 multicast
succeed to receive and send DataSegment on multicast
author | sugi |
---|---|
date | Fri, 16 May 2014 17:39:33 +0900 |
parents | 3c9446fa4073 |
children | 8072df9130c6 |
files | src/main/java/alice/daemon/IncomingUdpConnection.java src/main/java/alice/datasegment/MulticastDataSegmentManager.java |
diffstat | 2 files changed, 36 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/daemon/IncomingUdpConnection.java Fri May 16 16:50:38 2014 +0900 +++ b/src/main/java/alice/daemon/IncomingUdpConnection.java Fri May 16 17:39:33 2014 +0900 @@ -1,8 +1,13 @@ package alice.daemon; +import java.io.IOException; +import java.nio.ByteBuffer; + import org.msgpack.unpacker.Unpacker; import alice.codesegment.SingletonMessage; +import alice.datasegment.Command; +import alice.datasegment.CommandType; public class IncomingUdpConnection extends IncomingTcpConnection { public MulticastConnection mConnection; @@ -12,9 +17,32 @@ mConnection = mc; } - private Unpacker getUnpacker() { - //Unpacker unpacker = SingletonMessage.getInstance().createUnpacker(); - return null; - + @Override + public void run() { + ByteBuffer receive = ByteBuffer.allocate(4096); + while (true){ + try { + mConnection.receive(receive); + Unpacker unpacker = SingletonMessage.getInstance().createBufferUnpacker(receive); + receive.flip(); + CommandMessage msg = unpacker.read(CommandMessage.class); + CommandType type = CommandType.getCommandTypeFromId(msg.type); + switch (type){ + case UPDATE: + lmanager.getDataSegmentKey(msg.key) + .runCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey)); + break; + case PUT: + lmanager.getDataSegmentKey(msg.key) + .runCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey)); + break; + default: + break; + } + } catch (IOException e) { + e.printStackTrace(); + } + } } + }
--- a/src/main/java/alice/datasegment/MulticastDataSegmentManager.java Fri May 16 16:50:38 2014 +0900 +++ b/src/main/java/alice/datasegment/MulticastDataSegmentManager.java Fri May 16 17:39:33 2014 +0900 @@ -69,7 +69,10 @@ @Override public void put(String key, Object val) { - + Command cmd = new Command(CommandType.PUT, null, key, val, 0, 0, null, null, null); + sender.sendCommand(cmd); // put command on the transmission thread + if (logger.isDebugEnabled()) + logger.debug(cmd.getCommandString()); } @Override