if (null != this.msgHandler) {
throw new AlreadyStartDeliveryException("A message handler " + msgHandler
+ " has been started for " + topicSubscriber);
}
if (null != messageHandler && messageHandler instanceof FilterableMessageHandler) {
FilterableMessageHandler filterMsgHandler =
(FilterableMessageHandler) messageHandler;
if (filterMsgHandler.hasMessageFilter()) {
if (null == preferences) {
// no preferences means talking to an old version hub server
logger.warn("Start delivering messages with filter but no subscription "
+ "preferences found. It might due to talking to an old version"
+ " hub server.");
// use the original message handler.
messageHandler = filterMsgHandler.getMessageHandler();
} else {
// pass subscription preferences to message filter
if (logger.isDebugEnabled()) {
logger.debug("Start delivering messages with filter on {}, preferences: {}",
va(topicSubscriber,
SubscriptionStateUtils.toString(preferences)));
}
ClientMessageFilter msgFilter = filterMsgHandler.getMessageFilter();
msgFilter.setSubscriptionPreferences(topicSubscriber.getTopic(),
topicSubscriber.getSubscriberId(),
preferences);
}
}