Mercurial > hg > Members > tatsuki > Alice
comparison src/alice/daemon/OutboundTcpConnection.java @ 122:d5d9ca4cbe87 working fish-example-worked
fix memory leak!
author | one |
---|---|
date | Fri, 27 Jul 2012 02:04:45 +0900 |
parents | b01fb5090e28 |
children | 1044a79ce4ef |
comparison
equal
deleted
inserted
replaced
121:bddb8be357f6 | 122:d5d9ca4cbe87 |
---|---|
8 import alice.datasegment.Command; | 8 import alice.datasegment.Command; |
9 | 9 |
10 public class OutboundTcpConnection extends Thread { | 10 public class OutboundTcpConnection extends Thread { |
11 | 11 |
12 public Connection connection; | 12 public Connection connection; |
13 private static MessagePack MSGPACK = new MessagePack(); | |
13 | 14 |
14 public OutboundTcpConnection(Connection connection) { | 15 public OutboundTcpConnection(Connection connection) { |
15 this.connection = connection; | 16 this.connection = connection; |
16 } | 17 } |
17 | 18 |
21 | 22 |
22 /** | 23 /** |
23 * pipeline thread for transmission | 24 * pipeline thread for transmission |
24 */ | 25 */ |
25 public void run() { | 26 public void run() { |
26 MessagePack msgpack = new MessagePack(); | |
27 while (true) { | 27 while (true) { |
28 try { | 28 try { |
29 Command cmd = connection.sendQueue.take(); | 29 Command cmd = connection.sendQueue.take(); |
30 switch (cmd.type) { | 30 switch (cmd.type) { |
31 case CLOSE: | 31 case CLOSE: |
36 return; | 36 return; |
37 default: | 37 default: |
38 break; | 38 break; |
39 } | 39 } |
40 CommandMessage cmdMsg = convert(cmd); | 40 CommandMessage cmdMsg = convert(cmd); |
41 ByteBuffer buffer = ByteBuffer.wrap(msgpack.write(cmdMsg)); | 41 ByteBuffer buffer = ByteBuffer.wrap(MSGPACK.write(cmdMsg)); |
42 while (buffer.hasRemaining()) { | 42 while (buffer.hasRemaining()) { |
43 connection.socket.getChannel().write(buffer); | 43 connection.socket.getChannel().write(buffer); |
44 } | 44 } |
45 } catch (InterruptedException e) { | 45 } catch (InterruptedException e) { |
46 e.printStackTrace(); | 46 e.printStackTrace(); |