private static Connection validateConnection(final Connection connection) { // the target addresses must have the format exchange/routingKey for RabbitMQ connection.getTargets() .stream() .map(Target::getAddress) .forEach(RabbitMQTarget::fromTargetAddress); return connection; }
private static Connection validateConnection(final Connection connection) { // the target addresses must have the format exchange/routingKey for RabbitMQ connection.getTargets() .stream() .map(Target::getAddress) .forEach(RabbitMQTarget::fromTargetAddress); return connection; }
/** * @return the targets configured for this connection or an empty set if no targets were configured. */ protected final Set<Target> getTargetsOrEmptySet() { return connection().getTargets(); }
/** * @return the targets configured for this connection or an empty set if no targets were configured. */ protected final Set<Target> getTargetsOrEmptySet() { return connection().getTargets(); }
/** * @return whether this client is publishing at all */ protected final boolean isPublishing() { return !connection().getTargets().isEmpty(); }
/** * @return whether this client is publishing at all */ protected final boolean isPublishing() { return !connection().getTargets().isEmpty(); }
/** * 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()); }
/** * 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 static void validateAddresses(final Connection connection, final DittoHeaders dittoHeaders) { connection.getSources() .stream() .flatMap(source -> source.getAddresses().stream()) .forEach(a -> validateAddress(a, true, dittoHeaders)); // no wildcards allowed for publish targets connection.getTargets() .stream() .map(Target::getAddress) .forEach(a -> validateAddress(a, false, dittoHeaders)); }
/** * Validate protocol-specific configurations of targets. * * @param connection the connection to check. * @param dittoHeaders headers of the command that triggered the connection validation. */ protected void validateTargetConfigs(final Connection connection, final DittoHeaders dittoHeaders) { connection.getTargets().forEach(target -> validateTarget(target, dittoHeaders, targetDescription(target, connection))); }
private static void validateAddresses(final Connection connection, final DittoHeaders dittoHeaders) { connection.getSources() .stream() .flatMap(source -> source.getAddresses().stream()) .forEach(a -> validateAddress(a, true, dittoHeaders)); // no wildcards allowed for publish targets connection.getTargets() .stream() .map(Target::getAddress) .forEach(a -> validateAddress(a, false, dittoHeaders)); }
/** * Validate protocol-specific configurations of targets. * * @param connection the connection to check. * @param dittoHeaders headers of the command that triggered the connection validation. */ protected void validateTargetConfigs(final Connection connection, final DittoHeaders dittoHeaders) { connection.getTargets().forEach(target -> validateTarget(target, dittoHeaders, targetDescription(target, connection))); }
private void subscribeForEvents() { checkConnectionNotNull(); // unsubscribe to previously subscribed topics unsubscribeFromEvents(); uniqueTopics = connection.getTargets().stream() .flatMap(target -> target.getTopics().stream().map(FilteredTopic::getTopic)) .collect(Collectors.toSet()); forEachPubSubTopicDo(pubSubTopic -> { final DistributedPubSubMediator.Subscribe subscribe = new DistributedPubSubMediator.Subscribe(pubSubTopic, PUB_SUB_GROUP_PREFIX + connectionId, getSelf()); log.debug("Subscribing to pub-sub topic <{}> for connection <{}>.", pubSubTopic, connectionId); pubSubMediator.tell(subscribe, getSelf()); }); }
private void subscribeForEvents() { checkConnectionNotNull(); // unsubscribe to previously subscribed topics unsubscribeFromEvents(); uniqueTopics = connection.getTargets().stream() .flatMap(target -> target.getTopics().stream().map(FilteredTopic::getTopic)) .collect(Collectors.toSet()); forEachPubSubTopicDo(pubSubTopic -> { final DistributedPubSubMediator.Subscribe subscribe = new DistributedPubSubMediator.Subscribe(pubSubTopic, PUB_SUB_GROUP_PREFIX + connectionId, getSelf()); log.debug("Subscribing to pub-sub topic <{}> for connection <{}>.", pubSubTopic, connectionId); pubSubMediator.tell(subscribe, getSelf()); }); }
private void validateSourceAndTargetAddressesAreNonempty(final Connection connection, final DittoHeaders dittoHeaders) { connection.getSources().forEach(source -> { if (source.getAddresses().isEmpty() || source.getAddresses().contains("")) { final String location = String.format("Source %d of connection <%s>", source.getIndex(), connection.getId()); throw emptyAddressesError(location, dittoHeaders); } }); connection.getTargets().forEach(target -> { if (target.getAddress().isEmpty()) { final String location = String.format("Targets of connection <%s>", connection.getId()); throw emptyAddressesError(location, dittoHeaders); } target.getTopics().forEach(topic -> topic.getFilter().ifPresent(filter -> { // will throw an InvalidRqlExpressionException if the RQL expression was not valid: queryFilterCriteriaFactory.filterCriteria(filter, dittoHeaders); })); }); }
private void validateSourceAndTargetAddressesAreNonempty(final Connection connection, final DittoHeaders dittoHeaders) { connection.getSources().forEach(source -> { if (source.getAddresses().isEmpty() || source.getAddresses().contains("")) { final String location = String.format("Source %d of connection <%s>", source.getIndex(), connection.getId()); throw emptyAddressesError(location, dittoHeaders); } }); connection.getTargets().forEach(target -> { if (target.getAddress().isEmpty()) { final String location = String.format("Targets of connection <%s>", connection.getId()); throw emptyAddressesError(location, dittoHeaders); } target.getTopics().forEach(topic -> topic.getFilter().ifPresent(filter -> { // will throw an InvalidRqlExpressionException if the RQL expression was not valid: queryFilterCriteriaFactory.filterCriteria(filter, dittoHeaders); })); }); }
/** * Returns a new {@code ConnectionBuilder} object. * * @param connection the connection to use for initializing the builder. * @return new instance of {@code ImmutableConnectionBuilder}. * @throws NullPointerException if {@code connection} is {@code null}. */ public static ConnectionBuilder getBuilder(final Connection connection) { checkNotNull(connection, "Connection"); return new Builder(connection.getConnectionType()) .id(connection.getId()) .connectionStatus(connection.getConnectionStatus()) .credentials(connection.getCredentials().orElse(null)) .uri(connection.getUri()) .trustedCertificates(connection.getTrustedCertificates().orElse(null)) .failoverEnabled(connection.isFailoverEnabled()) .validateCertificate(connection.isValidateCertificates()) .processorPoolSize(connection.getProcessorPoolSize()) .sources(connection.getSources()) .targets(connection.getTargets()) .clientCount(connection.getClientCount()) .specificConfig(connection.getSpecificConfig()) .mappingContext(connection.getMappingContext().orElse(null)) .name(connection.getName().orElse(null)) .tags(connection.getTags()); }
/** * Returns a new {@code ConnectionBuilder} object. * * @param connection the connection to use for initializing the builder. * @return new instance of {@code ImmutableConnectionBuilder}. * @throws NullPointerException if {@code connection} is {@code null}. */ public static ConnectionBuilder getBuilder(final Connection connection) { checkNotNull(connection, "Connection"); return new Builder(connection.getConnectionType()) .id(connection.getId()) .connectionStatus(connection.getConnectionStatus()) .credentials(connection.getCredentials().orElse(null)) .uri(connection.getUri()) .trustedCertificates(connection.getTrustedCertificates().orElse(null)) .failoverEnabled(connection.isFailoverEnabled()) .validateCertificate(connection.isValidateCertificates()) .processorPoolSize(connection.getProcessorPoolSize()) .sources(connection.getSources()) .targets(connection.getTargets()) .clientCount(connection.getClientCount()) .specificConfig(connection.getSpecificConfig()) .mappingContext(connection.getMappingContext().orElse(null)) .name(connection.getName().orElse(null)) .tags(connection.getTags()); }