view src/main/java/alice/test/topology/ring/FirstRingMessagePassing.java @ 345:8f71c3e6f11d

Change directory structure Maven standard
author sugi
date Wed, 16 Apr 2014 18:26:07 +0900
parents
children aefbe41fcf12
line wrap: on
line source

package alice.test.topology.ring;

import org.msgpack.type.ValueFactory;

import alice.codesegment.CodeSegment;
import alice.datasegment.CommandType;
import alice.datasegment.Receiver;

public class FirstRingMessagePassing extends CodeSegment {
	
	public Receiver ds1 = ids.create(CommandType.TAKE);
	private long startTime;
	private int count;
	private int nodeNum;
	
	public FirstRingMessagePassing(long startTime, int count, int nodeNum) {
		this.startTime = startTime;
		this.count = count;
		this.nodeNum = nodeNum;
	}
	
	public FirstRingMessagePassing(int count, int nodeNum) { // at first
		this.startTime = System.nanoTime();
		this.count = count;
		this.nodeNum = nodeNum;
	}
	
	@Override
	public void run() {
		ods.put("right", "c", ds1.getVal()); // copy whole DataSegment to the right
		if (ds1.index > count) {        // after count time update of ds1
			ods.put("right", "finish", ValueFactory.createNilValue());
			long endTime = System.nanoTime();
			long time = endTime - startTime;
			System.out.println(nodeNum + " " + time / count / 1000000.0);
			return;
		}
		
		FirstRingMessagePassing cs = new FirstRingMessagePassing(startTime, count, nodeNum);
		cs.ds1.setKey("c");
	}

}