annotate src/main/java/christie/daemon/IncomingTcpConnection.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
children bcd4f2c19185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 package christie.daemon;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 import christie.codegear.CodeGearManager;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 import christie.codegear.Command;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 import christie.codegear.CommandType;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 import christie.datagear.DataGear;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 import christie.datagear.RemoteDataGearManager;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 import org.msgpack.MessagePack;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 import org.msgpack.unpacker.Unpacker;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 import java.io.IOException;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 import java.nio.channels.ClosedChannelException;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 import java.util.concurrent.ConcurrentHashMap;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 public class IncomingTcpConnection extends Thread {
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 ConcurrentHashMap<String, CodeGearManager> cgms;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 Connection connection;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 private static final MessagePack packer = new MessagePack();
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 public IncomingTcpConnection(Connection connection, CodeGearManager cgm) {
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 this.cgms = cgm.getCgms();
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 this.connection = connection;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 }
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 public void run() {
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 Unpacker unpacker = null;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 try {
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 unpacker = packer.createUnpacker(connection.socket.getInputStream());
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 } catch (IOException e) {
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 e.printStackTrace();
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 }
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 if (unpacker == null) {
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 return;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 }
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 while (true) {
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 try {
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 Command cmd = null;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 DataGear dg = null;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 RemoteMessage msg = unpacker.read(RemoteMessage.class);
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 CommandType type = CommandType.getCommandTypeFromId(msg.type);
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 int dataSize = unpacker.readInt();
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 byte[] data = new byte[dataSize];
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 switch (type) {
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 case PUT:
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 connection.socket.getInputStream().read(data);
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 cgms.get(msg.cgmName).getDGM().put(msg.key, data);
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 break;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 /*
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 case PEEK:
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 case TAKE:
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 cmd = new Command(null, dg, null, null, null);
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 break;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 case REPLY:
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 connection.socket.getInputStream().read(data);
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 dg = new DataGear(data, data.getClass());
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 Command rCmd = new Command(null, dg, null, null, null);
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 //cmd.cg.idg.reply(cmd.dg, rCmd);
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 break;*/
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 default:
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 break;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 }
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 } catch (ClosedChannelException e) {
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 return;
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 } catch (IOException e) {
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 e.printStackTrace();
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 }
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 }
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 }
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
b49a926cbdd9 add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 }