Java Code Examples for com.bigdata.journal.Journal#getIndex()

The following examples show how to use com.bigdata.journal.Journal#getIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReadWriteIndexExample.java    From blazegraph-samples with GNU General Public License v2.0 2 votes vote down vote up
public static void main(String[] args) throws InterruptedException,
        ExecutionException {

    final Properties properties = new Properties();

    properties.setProperty(Journal.Options.FILE, "testJournal.jnl");
    
    final Journal store = new Journal(properties);

    try {

        /*
         * Register the index. There are a lot of options for the B+Tree,
         * but you only need to specify the index name and the UUID for the
         * index. Each store can hold multiple named indices.
         */
        {
            
            final IndexMetadata indexMetadata = new IndexMetadata(
                    "testIndex", UUID.randomUUID());

            store.registerIndex(indexMetadata);
            
            // commit the store so the index is on record.
            store.commit();
            
        }

        /*
         * Demonstrate that the each view has read/write concurrency against
         * the mutable B+Tree.
         */
        final List<Callable<Void>> tasks = new LinkedList<Callable<Void>>();

        final UnisolatedReadWriteIndex btree = new UnisolatedReadWriteIndex(
                store.getIndex("testIndex"));

        final int nops = 50000;

        tasks.add(new ReadWriteTask(btree, nops));

        tasks.add(new ReadWriteTask(btree, nops));

        tasks.add(new ReadWriteTask(btree, nops));

        // run tasks on the journal's executor service.
        final List<Future<Void>> futures = store.getExecutorService()
                .invokeAll(tasks);

        for(final Future<Void> future : futures) {
            
            // check for errors.
            future.get();
            
        }
        
        // commit the store.
        store.commit();
        
        // show #of operations executed and #of tuples in the B+Tree.
        System.out.println("nops=" + (nops * tasks.size())
                + ", rangeCount=" + btree.rangeCount());

        System.out.println(new Date().toString());

    } finally {

        // destroy the backing store.
        store.destroy();

    }

}
 
Example 2
Source File: CounterSetLoader.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Reads counters from XML files into a Journal.
 * 
 * @param args
 * @throws SAXException
 * @throws ParserConfigurationException
 * @throws IOException
 */
static public void main(String[] args) throws IOException,
        ParserConfigurationException, SAXException {

    final Properties properties = new Properties();

    // @todo config
    properties.setProperty(Journal.Options.FILE,"counters.jnl");
    
    // (re-)open the store.
    final Journal store = new Journal(properties);

    // (re-)open/create the counter set B+Tree on the store.
    CounterSetBTree btree = (CounterSetBTree) store.getIndex("counters");

    if (btree == null) {

        // not registered, so create and register it now.
        btree = CounterSetBTree.create(store);

        store.registerIndex("counters", btree);

        // commit the registered index.
        store.commit();
        
    }
    
    /*
     * Process each file, loading data into the counter set B+Tree. 
     */
    for (String s : args) {

        final File file = new File(s);

        loadFile(btree, file);
        
    } // next source file.

    System.err.println("There are " + btree.rangeCount()
            + " counter values covering "
            + new Date(btree.getFirstTimestamp()) + " to "
            + new Date(btree.getLastTimestamp()));

}