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

📄 resourcemng.java

📁 本人历尽千辛万苦找的clustream中的jar包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			xmlWriter.initXMLConfig_for_static();		}		catch(Exception e)		{			log.error(e);			return null;		}		//Initialize the DynamicEnv's numVisits		for(i = 0; i < ga_final.n; i ++)			ga_final.d[i].numVisits = 0;		for(i = 1; i <= nSources; i ++)		{			if((treenode = ga_final.getTreeNode(strSources[i], 1, i)) == null)			{				if((treenode =  ga_final.getTreeNode(strSources[i], -1, -1)) == null)				{					log.error("can't find node");					continue;				}			}/*			treenode.getLevel() + 1 > nStages)				bSpecialBranch= true;			else				bSpecialBranch= false; */			WriteToConfigFile(xmlWriter, treenode, treenode.getLevel(), numPlacementsInStage); //this is a recursive function		}		for(i = 2; i <= fakeNumStages; i ++)		{			if(i == numStages)				continue;			tempInt = new Integer(numPlacementsInStage[i]);			xmlWriter.addPara(i, "numPlacements", "Integer", tempInt.toString());		}		tempInt = new Integer(fakeNumStages);		xmlWriter.addPara("fakeNumStages", "Integer", tempInt.toString());		//Write the special_class information		String specialclass_name, specialclass_location;		specialclass_name = (String)XMLConfigurator.getParameter("special_class|class_name");		specialclass_location = ((URL)XMLConfigurator.getParameter("special_class|location")).toString();		xmlWriter.addSpecialClass(specialclass_name, specialclass_location);		//Write about Envirnoment service		String envHandle = ((URL)XMLConfigurator.getParameter("EnvironmentSimulator")).toString();		xmlWriter.addObject("EnvironmentSimulator", "java.net.URL", "String", envHandle);		//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);		outstream.connect(instream);*/		log.debug("generating a configuration string ");		String strCnfResults;/*			String strCnfResults = XMLUtils.ElementToString(xmlWriter.getApp());                        byte [] tempBytes = strCnfResults.getBytes();			ByteArrayInputStream byteIn = new ByteArrayInputStream(tempBytes);*//*			StringWriter writer = new StringWriter();			XMLUtils.PrettyElementToWriter(xmlWriter.getApp(), writer);			strCnfResults = writer.toString();*/		strCnfResults = XMLUtils.ElementToString(xmlWriter.getApp());		log.debug(strCnfResults);		//polish the strCnfResults		int index;		String result = new String("");		String result1;						while(true)		{			index = strCnfResults.indexOf('>');			if(index < 0)				break;			result1 = strCnfResults.substring(0, index + 1);			if(result1.lastIndexOf("</") < 0)				result += result1;			else				result += result1 + "\n";			if(index + 1 == strCnfResults.length())				break;			strCnfResults = strCnfResults.substring(index + 1, strCnfResults.length());		}		log.debug(result);		return result;		/*log.debug(result);	        byte [] tempBytes = result.getBytes();		for(int f = 0; f < tempBytes.length; f ++)		System.out.println((char)tempBytes[f]);       	        ByteArrayInputStream byteIn = new ByteArrayInputStream(tempBytes);		l.start(byteIn);*/	}	private String WriteToConfigFile(WriteXml xmlWriter, DefaultMutableTreeNode treenode, int nDepth, int [] numPlacementsInStage)	{		if(treenode == null)			return null;		log.debug(((DynamicEnv)(treenode.getUserObject())).name);		DynamicEnv dNode = (DynamicEnv)(treenode.getUserObject());		int []newPlacement;		int curVisit = dNode.numVisits;		log.debug("curVisit:"+curVisit);		dNode.numVisits ++;		Visit vis = dNode.visitArray[curVisit];		Integer tempInt;		boolean bSpecialStage = false;		tempInt = (Integer)XMLConfigurator.getParameter("numStages");		int numStages = tempInt.intValue();		int nstage, index ;		newPlacement = new int[vis.myStage2 - vis.myStage1 + 1];		for(nstage = vis.myStage1; nstage <= vis.myStage2; nstage ++)		{			index = nstage - vis.myStage1;			log.debug("my visit no. is" + vis.visitnodeIndex[index]);			log.debug("actual visit no. is" + vis.no);			log.debug("myStage1:" + vis.myStage1 + "["+nstage+"] myStage2:" + vis.myStage2); 			if(nstage == 1)			{ //Placement info. has been done, go to the next part of this function				numPlacementsInStage[nstage] ++;				newPlacement[index] = assignPlacement(dNode, treenode, 1);				continue;			}			else if(nstage == numStages)			{//Everything is known and done, return;				numPlacementsInStage[nstage] = 1;				newPlacement[index] = 1;//				vis.strPlacements[index] = "stage"+nstage+":placement1";				log.debug("the last stage, go on to the next step");				break;				//log.debug("returning: stage"+ nstage + ":placement1");				//return "stage"+nstage+":placement1";			}			//log.debug("my visit no. is" + vis.visitnodeIndex[index]);			//log.debug("actual visit no. is" + vis.no);			if(vis.visitnodeIndex[index] < vis.no)			{//the placement and connection has been done by previous visit			 //return the previous connection information.			 	int visitIndex = vis.visitnodeIndex[index];				DefaultMutableTreeNode tempNode = null;				tempNode = (DefaultMutableTreeNode)treenode.getParent();				while(tempNode != null)				{					 ((DynamicEnv)(tempNode.getUserObject())).numVisits++;					 tempNode = (DefaultMutableTreeNode)tempNode.getParent();				}				//get the placement information from dNode				InstanceIndex ii = dNode.getInstanceIndex(treenode, nstage);				if(ii == null)				{					log.error("some thing error with the structure");					return null;				}				log.debug("returning: stage"+ nstage);				log.debug("returning: should be " + nstage + " now: " + ii.nstage+ ":placement"+ii.nplacement);				return "stage"+ii.nstage+":placement"+ii.nplacement; //return gaNode.visitArray[visitIndex].strConnections[index];			}			vis.strPlacements[index] = dNode.name;			newPlacement[index] = assignPlacement(dNode, treenode, nstage);			numPlacementsInStage[nstage] ++;			log.debug(vis.strPlacements[index]);			log.debug("the assigned placement is:" + newPlacement[index]);						//write to xml configuration file			xmlWriter.addObject(nstage, "placement"+newPlacement[index],					   "java.net.URL",					   "String",					   "http://"+  vis.strPlacements[index] +":8080/ogsa/services/Stream/StreamService"					   );			//Add a "index_service" to the configuration file/*			xmlWriter.addPara(nstage, "index_service"+stagePlacements[nstage], 					   "String",					   "http://"+  vis.strPlacements[index] +":8080/ogsa/services/Stream/StreamService"					   ); */		}		String connection_name, myConnectionValue, class_name, location;		int nStoreFirstStagePlacement = 0, nextStage = 0;		//What is the first stage in this branch		//Get the connection information.		for(nstage = vis.myStage1; nstage <= vis.myStage2; nstage ++)		{			log.debug("myStage1:" + vis.myStage1 + "["+nstage+"] myStage2:" + vis.myStage2); 			index = nstage - vis.myStage1;			connection_name = "connection" + newPlacement[index];			//get the placement information of the next stage			if(nstage == vis.myStage2) //The last stage in this node			{				String myName = ((DynamicEnv)(treenode.getUserObject())).name;				DefaultMutableTreeNode parent = (DefaultMutableTreeNode)treenode.getParent();				if(parent == null) //the last stage					break;				String myParentName = ((DynamicEnv)(parent.getUserObject())).name;				if(ga_final.findEdge(myName, myParentName) < 0)				{					log.error("can't find " + myName + " and " + myParentName + " 's edge");					continue;				}				int new_bandwidth = ga_final.getEdgeLength(myName, myParentName);				double new_util = ga_final.getEdgeUtil(myName, myParentName);				//Add a "bandwidth" to the configuration file				xmlWriter.addPara(nstage, "bandwidth"+newPlacement[index], "String", Integer.toString(new_bandwidth)+":" + Double.toString(new_util));				//We need to recurviely call WriteToConfigFile				//and pass the parent node to the function				myConnectionValue = WriteToConfigFile(xmlWriter, parent, nDepth, numPlacementsInStage);				if(myConnectionValue == null)				{					vis.strConnections[index] = myConnectionValue;					return "stage" + nstage + ":placement1";				}			}			else//Get the the information from the node itself			{				myConnectionValue = "stage"+(nstage+1)+":placement"+newPlacement[index+1];				//Add a "bandwidth" to the configuration file				log.debug("adding bandwidth"+newPlacement[index]+ ":-1 to stage" + nstage);				xmlWriter.addPara(nstage, "bandwidth"+newPlacement[index], "String", "-1");			}			//Get the classname and location			vis.strConnections[index] = myConnectionValue;			if(nstage > numStages)			{				String specialclass_name, specialclass_location;				specialclass_name = (String)XMLConfigurator.getParameter("special_class|class_name");				specialclass_location = ((URL)XMLConfigurator.getParameter("special_class|location")).toString();				xmlWriter.addClass(nstage, specialclass_name, specialclass_location);			}			xmlWriter.addPara(nstage, connection_name, "String", myConnectionValue);			log.debug(connection_name+ " "+myConnectionValue);		}		((DynamicEnv)(treenode.getUserObject())).bVisited = true;		return "stage"+vis.myStage1+":placement"+newPlacement[0];	}	private int assignPlacement(DynamicEnv dNode, DefaultMutableTreeNode treenode, int nstage)	{		InstanceIndex ii = dNode.getInstanceIndex(treenode, nstage);		if(ii == null || ii.nplacement <= 0)		{			int j;			//stagePlacements[1][j] == true: occupied			//stagePlacements[1][j] == false: unoccupied			for(j = 1; j < 10 && stagePlacements[nstage][j]; j ++)				;			if(j == 10)			{					log.error("the buffer doesn't have enough space");				return -1;			}			stagePlacements[nstage][j] = true;			dNode.put(treenode, nstage, j);			log.debug("assiged :" + j);			return j;		}		else		{			log.debug("assiged :" + ii.nplacement);			return ii.nplacement;		}	}}

⌨️ 快捷键说明

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