public void run()

in src/main/java/org/apache/sling/discovery/commons/providers/spi/base/AbstractServiceWithBackgroundCheck.java [75:129]


        public void run() {
            logger.debug("backgroundCheck.run: start");
            long start = System.currentTimeMillis();
            try{
                while(!cancelled()) {
                    if (check.check()) {
                        if (callback != null) {
                            callback.run();
                        }
                        return;
                    }
                    if (timeoutMillis != -1 && 
                            (System.currentTimeMillis() > start + timeoutMillis)) {
                        if (callback == null) {
                            logSilencer.infoOrDebug("backgroundCheck.run", "backgroundCheck.run: timeout hit (no callback to invoke)");
                        } else {
                            logSilencer.infoOrDebug("backgroundCheck.run", "backgroundCheck.run: timeout hit, invoking callback.");
                            callback.run();
                        }
                        return;
                    }
                    logger.trace("backgroundCheck.run: waiting another sec.");
                    synchronized(waitObj) {
                        waitCnt++;
                        try {
                            waitObj.notify();
                            waitObj.wait(waitInterval);
                        } catch (InterruptedException e) {
                            logger.debug("backgroundCheck.run: got interrupted");
                        }
                    }
                }
                logger.debug("backgroundCheck.run: this run got cancelled. {}", check);
            } catch(RuntimeException re) {
                logger.error("backgroundCheck.run: RuntimeException: "+re, re);
                // nevertheless calling runnable.run in this case
                if (callback != null) {
                    logger.info("backgroundCheck.run: RuntimeException -> invoking callback");
                    callback.run();
                }
                throw re;
            } catch(Error er) {
                logger.error("backgroundCheck.run: Error: "+er, er);
                // not calling runnable.run in this case!
                // since Error is typically severe
                logger.info("backgroundCheck.run: NOT invoking callback");
                throw er;
            } finally {
                logger.debug("backgroundCheck.run: end");
                synchronized(waitObj) {
                    done = true;
                    waitObj.notify();
                }
            }
        }