Mercurial > hg > Database > Alice
changeset 447:d30451d1882f dispose
fix IncomingUdpConnection and passed UdpTest
author | sugi |
---|---|
date | Mon, 27 Oct 2014 01:29:32 +0900 |
parents | a91890dff56e |
children | 4840d0e2b605 |
files | src/main/java/alice/daemon/IncomingTcpConnection.java src/main/java/alice/daemon/IncomingUdpConnection.java |
diffstat | 2 files changed, 19 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/daemon/IncomingTcpConnection.java Mon Oct 27 00:26:35 2014 +0900 +++ b/src/main/java/alice/daemon/IncomingTcpConnection.java Mon Oct 27 01:29:32 2014 +0900 @@ -51,8 +51,8 @@ } while (true) { try { + Command cmd = null; byte[] val = null; - Command cmd = null; CommandMessage msg = unpacker.read(CommandMessage.class); CommandType type = CommandType.getCommandTypeFromId(msg.type); switch (type) {
--- a/src/main/java/alice/daemon/IncomingUdpConnection.java Mon Oct 27 00:26:35 2014 +0900 +++ b/src/main/java/alice/daemon/IncomingUdpConnection.java Mon Oct 27 01:29:32 2014 +0900 @@ -26,45 +26,45 @@ super(manager); receiver = r; sender = s; + reverseKey = "multicast"; } @Override public void run() { while (true){ try { + Command cmd = null; + byte[] val = null; // Max data length is 65507 because of the max length of UDP payload ByteBuffer receive = ByteBuffer.allocate(65507); receiver.receive(receive); Unpacker unpacker = SingletonMessage.getInstance().createBufferUnpacker(receive); receive.flip(); CommandMessage msg = unpacker.read(CommandMessage.class); - byte[] val = unpacker.readByteArray(); CommandType type = CommandType.getCommandTypeFromId(msg.type); switch (type) { case UPDATE: - getLocalDataSegmentManager().getDataSegmentKey(msg.key) - .runCommand(new Command(type, null, null, val, 0, 0, null, null, reverseKey)); - break; - case PUT: - getLocalDataSegmentManager().getDataSegmentKey(msg.key) - .runCommand(new Command(type, null, null, val, 0, 0, null, null, reverseKey)); + case PUT: + val = new byte[unpacker.readInt()]; + receive.get(val); + cmd = new Command(type, null, null, val, 0, 0, null, null, reverseKey); + getLocalDataSegmentManager().getDataSegmentKey(msg.key).runCommand(cmd); break; case PEEK: - getLocalDataSegmentManager().getDataSegmentKey(msg.key) - .runCommand(new Command(type, null, null, null, msg.index, msg.seq, sender, null, null, msg.flag)); + case TAKE: + cmd = new Command(type, null, null, null, msg.index, msg.seq, null, null ,sender); + cmd.setQuickFlag(msg.flag); + getLocalDataSegmentManager().getDataSegmentKey(msg.key).runCommand(cmd); break; - case TAKE: - getLocalDataSegmentManager().getDataSegmentKey(msg.key) - .runCommand(new Command(type, null, null, null, msg.index, msg.seq, sender, null, null, msg.flag)); - break; case REMOVE: - getLocalDataSegmentManager().getDataSegmentKey(msg.key) - .runCommand(new Command(type, null, null, null, 0, 0, null, null, null)); + cmd = new Command(type, null, null, null, 0, 0, null, null, ""); + getLocalDataSegmentManager().getDataSegmentKey(msg.key).runCommand(cmd); break; case REPLY: - Command cmd = manager.getAndRemoveCmd(msg.seq); - cmd.cs.ids.reply(cmd.receiver, new Command(type, null, null, val, msg.index, msg.seq, null, null, null)); - cmd=null; + cmd = manager.getAndRemoveCmd(msg.seq); + val = new byte[unpacker.readInt()]; + receive.get(val); + cmd.cs.ids.reply(cmd.receiver, new Command(type, null, null, val, msg.index, msg.seq, null, null, "")); break; case PING: DataSegment.get(reverseKey).response(msg.key);