📄 resourcemng.java
字号:
package org.osu.ogsa.stream.util;/*import java.util.Random;import java.lang.Math;import java.lang.System;import org.apache.log4j.*; */ 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()); public boolean [][] stagePlacements; int nSources = 0, numStages= 0; String strDest; String strSources[]; Prim [] ga; Prim 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[] ) { try{ int i, j; if(args.length != 2) { log.fatal("Usage: ResourceMng <Net Throughput file> <config file>"); System.exit(-1); } ResourceMng res = new ResourceMng(); Prim ga_ok = res.init(args); String result = res.generatingConfigString(ga_ok); log.debug("finish WriteXML"); //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);*//* if(DefConstants.IFLAUNCHING) { log.debug("launching the stages"); Launcher l = new Launcher(); 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); } */ } catch(Exception e) { System.out.println(e); } } public Prim init(String [] args) //args[0]: netTopology, args[1]: configFile { int i, j; String [] stagesConfigFile = new String[1]; stagesConfigFile[0] = args[1]; try{ XMLConfigurator.init(stagesConfigFile); } catch(Exception e) { log.debug(e); } //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(); log.debug("numStages:"+numStages); //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(); //Get the destination strDest = (String)XMLConfigurator.getParameter("destination"); strSources = new String[nSources + 1]; stagePlacements = new boolean[50][10]; for(i = 0; i < 50; i ++) for(j = 0; j < 10 ; j++) stagePlacements[i][j] = false; ga_final = new Prim(); ga_final.init(args[0]); ga_final.init_dynamic_variables(0); ga = new Prim[nSources]; String strSpotName = new String("sources|spot"); DefaultMutableTreeNode [] trees = new DefaultMutableTreeNode[nSources]; for(int k= 0; k < nSources; k ++) { ga[k] = new Prim(); //Get the source strSources[k+1] = (String)XMLConfigurator.getParameter(strSpotName+(k+1)); //calculate the paths ga[k].init_dynamic_variables(strSources[k+1]); log.debug(strSources[k+1]); //Construct a corresponding tree with the paths ga[k].calculateKeyPaths(strSources[k+1]); if((trees[k] = ga[k].constructPath(strDest)) == null) { log.error("can't find destination node" + i); return null; } if(ga_final.merge(ga[k], trees[k]) == false) { log.error("something is wrong with the merge operation"); return null; } } return ga_final; } public String generatingConfigString(GraphAlgorithm ga_final) { int curStage, nLevel, tempJ, fakeNumStages, i; String strTemp; int nDepth[] = new int[nSources + 1]; DefaultMutableTreeNode [] trees = new DefaultMutableTreeNode[nSources]; DefaultMutableTreeNode treenode, treeRoot, treenode_final; //Initialize the DynamicEnv's numVisits for(i = 0; i < ga_final.n; i ++) ga_final.d[i].numVisits = 0; int [] numPlacementsInStage = new int[100]; for(i = 1; i < 100; i ++) numPlacementsInStage[i] = 0; Integer tempInt; fakeNumStages = -1; log.debug("come to here"); for(int out_loop = 1; out_loop <= nSources; out_loop ++) { log.debug(strSources[out_loop]); if((treenode = ga_final.getTreeNode(strSources[out_loop], 1, out_loop)) == null) { if((treenode = ga_final.getTreeNode(strSources[out_loop], -1, -1)) == null) { log.error("can't find node"); 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(((DynamicEnv)(treenode.getUserObject())).name); log.debug("mystage1:"+myStage1+" mystage2:"+myStage2); log.debug("myLevel:"+myLevel+" nDepth:"+nDepth[out_loop]); DynamicEnv dNode = (DynamicEnv)(treenode.getUserObject()); int curVisit = dNode.numVisits; log.debug("curVisit:"+curVisit); dNode.numVisits ++; dNode.visitArray[curVisit] = new Visit(treenode, curVisit, myStage1, myStage2); log.debug("comet to here"); //not necessary // | // | // + // The match function in fact change visitArray[] for(int lpIndex = 0; lpIndex <= curVisit - 1; lpIndex ++) if(dNode.visitArray[curVisit].Match(dNode.visitArray[lpIndex])) break; // ^ // | // | //not necessary/* if(myStage1 == myStage2 && myStage1 == 1) //the first stage { dNode.visitArray[curVisit].strPlacements[0] = ((URL)XMLConfigurator.getParameter("stages|stage1|placement"+out_loop )).toString(); }*/ 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; try{ xmlWriter = new WriteXml();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -