Search in sources :

Example 1 with TCPChannel

use of edu.iu.dsc.tws.common.net.tcp.TCPChannel in project twister2 by DSC-SPIDAL.

the class TWSTCPChannel method createChannel.

/**
 * Start the TCP servers here
 *
 * @param cfg the configuration
 * @param workerId worker id
 */
private static TCPChannel createChannel(Config cfg, String workerIP, int workerPort, int workerId) {
    NetworkInfo netInfo = new NetworkInfo(workerId);
    netInfo.addProperty(TCPContext.NETWORK_HOSTNAME, workerIP);
    netInfo.addProperty(TCPContext.NETWORK_PORT, workerPort);
    return new TCPChannel(cfg, netInfo);
}
Also used : NetworkInfo(edu.iu.dsc.tws.common.net.NetworkInfo) TCPChannel(edu.iu.dsc.tws.common.net.tcp.TCPChannel)

Example 2 with TCPChannel

use of edu.iu.dsc.tws.common.net.tcp.TCPChannel in project twister2 by DSC-SPIDAL.

the class TCPChannelExample method setUp.

public void setUp() throws Exception {
    cfg = Config.newBuilder().build();
    NetworkInfo selfInfo = new NetworkInfo(workerID);
    selfInfo.addProperty(TCPContext.NETWORK_PORT, 10010 + workerID);
    selfInfo.addProperty(TCPContext.NETWORK_HOSTNAME, "localhost");
    channel = new TCPChannel(cfg, selfInfo);
    channel.startListening();
    // network info of all workers except the self
    networkInfos = new ArrayList<>();
    for (int i = 0; i < numberOfWorkers; i++) {
        NetworkInfo info = new NetworkInfo(i);
        info.addProperty(TCPContext.NETWORK_PORT, 10010 + i);
        info.addProperty(TCPContext.NETWORK_HOSTNAME, "localhost");
        networkInfos.add(info);
    }
    // wait for all workers to start their tcp servers
    Thread.sleep(3000);
    // connect to all workers
    channel.startConnections(networkInfos);
    channel.waitForConnections(10000);
    LOG.info("all connected...");
    // wait for all to all connections to be established
    Thread.sleep(5000);
    if (workerID == 0) {
        throw new RuntimeException("killing intentionally");
    }
    // wait for worker 0 to die
    Thread.sleep(5000);
}
Also used : NetworkInfo(edu.iu.dsc.tws.common.net.NetworkInfo) TCPChannel(edu.iu.dsc.tws.common.net.tcp.TCPChannel)

Example 3 with TCPChannel

use of edu.iu.dsc.tws.common.net.tcp.TCPChannel in project twister2 by DSC-SPIDAL.

the class TwoChannelTest method sendMessagesTest.

@Test
public void sendMessagesTest() {
    List<TCPMessage> sends = new ArrayList<>();
    List<TCPMessage> recvs = new ArrayList<>();
    for (int i = 0; i < NO_OF_CHANNELS; i++) {
        TCPChannel channel = channels.get(i);
        for (int j = 0; j < NO_OF_CHANNELS; j++) {
            if (j != i) {
                ByteBuffer buffer = buffers.get(j);
                buffer.clear();
                TCPMessage message = channel.iRecv(buffer, 10, j, 1);
                recvs.add(message);
            }
        }
    }
    for (int i = 0; i < NO_OF_CHANNELS; i++) {
        TCPChannel channel = channels.get(i);
        for (int j = 0; j < NO_OF_CHANNELS; j++) {
            if (j != i) {
                ByteBuffer buffer = buffers.get(j);
                buffer.clear();
                buffer.put(new byte[10]);
                TCPMessage message = channel.iSend(buffer, 10, j, 1);
                sends.add(message);
            }
        }
    }
    List<Integer> completedSends = new ArrayList<>();
    List<Integer> completedRcvs = new ArrayList<>();
    while (completedRcvs.size() != NO_OF_CHANNELS || completedSends.size() != NO_OF_CHANNELS) {
        for (int i = 0; i < NO_OF_CHANNELS; i++) {
            TCPMessage sendMsg = sends.get(i);
            TCPMessage rcvMsg = recvs.get(i);
            if (sendMsg.isComplete()) {
                if (!completedSends.contains(i)) {
                    completedSends.add(i);
                }
            }
            if (rcvMsg.isComplete()) {
                if (!completedRcvs.contains(i)) {
                    completedRcvs.add(i);
                }
            }
            TCPChannel ch = channels.get(i);
            ch.progress();
        }
    }
}
Also used : TCPMessage(edu.iu.dsc.tws.common.net.tcp.TCPMessage) TCPChannel(edu.iu.dsc.tws.common.net.tcp.TCPChannel) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with TCPChannel

use of edu.iu.dsc.tws.common.net.tcp.TCPChannel in project twister2 by DSC-SPIDAL.

the class TwoChannelTest method setUp.

@Before
public void setUp() throws Exception {
    cfg = Config.newBuilder().build();
    channels = new ArrayList<>();
    networkInfos = new ArrayList<>();
    for (int i = 0; i < NO_OF_CHANNELS; i++) {
        NetworkInfo info = new NetworkInfo(i);
        info.addProperty(TCPContext.NETWORK_PORT, 10025 + i);
        info.addProperty(TCPContext.NETWORK_HOSTNAME, "localhost");
        TCPChannel channel = new TCPChannel(cfg, info);
        channel.startListening();
        channels.add(channel);
        networkInfos.add(info);
    }
    // we use only one buffer
    for (int i = 0; i < NO_OF_CHANNELS; i++) {
        ByteBuffer b = ByteBuffer.allocate(1024);
        buffers.add(b);
    }
    for (int i = 0; i < NO_OF_CHANNELS; i++) {
        final int j = i;
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                TCPChannel channel = channels.get(j);
                channel.startConnections(networkInfos);
                channel.waitForConnections(10000);
            }
        });
        t.start();
        threads.add(t);
    }
    // lets wait for the connections to be made
    for (int i = 0; i < NO_OF_CHANNELS; i++) {
        Thread t = threads.get(i);
        t.join();
    }
}
Also used : NetworkInfo(edu.iu.dsc.tws.common.net.NetworkInfo) TCPChannel(edu.iu.dsc.tws.common.net.tcp.TCPChannel) ByteBuffer(java.nio.ByteBuffer) Before(org.junit.Before)

Aggregations

TCPChannel (edu.iu.dsc.tws.common.net.tcp.TCPChannel)4 NetworkInfo (edu.iu.dsc.tws.common.net.NetworkInfo)3 ByteBuffer (java.nio.ByteBuffer)2 TCPMessage (edu.iu.dsc.tws.common.net.tcp.TCPMessage)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Test (org.junit.Test)1