コード例 #1
0
ファイル: Broker.java プロジェクト: fmichel/MaDKit-demos
 protected void live() {
   while (true) {
     Message m = purgeMailbox(); // to always treat the last request
     if (m == null) {
       m = waitNextMessage(); // waiting a request
     }
     String role = m.getSender().getRole();
     if (role.equals(MarketOrganization.CLIENT_ROLE)) {
       handleClientRequest((StringMessage) m);
     }
   }
 }
コード例 #2
0
  /* (non-Javadoc)
   * @see madkit.kernel.Agent#live()
   */
  public void live() {
    while (alive) {
      Message m = waitNextMessage();

      exitImmediatlyOnKill();
      if (!alive) break;
      if (m instanceof NetworkMessage) {
        handleNetworkMessage((NetworkMessage) m);
      } else if (m instanceof NetConfigMessage) {
        handleConfigMessage((NetConfigMessage) m);
      } else {
        debug(m.toString());
      }
    }
  }
コード例 #3
0
  /**
   * Sends a message to a Distant Kernel.
   *
   * @param message message to send.
   */
  private void sendDistantMessage(KernelMessage message) {
    Message orig;
    if (message instanceof KernelMessage) {
      KernelMessage temp = (KernelMessage) message;
      orig = (Message) (temp.getArgument());
    } else orig = message;

    if (shouldUseUDP(orig)) {
      println("WARN:  No udp message routing yet!!!");
    } else {
      DistantKernelInformation info = getP2PAddress(orig);
      if (info != null) {
        AgentAddress p2p = info.getP2PAgent();
        sendMessage(p2p, new NetworkMessage(NetworkMessage.DISTANT_MESSAGE, orig));
      } else {
        println("WARN : unknown destination kernel" + orig.getReceiver().getKernel());
      }
    }
  }
コード例 #4
0
 private DistantKernelInformation getP2PAddress(Message orig) {
   DistantKernelInformation info =
       (DistantKernelInformation) routeTable.get(orig.getReceiver().getKernel().getID());
   return info;
 }