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);
 }
示例#3
0
 /**
  * Send a subscription represented by the String subStr to the broker with URI brokerURI.
  *
  * @param subStr Subscription in String format. Check the PADRES message format for the syntax.
  * @param brokerURI The URI of the broker to which the subscription is to be sent.
  * @return The SubscriptionMessage sent to the broker containing the given subscription.
  * @throws ClientException If there is a synatx error in the given subscription string or an
  *     thrown by the {@link #subscribe(Subscription, String)} method called by this method.
  * @throws ParseException
  */
 public SubscriptionMessage subscribe(String subStr, String brokerURI)
     throws ClientException, ParseException {
   Subscription newSub = MessageFactory.createSubscriptionFromString(subStr);
   if (newSub.getClassVal() == null) {
     throw new ClientException("Subscription syntax error");
   }
   return subscribe(newSub, brokerURI);
 }
示例#4
0
 /**
  * Send an advertisement to a broker. The advertisemnet is given as a String comforming the PADRES
  * message format. The broker is specified with its URI.
  *
  * @param advStr The advertisement string conforming PADRES message format.
  * @param brokerURI The URI of the broker to send the advertisement to.
  * @return The {@link AdvertisementMessage} produced by the given advertisement string. The
  *     message ID of the message is returned by the broker.
  * @throws ClientException Either their is a syntax error the advertisement string or other error
  *     during advertisement.
  * @throws ParseException
  * @see #advertise(Advertisement, String)
  */
 public AdvertisementMessage advertise(String advStr, String brokerURI)
     throws ClientException, ParseException {
   Advertisement newAdv = MessageFactory.createAdvertisementFromString(advStr);
   if (newAdv.getClassVal() == null) {
     throw new ClientException("Advertisement syntax error");
   }
   return advertise(newAdv, brokerURI);
 }
示例#5
0
 public PublicationMessage publish(String pubStr, String brokerID) throws ClientException {
   try {
     Publication newPub = MessageFactory.createPublicationFromString(pubStr);
     if (newPub.getClassVal() == null) {
       throw new ClientException("Publication syntax error");
     }
     return publish(newPub, brokerID);
   } catch (ParseException e) {
     throw new ClientException(e);
   }
 }
  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());
    }
  }