Search in sources :

Example 1 with ObjectProcedure

use of jetbrains.exodus.core.dataStructures.hash.ObjectProcedure in project xodus by JetBrains.

the class Memory method dump.

public void dump(@NotNull final File location) {
    location.mkdirs();
    final ObjectProcedure<Map.Entry<Long, Block>> saver = new ObjectProcedure<Map.Entry<Long, Block>>() {

        @Override
        public boolean execute(Map.Entry<Long, Block> object) {
            try {
                final File dest = new File(location, LogUtil.getLogFilename(object.getKey()));
                final RandomAccessFile output = new RandomAccessFile(dest, "rw");
                final Block block = object.getValue();
                output.write(block.getData(), 0, block.getSize());
                output.close();
            // output.getChannel().force(false);
            } catch (IOException e) {
                throw new ExodusException(e);
            }
            return true;
        }
    };
    synchronized (data) {
        data.forEachEntry(saver);
        removedBlocks.forEachEntry(saver);
    }
}
Also used : ObjectProcedure(jetbrains.exodus.core.dataStructures.hash.ObjectProcedure) RandomAccessFile(java.io.RandomAccessFile) IOException(java.io.IOException) Map(java.util.Map) LongHashMap(jetbrains.exodus.core.dataStructures.hash.LongHashMap) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) ExodusException(jetbrains.exodus.ExodusException)

Example 2 with ObjectProcedure

use of jetbrains.exodus.core.dataStructures.hash.ObjectProcedure in project xodus by JetBrains.

the class PersistentHashSetTest method forEachKeyTest.

@SuppressWarnings({ "OverlyLongMethod" })
@Test
public void forEachKeyTest() {
    Random random = new Random(8234890);
    PersistentHashSet.MutablePersistentHashSet<Integer> tree = new PersistentHashSet<Integer>().beginWrite();
    int[] p = genPermutation(random);
    HashSet<Integer> added = new HashSet<>();
    for (int i = 0; i < ENTRIES_TO_ADD; i++) {
        int size = tree.size();
        Assert.assertEquals(i, size);
        if ((size & 1023) == 0 || size < 100) {
            final Collection<Integer> actual = new HashSet<>(size);
            ObjectProcedure<Integer> proc = new ObjectProcedure<Integer>() {

                @Override
                public boolean execute(Integer object) {
                    Assert.assertFalse(actual.contains(object));
                    actual.add(object);
                    return true;
                }
            };
            tree.forEachKey(proc);
            Assert.assertEquals(size, actual.size());
            for (Integer key : added) {
                Assert.assertTrue(actual.contains(key));
            }
        }
        tree.add(p[i]);
        added.add(p[i]);
    }
}
Also used : ObjectProcedure(jetbrains.exodus.core.dataStructures.hash.ObjectProcedure) Random(jetbrains.exodus.util.Random) Test(org.junit.Test)

Aggregations

ObjectProcedure (jetbrains.exodus.core.dataStructures.hash.ObjectProcedure)2 File (java.io.File)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 Map (java.util.Map)1 ExodusException (jetbrains.exodus.ExodusException)1 LongHashMap (jetbrains.exodus.core.dataStructures.hash.LongHashMap)1 Random (jetbrains.exodus.util.Random)1 Test (org.junit.Test)1