private void restoreConnection(@Nullable final Connection theConnection) { connection = theConnection; if (theConnection != null) { signalFilter = new SignalFilter(theConnection); } }
private boolean isTargetSubscribedForTopic(final Target target, final Signal<?> signal) { return target.getTopics().stream() .filter(applyTopicFilter(signal)) .filter(applyRqlFilter(signal)) .anyMatch(applyNamespaceFilter(signal)); }
/** * Filters the passed {@code signal} by extracting those {@link Target}s which should receive the signal. * * @param signal the signal to filter / determine the {@link Target}s for * @return the determined Targets for the passed in {@code signal} * @throws org.eclipse.ditto.model.base.exceptions.InvalidRqlExpressionException if the optional filter string of a Target * cannot be mapped to a valid criterion */ Set<Target> filter(final Signal<?> signal) { return connection.getTargets().stream() .filter(t -> isTargetAuthorized(t, signal)) // this is cheaper, so check this first .filter(t -> isTargetSubscribedForTopic(t, signal)) .collect(Collectors.toSet()); }
private Predicate<FilteredTopic> applyRqlFilter(final Signal<?> signal) { return t -> !t.hasFilter() || t.getFilter().filter(f -> matchesFilter(f, signal)).isPresent(); }
private static Predicate<FilteredTopic> applyNamespaceFilter(final WithId signal) { return t -> t.getNamespaces().isEmpty() || t.getNamespaces().contains(namespaceFromId(signal)); }
private static Optional<Topic> topicFromSignal(final Signal<?> signal) { // only things as group supported final TopicPath.Group group = signal instanceof WithThingId ? TopicPath.Group.THINGS : null; final TopicPath.Channel channel = signal.getDittoHeaders() .getChannel() .flatMap(TopicPath.Channel::forName) .orElse(TopicPath.Channel.TWIN); final TopicPath.Criterion criterion = getCriterionOfSignal(signal); if (TopicPath.Group.THINGS.equals(group)) { if (TopicPath.Channel.TWIN.equals(channel)) { if (EVENTS.equals(criterion)) { return Optional.of(Topic.TWIN_EVENTS); } } else if (TopicPath.Channel.LIVE.equals(channel) && criterion != null) { switch (criterion) { case COMMANDS: return Optional.of(Topic.LIVE_COMMANDS); case EVENTS: return Optional.of(Topic.LIVE_EVENTS); case MESSAGES: return Optional.of(Topic.LIVE_MESSAGES); default: return Optional.empty(); } } } return Optional.empty(); }
final Set<Target> subscribedAndAuthorizedTargets = signalFilter.filter(signal); if (subscribedAndAuthorizedTargets.isEmpty()) { log.debug("Signal dropped: No subscribed and authorized targets present");
private Predicate<FilteredTopic> applyRqlFilter(final Signal<?> signal) { return t -> !t.hasFilter() || t.getFilter().filter(f -> matchesFilter(f, signal)).isPresent(); }
private static Predicate<FilteredTopic> applyNamespaceFilter(final WithId signal) { return t -> t.getNamespaces().isEmpty() || t.getNamespaces().contains(namespaceFromId(signal)); }
private static Optional<Topic> topicFromSignal(final Signal<?> signal) { // only things as group supported final TopicPath.Group group = signal instanceof WithThingId ? TopicPath.Group.THINGS : null; final TopicPath.Channel channel = signal.getDittoHeaders() .getChannel() .flatMap(TopicPath.Channel::forName) .orElse(TopicPath.Channel.TWIN); final TopicPath.Criterion criterion = getCriterionOfSignal(signal); if (TopicPath.Group.THINGS.equals(group)) { if (TopicPath.Channel.TWIN.equals(channel)) { if (EVENTS.equals(criterion)) { return Optional.of(Topic.TWIN_EVENTS); } } else if (TopicPath.Channel.LIVE.equals(channel) && criterion != null) { switch (criterion) { case COMMANDS: return Optional.of(Topic.LIVE_COMMANDS); case EVENTS: return Optional.of(Topic.LIVE_EVENTS); case MESSAGES: return Optional.of(Topic.LIVE_MESSAGES); default: return Optional.empty(); } } } return Optional.empty(); }
final Set<Target> subscribedAndAuthorizedTargets = signalFilter.filter(signal); if (subscribedAndAuthorizedTargets.isEmpty()) { log.debug("Signal dropped: No subscribed and authorized targets present");
private boolean isTargetSubscribedForTopic(final Target target, final Signal<?> signal) { return target.getTopics().stream() .filter(applyTopicFilter(signal)) .filter(applyRqlFilter(signal)) .anyMatch(applyNamespaceFilter(signal)); }
/** * Filters the passed {@code signal} by extracting those {@link Target}s which should receive the signal. * * @param signal the signal to filter / determine the {@link Target}s for * @return the determined Targets for the passed in {@code signal} * @throws org.eclipse.ditto.model.base.exceptions.InvalidRqlExpressionException if the optional filter string of a Target * cannot be mapped to a valid criterion */ Set<Target> filter(final Signal<?> signal) { return connection.getTargets().stream() .filter(t -> isTargetAuthorized(t, signal)) // this is cheaper, so check this first .filter(t -> isTargetSubscribedForTopic(t, signal)) .collect(Collectors.toSet()); }
private void restoreConnection(@Nullable final Connection theConnection) { connection = theConnection; if (theConnection != null) { signalFilter = new SignalFilter(theConnection); } }