view src/main/java/alice/datasegment/CompressedRemoteDataSegmentManager.java @ 525:30a74eee59c7 dispose

working TestRemoteAlice
author Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
date Thu, 16 Apr 2015 20:33:53 +0900
parents
children
line wrap: on
line source

package alice.datasegment;

import alice.daemon.Connection;
import alice.daemon.IncomingTcpConnection;
import alice.daemon.OutboundTcpConnection;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;

/**
 * Created by e125769 on 4/11/15.
 */
public class CompressedRemoteDataSegmentManager extends RemoteDataSegmentManager {

    public CompressedRemoteDataSegmentManager(){}

    public CompressedRemoteDataSegmentManager(final String connectionKey, final String reverseKey, final String hostName, final int port) {
        logger = Logger.getLogger(connectionKey);
        connection = new Connection();
        connection.name = connectionKey;
        final RemoteDataSegmentManager manager = this;
        //new Thread(replyThread, "RemoteDataSegmentManager-" + connectionKey).start();
        new Thread("Connect-" + connectionKey) {
            public void run() {
                boolean connect = true;
                do {
                    try {
                        SocketChannel sc = SocketChannel.open(new InetSocketAddress(hostName, port));
                        connection.socket = sc.socket();
                        connection.socket.setTcpNoDelay(true);
                        connect = false;
                        logger.info("Connect to " + connection.getInfoString());
                    } catch (IOException e) {
                        try {
                            Thread.sleep(50);
                        } catch (InterruptedException e1) {
                            e1.printStackTrace();
                        }
                    }
                } while (connect);
                IncomingTcpConnection in = new IncomingTcpConnection(connection, manager, reverseKey);
                in.setName(reverseKey+"-IncomingTcp");
                in.setPriority(MAX_PRIORITY);
                in.start();
                OutboundTcpConnection out = new OutboundTcpConnection(connection);
                out.setName(connectionKey+"-OutboundTcp");
                out.setPriority(MAX_PRIORITY);
                out.start();
            }
        }.start();
    }
}