Search in sources :

Example 1 with ClosableIterable

use of org.neo4j.helpers.collection.ClosableIterable in project neo4j-mobile-android by neo4j-contrib.

the class NeoStoreXaDataSource method listStoreFiles.

@Override
public ClosableIterable<File> listStoreFiles(boolean includeLogicalLogs) {
    final Collection<File> files = new ArrayList<File>();
    File neostoreFile = null;
    Pattern logFilePattern = getXaContainer().getLogicalLog().getHistoryFileNamePattern();
    for (File dbFile : new File(storeDir).listFiles()) {
        String name = dbFile.getName();
        // maybe should be
        if (dbFile.isFile()) {
            if (name.equals(NeoStore.DEFAULT_NAME)) {
                neostoreFile = dbFile;
            } else if ((name.startsWith(NeoStore.DEFAULT_NAME) || name.equals(IndexStore.INDEX_DB_FILE_NAME)) && !name.endsWith(".id")) {
                // Store files
                files.add(dbFile);
            } else if (includeLogicalLogs && logFilePattern.matcher(dbFile.getName()).matches()) {
                // Logs
                files.add(dbFile);
            }
        }
    }
    files.add(neostoreFile);
    return new ClosableIterable<File>() {

        public Iterator<File> iterator() {
            return files.iterator();
        }

        public void close() {
        }
    };
}
Also used : Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) ClosableIterable(org.neo4j.helpers.collection.ClosableIterable) File(java.io.File)

Example 2 with ClosableIterable

use of org.neo4j.helpers.collection.ClosableIterable in project graphdb by neo4j-attic.

the class LuceneDataSource method listStoreFiles.

@Override
public ClosableIterable<File> listStoreFiles() throws IOException {
    final Collection<File> files = new ArrayList<File>();
    final Collection<SnapshotDeletionPolicy> snapshots = new ArrayList<SnapshotDeletionPolicy>();
    for (Map.Entry<IndexIdentifier, Triplet<IndexWriter, AtomicBoolean, SnapshotDeletionPolicy>> writer : indexWriters.entrySet()) {
        SnapshotDeletionPolicy deletionPolicy = writer.getValue().third();
        File indexDirectory = getFileDirectory(baseStorePath, writer.getKey());
        for (String fileName : deletionPolicy.snapshot().getFileNames()) {
            files.add(new File(indexDirectory, fileName));
        }
        snapshots.add(deletionPolicy);
    }
    files.add(providerStore.getFile());
    return new ClosableIterable<File>() {

        public Iterator<File> iterator() {
            return files.iterator();
        }

        public void close() {
            for (SnapshotDeletionPolicy deletionPolicy : snapshots) {
                deletionPolicy.release();
            }
        }
    };
}
Also used : Triplet(org.neo4j.helpers.Triplet) ArrayList(java.util.ArrayList) ClosableIterable(org.neo4j.helpers.collection.ClosableIterable) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) SnapshotDeletionPolicy(org.apache.lucene.index.SnapshotDeletionPolicy)

Example 3 with ClosableIterable

use of org.neo4j.helpers.collection.ClosableIterable in project neo4j-mobile-android by neo4j-contrib.

the class LuceneDataSource method listStoreFiles.

@Override
public ClosableIterable<File> listStoreFiles(boolean includeLogicalLogs) throws IOException {
    // Never include logical logs since they are of little importance
    final Collection<File> files = new ArrayList<File>();
    final Collection<SnapshotDeletionPolicy> snapshots = new ArrayList<SnapshotDeletionPolicy>();
    makeSureAllIndexesAreInstantiated();
    for (Map.Entry<IndexIdentifier, Pair<IndexWriter, AtomicBoolean>> writer : indexWriters.entrySet()) {
        SnapshotDeletionPolicy deletionPolicy = (SnapshotDeletionPolicy) writer.getValue().first().getConfig().getIndexDeletionPolicy();
        File indexDirectory = getFileDirectory(baseStorePath, writer.getKey());
        try {
            // Throws IllegalStateException if no commits yet
            IndexCommit commit = deletionPolicy.snapshot(SNAPSHOT_ID);
            for (String fileName : commit.getFileNames()) {
                files.add(new File(indexDirectory, fileName));
            }
            snapshots.add(deletionPolicy);
        } catch (IllegalStateException e) {
        // TODO Review this
        /*
                 * This is insane but happens if we try to snapshot an existing index
                 * that has no commits. This is a bad API design - it should return null
                 * or something. This is not exceptional.
                 */
        }
    }
    files.add(providerStore.getFile());
    return new ClosableIterable<File>() {

        public Iterator<File> iterator() {
            return files.iterator();
        }

        public void close() {
            for (SnapshotDeletionPolicy deletionPolicy : snapshots) {
                try {
                    deletionPolicy.release(SNAPSHOT_ID);
                } catch (IOException e) {
                    // TODO What to do?
                    e.printStackTrace();
                }
            }
        }
    };
}
Also used : ArrayList(java.util.ArrayList) ClosableIterable(org.neo4j.helpers.collection.ClosableIterable) IOException(java.io.IOException) SnapshotDeletionPolicy(org.apache.lucene.index.SnapshotDeletionPolicy) IndexCommit(org.apache.lucene.index.IndexCommit) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) Pair(org.neo4j.helpers.Pair)

Aggregations

File (java.io.File)3 ArrayList (java.util.ArrayList)3 ClosableIterable (org.neo4j.helpers.collection.ClosableIterable)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SnapshotDeletionPolicy (org.apache.lucene.index.SnapshotDeletionPolicy)2 IOException (java.io.IOException)1 Pattern (java.util.regex.Pattern)1 IndexCommit (org.apache.lucene.index.IndexCommit)1 Pair (org.neo4j.helpers.Pair)1 Triplet (org.neo4j.helpers.Triplet)1