# HG changeset patch # User sugi # Date 1370937202 -32400 # Node ID 2a8bcf09bd06ca6b579d97469cc70ca5dea11dc0 # Parent 913ee9dfec4ff6d6d4dbf9c89b72d7756565b766 Refactor diff -r 913ee9dfec4f -r 2a8bcf09bd06 src/alice/daemon/Connection.java --- a/src/alice/daemon/Connection.java Wed May 29 15:39:55 2013 +0900 +++ b/src/alice/daemon/Connection.java Tue Jun 11 16:53:22 2013 +0900 @@ -1,8 +1,11 @@ package alice.daemon; +import java.io.IOException; import java.net.Socket; +import java.nio.ByteBuffer; import java.util.concurrent.LinkedBlockingQueue; +import alice.codesegment.SingletonMessage; import alice.datasegment.Command; public class Connection { @@ -29,4 +32,17 @@ + ":" + socket.getPort(); } + public synchronized void write(Command cmd) { + CommandMessage cmdMsg = cmd.convert(); + ByteBuffer buffer; + try { + buffer = ByteBuffer.wrap(SingletonMessage.getInstance().write(cmdMsg)); + while (buffer.hasRemaining()) { + socket.getChannel().write(buffer); + } + } catch (IOException e) { + + } + } + } diff -r 913ee9dfec4f -r 2a8bcf09bd06 src/alice/daemon/OutboundTcpConnection.java --- a/src/alice/daemon/OutboundTcpConnection.java Wed May 29 15:39:55 2013 +0900 +++ b/src/alice/daemon/OutboundTcpConnection.java Tue Jun 11 16:53:22 2013 +0900 @@ -1,9 +1,6 @@ package alice.daemon; import java.io.IOException; -import java.nio.ByteBuffer; - -import alice.codesegment.SingletonMessage; import alice.datasegment.Command; public class OutboundTcpConnection extends Thread { @@ -14,16 +11,7 @@ this.connection = connection; } - public CommandMessage convert(Command cmd) { - if (cmd.val==null&&cmd.obj!=null){ - try { - cmd.val = SingletonMessage.getInstance().unconvert(cmd.obj); - } catch (IOException e) { - e.printStackTrace(); - } - } - return new CommandMessage(cmd.type.id, cmd.index, cmd.seq, cmd.key, cmd.val); - } + /** * pipeline thread for transmission @@ -42,11 +30,7 @@ default: break; } - CommandMessage cmdMsg = convert(cmd); - ByteBuffer buffer = ByteBuffer.wrap(SingletonMessage.getInstance().write(cmdMsg)); - while (buffer.hasRemaining()) { - connection.socket.getChannel().write(buffer); - } + connection.write(cmd); } catch (InterruptedException e) { e.printStackTrace(); } catch (IOException e) {