view src/fdl/test/TestMonitor.java @ 35:fe338d497c72 meta-comdebug-wokred

FederatedLinda was static singleton. It does not work on Thread based test.
author kono
date Sun, 24 Aug 2008 19:07:28 +0900
parents 64071f8e2e0d
children 2a366abc3f1f
line wrap: on
line source

package fdl.test;

import java.net.InetAddress;
import java.net.UnknownHostException;

import fdl.ComDebug_Client;
import fdl.FDLindaServ;
import fdl.FederatedLinda;

public class TestMonitor {

	public FederatedLinda fdl;
	public FDLindaServ fds;
	public String localhost;
	public static final int PORT = 10000;

	class Server implements Runnable {
		public void run() {
			String[] args = {"-p",Integer.toString(PORT)};
			System.out.println("Linda server start.");
			FDLindaServ.main(args);
		}
	}

	class Client implements Runnable {
		public void run() {
			String[] args = {};
			sleep(4000);
			System.err.println("Client start.");
			TestMetaLinda.main(args);
		}
		public synchronized void sleep(int time) {
			try {
				wait(time);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	class Monitor implements Runnable {
		public void run() {
			String[] args = {"-h",localhost,"-p",Integer.toString(PORT)};
			sleep(2000);
			System.err.println("Monitor start.");
			ComDebug_Client.main(args);
		}
		public synchronized void sleep(int time) {
			try {
				wait(time);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String[] arg) {
		TestMonitor me = new TestMonitor();
		me.test1();
	}
	
	public void test1() {
		try {
			localhost = InetAddress.getLocalHost().getHostName();
		} catch (UnknownHostException e) {
			return;
		}
		System.err.println("Monitor Test start.");
		Server s = new Server();
		Client c = new Client();
		Monitor m = new Monitor();
		Thread ts = new Thread(s); ts.start();
		Thread tm = new Thread(m); tm.start();
		Thread tc = new Thread(c); tc.start();
		try {
			ts.join(); tm.join(); 
			tc.join();
		} catch (InterruptedException e) {
		}
	}
	

}