Example #1
0
 /**
  * Get a handle to a bootstrap node. This is only a simulation, so we pick the most recently
  * created node.
  *
  * @return handle to bootstrap node, or null.
  */
 private NodeHandle getBootstrap() {
   NodeHandle bootstrap = null;
   try {
     PastryNode lastnode = (PastryNode) pastryNodes.lastElement();
     bootstrap = lastnode.getLocalHandle();
   } catch (NoSuchElementException e) {
   }
   return bootstrap;
 }
Example #2
0
  /**
   * Create a Pastry node and add it to pastryNodes. Also create a client application for this node.
   */
  public void makePastryNode(int num) {
    PastryNode pn = factory.newNode(getBootstrap());
    pastryNodes.addElement(pn);

    HelloWorldApp app = new HelloWorldApp(pn);
    helloClients.addElement(app);

    synchronized (pn) {
      while (!pn.isReady()) {
        try {
          pn.wait(300);
        } catch (InterruptedException ie) {
        }
      }
    }

    System.out.println("created " + num + " " + pn);
  }
Example #3
0
 /**
  * Invoke a HelloWorldApp method called sendRndMsg. First choose a random application from
  * helloClients.
  */
 private void sendRandomMessage() {
   int n = helloClients.size();
   int client = environment.getRandomSource().nextInt(n);
   HelloWorldApp app = (HelloWorldApp) helloClients.get(client);
   app.sendRndMsg(environment.getRandomSource());
 }
Example #4
0
 /** Print leafsets of all nodes in pastryNodes. */
 private void printLeafSets() {
   for (int i = 0; i < pastryNodes.size(); i++) {
     PastryNode pn = (PastryNode) pastryNodes.get(i);
     System.out.println(pn.getLeafSet().toString());
   }
 }