comparison src/alice/daemon/IncomingTcpConnection.java @ 69:1d4f2b72fb31

delete KeyThread
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Tue, 21 Feb 2012 19:44:33 +0900
parents 7aaadd08288c
children 4bfd81352cfa 669dba7cbb69
comparison
equal deleted inserted replaced
68:d4c7f7b1096b 69:1d4f2b72fb31
18 18
19 private static MessagePack MSGPACK = new MessagePack(); 19 private static MessagePack MSGPACK = new MessagePack();
20 public Connection connection; 20 public Connection connection;
21 public DataSegmentManager manager; 21 public DataSegmentManager manager;
22 public String reverseKey; 22 public String reverseKey;
23 private LocalDataSegmentManager lmanager = DataSegment.getLocal();;
24
23 public IncomingTcpConnection(Connection connection, DataSegmentManager manager, String reverseKey) { 25 public IncomingTcpConnection(Connection connection, DataSegmentManager manager, String reverseKey) {
24 this.manager = manager; 26 this.manager = manager;
25 this.connection = connection; 27 this.connection = connection;
26 this.reverseKey = reverseKey; 28 this.reverseKey = reverseKey;
27 } 29 }
40 try { 42 try {
41 CommandMessage msg = unpacker.read(CommandMessage.class); 43 CommandMessage msg = unpacker.read(CommandMessage.class);
42 CommandType type = CommandType.getCommandTypeFromId(msg.type); 44 CommandType type = CommandType.getCommandTypeFromId(msg.type);
43 switch (type) { 45 switch (type) {
44 case UPDATE: 46 case UPDATE:
45 getDataSegmentKey(msg).addCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey)); 47 lmanager.addCommand(getDataSegmentKey(msg),
48 new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey));
46 break; 49 break;
47 case PUT: 50 case PUT:
48 getDataSegmentKey(msg).addCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey)); 51 lmanager.addCommand(getDataSegmentKey(msg),
52 new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey));
49 break; 53 break;
50 case PEEK: 54 case PEEK:
51 //Command(CommandType cmdType, String argKey, Value val, int index, int seq, BlockingQueue<Command> replyQueue, CodeSegment cs) { 55 lmanager.addCommand(getDataSegmentKey(msg),
52 getDataSegmentKey(msg).addCommand(new Command(type, null, null, null, msg.index, msg.seq, connection.sendQueue, null, null)); 56 new Command(type, null, null, null, msg.index, msg.seq, connection.sendQueue, null, null));
53 break; 57 break;
54 case TAKE: 58 case TAKE:
55 getDataSegmentKey(msg).addCommand(new Command(type, null, null, null, msg.index, msg.seq, connection.sendQueue, null, null)); 59 lmanager.addCommand(getDataSegmentKey(msg),
60 new Command(type, null, null, null, msg.index, msg.seq, connection.sendQueue, null, null));
56 break; 61 break;
57 case REMOVE: 62 case REMOVE:
58 getDataSegmentKey(msg).addCommand(new Command(type, null, null, null, 0, 0, null, null, null)); 63 lmanager.addCommand(getDataSegmentKey(msg),
64 new Command(type, null, null, null, 0, 0, null, null, null));
59 break; 65 break;
60 case REPLY: 66 case REPLY:
61 try { 67 manager.addReplyCommand(new Command(type, null, null, msg.val, msg.index, msg.seq, null, null, null));
62 manager.replyQueue.put(new Command(type, null, null, msg.val, msg.index, msg.seq, null, null, null));
63 } catch (InterruptedException e) {
64 e.printStackTrace();
65 }
66 break; 68 break;
67 default: 69 default:
68 break; 70 break;
69 } 71 }
70 } catch (ClosedChannelException e) { 72 } catch (ClosedChannelException e) {
71 try { 73 connection.sendCommand(new Command(CommandType.CLOSE, null, null, null, 0, 0, null, null, null));
72 connection.sendQueue.put(new Command(CommandType.CLOSE, null, null, null, 0, 0, null, null, null));
73 } catch (InterruptedException e1) {
74 e1.printStackTrace();
75 }
76 return; 74 return;
77 } catch (EOFException e) { 75 } catch (EOFException e) {
78 try { 76 connection.sendCommand(new Command(CommandType.CLOSE, null, null, null, 0, 0, null, null, null));
79 connection.sendQueue.put(new Command(CommandType.CLOSE, null, null, null, 0, 0, null, null, null));
80 } catch (InterruptedException e1) {
81 e1.printStackTrace();
82 }
83 return; 77 return;
84 } catch (IOException e) { 78 } catch (IOException e) {
85 e.printStackTrace(); 79 e.printStackTrace();
86 } 80 }
87 } 81 }
88 } 82 }
89 private DataSegmentKey getDataSegmentKey(CommandMessage msg) { 83 private DataSegmentKey getDataSegmentKey(CommandMessage msg) {
90 LocalDataSegmentManager lmanager = DataSegment.getLocal();
91 return lmanager.getDataSegmentKey(msg.key); 84 return lmanager.getDataSegmentKey(msg.key);
92 } 85 }
93 } 86 }