Mercurial > hg > Members > tatsuki > Alice
view src/main/java/alice/daemon/IncomingUdpConnection.java @ 364:1494d44392a2 multicast
succeed to receive and send DataSegment on multicast
author | sugi |
---|---|
date | Fri, 16 May 2014 17:39:33 +0900 |
parents | 60eee1fb0fd3 |
children | 8072df9130c6 |
line wrap: on
line source
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; public IncomingUdpConnection(MulticastConnection mc) { super(null, null, "multicast"); mConnection = mc; } @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(); } } } }