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

📄 pastrynode.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.pastry;import java.io.IOException;import java.util.*;import rice.*;import rice.environment.Environment;import rice.environment.logging.Logger;import rice.p2p.commonapi.appsocket.AppSocketReceiver;import rice.p2p.commonapi.rawserialization.InputBuffer;import rice.pastry.client.PastryAppl;import rice.pastry.leafset.LeafSet;import rice.pastry.messaging.*;import rice.pastry.routing.*;/** * A Pastry node is single entity in the pastry network. * * @version $Id: PastryNode.java 3274 2006-05-15 16:17:47Z jeffh $ * @author Andrew Ladd */public abstract class PastryNode extends Observable implements rice.p2p.commonapi.Node, Destructable, NodeHandleFactory {  /**   * DESCRIBE THE FIELD   */  protected Id myNodeId;  private Environment myEnvironment;  private MessageDispatch myMessageDispatch;  private LeafSet leafSet;  private RoutingTable routeSet;  /**   * DESCRIBE THE FIELD   */  protected NodeHandle localhandle;  private boolean ready;  /**   * DESCRIBE THE FIELD   */  protected Vector apps;  /**   * DESCRIBE THE FIELD   */  protected Logger logger;  /**   * This variable makes it so notifyReady() is only called on the apps once.   * Deprecating   */  private boolean neverBeenReady = true;  /**   * Constructor, with NodeId. Need to set the node's ID before this node is   * inserted as localHandle.localNode.   *   * @param id DESCRIBE THE PARAMETER   * @param e DESCRIBE THE PARAMETER   */  protected PastryNode(Id id, Environment e) {    myEnvironment = e;    myNodeId = id;    ready = false;    apps = new Vector();    logger = e.getLogManager().getLogger(getClass(), null);  }  /**   * Gets the LocalNodeHandle attribute of the PastryNode object   *   * @return The LocalNodeHandle value   */  public rice.p2p.commonapi.NodeHandle getLocalNodeHandle() {    return localhandle;  }  /**   * Gets the Environment attribute of the PastryNode object   *   * @return The Environment value   */  public Environment getEnvironment() {    return myEnvironment;  }  /**   * Gets the LocalHandle attribute of the PastryNode object   *   * @return The LocalHandle value   */  public NodeHandle getLocalHandle() {    return localhandle;  }  /**   * Gets the NodeId attribute of the PastryNode object   *   * @return The NodeId value   */  public Id getNodeId() {    return myNodeId;  }  /**   * Gets the Ready attribute of the PastryNode object   *   * @return The Ready value   */  public boolean isReady() {    return ready;  }  /**   * FOR TESTING ONLY - DO NOT USE!   *   * @return The MessageDispatch value   */  public MessageDispatch getMessageDispatch() {    return myMessageDispatch;  }  /**   * Called by the layered Pastry application to check if the local pastry node   * is the one that is currently closest to the object key id.   *   * @param key the object key id   * @return true if the local node is currently the closest to the key.   */  public boolean isClosest(Id key) {    if (leafSet.mostSimilar(key) == 0) {      return true;    } else {      return false;    }  }  /**   * Gets the LeafSet attribute of the PastryNode object   *   * @return The LeafSet value   */  public LeafSet getLeafSet() {    return leafSet;  }  /**   * Gets the RoutingTable attribute of the PastryNode object   *   * @return The RoutingTable value   */  public RoutingTable getRoutingTable() {    return routeSet;  }  /**   * This returns a Endpoint specific to the given application and instance name   * to the application, which the application can then use in order to send an   * receive messages. This method allows advanced developers to specify which   * "port" on the node they wish their application to register as. This "port"   * determines which of the applications on top of the node should receive an   * incoming message.   *   * @return The endpoint specific to this applicationk, which can be used for   *      message sending/receiving.   *///  public rice.p2p.commonapi.Endpoint registerApplication(//      rice.p2p.commonapi.Application application, int port) {//    return new rice.pastry.commonapi.PastryEndpoint(this, application, port);//  }  /**   * Returns the Id of this node   *   * @return This node's Id   */  public rice.p2p.commonapi.Id getId() {    return getNodeId();  }  /**   * Returns a factory for Ids specific to this node's protocol.   *   * @return A factory for creating Ids.   */  public rice.p2p.commonapi.IdFactory getIdFactory() {    return new rice.pastry.commonapi.PastryIdFactory(getEnvironment());  }  /**   * Combined accessor method for various members of PastryNode. These are   * generated by node factories, and assigned here. Other elements specific to   * the wire protocol are assigned via methods set{RMI,Direct}Elements in the   * respective derived classes.   *   * @param lh Node handle corresponding to this node.   * @param md Message dispatcher.   * @param ls Leaf set.   * @param rt Routing table.   */  public void setElements(NodeHandle lh, MessageDispatch md, LeafSet ls, RoutingTable rt) {    localhandle = lh;    myMessageDispatch = md;    leafSet = ls;    routeSet = rt;  }  /**   * Sets the MessageDispatch attribute of the PastryNode object   *   * @param md The new MessageDispatch value   */  public void setMessageDispatch(MessageDispatch md) {    myMessageDispatch = md;  }  /**   * Sets the Ready attribute of the PastryNode object   */  public void setReady() {    setReady(true);  }  /**   * Sets the Ready attribute of the PastryNode object   *   * @param r The new Ready value   */  public void setReady(boolean r) {    // It is possible to have the setReady() invoked more than once if the    // message    // denoting the termination of join protocol is duplicated.    if (ready == r) {      return;    }    //      if (r == false)    if (logger.level <= Logger.INFO) {      logger.log("PastryNode.setReady(" + r + ")");    }    ready = r;    if (ready) {      nodeIsReady();      // deprecate this      nodeIsReady(true);      setChanged();      notifyObservers(new Boolean(true));      if (neverBeenReady) {        // notify applications        // we iterate over private copy to allow addition of new apps in the        // context of notifyReady()        Vector tmpApps = new Vector(apps);        Iterator it = tmpApps.iterator();        while (it.hasNext()) {          ((PastryAppl) (it.next())).notifyReady();        }        neverBeenReady = false;      }

⌨️ 快捷键说明

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