view src/alice/test/topology/ring/FirstRingMessagePassing.java @ 55:0c2ad7c70f4e

change ring calculate time unit, milli to nano
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Tue, 07 Feb 2012 19:34:50 +0900
parents f60c0246c8ce
children a76e603c43a0
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 counter = ids.create(CommandType.TAKE);
	private long startTime;
	private int count; 
	
	public FirstRingMessagePassing(long startTime, int count) {
		this.startTime = startTime;
		this.count = count;
	}
	
	@Override
	public void run() {
		int counter = this.counter.asInteger();
		++counter;
		ods.put("right", "counter", counter);
		if (counter >= count) {
			ods.put("right", "finish", ValueFactory.createNilValue());
			long endTime = System.nanoTime();
			long time = endTime - startTime;
			System.out.println(count + ", " + time);
			return;	
		}
		
		FirstRingMessagePassing cs = new FirstRingMessagePassing(startTime, count);
		cs.counter.setKey("local", "counter");
	}

}