⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dispatcher.java

📁 分布式计算平台P2HP-1的源代码;P2HP-1是基于P2P的高性能计算平台
💻 JAVA
字号:
package cn.edu.hust.cgcl.biogrid.dispatcher;

import java.net.InetAddress;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class Dispatcher extends Thread {

	DispatcherNode dn;

	DispatcherInfo di;

	DispatcherJoin joiner;

	DispatcherDB ddb;

	private Integer synFlag;

	public Dispatcher(Integer synFlag) {
		this.synFlag = synFlag;
	}

	public Dispatcher(String line) {
		dn = new DispatcherNode("");
		joiner = new DispatcherJoin(Parameter.MonitorIpAddr,
				Parameter.MonitorPort, dn);
		if (!joiner.join()) {
			System.out.println("The joinning failed!");
			dn.quit();
		} else
			dn.start();
	}

	public void run() {
		dn = new DispatcherNode();
		//log
		if(Parameter.dispatcherLogIsActive)
	       {
	       	LogFile lf=new LogFile(Parameter.logFileName);
	       	try{
	       		lf.logDispatcher_login(InetAddress.getLocalHost().getHostAddress());
	       	}
	       	catch(Exception e)
			{
	       		e.printStackTrace();
			}
	       }//log
		joiner = new DispatcherJoin(Parameter.MonitorIpAddr,
				Parameter.MonitorPort, dn);
		if (!joiner.join()) {
			System.out.println("The joinning failed!");
			dn.quit();
			synchronized (synFlag) {
				synFlag.notifyAll();
			}
		} else {
			//log
			if(Parameter.dispatcherLogIsActive)
            {
            	LogFile lf=new LogFile(Parameter.logFileName);
            	try{
            		lf.logDispatcher_login_Succ(InetAddress.getLocalHost().getHostAddress(),dn.getDispatcherInfo().getDispatcherId(),dn.getDispatcherInfo().getFirstMonitorId());
            	}
            	catch(Exception e)
     		{
            		e.printStackTrace();
     		}
            }//log
			synchronized (synFlag) {
				synFlag.notifyAll();
			}
			dn.start();
			try {
				while (!interrupted() && true) {

					Thread.sleep(1000 * 60);
				} // while
			} catch (InterruptedException e) {
				System.out.println("Dispatcher start to quiting...");
				quit();//stop the thread. include notify dispatcher and worker to deal with.
				System.out.println("Dispatcher's quitting finished!");
				return;
			}
			System.out.println("Dispatcher start to quiting...");
			quit();
			System.out.println("Dispatcher's quitting finished!");
		}
		return;
	}

	public void quit() {
		if(Parameter.dispatcherLogIsActive)
	       {
	       	LogFile lf=new LogFile(Parameter.logFileName);
	       	try{
	       		lf.logDispatcher_quit(InetAddress.getLocalHost().getHostAddress(),dn.getDispatcherInfo().getDispatcherId());
	       	}
	       	catch(Exception e)
			{
	       		e.printStackTrace();
			}
	       }
		dn.quit();
		
	}

	public static void main(String args[]) {
		boolean quitSymbol = false;
		Dispatcher d = new Dispatcher("");
		//d.start();
		try {
			if (quitSymbol) {
				d.dn.quit();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -