Mercurial > hg > Database > Alice
annotate src/main/java/alice/datasegment/Command.java @ 650:4289b232b3fd
nulValue
author | suruga |
---|---|
date | Fri, 02 Feb 2018 18:26:49 +0900 |
parents | ea21af9a4762 |
children | 3284428f525e |
rev | line source |
---|---|
345 | 1 package alice.datasegment; |
2 | |
3 import java.io.IOException; | |
443 | 4 import java.nio.ByteBuffer; |
345 | 5 import java.util.concurrent.BlockingQueue; |
6 | |
443 | 7 import org.msgpack.MessagePack; |
452 | 8 |
345 | 9 import alice.codesegment.CodeSegment; |
10 import alice.daemon.CommandMessage; | |
11 import alice.daemon.Connection; | |
12 | |
523
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
13 /** |
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
14 * DSMで使われる各コマンドのセット(ReceiveDataからのDSの読み込み) |
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
15 */ |
345 | 16 public class Command { |
523
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
17 public CommandType type;//PEEK, PUTなどのコマンドタイプ |
419 | 18 public String key; |
19 public Receiver receiver; | |
458 | 20 public ReceiveData rData; |
523
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
21 public int index;//使ってない。アクセス用のindex。負の遺産。 |
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
22 public int seq;//DSの待ち合わせを行っているCSを表すunique number。リモート用。対応コマンドを表す。 |
419 | 23 public Connection connection; // for remote |
523
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
24 public BlockingQueue<Command> replyQueue;//PEEK/TAKE必要な返り値? |
419 | 25 public CodeSegment cs; |
523
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
26 public String reverseKey;//どこからput/updateされたか |
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
27 private boolean quickFlag = false;//SEDAを挟まずに処理を行うかどうか。trueだとリモート |
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
28 private boolean compressFlag = false;//trueだったら圧縮する必要がある |
419 | 29 |
529
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
30 private static final MessagePack packer = new MessagePack(); |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
31 |
523
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
32 /** |
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
33 * for PEEK/TAKE |
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
34 */ |
458 | 35 public Command(CommandType cmdType, Receiver receiver, String key, ReceiveData rData, int index, int seq, BlockingQueue<Command> replyQueue, CodeSegment cs, String reverseKey) { |
419 | 36 this.type = cmdType; |
37 this.receiver = receiver; | |
38 this.key = key; | |
458 | 39 this.rData = rData; |
419 | 40 this.index = index; |
41 this.seq = seq; | |
42 this.replyQueue = replyQueue; | |
43 this.cs = cs; | |
44 this.reverseKey = reverseKey; | |
45 } | |
46 | |
523
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
47 /** |
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
48 * for PUT/UPDATE/REPLY/PING/RESPONSE |
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
49 */ |
458 | 50 public Command(CommandType cmdType, Receiver receiver, String key, ReceiveData rData, int index, int seq, CodeSegment cs, String reverseKey, Connection connection) { |
419 | 51 this.type = cmdType; |
52 this.receiver = receiver; | |
53 this.key = key; | |
458 | 54 this.rData = rData; |
419 | 55 this.index = index; |
56 this.seq = seq; | |
57 this.connection = connection; | |
58 this.cs = cs; | |
59 this.reverseKey = reverseKey; | |
60 } | |
61 | |
523
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
62 /** |
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
63 * String型でコマンドを取得するメソッド。たぶんログ表示用。 |
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
64 * @return |
145c425db88d
add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
488
diff
changeset
|
65 */ |
419 | 66 public String getCommandString() { |
67 String csName = "null"; | |
68 if (cs != null) { | |
69 csName = cs.toString(); | |
70 } | |
458 | 71 return this.type + "\t" + key + "\t" + rData + "\tindex=" + index + "\tcs=" + csName; |
419 | 72 } |
445 | 73 /** |
74 * @return serialized ByteBuffer | |
75 */ | |
529
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
76 public ByteBuffer convert() { |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
77 ByteBuffer buf = null; |
527 | 78 |
529
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
79 try { |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
80 byte[] header = null; |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
81 byte[] data = null; |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
82 byte[] dataSize = null; |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
83 switch (type) { |
527 | 84 /* |
85 * UPDATE, PUT, REPLY need send DataSegment to RemoteDataSegment | |
86 * case UPDATE and PUT | |
87 * compress and serialize flag are selected by user, so if true, need convert. | |
88 * case REPLY | |
89 * these flags represent DataSegment status. | |
90 * for example, serializeFlag is true. DataSegment had already converted, so no need convert. | |
91 */ | |
529
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
92 case UPDATE: |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
93 case PUT: |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
94 case REPLY: |
530 | 95 if(compressFlag){ |
574
ea21af9a4762
delete serializeFlag, fix MessagePack pack&unpack
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
561
diff
changeset
|
96 data = rData.getZMessagePack(); |
529
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
97 } else { |
530 | 98 data = rData.getMessagePack(); |
529
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
99 } |
530 | 100 |
574
ea21af9a4762
delete serializeFlag, fix MessagePack pack&unpack
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
561
diff
changeset
|
101 CommandMessage cm = new CommandMessage(type.id, index, seq, key, false, compressFlag, rData.getDataSize()); |
554
1dc473a637c6
add setter/getter to setTime of ReceivedData
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
536
diff
changeset
|
102 if (rData.getSetTime()) { |
529
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
103 cm.setTime = true; |
554
1dc473a637c6
add setter/getter to setTime of ReceivedData
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
536
diff
changeset
|
104 cm.time = rData.getTime(); |
1dc473a637c6
add setter/getter to setTime of ReceivedData
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
536
diff
changeset
|
105 cm.depth = rData.getDepth() + 1; |
529
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
106 } |
525
30a74eee59c7
working TestRemoteAlice
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
523
diff
changeset
|
107 |
561
f1777341c5a2
add setZipped to CommandMessage&ReceiveData
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
554
diff
changeset
|
108 if (rData.getSetZipped()){ |
f1777341c5a2
add setZipped to CommandMessage&ReceiveData
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
554
diff
changeset
|
109 cm.setZepped = true; |
f1777341c5a2
add setZipped to CommandMessage&ReceiveData
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
554
diff
changeset
|
110 cm.zippedDataSize = rData.getZippedDataSize(); |
f1777341c5a2
add setZipped to CommandMessage&ReceiveData
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
554
diff
changeset
|
111 } |
f1777341c5a2
add setZipped to CommandMessage&ReceiveData
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
554
diff
changeset
|
112 |
529
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
113 header = packer.write(cm); |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
114 dataSize = packer.write(data.length); |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
115 buf = ByteBuffer.allocate(header.length+dataSize.length+data.length); |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
116 buf.put(header); |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
117 buf.put(dataSize); |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
118 buf.put(data); |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
119 break; |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
120 default: |
574
ea21af9a4762
delete serializeFlag, fix MessagePack pack&unpack
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
561
diff
changeset
|
121 header = packer.write(new CommandMessage(type.id, index, seq, key, quickFlag, compressFlag, 0)); |
529
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
122 buf = ByteBuffer.allocate(header.length); |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
123 buf.put(header); |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
124 break; |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
125 } |
528
6ebddfac7ff6
delete RecieveData.setCompressFlag
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
527
diff
changeset
|
126 |
529
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
127 buf.flip(); |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
128 } catch (IOException e) { |
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
129 e.printStackTrace(); |
527 | 130 } |
443 | 131 return buf; |
419 | 132 } |
467 | 133 |
458 | 134 /** |
135 * If this flag is true, command isn't send queue. | |
136 * command is executed right now. | |
467 | 137 * |
458 | 138 * @param flag |
139 */ | |
467 | 140 |
529
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
141 public void setQuickFlag(boolean flag){ |
446 | 142 quickFlag = flag; |
143 } | |
467 | 144 |
529
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
145 public boolean getQuickFlag(){ |
448 | 146 return quickFlag; |
147 } | |
467 | 148 |
458 | 149 /** |
150 * Before sending Remote DataSegment, DataSegment type is ByteArray. | |
151 * If this flag true, ByteArray is compressed with ZRLEE(ZRIB) algorithm | |
467 | 152 * |
458 | 153 * @param flag |
154 */ | |
467 | 155 |
529
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
156 public void setCompressFlag(boolean flag){ |
446 | 157 compressFlag = flag; |
158 } | |
467 | 159 |
529
cb7c31848d16
add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
528
diff
changeset
|
160 public boolean getCompressFlag(){ |
448 | 161 return compressFlag; |
162 } | |
536
d2f7d02c4976
remoteDSM refactoring
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
532
diff
changeset
|
163 |
d2f7d02c4976
remoteDSM refactoring
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
532
diff
changeset
|
164 public void setSeq(int seq) { |
d2f7d02c4976
remoteDSM refactoring
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
532
diff
changeset
|
165 this.seq = seq; |
d2f7d02c4976
remoteDSM refactoring
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
532
diff
changeset
|
166 } |
345 | 167 } |