Search in sources :

Example 1 with UniqueIdentifierGenerator

use of org.openremote.container.util.UniqueIdentifierGenerator in project openremote by openremote.

the class MQTTProtocol method doCreateIoClient.

@Override
protected MQTT_IOClient doCreateIoClient() throws Exception {
    String host = agent.getHost().orElse(null);
    int port = agent.getPort().orElseGet(() -> {
        if (agent.isSecureMode().orElse(false)) {
            return agent.isWebsocketMode().orElse(false) ? 443 : 8883;
        } else {
            return agent.isWebsocketMode().orElse(false) ? 80 : 1883;
        }
    });
    URI websocketURI = null;
    if (agent.isWebsocketMode().orElse(false)) {
        URIBuilder builder = new URIBuilder().setHost(host).setPort(port);
        agent.getWebsocketPath().ifPresent(builder::setPath);
        agent.getWebsocketQuery().map(query -> query.startsWith("?") ? query.substring(1) : query).ifPresent(builder::setCustomQuery);
        websocketURI = builder.build();
    }
    return new MQTT_IOClient(agent.getClientId().orElseGet(UniqueIdentifierGenerator::generateId), host, port, agent.isSecureMode().orElse(false), !agent.isResumeSession().orElse(false), agent.getUsernamePassword().orElse(null), websocketURI);
}
Also used : AttributeState(org.openremote.model.attribute.AttributeState) URIBuilder(org.apache.http.client.utils.URIBuilder) AttributeRef(org.openremote.model.attribute.AttributeRef) HashMap(java.util.HashMap) ValueUtil(org.openremote.model.util.ValueUtil) Logger(java.util.logging.Logger) PROTOCOL(org.openremote.model.syslog.SyslogCategory.PROTOCOL) Consumer(java.util.function.Consumer) UniqueIdentifierGenerator(org.openremote.container.util.UniqueIdentifierGenerator) Attribute(org.openremote.model.attribute.Attribute) AttributeEvent(org.openremote.model.attribute.AttributeEvent) Map(java.util.Map) Optional(java.util.Optional) SyslogCategory(org.openremote.model.syslog.SyslogCategory) URI(java.net.URI) URI(java.net.URI) URIBuilder(org.apache.http.client.utils.URIBuilder)

Aggregations

URI (java.net.URI)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Logger (java.util.logging.Logger)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 UniqueIdentifierGenerator (org.openremote.container.util.UniqueIdentifierGenerator)1 Attribute (org.openremote.model.attribute.Attribute)1 AttributeEvent (org.openremote.model.attribute.AttributeEvent)1 AttributeRef (org.openremote.model.attribute.AttributeRef)1 AttributeState (org.openremote.model.attribute.AttributeState)1 SyslogCategory (org.openremote.model.syslog.SyslogCategory)1 PROTOCOL (org.openremote.model.syslog.SyslogCategory.PROTOCOL)1 ValueUtil (org.openremote.model.util.ValueUtil)1