コード例 #1
0
 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);
 }
コード例 #2
0
ファイル: Client.java プロジェクト: jkasaudhan/padres
 protected void unAdvertiseAll(BrokerState brokerState) throws ClientException {
   if (!clientConfig.detailState)
     throw new ClientException("unAdertiseAll() not supported with client.store_detail_state=OFF");
   MessageDestination clientDest =
       MessageDestination.formatClientDestination(
           clientID, brokerState.getBrokerAddress().getNodeURI());
   MessageSender msgSender = brokerState.getMsgSender();
   if (msgSender == null)
     throw new ClientException(
         "Connection not found for broker " + brokerState.getBrokerAddress());
   AdvertisementMessage[] advMsgArray =
       brokerState.getAdvMessages().toArray(new AdvertisementMessage[0]);
   for (AdvertisementMessage advMsg : advMsgArray) {
     Unadvertisement unAdv = new Unadvertisement(advMsg.getMessageID());
     UnadvertisementMessage unAdvMsg =
         new UnadvertisementMessage(
             unAdv, getNextMessageID(brokerState.getBrokerAddress().getNodeURI()), clientDest);
     try {
       msgSender.send(unAdvMsg, HostType.CLIENT);
       brokerState.removeAdvMsg(advMsg);
     } catch (CommunicationException e) {
       throw new ClientException(e.getMessage());
     }
   }
 }
コード例 #3
0
ファイル: Client.java プロジェクト: jkasaudhan/padres
 /**
  * Returns all the advertisement messages the client has sent in the past. This method is
  * operational only when the store_detail_state option is switched ON.
  *
  * @return
  * @throws ClientException If the client.store_detail_state option is OFF
  */
 public Map<String, AdvertisementMessage> getAdvertisements() throws ClientException {
   if (!clientConfig.detailState)
     throw new ClientException(
         "getAdvertisements() not supported with client.store_detail_state=OFF");
   HashMap<String, AdvertisementMessage> idMsgMap = new HashMap<String, AdvertisementMessage>();
   for (BrokerState brokerState : brokerStates.values()) {
     Set<AdvertisementMessage> advs = brokerState.getAdvMessages();
     for (AdvertisementMessage advMsg : advs) idMsgMap.put(advMsg.getMessageID(), advMsg);
   }
   return idMsgMap;
 }
コード例 #4
0
ファイル: Client.java プロジェクト: jkasaudhan/padres
 /**
  * Sends an advertisement to a given broker.
  *
  * @param adv The advertisement to be sent. It is an {@link Advertisement} object.
  * @param brokerURI The URI of the broker to where the advertisement is sent.
  * @return The {@link AdvertisementMessage} produced by the given advertisement. The message ID of
  *     the message is returned by the broker.
  * @throws ClientException If the given URI is malformatted, the client is not connected to the
  *     broker, or there is a communication error while sending the advertisement.
  */
 public AdvertisementMessage advertise(Advertisement adv, String brokerURI)
     throws ClientException {
   if (!isConnected()) throw new ClientException("Not connected to any broker");
   try {
     if (brokerURI == null || brokerURI.equals("")) brokerURI = defaultBrokerAddress.getNodeURI();
     BrokerState brokerState = getBrokerState(brokerURI);
     if (brokerState == null) {
       throw new ClientException("Not connected to broker " + brokerURI);
     }
     MessageDestination clientDest =
         MessageDestination.formatClientDestination(
             clientID, brokerState.getBrokerAddress().getNodeURI());
     AdvertisementMessage advMsg =
         new AdvertisementMessage(
             adv, getNextMessageID(brokerState.getBrokerAddress().getNodeURI()), clientDest);
     String msgID = brokerState.getMsgSender().send(advMsg, HostType.CLIENT);
     advMsg.setMessageID(msgID);
     if (clientConfig.detailState) brokerState.addAdvMsg(advMsg);
     return advMsg;
   } catch (CommunicationException e) {
     throw new ClientException(e.getMessage());
   }
 }