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

📄 resourcemng.java

📁 本人历尽千辛万苦找的clustream中的jar包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.osu.ogsa.stream.info;/*import java.util.Random;import java.lang.Math;import java.lang.System;import org.apache.log4j.*; */	import org.osu.ogsa.stream.util.*;import org.osu.ogsa.stream.util.xmlconfig.*;import java.io.*;import java.nio.*;import java.nio.channels.*;import java.nio.channels.spi.*;import java.nio.charset.*;import java.net.*;import java.util.*;import java.lang.*;import org.apache.log4j.*;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.axis.client.Stub;import javax.swing.tree.DefaultMutableTreeNode;import org.apache.axis.utils.XMLUtils;import org.w3c.dom.Document;import org.w3c.dom.DOMException;import org.w3c.dom.Element;import org.w3c.dom.Node;public class ResourceMng{        //private static Category log = Category.getInstance(ResourceMng.class.getName());        static Log log = LogFactory.getLog(ResourceMng.class.getName());	private static int [] orderStage = new int[100];	/*	 * orderStage[1] = 2 means that system has assigned the 2nd place for the stage 1	 */  //	private static int iPort = 58888;//, 57777, 56666, 55555;	public static void main(String args[] ) 	{		try{			int i, j;			int nSources = 0, numStages= 0;			if(args.length != 2)			{				log.fatal("Usage: ResourceMng <Net Throughput file> <config file>");				System.exit(-1);			}			orderStage[1] = 1;			for(i = 1; i < 100; i ++)				orderStage[i] = 0;			String [] stagesConfigFile = new String[1];			stagesConfigFile[0] = args[1];			XMLConfigurator.init(stagesConfigFile);			//Get the number of stages			Integer nInt;			String strTemp;			if((nInt = (Integer)XMLConfigurator.getParameter("numStages")) == null)			{				log.fatal("null");				System.exit(-1);			}			else if(nInt.intValue() < 1)			{				log.fatal("the number of stage has to be larger than 0");				System.exit(-1);			}			else 				numStages = nInt.intValue();			//Get the number of sources			if((nInt = (Integer)XMLConfigurator.getParameter("sources|numSpots")) == null)			{				log.fatal("error with config information of sources");				System.exit(-1);			}			else if(nInt.intValue() < 1)			{				log.fatal("the number of sources has to be larger than 0");				System.exit(-1);			}			else 				nSources = nInt.intValue();									GraphAlgorithm [] ga = new Prim[nSources];			GraphAlgorithm ga_final = new Prim();			DefaultMutableTreeNode [] trees = new DefaultMutableTreeNode[nSources];			DefaultMutableTreeNode treenode;			DefaultMutableTreeNode treeRoot;			DefaultMutableTreeNode treenode_final;			String strSpotName = new String("sources|spot");			//Get the destination			String strDest = (String)XMLConfigurator.getParameter("destination");			String strSource;			//We can random choose a source to calculate the path			//But here, we just choose the first data source			//			for(int k= 0; k < nSources; k ++)			{			ga[k] = new Prim();			//Get the source			strSource = (String)XMLConfigurator.getParameter(strSpotName+(k+1));			//calculate the paths			ga[k].init(args[0], strSource);			if(k == 0)				ga_final.init(args[0], strSource);			log.debug(strSource);			//Construct a corresponding tree with the paths			if((trees[k] = ga[k].constructTree(strDest)) == null)			{				log.error("can't find destination node" + i);				return;			}			ga_final.merge(ga[k], strSource);			}			Vector v;			int curStage, nLevel, tempJ, fakeNumStages;			int nDepth[] = new int[nSources + 1];			Integer tempInt;			log.debug("come to here");			fakeNumStages = -1;			for(int out_loop = 1; out_loop <= nSources; out_loop ++)			{				strSource = (String)XMLConfigurator.getParameter(strSpotName+out_loop);				log.debug(strSource);				if((treenode = ga_final.getTreeNode(strSource)) == null)					continue;				//As regard with the stage 1st, we don't need to specify anything				curStage = 1;				nDepth[out_loop] = treenode.getLevel();				if(nDepth[out_loop] + 1> fakeNumStages)					fakeNumStages = nDepth[out_loop] + 1;				int myLevel, myDepth, myStage1, myStage2;				myLevel = myDepth = myStage1 = myStage2 = -1;				do{					myLevel = treenode.getLevel();					//Determine what stages in this tree node					myDepth = nDepth[out_loop] + 1 - myLevel;					myStage1 = myStage2 = -1;					if(nDepth[out_loop] + 1 >= numStages)					{					//there is only one stage in this tree node						if(nDepth[out_loop] + 1 == numStages)							myStage1 = nDepth[out_loop] + 1 - myLevel;						else						{							if(myDepth == nDepth[out_loop] + 1)							//This is the last stage								myStage1 = numStages;							else if( myDepth < numStages)								myStage1 = myDepth;							else								myStage1 = myDepth + 1;						}						myStage2 = myStage1;					}					else					{						if(myDepth == 2)						{							myStage1 = 2;							myStage2 = numStages - (nDepth[out_loop] + 1) + myStage1;						}						else if(myDepth == 1)							myStage1 = myStage2 = 1;						else							myStage1 = myStage2 = myDepth + (numStages - (nDepth[out_loop] + 1));					}					log.debug(((GANode)(treenode.getUserObject())).name);					log.debug("mystage1:"+myStage1+" mystage2:"+myStage2);					log.debug("myLevel:"+myLevel+" nDepth:"+nDepth[out_loop]);					GANode gaNode = (GANode)(treenode.getUserObject());					int curVisit = gaNode.numVisits;					log.debug("curVisit:"+curVisit);					gaNode.numVisits ++;					gaNode.visitArray[curVisit] = new Visit(treenode, curVisit, myStage1, myStage2);					for(int lpIndex = 0; lpIndex <= curVisit - 1; lpIndex ++)						if(gaNode.visitArray[curVisit].Match(gaNode.visitArray[lpIndex]))							break;					if(myStage1 == myStage2 && myStage1 == 1) //the first stage					{						String strName = "sources|spot" + out_loop;						gaNode.visitArray[curVisit].strPlacements[0] = (String)(XMLConfigurator.getParameter(strName));					}					treenode = (DefaultMutableTreeNode)treenode.getParent();				}while(treenode != null);			}			//Query the individual information center to get the IP address of available nodes			log.debug("come to WriteXML");			WriteXml xmlWriter = new WriteXml();			xmlWriter.initXMLConfig();			//Initialize the GANode's numVisits			for(i = 0; i < ga_final.n; i ++)				ga_final.v[i].numVisits = 0;			for(i = 1; i <= nSources; i ++)			{				strSource = (String)XMLConfigurator.getParameter(strSpotName+i);//				if((treenode = ga[i-1].getTreeNode(strSource)) == null)				if((treenode = ga_final.getTreeNode(strSource)) == null)					continue;/*				treenode.getLevel() + 1 > nStages)					bSpecialBranch= true;				else					bSpecialBranch= false; */				WriteToConfigFile(xmlWriter, treenode, treenode.getLevel()); //this is a recursive function			}			for(i = 2; i <= fakeNumStages; i ++)			{				if(i == numStages)					continue;				tempInt = new Integer(orderStage[i]);				xmlWriter.addPara(i, "numPlacements", "Integer", tempInt.toString());			}			tempInt = new Integer(fakeNumStages);			xmlWriter.addPara("fakeNumStages", "Integer", tempInt.toString());			//Debug			log.debug("finish WriteXML");//			XMLUtils.PrettyElementToStream(xmlWriter.getApp(), System.out);//			XMLUtils.ElementToStream(xmlWriter.getApp(), System.out);			//Launch the stages			//********************			//********************			//Write the configuration file to StreamClient			//Create a PipedInputStream and a PipedOutputStream			/*PipedOutputStream outstream = new PipedOutputStream();			PipedInputStream instream = new PipedInputStream(outstream);			XMLUtils.ElementToStream(xmlWriter.getApp(), outstream);

⌨️ 快捷键说明

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