示例#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);
  }
示例#2
0
  /**
   * Inserts message into queue
   *
   * @param message - message to insert
   * @throws RemoteException
   */
  @Override
  public synchronized void putMessage(Message message) throws RemoteException {
    Message messageTmp = new Message();
    messageTmp.setClock(message.getClock());
    messageTmp.setColor(message.getColor());
    messageTmp.setPayload(message.getPayload());
    messageTmp.setType(message.getType());

    this.messageQueue.add(message);
  }