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

📄 genserializedfile.java

📁 p2p仿真器。开发者可以工作在覆盖层中进行创造和测试逻辑算法或者创建和测试新的服务。PlanetSim还可以将仿真代码平稳转换为在Internet上的实验代码
💻 JAVA
字号:
package planet.test.serialize;

import java.util.Vector;

import planet.commonapi.exception.InitializationException;
import planet.generic.commonapi.GenericApp;
import planet.generic.commonapi.factory.GenericFactory;
import planet.generic.commonapi.factory.Topology;
import planet.simulate.EventParser;
import planet.simulate.NetworkSimulator;
import planet.simulate.Scheduler;
import planet.test.TestNames;
import planet.util.Properties;
/**
 * Builds a network based with events file "test_join1000d.txt" and serialize 
 * obtained network.
 * @author Ruben Mondejar
 * @author Jordi Pujol
 */
 
public class GenSerializedFile extends GenericApp {

    /**
	 * Builds a network based with events file "test_join1000d.txt" and
	 * serialize it to file "test_1000.dat".
     * @throws InitializationException if the events file is not found.
     */
    public GenSerializedFile() throws InitializationException
    {
        //arguments: properties file, application level, events, results, serialization
        super("../conf/master.properties",TestNames.SERIALIZE_GENSERIALIZEDFILE,true,true,false,true);

        //ensure a network size to zero to adding events
        Properties.factoriesNetworkSize = 0;
        Properties.factoriesNetworkTopology = Topology.RANDOM;
        restart(true,true,false,true);
        
		//load events
        Vector events = null;
        try {
            events = EventParser.parseEvents(Properties.simulatorEventFile);
        } catch (java.io.IOException e)
        {
            throw new InitializationException("Cannot load the events file called ["+Properties.simulatorEventFile+"]",e);
        }
		Scheduler timer = new Scheduler();
		timer.addEvents(events);
			
		//build network and add all events
		long t1,t2;
		t1 = System.currentTimeMillis();
		NetworkSimulator sim = new NetworkSimulator(timer);
		sim.stabilize();
		t2 = System.currentTimeMillis();
		int steps = sim.getInternalNetwork().getSimulatedSteps();
		System.out.println("Simulation time ["+GenericApp.timeElapsedInSeconds(t1,t2)+"] seconds for 1000 nodes with ["+steps+"] steps.");
        System.out.println("RouteMessages: Created["+GenericFactory.getBuiltRouteMessages()+"], reused["+GenericFactory.getReusedRouteMessages()+"], free["+GenericFactory.getFreeRouteMessages()+"]");
		sim.saveState();
    }
    
	/**
	 * @param args Nothing waiting.
	 */
	public static void main(String[] args) {
	    try {
	        new GenSerializedFile();
	    } catch (InitializationException e)
	    {
	        System.out.println("Initialization error in GenSerializedFile...");
	        e.printStackTrace();
	    }
	}
}

⌨️ 快捷键说明

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