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

📄 scribepolicy.java

📁 p2p仿真器。开发者可以工作在覆盖层中进行创造和测试逻辑算法或者创建和测试新的服务。PlanetSim还可以将仿真代码平稳转换为在Internet上的实验代码
💻 JAVA
字号:
/*************************************************************************"Free Pastry" Peer-to-Peer Application Development SubstrateCopyright 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 planet.scribe;import planet.commonapi.*;import planet.scribe.messaging.*;/** * This interface represents a policy for Scribe, which is asked whenever a * child is about to be added or removed, or when the the local node is about to be implicitly * subscribed to a new topic. * * @version $Id: ScribePolicy.java,v 1.1 2003/09/28 08:16:29 amislove Exp $ * @author Alan Mislove */public interface ScribePolicy {  /**   * This method is called when the newChild is about to become our child, and the policy should   * return whether or not the child should be allowed to become our child. If the length of   * children and clients is both 0, allowing the child to join will have the effect of implicitly   * subscribing this node the the given topic.   *   * @param message The subscribe message in question   * @param children The list of children who are currently subscribed to this topic   * @param clients The list of clients are are currently subscribed to this topic   * @return Whether or not this child should be allowed add.   */  public boolean allowSubscribe(SubscribeMessage message, ScribeClient[] clients, NodeHandle[] children);  /**   * This method is called when an anycast is received which is not satisfied at the local node.   * This method should add both the parent and child nodes to the anycast's to-search list, but   * this method allows different policies concerning the order of the adding as well as selectively   * adding nodes.   *   * @param message The anycast message in question   * @param parent Our current parent for this message's topic   * @param children Our current children for this message's topic   */  public void directAnycast(AnycastMessage message, NodeHandle parent, NodeHandle[] children);  /**   * The default policy for Scribe, which always allows new children to join and adds children in   * the order in which they are provided, implicitly providing a depth-first search.   *   * @version $Id: ScribePolicy.java,v 1.1 2003/09/28 08:16:29 amislove Exp $   * @author amislove   */  public static class DefaultScribePolicy implements ScribePolicy {    /**     * This method always return true;     *     * @param message The subscribe message in question     * @param children The list of children who are currently subscribed     * @param clients The list of clients are are currently subscribed     * @return True.     */    public boolean allowSubscribe(SubscribeMessage message, ScribeClient[] clients, NodeHandle[] children) {      return true;    }    /**     * Simply adds the parent and children in order, which implements a depth-first-search.     *     * @param message The anycast message in question     * @param parent Our current parent for this message's topic     * @param children Our current children for this message's topic     */    public void directAnycast(AnycastMessage message, NodeHandle parent, NodeHandle[] children) {      if (parent != null) {        message.addLast(parent);      }      for (int i = 0; i < children.length; i++) {        message.addFirst(children[i]);      }    }  }  /**   * An optional policy for Scribe, which allows up to a specified number of children per topic.   *   * @version $Id: ScribePolicy.java,v 1.1 2003/09/28 08:16:29 amislove Exp $   * @author amislove   */  public static class LimitedScribePolicy extends DefaultScribePolicy {    /**     * The number of children to allow per topic     */    protected int maxChildren;    /**     * Construtor which takes a maximum number     *     * @param max The maximum number of children     */    public LimitedScribePolicy(int max) {      this.maxChildren = max;    }    /**     * This method returns (children.length < maxChildren-1);     *     * @param message The subscribe message in question     * @param children The list of children who are currently subscribed     * @param clients The list of clients are are currently subscribed     * @return True.     */    public boolean allowSubscribe(SubscribeMessage message, ScribeClient[] clients, NodeHandle[] children) {      return (children.length < (maxChildren - 1));    }  }}

⌨️ 快捷键说明

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