@Async
public void attemptToInitialize() {
// count the attempt
setInitAttempts(getInitAttempts() + 1);
logger.debug("initialization attempt " + getInitAttempts());
// first - get the service information or register service with metadata
if (getService() != null) {
// if we were able to get the service data we're registered
setRegistered(true);
// second - invoke any custom initialization method
setInitialized(initialize(getServiceId()));
}
// if both are successful, then we're done
if (isRegistered() && isInitialized()) {
logger.info("initialization successful.");
} else {
// otherwise see if we need to keep going
if ((getInitRetries() == 0) || (getInitAttempts() < getInitRetries())) {
logger.debug("initialization unsuccessful. sleeping " + getInitInterval());
try {
Thread.sleep(getInitInterval());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
// start up the next thread
attemptToInitialize();
} else {
// here, we've failed and run out of retries, so just be done.
logger.info("initialization unsuccessful after " + getInitAttempts()
+ " attempts. Giving up.");
// TODO: what do we do here? exit?
Application.exit(-1);
}
}
}
BaseService.java 文件源码
java
阅读 29
收藏 0
点赞 0
评论 0
项目:device-bluetooth
作者:
评论列表
文章目录