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

📄 mspastryobserver.java

📁 pastry 协议在peersim下的仿真环境。测试无误。在eclipse下打开源文件夹为工程即可使用和做仿真实验。
💻 JAVA
字号:
package peersim.pastry;

import peersim.core.Control;
import peersim.util.IncrementalStats;
import peersim.core.Network;
import peersim.config.Configuration;
import peersim.core.CommonState;


//______________________________________________________________________________________________
public class MSPastryObserver implements Control {

    //______________________________________________________________________________________________
    /**
     * keep statistics of the number of hops of every message delivered.
     */
    public static IncrementalStats hopStore = new  IncrementalStats();

    /**
     * keep statistics of the time every every message needed for delivery.
     */
    public static IncrementalStats timeStore = new  IncrementalStats();

    /** Parameter of the protocol we want to observe */
    private static final String PAR_PROT = "protocol";

    //______________________________________________________________________________________________
    /** Protocol id */
    private int pid;

    /** Prefix to be printed in output */
    private String prefix;

    //______________________________________________________________________________________________
    public MSPastryObserver(String prefix) {
        this.prefix = prefix;
        pid = Configuration.getPid(prefix+"."+PAR_PROT);
    }

    //______________________________________________________________________________________________
    /**
     * print the statistical snapshot of the current situation
     * @return boolean
     */
    public boolean execute() {

        int sz = Network.size();
        for(int i = 0; i<Network.size();i++)
            if (!Network.get(i).isUp()) sz--;

        String s = String.format("[time=%d]:[with N=%d current nodes UP] [%f average hops] [%d msec average transimission time] ",
        CommonState.getTime(),
        sz,
        hopStore.getAverage(),
        (int)timeStore.getAverage()
               );

         System.err.println(s);

        //hopStore.reset();
        return false;
    }
    //______________________________________________________________________________________________
} // enf of class
//______________________________________________________________________________________________

⌨️ 快捷键说明

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