Search in sources :

Example 1 with OakViewChecker

use of org.apache.sling.discovery.oak.pinger.OakViewChecker in project sling by apache.

the class OakVirtualInstanceBuilder method createViewChecker.

@Override
protected ViewChecker createViewChecker() throws Exception {
    getOakViewChecker();
    return new ViewChecker() {

        private final Logger logger = LoggerFactory.getLogger(getClass());

        private SimulatedLease lease = new SimulatedLease(getResourceResolverFactory(), leaseCollection, getSlingId());

        protected void activate(ComponentContext c) throws Throwable {
            OakViewChecker pinger = getOakViewChecker();
            PrivateAccessor.invoke(pinger, "activate", new Class[] { ComponentContext.class }, new Object[] { c });
        }

        @Override
        public void checkView() {
            try {
                lease.updateDescriptor(getConfig());
            } catch (Exception e) {
                logger.error("run: could not update lease: " + e);
            }
        }

        public void run() {
            heartbeatAndCheckView();
        }

        @Override
        public void heartbeatAndCheckView() {
            //                as soon as I see others the descriptor is updated
            try {
                lease.updateLeaseAndDescriptor(getConfig());
            } catch (Exception e) {
                logger.error("run: could not update lease: " + e, e);
            }
            try {
                getOakViewChecker().run();
            } catch (Exception e) {
                logger.error("run: could not ping: " + e, e);
            }
            if (!getIdMapService().isInitialized()) {
                if (!getIdMapService().waitForInit(1500)) {
                    fail("init didnt work");
                }
            }
        }
    };
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) ViewChecker(org.apache.sling.discovery.base.commons.ViewChecker) OakViewChecker(org.apache.sling.discovery.oak.pinger.OakViewChecker) OakViewChecker(org.apache.sling.discovery.oak.pinger.OakViewChecker) Logger(org.slf4j.Logger)

Aggregations

ViewChecker (org.apache.sling.discovery.base.commons.ViewChecker)1 OakViewChecker (org.apache.sling.discovery.oak.pinger.OakViewChecker)1 ComponentContext (org.osgi.service.component.ComponentContext)1 Logger (org.slf4j.Logger)1