private void publishFailureDetected(String broker) {
    try {
      String pubStr =
          "[class,"
              + HeartbeatSubscriber.MESSAGE_CLASS
              + "],"
              + "[detectorID,'"
              + m_BrokerCore.getBrokerID()
              + "'],"
              + "[detectedID,'"
              + broker
              + "'],"
              + "[type,'FAILURE_DETECTED']";
      Publication pub = MessageFactory.createPublicationFromString(pubStr);
      PublicationMessage pubMsg =
          new PublicationMessage(
              pub, m_BrokerCore.getNewMessageID(), MessageDestination.HEARTBEAT_MANAGER);

      Map<MessageDestination, LinkInfo> statisticTable =
          m_BrokerCore.getOverlayManager().getORT().getStatisticTable();
      MessageDestination failureBroker = new MessageDestination(broker, DestinationType.BROKER);
      if (statisticTable.containsKey(failureBroker)) {
        LinkInfo link = statisticTable.get(failureBroker);
        link.setStatus();
      }

      heartbeatLogger.info("Sending failure of " + broker + " detected messsage.");
      m_BrokerCore.routeMessage(pubMsg, MessageDestination.INPUTQUEUE);
    } catch (ParseException e) {
      heartbeatLogger.error(e.getMessage());
      exceptionLogger.error(e.getMessage());
    }
  }
 private void advertiseHeartbeat() {
   String advStr =
       "[class,eq,"
           + HeartbeatSubscriber.MESSAGE_CLASS
           + "],"
           + "[brokerID,isPresent,'TEXT'],"
           + "[fromID,eq,'"
           + m_BrokerCore.getBrokerID()
           + "'],"
           + "[type,isPresent,'TEXT'],"
           + "[handle,isPresent,'TEXT']";
   Advertisement adv;
   try {
     adv = MessageFactory.createAdvertisementFromString(advStr);
   } catch (ParseException e) {
     exceptionLogger.error(e.getMessage());
     return;
   }
   AdvertisementMessage msg =
       new AdvertisementMessage(
           adv, m_BrokerCore.getNewMessageID(), MessageDestination.HEARTBEAT_MANAGER);
   msg.setTTL(1);
   heartbeatLogger.debug("Sending initial advertisement for heartbeat.");
   m_BrokerCore.routeMessage(msg, MessageDestination.INPUTQUEUE);
 }
  private void publishHeartbeats() {
    try {
      Map<MessageDestination, OutputQueue> neighbors =
          m_BrokerCore.getOverlayManager().getORT().getBrokerQueues();
      synchronized (neighbors) {
        for (MessageDestination md : neighbors.keySet()) {
          String brokerID = md.getDestinationID();

          // create and set a timer event for the heartbeat request
          TimerEvent event = new TimerEvent(this, m_HeartbeatTimeout, HEARTBEAT_TIMEOUT_TIMER);
          event.setAttachment(brokerID);
          int handle = m_TimerThread.setTimer(event);

          // publish the heartbeat request
          String pubStr =
              "[class,"
                  + HeartbeatSubscriber.MESSAGE_CLASS
                  + "],"
                  + "[brokerID,'"
                  + brokerID
                  + "'],"
                  + "[fromID,'"
                  + m_BrokerCore.getBrokerID()
                  + "'],"
                  + "[type,'HEARTBEAT_REQ'],"
                  + "[handle,'"
                  + handle
                  + "']";
          Publication pub = MessageFactory.createPublicationFromString(pubStr);
          PublicationMessage pubMsg =
              new PublicationMessage(
                  pub, m_BrokerCore.getNewMessageID(), MessageDestination.HEARTBEAT_MANAGER);
          heartbeatLogger.info(
              "Broker "
                  + m_BrokerCore.getBrokerID()
                  + " is sending heartbeat REQ to broker "
                  + brokerID
                  + " with handle "
                  + handle);
          m_BrokerCore.routeMessage(pubMsg, MessageDestination.INPUTQUEUE);
          // add by shuang for testing
          currentHandle = handle;
        }
      }
    } catch (ParseException e) {
      heartbeatLogger.error(e.getMessage());
      exceptionLogger.error(e.getMessage());
    }
  }