Example #1
0
  /**
   * This method sends a message to the process; this process also sets logical clock
   *
   * @param workMess
   * @param address
   */
  private void sendMessageToProcess(Message workMess, int address)
      throws RemoteException, NotBoundException {
    // 1]locate NodeInfo object
    NodeInfo[] nodeInfos = this.directory.listNodes();
    NodeInfo regNode = null;
    // System.out.println("NodeInfoLength = "+nodeInfos.length+"\n"+
    //        "Processing nodes:");
    for (int i = 0; i < nodeInfos.length; i++) {
      //  System.out.println("-->"+nodeInfos[i].toString()+" "+address);
      if (nodeInfos[i].getID() == address) {
        regNode = nodeInfos[i];
      }
    }

    // 2]Get remote registry
    Registry remoteRegistry = LocateRegistry.getRegistry(regNode.getIP(), regNode.getPort());

    // 3]Lookup and put data
    String nodeName = NODE_NAME_PREFIX + address;

    // set clock
    this.clock++; // increment clock
    workMess.setClock(clock);

    // message prepared
    this.log.logNode(
        "Sending message to processs " + address + "-->" + workMess.toString(),
        clock,
        this.nodeInfo.getID());
    NodeInterface nodeDirectory = (NodeInterface) remoteRegistry.lookup(nodeName);
    nodeDirectory.putMessage(workMess);
  }
Example #2
0
  /** Method for terminated message spam. */
  private void sendTerminatedMessage() throws RemoteException, NotBoundException {
    Message messTerm = new Message();
    messTerm.setType(MessageType.WORK_TERMINATED);
    this.log.logNode("Sending termination message to all nodes.", clock, this.nodeInfo.getID());

    for (NodeInfo node : this.directory.listNodes()) {
      this.sendMessageToProcess(messTerm, node.getID());
    }
  }