コード例 #1
0
  /** Specialized version to publish will testament message. */
  private void forwardPublishWill(WillMessage will, String clientID) {
    // it has just to publish the message downstream to the subscribers
    // NB it's a will publish, it needs a PacketIdentifier for this conn, default to 1
    Integer messageId = null;
    if (will.getQos() != AbstractMessage.QOSType.MOST_ONE) {
      messageId = m_messagesStore.nextPacketID(clientID);
    }

    IMessagesStore.StoredMessage tobeStored = asStoredMessage(will);
    tobeStored.setClientID(clientID);
    tobeStored.setMessageID(messageId);
    route2Subscribers(tobeStored);
  }
コード例 #2
0
  private boolean subscribeSingleTopic(final Subscription newSubscription) {
    subscriptions.add(newSubscription.asClientTopicCouple());

    // scans retained messages to be published to the new subscription
    // TODO this is ugly, it does a linear scan on potential big dataset
    Collection<IMessagesStore.StoredMessage> messages =
        m_messagesStore.searchMatching(
            new IMatchingCondition() {
              public boolean match(String key) {
                return SubscriptionsStore.matchTopics(key, newSubscription.getTopicFilter());
              }
            });

    ClientSession targetSession = m_sessionsStore.sessionForClient(newSubscription.getClientId());
    verifyToActivate(newSubscription.getClientId(), targetSession);
    for (IMessagesStore.StoredMessage storedMsg : messages) {
      // fire the as retained the message
      LOG.debug("send publish message for topic {}", newSubscription.getTopicFilter());
      // forwardPublishQoS0(newSubscription.getClientId(), storedMsg.getTopic(), storedMsg.getQos(),
      // storedMsg.getPayload(), true);
      Integer packetID =
          storedMsg.getQos() == QOSType.MOST_ONE
              ? null
              : m_messagesStore.nextPacketID(newSubscription.getClientId());
      directSend(
          targetSession,
          storedMsg.getTopic(),
          storedMsg.getQos(),
          storedMsg.getPayload(),
          true,
          packetID);
    }

    // notify the Observables
    m_interceptor.notifyTopicSubscribed(newSubscription);
    return true;
  }