Mercurial > hg > Database > Christie
annotate src/main/java/christie/codegear/Command.java @ 12:b49a926cbdd9
add RemotePutTest and that is working
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 09 Jan 2018 17:37:43 +0900 |
parents | 3ea61d0bfc34 |
children | bcd4f2c19185 |
rev | line source |
---|---|
1
3ea61d0bfc34
add dependency proccess but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 package christie.codegear; |
3ea61d0bfc34
add dependency proccess but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
3 import christie.daemon.RemoteMessage; |
1
3ea61d0bfc34
add dependency proccess but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 import christie.datagear.DataGear; |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
5 import org.msgpack.MessagePack; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
6 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
7 import java.io.IOException; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
8 import java.nio.ByteBuffer; |
1
3ea61d0bfc34
add dependency proccess but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 |
3ea61d0bfc34
add dependency proccess but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 public class Command { |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
11 public CodeGear cg = null; |
1
3ea61d0bfc34
add dependency proccess but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 public DataGear dg; |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
13 public String cgmName = "first"; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
14 public String dsmName = "local"; |
1
3ea61d0bfc34
add dependency proccess but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 public String key; |
3ea61d0bfc34
add dependency proccess but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 public CommandType type; |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
17 private static final MessagePack packer = new MessagePack(); |
1
3ea61d0bfc34
add dependency proccess but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
19 //for put |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
20 public Command(DataGear dg, String cgmName, String dsmName, String key, CommandType type){ |
1
3ea61d0bfc34
add dependency proccess but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 this.dg = dg; |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
22 this.cgmName = cgmName; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
23 this.dsmName = dsmName; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
24 this.key = key; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
25 this.type = type; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
26 } |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
27 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
28 //for take |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
29 public Command(CodeGear cg, DataGear dg, String cgmName, String dsmName, String key, CommandType type){ |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
30 this.cg = cg; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
31 this.dg = dg; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
32 this.cgmName = cgmName; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
33 this.dsmName = dsmName; |
1
3ea61d0bfc34
add dependency proccess but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 this.key = key; |
3ea61d0bfc34
add dependency proccess but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 this.type = type; |
3ea61d0bfc34
add dependency proccess but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 } |
3ea61d0bfc34
add dependency proccess but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
38 public ByteBuffer convert() { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
39 ByteBuffer buf = null; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
40 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
41 try { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
42 byte[] command = null; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
43 byte[] data = null; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
44 byte[] dataSize = null; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
45 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
46 switch (type) { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
47 case PUT: |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
48 case REPLY: |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
49 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
50 RemoteMessage cm = new RemoteMessage(); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
51 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
52 data = dg.getMessagePack(); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
53 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
54 command = packer.write(cm); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
55 dataSize = packer.write(data.length); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
56 buf = ByteBuffer.allocate(command.length+dataSize.length+data.length); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
57 buf.put(command); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
58 buf.put(dataSize); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
59 buf.put(data); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
60 break; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
61 default: |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
62 command = packer.write(new RemoteMessage()); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
63 buf = ByteBuffer.allocate(command.length); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
64 buf.put(command); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
65 break; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
66 } |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
67 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
68 buf.flip(); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
69 } catch (IOException e) { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
70 e.printStackTrace(); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
71 } |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
72 return buf; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
73 } |
1
3ea61d0bfc34
add dependency proccess but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 } |