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

📄 flow.java

📁 High performance DB query
💻 JAVA
字号:
/* * @(#)$Id: Flow.java,v 1.5 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 simulator.schedulers.network.IPMessage;import simulator.schedulers.network.NetworkEvent;import simulator.schedulers.network.NetworkStub;import util.FreeList;import util.FreeListFactory;import util.network.serialization.SerializationManager;/** A class to contain all information about a flow that is needed by the scheduler */public class Flow {    public static final int SOURCE = FairNetworkStub.OUTGOING;    public static final int DESTINATION = FairNetworkStub.INCOMING;    private NetworkEvent theEvent;    private NetworkStub[] stubs;    private double[] bandwidth;    private double timeLastScheduled;    private int bytesRemaining;    private static FreeList freeList = new FreeList(new FlowFactory());    /**     * Constructor Flow     */    protected Flow() {}    private void init(NetworkEvent theEvent, IPMessage theMessage,                      FairNetworkStub source, FairNetworkStub destination,                      double sourceBandwidth, double destinationBandwidth,                      double curTime) {        this.theEvent = theEvent;        this.stubs = new NetworkStub[2];        this.stubs[SOURCE] = source;        this.stubs[DESTINATION] = destination;        this.bandwidth = new double[2];        this.bandwidth[SOURCE] = sourceBandwidth;        this.bandwidth[DESTINATION] = destinationBandwidth;        this.timeLastScheduled = curTime;        this.bytesRemaining = SerializationManager.getPayloadSize(theMessage);    }    /**     * Method getNetworkEvent     * @return     */    public NetworkEvent getNetworkEvent() {        return theEvent;    }    /**     * Method resetNetworkEvent     *     * @param theEvent     */    public void resetNetworkEvent(NetworkEvent theEvent) {        this.theEvent = theEvent;    }    /**     * Method getBandwidth     *     * @param direction     * @return     */    public double getBandwidth(int direction) {        return bandwidth[direction];    }    /**     * Method setBandwidth     *     * @param direction     * @param newBandwidth     */    public void setBandwidth(int direction, double newBandwidth) {        bandwidth[direction] = newBandwidth;    }    /**     * Method getStub     *     * @param direction     * @return     */    public NetworkStub getStub(int direction) {        return stubs[direction];    }    private double curBandwidth() {        return Math.min(bandwidth[SOURCE], bandwidth[DESTINATION]);    }    /**     * Method calculate     *     * @param direction     * @param newBandwidth     * @param curTime     * @return     */    public double calculate(int direction, double newBandwidth,                            double curTime) {        // Subtract bytes sent since last scheduling        bytesRemaining -= curBandwidth() * (curTime - timeLastScheduled);        // Record new parameters        bandwidth[direction] = newBandwidth;        timeLastScheduled = curTime;        // Predict time till finish        return (bytesRemaining / curBandwidth());    }    /**     * Method allocate     *     * @param theEvent     * @param theMessage     * @param source     * @param destination     * @param sourceBandwidth     * @param destinationBandwidth     * @param curTime     * @return     */    public static Flow allocate(NetworkEvent theEvent, IPMessage theMessage,                                FairNetworkStub source,                                FairNetworkStub destination,                                double sourceBandwidth,                                double destinationBandwidth, double curTime) {        Flow flow = (Flow) freeList.allocate();        flow.init(theEvent, theMessage, source, destination, sourceBandwidth,                  destinationBandwidth, curTime);        return flow;    }    /**     * Method free     *     * @param flow     */    public static void free(Flow flow) {        freeList.free(flow);    }}/** * Class FlowFactory * */class FlowFactory implements FreeListFactory {    /**     * Method create     * @return     */    public Object create() {        return new Flow();    }}

⌨️ 快捷键说明

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