Skip to content

Commit

Permalink
Merge pull request #15 from netifi/feature/tagging-config
Browse files Browse the repository at this point in the history
Feature/tagging config
  • Loading branch information
kbahr authored Aug 19, 2019
2 parents 475d60e + 563f75b commit c9b3a16
Showing 1 changed file with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
* Gets current default configuration for {@link BrokerClient.Builder}. Can be overriden with System
Expand Down Expand Up @@ -148,27 +148,16 @@ static short getAdditionalConnectionFlags() {
static Tags getTags() {
Tags tags = Tags.empty();
try {
Stream<Tag> stream =
conf.getObject("netifi.client.tags")
.entrySet()
.stream()
.map(
e -> {
String key = e.getKey();
ConfigValue configValue = e.getValue();
if (configValue.valueType() == ConfigValueType.STRING) {
String value = (String) configValue.unwrapped();
if (value.isEmpty()) {
throw new IllegalArgumentException("Tag mapping " + key + " is empty");
}
return Tag.of(key, value);
}
throw new IllegalArgumentException(
"Tag mapping " + key + " is not a string: " + configValue);
});
tags = Tags.of(stream::iterator);
} catch (ConfigException.Missing m) {

Arrays.stream(conf.getString("netifi.client.tags").split(","))
.forEach(
s -> {
String[] t = s.split(":");
Tag tag = Tag.of(t[0], t[1]);
tags.and(tag);
});

} catch (Throwable t) {
System.err.println("error parsing tags from config: " + t.getMessage());
}

return tags;
Expand Down

0 comments on commit c9b3a16

Please sign in to comment.