Mercurial > hg > Database > Alice
diff src/alice/datasegment/RemoteDataSegmentManager.java @ 23:54bf607118ae
change method to create RemoteDSM
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 17 Jan 2012 01:10:29 +0900 |
parents | 0bb03861b5cd |
children | 50c75cb3de60 |
line wrap: on
line diff
--- a/src/alice/datasegment/RemoteDataSegmentManager.java Tue Jan 17 00:40:27 2012 +0900 +++ b/src/alice/datasegment/RemoteDataSegmentManager.java Tue Jan 17 01:10:29 2012 +0900 @@ -1,5 +1,9 @@ package alice.datasegment; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.channels.SocketChannel; + import org.msgpack.type.Value; import alice.codesegment.CodeSegment; @@ -11,6 +15,8 @@ Connection connection; + // TODO: delete this constructor later + @Deprecated public RemoteDataSegmentManager(Connection connection) { this.connection = connection; new IncomingTcpConnection(connection, this).start(); @@ -20,6 +26,34 @@ + ":" + connection.socket.getPort()).start(); } + public RemoteDataSegmentManager(String key, final String hostName, final int port) { + connection = new Connection(); + final RemoteDataSegmentManager manager = this; + new Thread(replyThread, "RemoteDataSegmentManager-" + + connection.socket.getInetAddress().getHostName() + + ":" + connection.socket.getPort()).start(); + new Thread("Connect-" + key) { + public void run() { + boolean connect = true; + do { + try { + SocketChannel sc = SocketChannel.open(new InetSocketAddress(hostName, port)); + connection.socket = sc.socket(); + connect = false; + } catch (IOException e) { + try { + Thread.sleep(500); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + } + } while (connect); + new IncomingTcpConnection(connection, manager).start(); + new OutboundTcpConnection(connection).start(); + } + }.start(); + } + @Override public void put(String key, Value val) { connection.sendCommand(new Command(CommandType.PUT, null, key, val, 0, 0, null, null));