BaseService.java 文件源码

java
阅读 31 收藏 0 点赞 0 评论 0

项目:device-bacnet 作者:
@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);
        }
    } 
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号