package org.arefgard.icerya.flow.node;

import java.util.List;

public class SyncNode extends Node {
	private List<String> flows = new java.util.ArrayList<String>();
	private String nextTo;
	public void addFlow(String flow) {
		this.flows.add(flow);
	}
	
	public String getFlow(int index) {
		return this.flows.get(index);
	}

	public String getNextTo() {
		return nextTo;
	}

	public void setNextTo(String nextTo) {
		this.nextTo = nextTo;
	}
	
	public String execute() {
		// create thread
		ThreadGroup group = new ThreadGroup("Usecase Flow Thread Group:" + this.getName());
		Thread[] threads = new Thread[flows.size()];
		for(int i = 0, n = flows.size();i < n; i++) {
			threads[i] = new Thread(group, this.getParent().getParent().getFlow(flows.get(i)));
			threads[i].start();
		}
		
		// すべての処理が終了するまで待つ
		while(true) {
			if(group.activeCount() == 0) {
				break;
			}
		}
		return this.nextTo;
	}
}

