Mercurial > hg > Database > Christie
annotate src/main/java/christie/daemon/IncomingTcpConnection.java @ 22:77583ea56656
add WaitList and implement RemoteTake but not work
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 23 Jan 2018 22:02:54 +0900 |
parents | 5baccb8f7fbd |
children | 695705dba324 |
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; |
22
77583ea56656
add WaitList and implement RemoteTake but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
21
diff
changeset
|
5 import christie.datagear.*; |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 import org.msgpack.MessagePack; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 import org.msgpack.unpacker.Unpacker; |
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 java.io.IOException; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 import java.nio.channels.ClosedChannelException; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 import java.util.concurrent.ConcurrentHashMap; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 public class IncomingTcpConnection extends Thread { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 |
21
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
16 RemoteDataGearManager manager; |
17
59fabebb67d8
delete cgmName as String, add cgmID as int
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
16
diff
changeset
|
17 ConcurrentHashMap<Integer, CodeGearManager> cgms; |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 Connection connection; |
16
186a86dc4c8a
working RemotePutTest by 2 node
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
14
diff
changeset
|
19 private MessagePack packer = new MessagePack(); |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 public IncomingTcpConnection(Connection connection, CodeGearManager cgm) { |
21
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
22 this.connection = connection; |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 this.cgms = cgm.getCgms(); |
21
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
24 } |
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
25 |
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
26 public void setManager(RemoteDataGearManager manager){ |
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
27 this.manager = manager; |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 } |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 public void run() { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 Unpacker unpacker = null; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 try { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 unpacker = packer.createUnpacker(connection.socket.getInputStream()); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 } catch (IOException e) { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 e.printStackTrace(); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 } |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 if (unpacker == null) { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 return; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 } |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 while (true) { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 try { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 Command cmd = null; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 RemoteMessage msg = unpacker.read(RemoteMessage.class); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 CommandType type = CommandType.getCommandTypeFromId(msg.type); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 int dataSize = unpacker.readInt(); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 byte[] data = new byte[dataSize]; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 switch (type) { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 case PUT: |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 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
|
50 try { |
20
7b45ccc0f70e
add MessagePackDataGear
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
51 MessagePackDataGear dg = new MessagePackDataGear(data, Class.forName(msg.clazz)); |
17
59fabebb67d8
delete cgmName as String, add cgmID as int
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
16
diff
changeset
|
52 |
59fabebb67d8
delete cgmName as String, add cgmID as int
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
16
diff
changeset
|
53 if (cgms.containsKey(msg.cgmID)){ |
59fabebb67d8
delete cgmName as String, add cgmID as int
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
16
diff
changeset
|
54 cgms.get(msg.cgmID).getLocalDGM().put(msg.key, dg); |
59fabebb67d8
delete cgmName as String, add cgmID as int
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
16
diff
changeset
|
55 } else { |
59fabebb67d8
delete cgmName as String, add cgmID as int
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
16
diff
changeset
|
56 throw new IllegalArgumentException("DGM_ID:" + msg.cgmID + "is not found"); |
59fabebb67d8
delete cgmName as String, add cgmID as int
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
16
diff
changeset
|
57 } |
59fabebb67d8
delete cgmName as String, add cgmID as int
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
16
diff
changeset
|
58 |
13
bcd4f2c19185
don't work MessagePack unconvert for remote put
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
59 } catch (ClassNotFoundException e) { |
bcd4f2c19185
don't work MessagePack unconvert for remote put
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
60 e.printStackTrace(); |
bcd4f2c19185
don't work MessagePack unconvert for remote put
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
61 } |
12
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 break; |
21
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
64 |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 case PEEK: |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 case TAKE: |
22
77583ea56656
add WaitList and implement RemoteTake but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
21
diff
changeset
|
67 cmd = new Command(type, null, msg.cgmID, msg.dgmName, msg.key, null, null, connection); |
21
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
68 |
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
69 if (cgms.containsKey(msg.cgmID)){ |
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
70 cgms.get(msg.cgmID).getLocalDGM().take(cmd); |
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
71 } else { |
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
72 throw new IllegalArgumentException("DGM_ID:" + msg.cgmID + "is not found"); |
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
73 } |
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
74 |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 break; |
21
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
76 case REPLY://待っていたwaitListに渡してcsにセット |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 connection.socket.getInputStream().read(data); |
21
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
78 try { |
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
79 MessagePackDataGear dg = new MessagePackDataGear(data, Class.forName(msg.clazz)); |
22
77583ea56656
add WaitList and implement RemoteTake but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
21
diff
changeset
|
80 |
77583ea56656
add WaitList and implement RemoteTake but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
21
diff
changeset
|
81 DataGearManager dgm = cgms.get(msg.cgmID).getDGM(msg.dgmName); |
77583ea56656
add WaitList and implement RemoteTake but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
21
diff
changeset
|
82 Command cm = dgm.waitList.getAndRemoveCommand(msg.key); |
77583ea56656
add WaitList and implement RemoteTake but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
21
diff
changeset
|
83 cm.dg = dg; |
77583ea56656
add WaitList and implement RemoteTake but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
21
diff
changeset
|
84 dgm.runCommand(cm); |
77583ea56656
add WaitList and implement RemoteTake but not work
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
21
diff
changeset
|
85 |
21
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
86 } catch (ClassNotFoundException e) { |
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
87 e.printStackTrace(); |
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
88 } |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 |
21
5baccb8f7fbd
add RemoteTake, but it isn't working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
90 break; |
12
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 default: |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 break; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 } |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 } catch (ClosedChannelException e) { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 return; |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96 } catch (IOException e) { |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 e.printStackTrace(); |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 } |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 } |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 } |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 |
b49a926cbdd9
add RemotePutTest and that is working
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 } |