-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6eacffa
commit f7f54ce
Showing
3 changed files
with
184 additions
and
170 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
hivemq-edge/src/main/java/com/hivemq/protocols/PollingContextWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.hivemq.protocols; | ||
|
||
import com.hivemq.adapter.sdk.api.config.MessageHandlingOptions; | ||
import com.hivemq.adapter.sdk.api.config.MqttUserProperty; | ||
import com.hivemq.adapter.sdk.api.config.PollingContext; | ||
import com.hivemq.persistence.mappings.NorthboundMapping; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
class PollingContextWrapper implements PollingContext { | ||
private final @NotNull String topic; | ||
private final @NotNull String tagName; | ||
private final @NotNull MessageHandlingOptions messageHandlingOptions; | ||
private final boolean includeTagNames; | ||
private final boolean includeTimestamp; | ||
private final @NotNull List<MqttUserProperty> userProperties; | ||
private final int maxQoS; | ||
private final long messageExpiryInterval; | ||
|
||
public PollingContextWrapper( | ||
final String topic, | ||
final String tagName, | ||
final MessageHandlingOptions messageHandlingOptions, | ||
final boolean includeTagNames, | ||
final boolean includeTimestamp, | ||
final List<MqttUserProperty> userProperties, | ||
final int maxQoS, | ||
final long messageExpiryInterval) { | ||
this.topic = topic; | ||
this.tagName = tagName; | ||
this.messageHandlingOptions = messageHandlingOptions; | ||
this.includeTagNames = includeTagNames; | ||
this.includeTimestamp = includeTimestamp; | ||
this.userProperties = userProperties; | ||
this.maxQoS = maxQoS; | ||
this.messageExpiryInterval = messageExpiryInterval; | ||
} | ||
|
||
@Override | ||
public @NotNull String getMqttTopic() { | ||
return topic; | ||
} | ||
|
||
@Override | ||
public @NotNull String getTagName() { | ||
return tagName; | ||
} | ||
|
||
@Override | ||
public int getMqttQos() { | ||
return maxQoS; | ||
} | ||
|
||
@Override | ||
public @NotNull MessageHandlingOptions getMessageHandlingOptions() { | ||
return messageHandlingOptions; | ||
} | ||
|
||
@Override | ||
public @NotNull Boolean getIncludeTimestamp() { | ||
return includeTimestamp; | ||
} | ||
|
||
@Override | ||
public @NotNull Boolean getIncludeTagNames() { | ||
return includeTagNames; | ||
} | ||
|
||
@Override | ||
public @NotNull List<MqttUserProperty> getUserProperties() { | ||
return userProperties; | ||
} | ||
|
||
@Override | ||
public @Nullable Long getMessageExpiryInterval() { | ||
return messageExpiryInterval; | ||
} | ||
|
||
public static @NotNull PollingContextWrapper from(final NorthboundMapping northboundMapping) { | ||
return new PollingContextWrapper(northboundMapping.getMqttTopic(), | ||
northboundMapping.getTagName(), | ||
northboundMapping.getMessageHandlingOptions(), | ||
northboundMapping.getIncludeTagNames(), | ||
northboundMapping.getIncludeTimestamp(), | ||
List.copyOf(northboundMapping.getUserProperties()), | ||
northboundMapping.getMqttQos(), | ||
northboundMapping.getMessageExpiryInterval()); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterInputImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.hivemq.protocols; | ||
|
||
import com.hivemq.adapter.sdk.api.config.PollingContext; | ||
import com.hivemq.adapter.sdk.api.config.ProtocolSpecificAdapterConfig; | ||
import com.hivemq.adapter.sdk.api.factories.AdapterFactories; | ||
import com.hivemq.adapter.sdk.api.model.ProtocolAdapterInput; | ||
import com.hivemq.adapter.sdk.api.services.ModuleServices; | ||
import com.hivemq.adapter.sdk.api.services.ProtocolAdapterMetricsService; | ||
import com.hivemq.adapter.sdk.api.state.ProtocolAdapterState; | ||
import com.hivemq.adapter.sdk.api.tag.Tag; | ||
import com.hivemq.edge.modules.adapters.impl.factories.AdapterFactoriesImpl; | ||
import com.hivemq.persistence.mappings.NorthboundMapping; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class ProtocolAdapterInputImpl<T extends ProtocolSpecificAdapterConfig> implements ProtocolAdapterInput<T> { | ||
public static final AdapterFactoriesImpl ADAPTER_FACTORIES = new AdapterFactoriesImpl(); | ||
private final String adapterId; | ||
private final @NotNull T configObject; | ||
private final @NotNull String version; | ||
private final @NotNull ProtocolAdapterState protocolAdapterState; | ||
private final @NotNull ModuleServices moduleServices; | ||
private final @NotNull ProtocolAdapterMetricsService protocolAdapterMetricsService; | ||
private final @NotNull List<Tag> tags; | ||
private final @NotNull List<PollingContext> pollingContexts; | ||
|
||
public ProtocolAdapterInputImpl( | ||
final @NotNull String adapterId, | ||
final @NotNull T configObject, | ||
final @NotNull List<Tag> tags, | ||
final @NotNull List<NorthboundMapping> northboundMappings, | ||
final @NotNull String version, | ||
final @NotNull ProtocolAdapterState protocolAdapterState, | ||
final @NotNull ModuleServices moduleServices, | ||
final @NotNull ProtocolAdapterMetricsService protocolAdapterMetricsService) { | ||
this.adapterId = adapterId; | ||
this.configObject = configObject; | ||
this.version = version; | ||
this.protocolAdapterState = protocolAdapterState; | ||
this.moduleServices = moduleServices; | ||
this.protocolAdapterMetricsService = protocolAdapterMetricsService; | ||
this.tags = tags; | ||
this.pollingContexts = | ||
northboundMappings.stream().map(PollingContextWrapper::from).collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public @NotNull String getAdapterId() { | ||
return adapterId; | ||
} | ||
|
||
@Override | ||
public @NotNull T getConfig() { | ||
return configObject; | ||
} | ||
|
||
@Override | ||
public @NotNull String getVersion() { | ||
return version; | ||
} | ||
|
||
@Override | ||
public @NotNull ProtocolAdapterState getProtocolAdapterState() { | ||
return protocolAdapterState; | ||
} | ||
|
||
@Override | ||
public @NotNull ModuleServices moduleServices() { | ||
return moduleServices; | ||
} | ||
|
||
@Override | ||
public @NotNull AdapterFactories adapterFactories() { | ||
return ADAPTER_FACTORIES; | ||
} | ||
|
||
@Override | ||
public @NotNull ProtocolAdapterMetricsService getProtocolAdapterMetricsHelper() { | ||
return protocolAdapterMetricsService; | ||
} | ||
|
||
@Override | ||
public @NotNull List<Tag> getTags() { | ||
return tags; | ||
} | ||
|
||
@Override | ||
public @NotNull List<PollingContext> getPollingContexts() { | ||
return pollingContexts; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters