Mercurial > hg > Database > Alice
diff src/alice/datasegment/DataSegmentKey.java @ 232:496b687f3793
peek or take command from local no use Reply Thread
author | sugi |
---|---|
date | Fri, 29 Mar 2013 18:32:27 +0900 |
parents | bc061ee5f31f |
children | 4dc2f09a8f7a |
line wrap: on
line diff
--- a/src/alice/datasegment/DataSegmentKey.java Fri Mar 29 02:23:35 2013 +0900 +++ b/src/alice/datasegment/DataSegmentKey.java Fri Mar 29 18:32:27 2013 +0900 @@ -52,11 +52,7 @@ boolean waitFlag2 = true; for (DataSegmentValue data : dataList) { if (data.index > cmd.index) { - try { - cmd.replyQueue.put(new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, cmd.seq, null, null, data.from)); - } catch (InterruptedException e) { - e.printStackTrace(); - } + replyValue(cmd ,data); waitFlag2 = false; break; } @@ -73,11 +69,7 @@ for (Iterator<DataSegmentValue> iter = dataList.iterator(); iter.hasNext(); ) { DataSegmentValue data = iter.next(); if (data.index > cmd.index) { - try { - cmd.replyQueue.put(new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, cmd.seq, null, null, data.from)); - } catch (InterruptedException e) { - e.printStackTrace(); - } + replyValue(cmd ,data); iter.remove(); waitFlag = false; break; @@ -94,4 +86,18 @@ } + public void replyValue(Command cmd, DataSegmentValue data){ + if (cmd.cs!=null){ // if cmd has cs-instance it means Command from local. + cmd.cs.ids.reply(cmd.receiver, new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, 0, null, null, data.from)); + DataSegment.getLocal().getAndRemoveCmd(cmd.seq); + cmd = null; // someone has been holding instance. + } else { + try { + cmd.replyQueue.put(new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, cmd.seq, null, null, data.from)); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + }