public void init()

in jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/CachingDataStore.java [259:384]


    public void init(String homeDir) throws RepositoryException {
        try {
            if (path == null) {
                path = homeDir + "/repository/datastore";
            }
            // create tmp inside path
            tmpDir = new File(path, "tmp");
            LOG.info("path=[{}],  tmpPath=[{}]", path, tmpDir.getAbsolutePath());
            directory = new File(path);
            mkdirs(directory);
            mkdirs(new File(homeDir));

            if (!mkdirs(tmpDir)) {
                FileUtils.cleanDirectory(tmpDir);
                LOG.info("tmp=[{}] cleaned.", tmpDir.getPath());
            }
            boolean asyncWriteCacheInitStatus = true;
            try {
                asyncWriteCache = new AsyncUploadCache();
                asyncWriteCache.init(homeDir, path, asyncUploadLimit);
            } catch (Exception e) {
                LOG.warn("Failed to initialize asyncWriteCache", e);
                asyncWriteCacheInitStatus = false;
            }
            backend = createBackend();
            backend.init(this, path, config);
            String markerFileName = getMarkerFile();
            if (markerFileName != null && !"".equals(markerFileName.trim())) {
                // create marker file in homeDir to avoid deletion in cache
                // cleanup.
                File markerFile = new File(homeDir, markerFileName);
                if (!markerFile.exists()) {
                    LOG.info("load files from local cache");
                    uploadFilesFromCache();
                    try {
                        markerFile.createNewFile();
                    } catch (IOException e) {
                        throw new DataStoreException(
                            "Could not create marker file "
                                + markerFile.getAbsolutePath(), e);
                    }
                } else {
                    LOG.info("marker file = [{}] exists ",
                        markerFile.getAbsolutePath());
                    if (!asyncWriteCacheInitStatus) {
                        LOG.info("Initialization of asyncWriteCache failed. "
                            + "Re-loading all files from local cache");
                        uploadFilesFromCache();
                        asyncWriteCache.reset();
                    }
                }
            } else {
                throw new DataStoreException("Failed to intialized DataStore."
                    + " MarkerFileName is null or empty. ");
            }
            // upload any leftover async uploads to backend during last shutdown
            Set<String> fileList = asyncWriteCache.getAll();
            if (fileList != null && !fileList.isEmpty()) {
                List<String> errorFiles = new ArrayList<String>();
                LOG.info("Uploading [{}] and size=[{}] from AsyncUploadCache.",
                    fileList, fileList.size());
                long totalSize = 0;
                List<File> files = new ArrayList<File>(fileList.size());
                for (String fileName : fileList) {
                    File f = new File(path, fileName);
                    if (!f.exists()) {
                        errorFiles.add(fileName);
                        LOG.error(
                            "Cannot upload pending file [{}]. File doesn't exist.",
                            f.getAbsolutePath());
                    } else {
                        totalSize += f.length();
                        files.add(new File(path, fileName));
                    }
                }
                new FilesUploader(files, totalSize, concurrentUploadsThreads,
                    true).upload();
                if (!continueOnAsyncUploadFailure && errorFiles.size() > 0) {
                    LOG.error(
                        "Pending uploads of files [{}] failed. Files do not exist in Local cache.",
                        errorFiles);
                    LOG.error("To continue set [continueOnAsyncUploadFailure] "
                        + "to true in Datastore configuration in "
                        + "repository.xml. There would be inconsistent data "
                        + "in repository due the missing files. ");
                    throw new RepositoryException(
                        "Cannot upload async uploads from local cache. Files not found.");
                } else {
                    if (errorFiles.size() > 0) {
                        LOG.error(
                            "Pending uploads of files [{}] failed. Files do" +
                            " not exist in Local cache. Continuing as " +
                            "[continueOnAsyncUploadFailure] is set to true.",
                            errorFiles);
                    }
                    LOG.info("Reseting AsyncWrite Cache list.");
                    asyncWriteCache.reset();
                }
            }
            downloadExecService = Executors.newFixedThreadPool(5,
                new NamedThreadFactory("backend-file-download-worker"));
            cache = new LocalCache(path, tmpDir.getAbsolutePath(), cacheSize,
                cachePurgeTrigFactor, cachePurgeResizeFactor, asyncWriteCache);
            /*
             * Initialize LRU cache of size {@link #recLengthCacheSize}
             */
            recLenCache = Collections.synchronizedMap(new LinkedHashMap<DataIdentifier, Long>(
                recLengthCacheSize, 0.75f, true) {

                private static final long serialVersionUID = -8752749075395630485L;

                @Override
                protected boolean removeEldestEntry(
                                Map.Entry<DataIdentifier, Long> eldest) {
                    if (size() > recLengthCacheSize) {
                        LOG.trace("evicted from recLengthCache [{}]",
                            eldest.getKey());
                        return true;
                    }
                    return false;
                }
            });
        } catch (Exception e) {
            throw new RepositoryException(e);
        }
    }