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

📄 rawscriberegrtest.java

📁 pastry的java实现的2.0b版
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }    if (numWithParent < NUM_NODES - 1) {      stepDone(FAILURE, "Expected at least " + (NUM_NODES - 1) + " nodes with parents, found " + numWithParent);    } else {      stepDone(SUCCESS);    }    stepStart("Killing Nodes");    for (int i = 0; i < NUM_NODES / 2; i++) {      scribes[i].destroy();      kill(i);      simulate();    }    stepDone(SUCCESS);    stepStart("Tree Recovery");    ScribeImpl local = scribes[environment.getRandomSource().nextInt(NUM_NODES / 2) + NUM_NODES / 2];    for (int i = 0; i < NUM_MESSAGES; i++) {      local.publish(topic, new TestScribeContent(topic, i));      simulate();    }    boolean failed = false;    for (int i = NUM_NODES / 2; i < NUM_NODES; i++) {      if (clients[i].getPublishMessages().length != NUM_MESSAGES) {        stepDone(FAILURE, "Expected client " + clients[i] + " to receive all messages, received " + clients[i].getPublishMessages().length);        failed = true;      }    }    if (!failed) {      stepDone(SUCCESS);    }    sectionDone();  }  /**   * Private method which generates a random Id   *   * @return A new random Id   */  private Id generateId() {    byte[] data = new byte[20];    environment.getRandomSource().nextBytes(data);    return FACTORY.buildId(data);  }  /**   * Usage: DistScribeRegrTest [-port p] [-bootstrap host[:port]] [-nodes n]   * [-protocol (rmi|wire)] [-help]   *   * @param args DESCRIBE THE PARAMETER   * @exception IOException DESCRIBE THE EXCEPTION   */  public static void main(String args[]) throws IOException {    Environment env = parseArgs(args);    RawScribeRegrTest scribeTest = new RawScribeRegrTest(env);    scribeTest.start();    env.destroy();  }  /**   * DESCRIBE THE CLASS   *   * @version $Id: ScribeRegrTest.java 3157 2006-03-19 12:16:58Z jeffh $   * @author amislove   */  protected class TestScribeClient implements ScribeClient {    /**     * DESCRIBE THE FIELD     */    protected Scribe scribe;    /**     * DESCRIBE THE FIELD     */    protected int i;    /**     * The publish messages received so far     */    protected Vector publishMessages;    /**     * The publish messages received so far     */    protected Vector anycastMessages;    /**     * The topic this client is listening for     */    protected Topic topic;    /**     * Whether or not this client should accept anycasts     */    protected boolean acceptAnycast;    /**     * Whether this client has had a subscribe fail     */    protected boolean subscribeFailed;    /**     * Constructor for TestScribeClient.     *     * @param scribe DESCRIBE THE PARAMETER     * @param i DESCRIBE THE PARAMETER     * @param topic DESCRIBE THE PARAMETER     */    public TestScribeClient(Scribe scribe, Topic topic, int i) {      this.scribe = scribe;      scribe.setContentDeserializer(        new ScribeContentDeserializer() {          public ScribeContent deserializeScribeContent(InputBuffer buf, Endpoint endpoint,                                                        short contentType) throws IOException {            switch (contentType) {              case TestScribeContent.TYPE:                return new TestScribeContent(buf, endpoint);            }            throw new IllegalArgumentException("Unknown type: " + contentType);          }        });      this.i = i;      this.topic = topic;      this.publishMessages = new Vector();      this.anycastMessages = new Vector();      this.acceptAnycast = false;      this.subscribeFailed = false;    }    /**     * Gets the PublishMessages attribute of the TestScribeClient object     *     * @return The PublishMessages value     */    public ScribeContent[] getPublishMessages() {      return (ScribeContent[]) publishMessages.toArray(new ScribeContent[0]);    }    /**     * Gets the AnycastMessages attribute of the TestScribeClient object     *     * @return The AnycastMessages value     */    public ScribeContent[] getAnycastMessages() {      return (ScribeContent[]) anycastMessages.toArray(new ScribeContent[0]);    }    /**     * Gets the SubscribeFailed attribute of the TestScribeClient object     *     * @return The SubscribeFailed value     */    public boolean getSubscribeFailed() {      return subscribeFailed;    }    /**     * DESCRIBE THE METHOD     *     * @param value DESCRIBE THE PARAMETER     */    public void acceptAnycast(boolean value) {      this.acceptAnycast = value;    }    /**     * DESCRIBE THE METHOD     *     * @param topic DESCRIBE THE PARAMETER     * @param content DESCRIBE THE PARAMETER     * @return DESCRIBE THE RETURN VALUE     */    public boolean anycast(Topic topic, ScribeContent content) {      if (acceptAnycast) {        anycastMessages.add(content);      }      return acceptAnycast;    }    /**     * DESCRIBE THE METHOD     *     * @param topic DESCRIBE THE PARAMETER     * @param content DESCRIBE THE PARAMETER     */    public void deliver(Topic topic, ScribeContent content) {      publishMessages.add(content);    }    /**     * DESCRIBE THE METHOD     *     * @param topic DESCRIBE THE PARAMETER     * @param child DESCRIBE THE PARAMETER     */    public void childAdded(Topic topic, NodeHandle child) {      // System.out.println("CHILD ADDED AT " + scribe.getId());    }    /**     * DESCRIBE THE METHOD     *     * @param topic DESCRIBE THE PARAMETER     * @param child DESCRIBE THE PARAMETER     */    public void childRemoved(Topic topic, NodeHandle child) {      // System.out.println("CHILD REMOVED AT " + scribe.getId());    }    /**     * DESCRIBE THE METHOD     *     * @param topic DESCRIBE THE PARAMETER     */    public void subscribeFailed(Topic topic) {      subscribeFailed = true;    }  }  /**   * DESCRIBE THE CLASS   *   * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $   * @author jeffh   */  public class TestScribePolicy extends ScribePolicy.DefaultScribePolicy {    /**     * DESCRIBE THE FIELD     */    protected Scribe scribe;    /**     * DESCRIBE THE FIELD     */    protected boolean allowSubscribe;    /**     * DESCRIBE THE FIELD     */    protected boolean neverAllowSubscribe;    /**     * Constructor for TestScribePolicy.     *     * @param scribe DESCRIBE THE PARAMETER     */    public TestScribePolicy(Scribe scribe) {      super(scribe.getEnvironment());      this.scribe = scribe;      allowSubscribe = true;      neverAllowSubscribe = false;    }    /**     * DESCRIBE THE METHOD     *     * @param allowSubscribe DESCRIBE THE PARAMETER     */    public void allowSubscribe(boolean allowSubscribe) {      this.allowSubscribe = allowSubscribe;    }    /**     * DESCRIBE THE METHOD     *     * @param neverAllowSubscribe DESCRIBE THE PARAMETER     */    public void neverAllowSubscribe(boolean neverAllowSubscribe) {      this.neverAllowSubscribe = neverAllowSubscribe;    }    /**     * DESCRIBE THE METHOD     *     * @param message DESCRIBE THE PARAMETER     * @param clients DESCRIBE THE PARAMETER     * @param children DESCRIBE THE PARAMETER     * @return DESCRIBE THE RETURN VALUE     */    public boolean allowSubscribe(SubscribeMessage message, ScribeClient[] clients, NodeHandle[] children) {      //System.out.println("Allow subscribe , client.size "+clients.length+", children "+children.length+" for subscriber "+message.getSubscriber());      return (!neverAllowSubscribe) && (allowSubscribe || (clients.length > 0) || this.scribe.isRoot(message.getTopic()));    }  }  /**   * Utility class for past content objects   *   * @version $Id: ScribeRegrTest.java 3157 2006-03-19 12:16:58Z jeffh $   * @author amislove   */  protected static class TestScribeContent implements RawScribeContent {    /**     * DESCRIBE THE FIELD     */    protected Topic topic;    /**     * DESCRIBE THE FIELD     */    protected int num;    /**     * DESCRIBE THE FIELD     */    public final static short TYPE = 1;    /**     * Constructor for TestScribeContent.     *     * @param topic DESCRIBE THE PARAMETER     * @param num DESCRIBE THE PARAMETER     */    public TestScribeContent(Topic topic, int num) {      this.topic = topic;      this.num = num;    }    /**     * Constructor for TestScribeContent.     *     * @param buf DESCRIBE THE PARAMETER     * @param endpoint DESCRIBE THE PARAMETER     * @exception IOException DESCRIBE THE EXCEPTION     */    public TestScribeContent(InputBuffer buf, Endpoint endpoint) throws IOException {      num = buf.readInt();      topic = new Topic(buf, endpoint);    }    /**     * Gets the Type attribute of the TestScribeContent object     *     * @return The Type value     */    public short getType() {      return TYPE;    }    /**     * DESCRIBE THE METHOD     *     * @param o DESCRIBE THE PARAMETER     * @return DESCRIBE THE RETURN VALUE     */    public boolean equals(Object o) {      if (!(o instanceof TestScribeContent)) {        return false;      }      return (((TestScribeContent) o).topic.equals(topic) &&        ((TestScribeContent) o).num == num);    }    /**     * DESCRIBE THE METHOD     *     * @return DESCRIBE THE RETURN VALUE     */    public String toString() {      return "TestScribeContent(" + topic + ", " + num + ")";    }    /**     * DESCRIBE THE METHOD     *     * @param buf DESCRIBE THE PARAMETER     * @exception IOException DESCRIBE THE EXCEPTION     */    public void serialize(OutputBuffer buf) throws IOException {      buf.writeInt(num);      topic.serialize(buf);    }  }  /**   * Utility class which simulates a route message   *   * @version $Id: ScribeRegrTest.java 3157 2006-03-19 12:16:58Z jeffh $   * @author amislove   */  protected static class TestRouteMessage implements RouteMessage {    private Id id;    private NodeHandle nextHop;    private Message message;    /**     * Constructor for TestRouteMessage.     *     * @param id DESCRIBE THE PARAMETER     * @param nextHop DESCRIBE THE PARAMETER     * @param message DESCRIBE THE PARAMETER     */    public TestRouteMessage(Id id, NodeHandle nextHop, Message message) {      this.id = id;      this.nextHop = nextHop;      this.message = message;    }    /**     * Gets the DestinationId attribute of the TestRouteMessage object     *     * @return The DestinationId value     */    public Id getDestinationId() {      return id;    }    /**     * Gets the NextHopHandle attribute of the TestRouteMessage object     *     * @return The NextHopHandle value     */    public NodeHandle getNextHopHandle() {      return nextHop;    }    /**     * Gets the Message attribute of the TestRouteMessage object     *     * @return The Message value     */    public Message getMessage() {      return message;    }    /**     * Gets the Message attribute of the TestRouteMessage object     *     * @param md DESCRIBE THE PARAMETER     * @return The Message value     */    public Message getMessage(MessageDeserializer md) {      return message;    }    /**     * Sets the DestinationId attribute of the TestRouteMessage object     *     * @param id The new DestinationId value     */    public void setDestinationId(Id id) {      this.id = id;    }    /**     * Sets the NextHopHandle attribute of the TestRouteMessage object     *     * @param nextHop The new NextHopHandle value     */    public void setNextHopHandle(NodeHandle nextHop) {      this.nextHop = nextHop;    }    /**     * Sets the Message attribute of the TestRouteMessage object     *     * @param message The new Message value     */    public void setMessage(Message message) {      this.message = message;    }    /**     * Sets the Message attribute of the TestRouteMessage object     *     * @param message The new Message value     */    public void setMessage(RawMessage message) {      this.message = message;    }  }}

⌨️ 快捷键说明

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