Skip to content

Commit 5409194

Browse files
committed
An logging example
Add the example how internal logger can be used. Follows on: #194
1 parent 4cbb457 commit 5409194

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/main/java/org/tarantool/cluster/TarantoolClusterStoredFunctionDiscoverer.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import org.tarantool.TarantoolClient;
44
import org.tarantool.TarantoolClientOps;
55
import org.tarantool.TarantoolClusterClientConfig;
6+
import org.tarantool.logging.Logger;
7+
import org.tarantool.logging.LoggerFactory;
68
import org.tarantool.util.StringUtils;
79

810
import java.util.LinkedHashSet;
911
import java.util.List;
1012
import java.util.Set;
11-
import java.util.stream.Collectors;
1213

1314
/**
1415
* A cluster nodes discoverer based on calling a predefined function
@@ -19,6 +20,8 @@
1920
*/
2021
public class TarantoolClusterStoredFunctionDiscoverer implements TarantoolClusterDiscoverer {
2122

23+
private static final Logger LOGGER = LoggerFactory.getLogger(TarantoolClusterStoredFunctionDiscoverer.class);
24+
2225
private TarantoolClient client;
2326
private String entryFunction;
2427

@@ -57,12 +60,23 @@ private Set<String> checkAndFilterAddresses(List<?> result) {
5760
throw new IllegalDiscoveryFunctionResult("The first value must be an array of strings");
5861
}
5962

60-
return ((List<Object>) result.get(0)).stream()
61-
.filter(item -> item instanceof String)
62-
.map(Object::toString)
63-
.filter(s -> !StringUtils.isBlank(s))
64-
.filter(this::isAddress)
65-
.collect(Collectors.toCollection(LinkedHashSet::new));
63+
LinkedHashSet<String> passed = new LinkedHashSet<>();
64+
LinkedHashSet<String> skipped = new LinkedHashSet<>();
65+
for (Object item : ((List<Object>) result.get(0))) {
66+
if (!(item instanceof String)) {
67+
continue;
68+
}
69+
String s = item.toString();
70+
if (!StringUtils.isBlank(s) && isAddress(s)) {
71+
passed.add(s);
72+
} else {
73+
skipped.add(s);
74+
}
75+
}
76+
if (!skipped.isEmpty()) {
77+
LOGGER.warn("Some of the addresses were skipped because of unsupported format: {0}", skipped);
78+
}
79+
return passed;
6680
}
6781

6882
/**

0 commit comments

Comments
 (0)