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

📄 createconfigfiles.java

📁 本人历尽千辛万苦找的clustream中的jar包
💻 JAVA
字号:
package org.osu.ogsa.stream.info;	import org.osu.ogsa.stream.util.*;import org.osu.ogsa.stream.info.*;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 CreateConfigFiles{        //private static Category log = Category.getInstance(ResourceMng.class.getName());        static Log log = LogFactory.getLog(CreateConfigFiles.class.getName());	int numStages, nSources;	int case1 = 24;	int case2 = 12;	int case3 = 4;	String strDest, strSource;	GraphAlgorithm ga_final;	/*	 * 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[] ) 	{		CreateConfigFiles c = new CreateConfigFiles();		c.go(args);	}	public CreateConfigFiles()	{		numStages = nSources = 0;	}	public void go(String args[])	{		try{			int i, j;			if(args.length != 2)			{				log.fatal("Usage: CreateConfigFiles <Net Throughput file> <config file>");				System.exit(-1);			}			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();									ga_final = new Prim();			String strSpotName = new String("sources|spot1");			//Get the destination			strDest = (String)XMLConfigurator.getParameter("destination");			//We can random choose a source to calculate the path			//But here, we just choose the first data source			//			//Get the source			strSource = (String)XMLConfigurator.getParameter(strSpotName);			//calculate the paths			ga_final.init(args[0], strSource);			Date forRand = new Date();			Random rand = new Random(forRand.getTime());			Hashtable hash = new Hashtable();			int k;			int nCount[] = new int[nSources];			int times = 3;			i = 1;			String filename, strValue;			WriteCnfString xmlWriter;			while(i <= case1)			{				//get 3 from 4				for(j = 0; j < times ; j ++)					nCount[j] = CreateConfigFiles.randnum(rand, 4);				if(nCount[0] == nCount[1] || 			    	   nCount[0] == nCount[2] ||				   nCount[1] == nCount[2])					continue;				strValue = nCount[0] + "_" + nCount[1] + "_" + nCount[2];				if(hash.containsKey(strValue))					continue;				else				{					hash.put(strValue, strValue);					xmlWriter = new WriteCnfString();					xmlWriter.initXMLConfig(7, 13);					construct1(xmlWriter, nCount);					filename = "/home/chenlia/random-config2/1_2/" + strValue + ".xml";					xmlWriter.writeToFile(filename);					i ++;				}			}			i = 1;			times = 2;			Date forRand2 = new Date();			Random rand2 = new Random(forRand2.getTime());			Hashtable hash2 = new Hashtable();			while(i <= case2)			{				//get 2 from 4				for(j = 0; j < times ; j ++)					nCount[j] = CreateConfigFiles.randnum(rand2, 4);				if(nCount[0] == nCount[1])  					continue;				strValue = nCount[0] + "_" + nCount[1];				if(hash2.containsKey(strValue))					continue;				else				{					hash2.put(strValue, strValue);					xmlWriter = new WriteCnfString();					xmlWriter.initXMLConfig(7, 13);					construct2(xmlWriter, nCount);					filename = "/home/chenlia/random-config2/2_3/" + strValue + ".xml";					xmlWriter.writeToFile(filename);					i ++;				}			}			i = 1;			times = 1;			Date forRand3 = new Date();			Random rand3 = new Random(forRand3.getTime());			Hashtable hash3 = new Hashtable();			while(i <= case3)			{				//get 2 from 4				for(j = 0; j < times ; j ++)					nCount[j] = CreateConfigFiles.randnum(rand3, 4);				strValue = Integer.toString(nCount[0]);				if(hash3.containsKey(strValue))					continue;				else				{					hash3.put(strValue, strValue);					xmlWriter = new WriteCnfString();					xmlWriter.initXMLConfig(20, 24);					construct3(xmlWriter, nCount);					filename = "/home/chenlia/random-config2/3_2/" + strValue + ".xml";					xmlWriter.writeToFile(filename);					i ++;				}			}		}		catch(Exception e)		{		}	}	public void construct1(WriteCnfString xmlWriter, int nCount[] )	{		try{			int i, j;			int bandwidth;			//stage 1			for(i = 1; i <= nSources; i ++)			{				//connections				xmlWriter.addPara(1, "connection" + i, "String", "stage2:placement"+i);				//bandwidth				strSource = (String)XMLConfigurator.getParameter("sources|spot" + i);				bandwidth = ga_final.getEdgeLength(strSource, "osumed0" + nCount[i-1]);				if(bandwidth <= 0 )					log.error("there is something wrong with bandwidth");				xmlWriter.addPara(1, "bandwidth" + i, "String", Integer.toString(bandwidth));			}			int start = 10;			xmlWriter.addPara(2, "numPlacements", "Integer", "3");			//stage 2, 3 placements			for(i = 1; i <= nSources; i++)			{				//placements				xmlWriter.addObject(2, "placement" + i, "java.net.URL", "String", "http://osumed" + (start + i - 1) + ":8080/ogsa/services/Stream/StreamService");				//connections				xmlWriter.addPara(2, "connection" + i, "String", "stage3:placement1");				//bandwidth				bandwidth = ga_final.getEdgeLength("osumed0" + nCount[i-1], strDest);				if(bandwidth <= 0 )					log.error("there is something wrong with bandwidth");				xmlWriter.addPara(2, "bandwidth" + i, "String", Integer.toString(bandwidth));			}		}		catch(Exception e)		{		}	}	public void construct2(WriteCnfString xmlWriter, int nCount[] )	{		try{			int i, j;			int bandwidth = 0;			//stage 1			for(i = 1; i <= nSources; i ++)			{				//connections				strSource = (String)XMLConfigurator.getParameter("sources|spot" + i);				if(i == 1 || i == 3)				{					xmlWriter.addPara(1, "connection" + i, "String", "stage2:placement"+1);					bandwidth = ga_final.getEdgeLength(strSource, "osumed0" + nCount[0]);				}				if(i == 2)				{					xmlWriter.addPara(1, "connection" + i, "String", "stage2:placement"+2);					bandwidth = ga_final.getEdgeLength(strSource, "osumed0" + nCount[1]);				}				//bandwidth				if(bandwidth <= 0 )					log.error("there is something wrong with bandwidth");				xmlWriter.addPara(1, "bandwidth" + i, "String", Integer.toString(bandwidth));			}			int start = 10;			xmlWriter.addPara(2, "numPlacements", "Integer", "2");			//stage 2, 3 placements			for(i = 1; i <= 2; i++)			{				//placements				xmlWriter.addObject(2, "placement" + i, "java.net.URL", "String", "http://osumed" + (start + i - 1) + ":8080/ogsa/services/Stream/StreamService");				//connections				xmlWriter.addPara(2, "connection" + i, "String", "stage3:placement1");				//bandwidth				bandwidth = ga_final.getEdgeLength("osumed0" + nCount[i-1], strDest);				if(bandwidth <= 0 )					log.error("there is something wrong with bandwidth");				xmlWriter.addPara(2, "bandwidth" + i, "String", Integer.toString(bandwidth));			}		}		catch(Exception e)		{		}	}	public void construct3(WriteCnfString xmlWriter, int nCount[] )	{		try{			int i, j;			int bandwidth;			//stage 1			for(i = 1; i <= nSources; i ++)			{				//connections				xmlWriter.addPara(1, "connection" + i, "String", "stage2:placement1");				//bandwidth				strSource = (String)XMLConfigurator.getParameter("sources|spot" + i);				bandwidth = ga_final.getEdgeLength(strSource, "osumed0" + nCount[0]);				if(bandwidth <= 0 )					log.error("there is something wrong with bandwidth");				xmlWriter.addPara(1, "bandwidth" + i, "String", Integer.toString(bandwidth));			}			int start = 23;			xmlWriter.addPara(2, "numPlacements", "Integer", "1");			//stage 2, 3 placements			for(i = 1; i <= 1; i++)			{				//placements				xmlWriter.addObject(2, "placement" + i, "java.net.URL", "String", "http://osumed" + (start + i - 1) + ":8080/ogsa/services/Stream/StreamService");				//connections				xmlWriter.addPara(2, "connection" + i, "String", "stage3:placement1");				//bandwidth				bandwidth = ga_final.getEdgeLength("osumed0" + nCount[i-1], strDest);				if(bandwidth <= 0 )					log.error("there is something wrong with bandwidth");				xmlWriter.addPara(2, "bandwidth" + i, "String", Integer.toString(bandwidth));			}		}		catch(Exception e)		{		}	}        public static int Biased_Coin(Random rand, double probability)	{		return Biased_Coin(rand, probability, 100);	}	public static int Biased_Coin(Random rand, double probability, int factor)	{		int rand_int = 1 + (Math.abs(rand.nextInt()) % factor );		if(rand_int <= (int)(probability* (double)factor))			return 1;		else			return 0;	}	public static int randnum(Random rand, int factor)	{		int rand_int = 1 + (Math.abs(rand.nextInt()) % factor );		return rand_int;	}}

⌨️ 快捷键说明

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