Mercurial > hg > Database > Christie
annotate src/main/java/christie/daemon/IncomingTcpConnection.java @ 13:bcd4f2c19185
don't work MessagePack unconvert for remote put
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 10 Jan 2018 20:37:47 +0900 |
parents | b49a926cbdd9 |
children | f2b30b47ef67 |
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); |
13
bcd4f2c19185
don't work MessagePack unconvert for remote put
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
49 try { |
bcd4f2c19185
don't work MessagePack unconvert for remote put
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
50 cgms.get(msg.cgmName).getDGM().put(msg.key, new DataGear(data, Class.forName(msg.clazz))); |
bcd4f2c19185
don't work MessagePack unconvert for remote put
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
51 } catch (ClassNotFoundException e) { |
bcd4f2c19185
don't work MessagePack unconvert for remote put
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
52 e.printStackTrace(); |
bcd4f2c19185
don't work MessagePack unconvert for remote put
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
53 } |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 break; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 /* |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 case PEEK: |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 case TAKE: |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 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
|
60 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 break; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 case REPLY: |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 connection.socket.getInputStream().read(data); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 dg = new DataGear(data, data.getClass()); |
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 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
|
67 //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
|
68 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 break;*/ |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 default: |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 break; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 } |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 } catch (ClosedChannelException e) { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 return; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 } catch (IOException e) { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 e.printStackTrace(); |
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 } |
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 } |