📄 simulatorengineforexp.java
字号:
package org.osu.ogsa.stream.services;/*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 org.osu.ogsa.stream.services.EnvironmentSimulatorImpl;import org.osu.ogsa.stream.StreamMonitor.StreamMonitorPortType;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 SimulatorEngineForExp implements Runnable //extends Thread{ //private static Category log = Category.getInstance(SimulatorEngine.class.getName()); static Log log = LogFactory.getLog(SimulatorEngineForExp.class.getName()); /* * orderStage[1] = 2 means that system has assigned the 2nd place for the stage 1 */ // private static int iPort = 58888;//, 57777, 56666, 55555; private int numEdges, numNodes; private int nEnvChangingTimes = DefConstants.BANDWIDTH_VARING_TIMES; private int sleeping_time = 1000; //1 millisecond private EnvironmentSimulatorImpl simulatorSrv; private static double [] nUtils = {0.3, 0.2, 0.45, 0.7}; private double BAD_UTIL = DefConstants.BAD_UTIL; SimulatorEngineForExp(EnvironmentSimulatorImpl simulatorSrv) { this.simulatorSrv = simulatorSrv; numEdges = simulatorSrv.ga_init.m; numNodes = simulatorSrv.ga_init.n; } public void run() { int i, j, nUtilIndex; Date forRand = new Date(); Random rand = new Random(forRand.getTime()); Random [] randArray = new Random[numEdges]; for(i = 0; i < numEdges; i++) randArray[i] = new Random(rand.nextLong()); Random rand_pickup_util = new Random(forRand.getTime() + 10); Random rand_generate_util = new Random(forRand.getTime() + 100); StreamMonitorPortType [] monitors; double probability = (double)nEnvChangingTimes/((double)DefConstants.LIFETIME*1000/(double)sleeping_time); // double probability = 0.01;//(double)nEnvChangingTimes/((double)DefConstants.LIFETIME*1000/(double)(sleeping_time*numEdges)); log.debug("the probability to change the network bandwidth is " + probability); //the following is for an experiment: //I just change one link's util at the half life time: int halfLifetime = DefConstants.LIFETIME/4; log.warn("the life time of this execution is" + halfLifetime); halfLifetime = halfLifetime*1000; int sleeptime = 0; int rndd_plus, rndd_minus, opp_i; rndd_plus = rndd_minus = opp_i= 0; try{ while(true) { Thread.sleep(sleeping_time); sleeptime += sleeping_time; //check if all monitor services signed in if(!simulatorSrv.isAllMonitorsSignedIn() || sleeptime < halfLifetime) continue; for(i = 0; i < numEdges ; i ++) { monitors = simulatorSrv.getMonitor(i); if(monitors == null) {// log.info("can't get the monitor's handle, edge: " + i); continue; } //check the opposite direction rndd_plus = simulatorSrv.ga_init.e[i].rndd_plus; rndd_minus = simulatorSrv.ga_init.e[i].rndd_minus; if(rndd_plus < 0 || rndd_minus < 0) { log.error("wrong information"); continue; } opp_i = simulatorSrv.ga_init.findEdge(simulatorSrv.ga_init.v[rndd_minus].name, simulatorSrv.ga_init.v[rndd_plus].name); if(opp_i >= 0) continue; //changing the bandwidth if(Utilities.Biased_Coin(rand_pickup_util, 0.70) != DefConstants.HEAD) continue; simulatorSrv.ga_init.setUtil(i, BAD_UTIL); log.warn("set new util at " + simulatorSrv.ga_init.v[rndd_plus].name); //Notify the monitor service to simulate the new bandwidth //Get the downstream's handle for(j = 0; monitors[j] != null; j ++) { String strDownstreamHandle = (String)simulatorSrv.hashStrDownstream.get((Object)monitors[j]); if(strDownstreamHandle == null) { log.error("can't get the downstream's handle:" + strDownstreamHandle); continue; } String downName = Utilities.getIPAddress(strDownstreamHandle); if(downName == null) { log.error(strDownstreamHandle + "'s ip address is null, that is impossible"); return; } if(!downName.equals(simulatorSrv.ga_init.v[rndd_minus].name)) continue; log.debug("change the bandwidth of the service of which downstream is " + strDownstreamHandle); log.debug("the new util:" + BAD_UTIL); monitors[j].netBandwidthNotification(simulatorSrv.ga_init.e[i].len, BAD_UTIL, strDownstreamHandle); if(DefConstants.IF_MIGRATE_IMMED) { monitors[j].setMigratable(true); monitors[j].tryMoveStreamSrv(1); monitors[j].setMigratable(false); } return; } } } } catch(Exception e) { log.error(e); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -