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

📄 worker.java

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

import java.io.File;
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 Worker extends Thread {

	WorkerNode wn;

	WorkerInfo wi;

	WorkerJoin joiner;

	WorkerDB wdb;

	private Integer synFlag;

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

	public void run() {
		wn = new WorkerNode();
		//log...
		if(Parameter.WorkerLogIsActive)
		{
			LogFile lf=new LogFile(Parameter.logFileName);
			try
			{
				lf.logWorker_login(InetAddress.getLocalHost().getHostAddress());
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}//log
		joiner = new WorkerJoin(Parameter.MonitorIpAddr, Parameter.MonitorPort,
				wn);
		if (!joiner.join()) {
			System.out.println("The joinning failed!");
			wn.quit();
			synchronized (synFlag) {
				synFlag.notifyAll();
			}
		} else {
			//log
			if(Parameter.WorkerLogIsActive)
			{
				LogFile lf=new LogFile(Parameter.logFileName);
				try
				{
					lf.logWorker_login_Succ(InetAddress.getLocalHost().getHostAddress(),wn.getWorkerInfo().getWorkerId());
				}
				catch(Exception e)
				{
					e.printStackTrace();
				}
			}//log
			synchronized (synFlag) {
				synFlag.notifyAll();
			}
			wn.start();
			try {
				while (!interrupted() && true) {

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

	public void quit() {
		if(Parameter.WorkerLogIsActive)
	       {
	       	LogFile lf=new LogFile(Parameter.logFileName);
	       	try{
	       		lf.logWorker_quit(InetAddress.getLocalHost().getHostAddress(),wn.getWorkerInfo().getWorkerIp());
	       	}
	       	catch(Exception e)
			{
	       		e.printStackTrace();
			}
	       }
		wn.quit();
		if(Parameter.workSpaceFlag==1)
		{
		//删除工作目录所有内容
		  FileHandle.delAllFolder(Parameter.workSpace+Parameter.separator+"workSpace");
		}
	}

	private void createFileFolder() {
		File f = new File(Parameter.programPath);
		if (!f.exists())
			f.mkdirs();
		f = new File(Parameter.dataPath);
		if (!f.exists())
			f.mkdirs();
		return;
	}

	public static void main(String args[]) {
		boolean quitSymbol = false;
		Integer synFlag = new Integer(0);
		Worker w = new Worker(synFlag);
		w.createFileFolder();
		w.start();
		if (quitSymbol) {
			w.wn.quit();
		}
	}

}

⌨️ 快捷键说明

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