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

📄 commonapitest.java

📁 pastry的java实现的2.0b版
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************"FreePastry" Peer-to-Peer Application Development Substrate Copyright 2002, Rice University. All rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions aremet:- Redistributions of source code must retain the above copyrightnotice, this list of conditions and the following disclaimer.- Redistributions in binary form must reproduce the above copyrightnotice, this list of conditions and the following disclaimer in thedocumentation and/or other materials provided with the distribution.- Neither  the name  of Rice  University (RICE) nor  the names  of itscontributors may be  used to endorse or promote  products derived fromthis software without specific prior written permission.This software is provided by RICE and the contributors on an "as is"basis, without any representations or warranties of any kind, expressor implied including, but not limited to, representations orwarranties of non-infringement, merchantability or fitness for aparticular purpose. In no event shall RICE or contributors be liablefor any direct, indirect, incidental, special, exemplary, orconsequential damages (including, but not limited to, procurement ofsubstitute goods or services; loss of use, data, or profits; orbusiness interruption) however caused and on any theory of liability,whether in contract, strict liability, or tort (including negligenceor otherwise) arising in any way out of the use of this software, evenif advised of the possibility of such damage.********************************************************************************/package rice.p2p.commonapi.testing;import rice.*;import rice.environment.Environment;import rice.environment.logging.*;import rice.environment.logging.simple.SimpleLogManager;import rice.environment.params.Parameters;import rice.environment.params.simple.SimpleParameters;import rice.environment.processing.Processor;import rice.environment.processing.sim.SimProcessor;import rice.environment.random.RandomSource;import rice.environment.random.simple.SimpleRandomSource;import rice.environment.time.TimeSource;import rice.environment.time.simple.SimpleTimeSource;import rice.environment.time.simulated.DirectTimeSource;import rice.p2p.commonapi.*;import rice.pastry.*;import rice.pastry.commonapi.*;import rice.pastry.direct.*;import rice.pastry.dist.*;import rice.pastry.standard.*;import rice.selector.SelectorManager;import java.util.*;import java.net.*;import java.io.*;/** * Provides regression testing setup for applications written on top of the * commonapi. Currently is written to use Pastry nodes, but this will be * abstracted away. * * @version $Id: CommonAPITest.java 3274 2006-05-15 16:17:47Z jeffh $ * @author Alan Mislove */public abstract class CommonAPITest {  // ----- VARAIBLES -----  // the collection of nodes which have been created  /**   * DESCRIBE THE FIELD   */  protected Node[] nodes;  // ----- PASTRY SPECIFIC VARIABLES -----  // the factory for creating pastry nodes  /**   * DESCRIBE THE FIELD   */  protected PastryNodeFactory factory;  // the factory for creating random node ids  /**   * DESCRIBE THE FIELD   */  protected NodeIdFactory idFactory;  // the simulator, in case of direct  /**   * DESCRIBE THE FIELD   */  protected NetworkSimulator simulator;  // the environment  /**   * DESCRIBE THE FIELD   */  protected Environment environment;  /**   * DESCRIBE THE FIELD   */  protected Parameters params;  // ----- STATIC FIELDS -----  // the number of nodes to create  /**   * DESCRIBE THE FIELD   */  public int NUM_NODES;  // the factory which creates pastry ids  /**   * DESCRIBE THE FIELD   */  public final IdFactory FACTORY;  // ----- PASTRY SPECIFIC FIELDS -----  // the port to begin creating nodes on  /**   * DESCRIBE THE FIELD   */  public int PORT;  // the host to boot the first node off of  /**   * DESCRIBE THE FIELD   */  public InetSocketAddress BOOTSTRAP;  // the procotol to use when creating nodes  /**   * DESCRIBE THE FIELD   */  public String PROTOCOL;  // = PROTOCOL_DIRECT; //DistPastryNodeFactory.PROTOCOL_DEFAULT;  // the simulator to use in the case of direct    /**   * DESCRIBE THE FIELD   */  public String SIMULATOR;  /**   * DESCRIBE THE FIELD   */  protected Logger logger;  //= new PastryIdFactory();  // ----- TESTING SPECIFIC FIELDS -----  // the text to print to the screen    /**   * DESCRIBE THE FIELD   */  public final static String SUCCESS = "SUCCESS";  /**   * DESCRIBE THE FIELD   */  public final static String FAILURE = "FAILURE";  // the width to pad the output  /**   * DESCRIBE THE FIELD   */  protected final static int PAD_SIZE = 60;  // the direct protocol  /**   * DESCRIBE THE FIELD   */  public final static String PROTOCOL_DIRECT = "direct";  // the possible network simulation models  /**   * DESCRIBE THE FIELD   */  public final static String SIMULATOR_SPHERE = "sphere";  /**   * DESCRIBE THE FIELD   */  public final static String SIMULATOR_EUCLIDEAN = "euclidean";  /**   * DESCRIBE THE FIELD   */  public final static String SIMULATOR_GT_ITM = "gt-itm";  // the port on the bootstrap to contact  /**   * DESCRIBE THE FIELD   */  public static int BOOTSTRAP_PORT = 5009;  // = SIMULATOR_SPHERE;  // the instance name to use    /**   * DESCRIBE THE FIELD   */  public static String INSTANCE_NAME = "DistCommonAPITest";  // ----- EXTERNALLY AVAILABLE METHODS -----  /**   * Constructor, which takes no arguments and sets up the factories in   * preparation for node creation.   *   * @param env DESCRIBE THE PARAMETER   * @exception IOException DESCRIBE THE EXCEPTION   */  public CommonAPITest(Environment env) throws IOException {    this.environment = env;    this.logger = env.getLogManager().getLogger(getClass(), null);    params = env.getParameters();    NUM_NODES = params.getInt("commonapi_testing_num_nodes");    PORT = params.getInt("commonapi_testing_startPort");    PROTOCOL = params.getString("commonapi_testing_protocol");    SIMULATOR = params.getString("direct_simulator_topology");    FACTORY = new PastryIdFactory(env);    //idFactory = new IPNodeIdFactory(PORT);    idFactory = new RandomNodeIdFactory(environment);    if (PROTOCOL.equalsIgnoreCase(PROTOCOL_DIRECT)) {      if (SIMULATOR.equalsIgnoreCase(SIMULATOR_SPHERE)) {        simulator = new SphereNetwork(env);      } else if (SIMULATOR.equalsIgnoreCase(SIMULATOR_GT_ITM)) {        simulator = new GenericNetwork(env, null);      } else {        simulator = new EuclideanNetwork(env);      }      factory = new DirectPastryNodeFactory(idFactory, simulator, env);    } else {      factory = DistPastryNodeFactory.getFactory(idFactory,        DistPastryNodeFactory.PROTOCOL_SOCKET,        PORT,        env);    }    nodes = new Node[NUM_NODES];  }  /**   * Gets a handle to a bootstrap node.   *   * @return handle to bootstrap node, or null.   */  protected rice.pastry.NodeHandle getBootstrap() {    if (PROTOCOL.equalsIgnoreCase(PROTOCOL_DIRECT)) {      return ((DirectPastryNode) nodes[0]).getLocalHandle();    } else {      try {        InetSocketAddress address = params.getInetSocketAddress("commonapi_testing_bootstrap");        return ((DistPastryNodeFactory) factory).getNodeHandle(address);      } catch (UnknownHostException uhe) {        throw new RuntimeException(uhe);      }    }  }  /**   * Method which creates the nodes   */  public void createNodes() {    for (int i = 0; i < NUM_NODES; i++) {      nodes[i] = createNode(i);      simulate();      processNode(i, nodes[i]);      simulate();      System.out.println("Created node " + i + " with id " + ((PastryNode) nodes[i]).getNodeId());    }    if (logger.level <= Logger.INFO) {      logger.log(((PastryNode) nodes[0]).getLeafSet().toString());    }  }  /**   * Method which starts the creation of nodes   */  public void start() {//    simulator.start();    createNodes();    System.out.println("\nTest Beginning\n");    runTest();  }  // ----- INTERNAL METHODS -----  /**   * In case we're using the direct simulator, this method simulates the message   * passing.   */  protected void simulate() {    if (environment.getSelectorManager().isSelectorThread()) {      return;    }    synchronized (this) {      try {        wait(300);      } catch (InterruptedException e) {      }    }

⌨️ 快捷键说明

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