Search in sources :

Example 1 with FileStore

use of org.apache.jackrabbit.oak.plugins.segment.file.FileStore in project jackrabbit by apache.

the class RepositoryStartupServlet method initRepository.

/**
     * Creates a new Repository based on the configuration and initializes the
     * {@link #repository} field if successful.
     *
     * @throws ServletException if an error occurs
     */
private void initRepository() throws ServletException {
    // get repository config
    File repHome;
    try {
        repHome = new File(config.getRepositoryHome()).getCanonicalFile();
    } catch (IOException e) {
        throw new ServletExceptionWithCause("Repository configuration failure: " + config.getRepositoryHome(), e);
    }
    String repConfig = config.getRepositoryConfig();
    if (repConfig != null) {
        // Jackrabbit Classic
        InputStream in = getServletContext().getResourceAsStream(repConfig);
        if (in == null) {
            try {
                in = new FileInputStream(new File(repConfig));
            } catch (FileNotFoundException e) {
                // fallback to old config
                try {
                    in = new FileInputStream(new File(repHome, repConfig));
                } catch (FileNotFoundException e1) {
                    throw new ServletExceptionWithCause("Repository configuration not found: " + repConfig, e);
                }
            }
        }
        try {
            repository = createRepository(new InputSource(in), repHome);
        } catch (RepositoryException e) {
            throw new ServletExceptionWithCause("Error while creating repository", e);
        }
    } else {
        // Jackrabbit Oak
        try {
            String model = System.getProperty("sun.arch.data.model", "32");
            store = new FileStore(repHome, 256, "64".equals(model));
            repository = new Jcr(new SegmentNodeStore(store)).createRepository();
        } catch (IOException e) {
            throw new ServletExceptionWithCause("Error while creating repository", e);
        }
    }
}
Also used : FileStore(org.apache.jackrabbit.oak.plugins.segment.file.FileStore) InputSource(org.xml.sax.InputSource) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) SegmentNodeStore(org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with FileStore

use of org.apache.jackrabbit.oak.plugins.segment.file.FileStore in project jackrabbit-oak by apache.

the class SegmentFactory method hasExternalBlobReferences.

@Override
public boolean hasExternalBlobReferences() throws IOException {
    Builder builder = FileStore.builder(new File(dir, "segmentstore"));
    builder.withMaxFileSize(256);
    builder.withMemoryMapping(false);
    FileStore fs;
    try {
        fs = builder.buildReadOnly();
    } catch (InvalidFileStoreVersionException e) {
        throw new IOException(e);
    }
    try {
        fs.getTracker().collectBlobReferences(new ReferenceCollector() {

            @Override
            public void addReference(String reference, @Nullable String nodeId) {
                // see java.nio.file.FileVisitor
                throw new ExternalBlobFound();
            }
        });
        return false;
    } catch (ExternalBlobFound e) {
        return true;
    } finally {
        fs.close();
    }
}
Also used : FileStore(org.apache.jackrabbit.oak.plugins.segment.file.FileStore) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.plugins.segment.file.InvalidFileStoreVersionException) Builder(org.apache.jackrabbit.oak.plugins.segment.file.FileStore.Builder) IOException(java.io.IOException) ReferenceCollector(org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector) File(java.io.File)

Example 3 with FileStore

use of org.apache.jackrabbit.oak.plugins.segment.file.FileStore in project jackrabbit-oak by apache.

the class SegmentFactory method create.

@Override
public NodeStore create(BlobStore blobStore, Closer closer) throws IOException {
    Builder builder = FileStore.builder(new File(dir, "segmentstore"));
    if (blobStore != null) {
        builder.withBlobStore(blobStore);
    }
    builder.withMaxFileSize(256);
    if (disableMmap) {
        builder.withMemoryMapping(false);
    } else {
        builder.withDefaultMemoryMapping();
    }
    final FileStore fs;
    try {
        if (readOnly) {
            fs = builder.buildReadOnly();
        } else {
            fs = builder.build();
        }
    } catch (InvalidFileStoreVersionException e) {
        throw new IllegalStateException(e);
    }
    closer.register(asCloseable(fs));
    return new TarNodeStore(SegmentNodeStore.builder(fs).build(), new TarNodeStore.SuperRootProvider() {

        @Override
        public NodeState getSuperRoot() {
            return fs.getHead();
        }
    });
}
Also used : FileStore(org.apache.jackrabbit.oak.plugins.segment.file.FileStore) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.plugins.segment.file.InvalidFileStoreVersionException) Builder(org.apache.jackrabbit.oak.plugins.segment.file.FileStore.Builder) File(java.io.File)

Aggregations

File (java.io.File)3 FileStore (org.apache.jackrabbit.oak.plugins.segment.file.FileStore)3 IOException (java.io.IOException)2 Builder (org.apache.jackrabbit.oak.plugins.segment.file.FileStore.Builder)2 InvalidFileStoreVersionException (org.apache.jackrabbit.oak.plugins.segment.file.InvalidFileStoreVersionException)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 RepositoryException (javax.jcr.RepositoryException)1 Jcr (org.apache.jackrabbit.oak.jcr.Jcr)1 ReferenceCollector (org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector)1 SegmentNodeStore (org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore)1 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)1 InputSource (org.xml.sax.InputSource)1