import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
private EtcdData(final Class> clazz) {
this.clazz = clazz;
this.logger = Annal.get(clazz);
// Read configuration
final JsonObject config = NODE.read();
if (config.containsKey(KEY)) {
final JsonObject root = config.getJsonObject(KEY);
// Verify the data
Fn.flingUp(() -> Fn.shuntZero(() -> Ruler.verify(KEY, root), root),
LOGGER);
if (root.containsKey(TIMEOUT)) {
this.timeout = root.getLong(TIMEOUT);
}
if (root.containsKey(MICRO)) {
this.application = root.getString(MICRO);
}
// Nodes
if (root.containsKey(NODES)) {
this.config.addAll(root.getJsonArray(NODES));
}
LOGGER.info(Info.ETCD_TIMEOUT,
this.application, this.timeout, this.config.size());
}
Fn.flingUp(this.config.isEmpty(), this.logger,
EtcdConfigEmptyException.class, this.clazz);
final Set uris = new HashSet<>();
final ConcurrentMap networks
= new ConcurrentHashMap<>();
Observable.fromIterable(this.config)
.filter(Objects::nonNull)
.map(item -> (JsonObject) item)
.filter(item -> item.containsKey(PORT) && item.containsKey(HOST))
.map(item -> {
final Integer port = item.getInteger(PORT);
final String host = item.getString(HOST);
networks.put(port, host);
return "http://" + host + ":" + port;
})
.map(URI::create)
.subscribe(uris::add);
// Network checking
networks.forEach((port, host) ->
Fn.flingUp(!Net.isReach(host, port), LOGGER,
EtcdNetworkException.class, getClass(), host, port));
LOGGER.info(Info.ETCD_NETWORK);
this.client = new EtcdClient(uris.toArray(new URI[]{}));
}