/** * Creates a new {@link MqttTarget} with MQTT specific configuration. * * @param target the delegate target * @param qos the target qos value * @return the created {@link Target} */ public static MqttTarget newMqttTarget(final Target target, final int qos) { return new ImmutableMqttTarget(target, qos); }
@Test public void fromJsonReturnsExpected() { final Target actual = ImmutableMqttTarget.fromJson(TARGET_JSON); assertThat(actual).isEqualTo(TARGET); }
/** * Creates a new {@code Target} object from the specified JSON object. Decides which specific {@link Target} * implementation to choose depending on the given {@link ConnectionType}. * * @param jsonObject a JSON object which provides the data for the Target to be created. * @param type the connection type required to decide which iplementation of {@link Source} to choose * @return a new Source Target is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static Target targetFromJson(final JsonObject jsonObject, final ConnectionType type) { switch (type) { case AMQP_091: case AMQP_10: return ImmutableTarget.fromJson(jsonObject); case MQTT: return ImmutableMqttTarget.fromJson(jsonObject); default: throw ConnectionConfigurationInvalidException .newBuilder("Unexpected connection type <" + type + ">") .build(); } }
/** * Creates a new {@code Target} object from the specified JSON object. Decides which specific {@link Target} * implementation to choose depending on the given {@link ConnectionType}. * * @param jsonObject a JSON object which provides the data for the Target to be created. * @param type the connection type required to decide which iplementation of {@link Source} to choose * @return a new Source Target is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static Target targetFromJson(final JsonObject jsonObject, final ConnectionType type) { switch (type) { case AMQP_091: case AMQP_10: return ImmutableTarget.fromJson(jsonObject); case MQTT: return ImmutableMqttTarget.fromJson(jsonObject); default: throw ConnectionConfigurationInvalidException .newBuilder("Unexpected connection type <" + type + ">") .build(); } }
/** * Creates a new {@link MqttTarget} with MQTT specific configuration. * * @param target the delegate target * @param qos the target qos value * @return the created {@link Target} */ public static MqttTarget newMqttTarget(final Target target, final int qos) { return new ImmutableMqttTarget(target, qos); }
@Override public Target withAddress(final String newAddress) { return new ImmutableMqttTarget(delegate.withAddress(newAddress), qos); }
@Override public Target withAddress(final String newAddress) { return new ImmutableMqttTarget(delegate.withAddress(newAddress), qos); }
/** * Creates a new {@link MqttTarget} with MQTT specific configuration. * * @param address the address where the signals will be published * @param authorizationContext the authorization context of the new {@link Target} * @param qos the target qos value * @param requiredTopic the required topic that should be published via this target * @param additionalTopics additional set of topics that should be published via this target * @return the created {@link Target} */ public static MqttTarget newMqttTarget(final String address, final AuthorizationContext authorizationContext, final int qos, final Topic requiredTopic, final Topic... additionalTopics) { final HashSet<Topic> topics = new HashSet<>(Collections.singletonList(requiredTopic)); topics.addAll(Arrays.asList(additionalTopics)); final Target target = newTarget(address, authorizationContext, null, topics.stream() .map(ConnectivityModelFactory::newFilteredTopic) .collect(Collectors.toSet())); return new ImmutableMqttTarget(target, qos); }
/** * Creates a new {@code Source} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the Source to be created. * @return a new Source which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static Target fromJson(final JsonObject jsonObject) { final Target target = ImmutableTarget.fromJson(jsonObject); final int readQos = jsonObject.getValue(MqttTarget.JsonFields.QOS).orElse(DEFAULT_QOS); return new ImmutableMqttTarget(target, readQos); }
/** * Creates a new {@link MqttTarget} with MQTT specific configuration. * * @param address the address where the signals will be published * @param authorizationContext the authorization context of the new {@link Target} * @param qos the target qos value * @param requiredTopic the required topic that should be published via this target * @param additionalTopics additional set of topics that should be published via this target * @return the created {@link Target} */ public static MqttTarget newMqttTarget(final String address, final AuthorizationContext authorizationContext, final int qos, final Topic requiredTopic, final Topic... additionalTopics) { final HashSet<Topic> topics = new HashSet<>(Collections.singletonList(requiredTopic)); topics.addAll(Arrays.asList(additionalTopics)); final Target target = newTarget(address, authorizationContext, null, topics.stream() .map(ConnectivityModelFactory::newFilteredTopic) .collect(Collectors.toSet())); return new ImmutableMqttTarget(target, qos); }
/** * Creates a new {@code Source} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the Source to be created. * @return a new Source which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static Target fromJson(final JsonObject jsonObject) { final Target target = ImmutableTarget.fromJson(jsonObject); final int readQos = jsonObject.getValue(MqttTarget.JsonFields.QOS).orElse(DEFAULT_QOS); return new ImmutableMqttTarget(target, readQos); }