📄 quotaobserver.java
字号:
/* * Copyright (c) 2003-2005 The BISON Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */package example.loadbalance;import peersim.config.*;import peersim.core.*;import peersim.util.*;/** * This class prints statistics about the actual quota consumptions. It is * assumed that the network nodes are instances of the * {@link example.loadbalance.BasicBalance} class. * * <p> * Note that this observer can be replaced by a library class * {@link peersim.vector.VectorObserver} the following way: class * {@link BasicBalance} needs to implement a public method "getQuota", and this * method needs to be configured as "getter". */public class QuotaObserver implements Control { // /////////////////////////////////////////////////////////////////////// // Constants // /////////////////////////////////////////////////////////////////////// /** * The protocol to operate on. * * @config */ private static final String PAR_PROT = "protocol"; // /////////////////////////////////////////////////////////////////////// // Fields // /////////////////////////////////////////////////////////////////////// /** * The name of this observer in the configuration file. Initialized by the * constructor parameter. */ private final String name; /** Protocol identifier, obtained from config property {@link #PAR_PROT}. */ private final int pid; // /////////////////////////////////////////////////////////////////////// // Constructor // /////////////////////////////////////////////////////////////////////// /** * Standard constructor that reads the configuration parameters. Invoked by * the simulation engine. * * @param name * the configuration prefix for this class. */ public QuotaObserver(String name) { this.name = name; pid = Configuration.getPid(name + "." + PAR_PROT); } // /////////////////////////////////////////////////////////////////////// // Methods // /////////////////////////////////////////////////////////////////////// // Comment inherited from interface public boolean execute() { IncrementalStats stats = new IncrementalStats(); long time = peersim.core.CommonState.getTime(); for (int i = 0; i < Network.size(); i++) { BasicBalance protocol = (BasicBalance) Network.get(i).getProtocol( pid); stats.add(protocol.quota); } /* Printing statistics */ System.out.println(name + ": " + time + " " + stats); return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -