comparison src/alice/daemon/OutboundTcpConnection.java @ 30:b5a21baf0b07

implements RingTopology
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Tue, 17 Jan 2012 16:13:03 +0900
parents 433e601a8e28
children f9334781344a
comparison
equal deleted inserted replaced
29:414fcce36e90 30:b5a21baf0b07
4 import java.nio.ByteBuffer; 4 import java.nio.ByteBuffer;
5 5
6 import org.msgpack.MessagePack; 6 import org.msgpack.MessagePack;
7 7
8 import alice.datasegment.Command; 8 import alice.datasegment.Command;
9 import alice.datasegment.CommandType;
9 10
10 public class OutboundTcpConnection extends Thread { 11 public class OutboundTcpConnection extends Thread {
11 12
12 public Connection connection; 13 public Connection connection;
13 14
21 22
22 public void run() { 23 public void run() {
23 MessagePack msgpack = new MessagePack(); 24 MessagePack msgpack = new MessagePack();
24 while (true) { 25 while (true) {
25 try { 26 try {
26 CommandMessage cmdMsg = convert(connection.sendQueue.take()); 27 Command cmd = connection.sendQueue.take();
28 if (cmd.type == CommandType.FINISH) {
29 System.exit(0);
30 return;
31 }
32 CommandMessage cmdMsg = convert(cmd);
27 byte[] buf = msgpack.write(cmdMsg); 33 byte[] buf = msgpack.write(cmdMsg);
28 ByteBuffer buffer = ByteBuffer.allocateDirect(4 + buf.length); 34 ByteBuffer buffer = ByteBuffer.allocateDirect(4 + buf.length);
29 buffer.putInt(buf.length); 35 buffer.putInt(buf.length);
30 buffer.put(buf); 36 buffer.put(buf);
31 buffer.flip(); 37 buffer.flip();
33 } catch (InterruptedException e) { 39 } catch (InterruptedException e) {
34 e.printStackTrace(); 40 e.printStackTrace();
35 } catch (IOException e) { 41 } catch (IOException e) {
36 e.printStackTrace(); 42 e.printStackTrace();
37 } 43 }
38
39 } 44 }
40 } 45 }
41 46
42 } 47 }