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

📄 fairnetworkstub.java

📁 High performance DB query
💻 JAVA
字号:
/* * @(#)$Id: FairNetworkStub.java,v 1.4 2004/07/02 23:59:22 huebsch Exp $ * * Copyright (c) 2001-2004 Regents of the University of California. * All rights reserved. * * This file is distributed under the terms in the attached BERKELEY-LICENSE * file. If you do not find these files, copies can be found by writing to: * Computer Science Division, Database Group, Universite of California, * 617 Soda Hall #1776, Berkeley, CA 94720-1776. Attention: Berkeley License * * Copyright (c) 2003-2004 Intel Corporation. All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE file. * If you do not find these files, copies can be found by writing to: * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, * Berkeley, CA, 94704.  Attention:  Intel License Inquiry. */package simulator.schedulers.network.node.fair;import java.net.InetAddress;import java.util.HashMap;import java.util.Iterator;import simulator.schedulers.network.NetworkEvent;import simulator.schedulers.network.NetworkScheduler;import simulator.schedulers.network.node.naive.NaiveNetworkStub;/** * Class FairNetworkStub * */public class FairNetworkStub extends NaiveNetworkStub {    protected HashMap[] flows;    protected int[] maxFlows;    protected int[] curFlows;    /**     * Constructor FairNetworkStub     *     * @param scheduler     * @param inBandwidth     * @param outBandwidth     * @param shareBandwidth     * @param myIP     */    public FairNetworkStub(NetworkScheduler scheduler, double inBandwidth,                           double outBandwidth, boolean shareBandwidth,                           InetAddress myIP) {        super(scheduler, inBandwidth, outBandwidth, shareBandwidth, myIP);        flows = new HashMap[2];        maxFlows = new int[2];        curFlows = new int[2];        for (int i = 0; i < (shareBandwidth                             ? 1                             : 2); i++) {            flows[i] = new HashMap();            maxFlows[i] = 0;            curFlows[i] = 0;        }    }    /**     * Method getNewFlowBandwidth     *     * @param direction     * @return     */    protected double getNewFlowBandwidth(int direction) {        int theDirection = shareBandwidth                           ? OUTGOING                           : direction;        // Calculate new fair allocation if there was one more flow        double newBandwidth = bandwidth[theDirection]                              / (curFlows[theDirection] + 1);        return newBandwidth;    }    /**     * Method adjustFlows     *     * @param direction     * @param newBandwidth     */    protected void adjustFlows(int direction, double newBandwidth) {        int theDirection = shareBandwidth                           ? OUTGOING                           : direction;        // The HashMap is cloned (shallow copy) in order to do concurrent access on the real version        Iterator theFlows =            ((HashMap) flows[theDirection].clone()).values().iterator();        while (theFlows.hasNext()) {            Flow theFlow = (Flow) theFlows.next();            double timeRemaining =                theFlow.calculate(                    direction, newBandwidth,                    ((FairNetworkScheduler) scheduler).getCurrentTime());            ((FairNetworkScheduler) scheduler).rescheduleFlow(theFlow,                    timeRemaining);        }    }    /**     * Method updateRegisteredFlow     *     * @param direction     * @param oldEvent     * @param newEvent     */    protected void updateRegisteredFlow(int direction, NetworkEvent oldEvent,                                        NetworkEvent newEvent) {        int theDirection = shareBandwidth                           ? OUTGOING                           : direction;        Flow theFlow = (Flow) flows[direction].remove(oldEvent);        flows[direction].put(newEvent, theFlow);    }    /**     * Method registerFlow     *     * @param direction     * @param theEvent     * @param theFlow     */    protected void registerFlow(int direction, FairNetworkEvent theEvent,                                Flow theFlow) {        int theDirection = shareBandwidth                           ? OUTGOING                           : direction;        // Calculate new fair allocation        curFlows[theDirection]++;        // Adjust new maximum counts        if (curFlows[theDirection] > maxFlows[theDirection]) {            maxFlows[theDirection] = curFlows[theDirection];        }        double newBandwidth = bandwidth[theDirection] / curFlows[theDirection];        // Adjust existing flows        adjustFlows(theDirection, newBandwidth);        // Store the new flow        flows[theDirection].put(theEvent, theFlow);    }    /**     * Method deregisterFlow     *     * @param direction     * @param theEvent     * @return     */    protected Flow deregisterFlow(int direction, NetworkEvent theEvent) {        int theDirection = shareBandwidth                           ? OUTGOING                           : direction;        // Retrieve the flow        Flow flow = (Flow) flows[theDirection].remove(theEvent);        // Calculate new fair allocation        curFlows[theDirection]--;        double newBandwidth = bandwidth[theDirection] / curFlows[theDirection];        // Adjust existing flows        adjustFlows(direction, newBandwidth);        return flow;    }}

⌨️ 快捷键说明

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