コード例 #1
0
ファイル: MailboxAddress.java プロジェクト: johangas/moped
  /**
   * This method looks up a MailboxAddress that has been registered with the system, and implicitly
   * opens the connection to the remote Mailbox. It also opens the reply address for the remote
   * mailbox, so it may send responses back to this Isolate.
   *
   * @param name the name of the Mailbox to lookup.
   * @param replyMailbox the address of a local mailbox that the remote isolate can send replies to.
   * @return an open address to the remote mailbox named <code>name</code>.
   * @throws NoSuchMailboxException if there is no mailbox named <code>name</code>.
   */
  public static MailboxAddress lookupMailbox(String name, Mailbox replyMailbox)
      throws NoSuchMailboxException {
    Mailbox box = VM.lookupMailbox(name);

    if (box == null) {
      throw new NoSuchMailboxException(name);
    }

    MailboxAddress replyAddress = new MailboxAddress(replyMailbox);
    MailboxAddress startingAddress = new MailboxAddress(box);
    MailboxAddress finalAddress = box.callHandleOpen(startingAddress, replyAddress);

    if (finalAddress == null) {
      // something fell apart in callHandleOpen
      throw new NoSuchMailboxException(name);
    }

    // record the address of the remote mailbox with this isolate:
    finalAddress.recordAddress(Isolate.currentIsolate(), replyAddress);

    // also, tell the isolate containing the remote mailbox about the
    // reply address that it will use to send replies back to this isolate.
    replyAddress.recordAddress(box.getOwner(), finalAddress);

    return finalAddress;
  }