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