Mercurial > hg > Database > Christie
annotate src/main/java/christie/daemon/IncomingTcpConnection.java @ 14:f2b30b47ef67
RemotePutTest is working
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 11 Jan 2018 18:02:59 +0900 |
parents | bcd4f2c19185 |
children | 186a86dc4c8a |
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 RemoteMessage msg = unpacker.read(RemoteMessage.class); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 CommandType type = CommandType.getCommandTypeFromId(msg.type); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 int dataSize = unpacker.readInt(); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 byte[] data = new byte[dataSize]; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 switch (type) { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 case PUT: |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 connection.socket.getInputStream().read(data); |
13
bcd4f2c19185
don't work MessagePack unconvert for remote put
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
48 try { |
14
f2b30b47ef67
RemotePutTest is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
49 DataGear dg = new DataGear(); |
f2b30b47ef67
RemotePutTest is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
50 dg.setMessagePack(data, Class.forName(msg.clazz)); |
f2b30b47ef67
RemotePutTest is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
51 cgms.get(msg.cgmName).getLocalDGM().put(msg.key, dg); |
13
bcd4f2c19185
don't work MessagePack unconvert for remote put
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
52 } catch (ClassNotFoundException e) { |
bcd4f2c19185
don't work MessagePack unconvert for remote put
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
53 e.printStackTrace(); |
bcd4f2c19185
don't work MessagePack unconvert for remote put
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
54 } |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 break; |
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 case PEEK: |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 case TAKE: |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 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
|
61 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 break; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 case REPLY: |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 connection.socket.getInputStream().read(data); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 dg = new DataGear(data, data.getClass()); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 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
|
68 //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
|
69 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 break;*/ |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 default: |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 break; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 } |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 } catch (ClosedChannelException e) { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 return; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 } catch (IOException e) { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 e.printStackTrace(); |
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 } |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 } |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 } |