Fix startup issue.

This commit is contained in:
wusheng 2017-03-24 17:00:52 +08:00
parent c16d7b8bde
commit 26841dfc75
1 changed files with 12 additions and 6 deletions

View File

@ -21,6 +21,7 @@ public enum ServiceManager {
public void boot() {
bootedServices = loadAllServices();
startup();
}
private Map<Class, BootService> loadAllServices() {
@ -28,16 +29,21 @@ public enum ServiceManager {
Iterator<BootService> serviceIterator = load().iterator();
while (serviceIterator.hasNext()) {
BootService bootService = serviceIterator.next();
try {
bootService.bootUp();
bootedServices.put(bootService.getClass(), bootService);
} catch (Throwable e) {
logger.error(e, "ServiceManager try to start [{}] fail.", bootService.getClass().getName());
}
bootedServices.put(bootService.getClass(), bootService);
}
return bootedServices;
}
private void startup() {
for (BootService service : bootedServices.values()) {
try {
service.bootUp();
} catch (Throwable e) {
logger.error(e, "ServiceManager try to start [{}] fail.", service.getClass().getName());
}
}
}
/**
* Find a {@link BootService} implementation, which is already started.
*