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

📄 helloworldapp.java

📁 pastry的java实现的2.0b版
💻 JAVA
字号:
/*************************************************************************"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.testing;import rice.environment.random.RandomSource;import rice.pastry.*;import rice.pastry.client.*;import rice.pastry.messaging.*;import rice.pastry.routing.*;import java.util.*;import java.io.*;/** * A hello world example for pastry. This is the per-node app object. * * @version $Id: HelloWorldApp.java 3274 2006-05-15 16:17:47Z jeffh $ * @author Sitaram Iyer */public class HelloWorldApp extends PastryAppl {  private int msgid = 0;  private static int addr = HelloAddress.getCode();  /**   * Constructor for HelloWorldApp.   *   * @param pn DESCRIBE THE PARAMETER   */  public HelloWorldApp(PastryNode pn) {    super(pn, null, addr, null);    register();  }  // The remaining methods override abstract methods in the PastryAppl API.  /**   * Get address.   *   * @return the address of this application.   */  public int getAddress() {    return addr;  }  /**   * Sends a message to a randomly chosen node. Yeah, for fun.   *   * @param rng Randon number generator.   */  public void sendRndMsg(RandomSource rng) {    Id rndid = Id.makeRandomId(rng);    System.out.println("Sending message from " + getNodeId() + " to random dest " + rndid);    Message msg = new HelloMsg(addr, thePastryNode.getLocalHandle(), rndid,      ++msgid);    routeMsg(rndid, msg, new SendOptions());  }  /**   * Invoked on destination node when a message arrives.   *   * @param msg Message being routed around   */  public void messageForAppl(Message msg) {    System.out.println("Received " + msg + " at " + getNodeId());  }  /**   * Invoked on intermediate nodes in routing path.   *   * @param msg Message that's passing through this node.   * @param key destination   * @param nextHop next hop   * @param opt send options   * @return true if message needs to be forwarded according to plan.   */  public boolean enrouteMessage(Message msg, Id key, NodeHandle nextHop,                                SendOptions opt) {    System.out.println("Enroute " + msg + " at " + getNodeId());    return true;  }  /**   * Invoked upon change to leafset.   *   * @param nh node handle that got added/removed   * @param wasAdded added (true) or removed (false)   */  public void leafSetChange(NodeHandle nh, boolean wasAdded) {    String s = "In " + getNodeId() + "'s leaf set, " + "node " + nh.getNodeId()      + " was ";    if (wasAdded) {      s += "added";    } else {      s += "removed";    }    System.out.println(s);  }  /**   * Invoked upon change to routing table.   *   * @param nh node handle that got added/removed   * @param wasAdded added (true) or removed (false)   */  public void routeSetChange(NodeHandle nh, boolean wasAdded) {    String s = "In " + getNodeId() + "'s route set, " + "node "      + nh.getNodeId() + " was ";    if (wasAdded) {      s += "added";    } else {      s += "removed";    }    System.out.println(s);  }  /**   * Invoked by {RMI,Direct}PastryNode when the node has something in its leaf   * set, and has become ready to receive application messages.   */  public void notifyReady() {    if (true    /*     *  Log.ifp(6)     */      ) {      System.out.println("Node " + getNodeId()        + " ready, waking up any clients");    }    //sendRndMsg(new Randon());  }  /**   * DESCRIBE THE CLASS   *   * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $   * @author jeffh   */  private static class HelloAddress {    private static int myCode = 0x1984abcd;    /**     * Gets the Code attribute of the HelloAddress class     *     * @return The Code value     */    public static int getCode() {      return myCode;    }  }}

⌨️ 快捷键说明

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