Mercurial > hg > Database > Alice
annotate src/alice/daemon/OutboundTcpConnection.java @ 16:433e601a8e28
network bug fix
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 15 Jan 2012 12:17:30 +0900 |
parents | e3f1b21718b0 |
children | b5a21baf0b07 |
rev | line source |
---|---|
13 | 1 package alice.daemon; |
2 | |
3 import java.io.IOException; | |
4 import java.nio.ByteBuffer; | |
5 | |
6 import org.msgpack.MessagePack; | |
7 | |
8 import alice.datasegment.Command; | |
9 | |
10 public class OutboundTcpConnection extends Thread { | |
11 | |
12 public Connection connection; | |
13 | |
14 public OutboundTcpConnection(Connection connection) { | |
15 this.connection = connection; | |
16 } | |
17 | |
18 public CommandMessage convert(Command cmd) { | |
14
e3f1b21718b0
implements RemoteDataSegment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
19 return new CommandMessage(cmd.type.id, cmd.index, cmd.seq, cmd.key, cmd.val); |
13 | 20 } |
21 | |
22 public void run() { | |
23 MessagePack msgpack = new MessagePack(); | |
24 while (true) { | |
25 try { | |
26 CommandMessage cmdMsg = convert(connection.sendQueue.take()); | |
27 byte[] buf = msgpack.write(cmdMsg); | |
28 ByteBuffer buffer = ByteBuffer.allocateDirect(4 + buf.length); | |
29 buffer.putInt(buf.length); | |
30 buffer.put(buf); | |
16 | 31 buffer.flip(); |
13 | 32 connection.socket.getChannel().write(buffer); |
33 } catch (InterruptedException e) { | |
34 e.printStackTrace(); | |
35 } catch (IOException e) { | |
36 e.printStackTrace(); | |
37 } | |
38 | |
39 } | |
40 } | |
41 | |
42 } |