public Result execute()

in src/main/java/org/apache/sling/jcr/contentloader/hc/BundleContentLoadedCheck.java [116:219]


    public Result execute() {
        FormattingResultLog log = new FormattingResultLog();

        Bundle[] bundles = this.bundleContext.getBundles();
        log.debug("Framwork has {} bundles in total", bundles.length);
 
        int countExcluded = 0;
        int relevantBundlesCount = 0;
        int notLoadedCount = 0;

        Session metadataSession = null;
        try {
            metadataSession = repository.loginService(null, null);
           
            for (Bundle bundle : bundles) {
                String bundleSymbolicName = bundle.getSymbolicName();
                boolean skip = false;
                if (!includesRegex.matcher(bundleSymbolicName).matches()) {
                    LOG.debug("Bundle {} not matched by {}", bundleSymbolicName, includesRegex);
                    skip = true;
                }

                if (excludesRegex!=null && excludesRegex.matcher(bundleSymbolicName).matches()) {
                    LOG.debug("Bundle {} excluded {}", bundleSymbolicName, excludesRegex);
                    countExcluded ++;
                    skip = true;
                }

                if (skip) {
                    continue;
                }

                // check if bundle has initial content
                final Iterator<PathEntry> pathIter = PathEntry.getContentPaths(bundle);
                if (pathIter == null) {
                    log.debug("Bundle {} has no initial content", bundleSymbolicName);
                } else {
                    relevantBundlesCount++;

                    // check if the content has already been loaded
                    final Map<String, Object> bundleContentInfo = bundleHelper.getBundleContentInfo(metadataSession, bundle, false);

                    // if we don't get an info, someone else is currently loading
                    if (bundleContentInfo == null) {
                        notLoadedCount++;
                        String msg = "Not loaded bundle {} {}";
                        Object[] msgObjs = new Object[] {bundle.getBundleId(), bundleSymbolicName};
                        LOG.debug(msg, msgObjs);
                        if (useCriticalForNotLoaded) {
                            log.critical(msg, msgObjs);
                        } else {
                            log.warn(msg, msgObjs);
                        }
                    } else {
                        try {
                            final boolean contentAlreadyLoaded = ((Boolean) bundleContentInfo.get(BundleContentLoaderListener.PROPERTY_CONTENT_LOADED)).booleanValue();
                            boolean isBundleUpdated = false;
                            Calendar lastLoadedAt = (Calendar) bundleContentInfo.get(BundleContentLoaderListener.PROPERTY_CONTENT_LOADED_AT);
                            if (lastLoadedAt != null && lastLoadedAt.getTimeInMillis() < bundle.getLastModified()) {
                                isBundleUpdated = true;
                            }
                            if (!isBundleUpdated && contentAlreadyLoaded) {
                                log.debug("Content of bundle is already loaded {} {}.", bundle.getBundleId(), bundleSymbolicName);
                            } else {
                                notLoadedCount++;
                                String msg = "Not loaded bundle {} {}";
                                Object[] msgObjs = new Object[] {bundle.getBundleId(), bundleSymbolicName};
                                LOG.debug(msg, msgObjs);
                                if (useCriticalForNotLoaded) {
                                    log.critical(msg, msgObjs);
                                } else {
                                    log.warn(msg, msgObjs);
                                }
                            }
                        } finally {
                            bundleHelper.unlockBundleContentInfo(metadataSession, bundle, false, null);
                        }
                    }
                }
            }
        } catch (RepositoryException t) {
            String msg = "Unexpected error: " + t.getMessage();
            LOG.error(msg, t);
            log.critical(msg);
        } finally {
            if (metadataSession != null) {
                try {
                    metadataSession.logout();
                } catch (Exception t) {
                    LOG.error("Unable to log out of session: " + t.getMessage(), t);
                }
            }
        }
                
        String baseMsg = relevantBundlesCount + " bundles" + (!includesRegex.pattern().equals(".*") ? " for pattern " + includesRegex.pattern() : "");
        String excludedMsg = countExcluded > 0 ? " (" + countExcluded + " excluded via pattern "+excludesRegex.pattern()+")" : "";
        if (notLoadedCount > 0) {
            log.info("Found " + notLoadedCount + " not content loaded of " + baseMsg + excludedMsg);
        } else {
            log.info("All " + baseMsg + " are content loaded" + excludedMsg);
        }

        return new Result(log);
    }