com.aol.micro.server.application.registry.Finder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micro-application-register Show documentation
Show all versions of micro-application-register Show documentation
Opinionated rest microservices
package com.aol.micro.server.application.registry;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import org.apache.commons.io.FileUtils;
import org.pcollections.ConsPStack;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.aol.micro.server.rest.jackson.JacksonUtil;
@Component
public class Finder {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final RegisterConfig config;
@Autowired
public Finder(RegisterConfig config) {
this.config = config;
}
public List find() {
return findDir(new File(config.getOutputDir()));
}
private List findDir(File dir) {
List result = new ArrayList<>();
Stream.of(dir.listFiles()).forEach(
(next) -> {
if (next.isDirectory())
result.addAll(findDir(next));
if (next.isFile()) {
try {
String fileString = FileUtils.readFileToString(next);
result.add(JacksonUtil.convertFromJson(fileString, RegisterEntry.class));
} catch (Exception e) {
logger.error("Error loading service entry from disk {}", e,
next.getAbsolutePath());
}
}
});
return ConsPStack.from(result);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy