-
Notifications
You must be signed in to change notification settings - Fork 216
/
DefaultHonoConnectionFactory.java
87 lines (71 loc) · 2.69 KB
/
DefaultHonoConnectionFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.connectivity.service.messaging.hono;
import java.net.URI;
import java.text.MessageFormat;
import java.util.Set;
import org.eclipse.ditto.connectivity.model.HonoAddressAlias;
import org.eclipse.ditto.connectivity.model.UserPasswordCredentials;
import org.eclipse.ditto.connectivity.service.config.DefaultHonoConfig;
import org.eclipse.ditto.connectivity.service.config.HonoConfig;
import com.typesafe.config.Config;
import akka.actor.ActorSystem;
/**
* Default implementation of {@link HonoConnectionFactory}.
* This implementation uses {@link HonoConfig} to obtain the required properties for creating the Hono connection.
*/
public final class DefaultHonoConnectionFactory extends HonoConnectionFactory {
private final HonoConfig honoConfig;
/**
* Constructs a {@code DefaultHonoConnectionFactory} for the specified arguments.
*
* @param actorSystem the actor system in which to load the factory.
* @param config configuration properties for this factory.
* @throws NullPointerException if {@code actorSystem} is {@code null}.
*/
public DefaultHonoConnectionFactory(final ActorSystem actorSystem, final Config config) {
honoConfig = new DefaultHonoConfig(actorSystem);
}
@Override
public URI getBaseUri() {
return honoConfig.getBaseUri();
}
@Override
public boolean isValidateCertificates() {
return honoConfig.isValidateCertificates();
}
@Override
public HonoConfig.SaslMechanism getSaslMechanism() {
return honoConfig.getSaslMechanism();
}
@Override
public Set<URI> getBootstrapServerUris() {
return honoConfig.getBootstrapServerUris();
}
@Override
protected String getGroupId(final String suffix) {
return suffix;
}
@Override
protected UserPasswordCredentials getCredentials() {
return honoConfig.getUserPasswordCredentials();
}
@Override
protected String resolveSourceAddress(final HonoAddressAlias honoAddressAlias) {
return MessageFormat.format("hono.{0}", honoAddressAlias.getAliasValue());
}
@Override
protected String resolveTargetAddress(final HonoAddressAlias honoAddressAlias) {
return MessageFormat.format("hono.{0}/'{{thing:id}}'", honoAddressAlias.getAliasValue());
}
}