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);
}
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);
}
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();
}
}
}
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();
}
}
Aggregations