Java Code Examples for com.bigdata.rdf.sail.BigdataSail#shutDown()

The following examples show how to use com.bigdata.rdf.sail.BigdataSail#shutDown() . 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: AbstractTestNanoSparqlClient.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private void createTripleStore(
         final IIndexManager indexManager, final String namespace,
         final Properties properties) throws InterruptedException,
         ExecutionException, SailException {

		if(log.isInfoEnabled())
			log.info("KB namespace=" + namespace);

       boolean ok = false;
       final BigdataSail sail = new BigdataSail(namespace,indexManager);
       try {
           sail.initialize();
           sail.create(properties);
        if(log.isInfoEnabled())
        	log.info("Created tripleStore: " + namespace);
           ok = true;
           return;
       } finally {
           if (!ok)
               sail.shutDown();
       }
       
//      AbstractApiTask.submitApiTask(indexManager, new CreateKBTask(namespace,
//            properties)).get();
//		
//        /**
//         * Return a view of the new KB to the caller.
//         * 
//         * Note: The caller MUST NOT attempt to modify this KB view outside of
//         * the group commit mechanisms. Therefore I am now returning a read-only
//         * view.
//         */
//      final AbstractTripleStore tripleStore = (AbstractTripleStore) indexManager
//            .getResourceLocator().locate(namespace, ITx.READ_COMMITTED);
//
//      assert tripleStore != null;
//
//      return tripleStore;
      
    }
 
Example 2
Source File: TestRollbacks.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private void doTest(final int maxCounter) throws InterruptedException, Exception {

        /*
         * Note: Each run needs to be in a distinct namespace since we otherwise
         * can have side-effects through the BigdataValueFactoryImpl for a given
         * namespace.
         */
        
        final Properties properties = new Properties(getProperties());
        
        properties.setProperty(BigdataSail.Options.NAMESPACE,
                "kb" + runCount.incrementAndGet());
        
        final BigdataSail sail = getSail(properties);
        
        try {
        	// Note: Modified to use the BigdataSailRepository rather than the base SailRepository class.
            final BigdataSailRepository repo = new BigdataSailRepository(sail);
            repo.initialize();
            runConcurrentStuff(repo,maxCounter);
        } finally {
			final IIndexManager db = sail.getIndexManager();
			try {
				if (sail.isOpen()) {
					try {
						sail.shutDown();
					} catch (Throwable t) {
						log.error(t, t);
					}
				}
			} finally {
				db.destroy();
			}
        }
    }
 
Example 3
Source File: BigdataGASRunner.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void loadFiles() throws IOException {

    final BigdataOptionData opt = getOptionData();

    final Journal jnl = opt.jnl;
    final String namespace = opt.namespace;
    final String[] loadSet = opt.loadSet.toArray(new String[0]);

    // Load data using the unisolated view.
    final AbstractTripleStore kb = (AbstractTripleStore) jnl
            .getResourceLocator().locate(namespace, ITx.UNISOLATED);

    if (opt.newKB && loadSet.length > 0) {

        final BigdataSail sail = new BigdataSail(kb);
        try {
            try {
                sail.initialize();
                loadFiles(sail, loadSet);
            } finally {
                if (sail.isOpen())
                    sail.shutDown();
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    // total #of edges in that graph.
    opt.nedges = kb.getStatementCount();

}
 
Example 4
Source File: AbstractTestBigdataGraph.java    From database with GNU General Public License v2.0 4 votes vote down vote up
protected BigdataSail reopenSail(final BigdataSail sail) {

//        final Properties properties = sail.getProperties();

        if (sail.isOpen()) {

            try {

                sail.shutDown();

            } catch (Exception ex) {

                throw new RuntimeException(ex);

            }

        }
        
        return getSail(properties);
        
    }
 
Example 5
Source File: TestServiceRegistry.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Unit test a {@link CustomServiceFactory} which hooks the connection start
 * for the {@link BigdataSail}.
 * 
 * @throws SailException
 */
public void test_customService() throws SailException {

    final URI serviceURI1 = new URIImpl("http://www.bigdata.com/myService/"
            + getName() + "/" + UUID.randomUUID());

    final MyCustomServiceFactory serviceFactory = new MyCustomServiceFactory(
            new OpenrdfNativeServiceOptions());

    try {

        // Verify not registered.
        assertNull(ServiceRegistry.getInstance().get(serviceURI1));

        // Register.
        ServiceRegistry.getInstance().add(serviceURI1, serviceFactory);

        // Verify discovery.
        assertNotNull(ServiceRegistry.getInstance().get(serviceURI1));

        // Verify same object.
        assertTrue(serviceFactory == ServiceRegistry.getInstance().get(
                serviceURI1));

        /*
         * Verify custom service visitation.
         */
        {

            final Iterator<CustomServiceFactory> itr = ServiceRegistry
                    .getInstance().customServices();

            boolean found = false;

            while (itr.hasNext()) {

                final CustomServiceFactory t = itr.next();

                if (t == serviceFactory) {

                    found = true;

                }

            }

            assertTrue(found);

        }

        /*
         * Verify hooked on connection start.
         */
        {
            final AbstractTripleStore store = getStore(getProperties());
            try {

                final BigdataSail sail = new BigdataSail(store.getNamespace(),store.getIndexManager());
                try {
                    sail.initialize();
                    // Nothing started yet.
                    assertEquals("nstarted", 0,
                            serviceFactory.nstarted.get());
                    final BigdataSailConnection conn = sail.getConnection();
                    try {
                        // Verify the service was notified.
                        assertEquals("nstarted", 1,
                                serviceFactory.nstarted.get());
                    } finally {
                        conn.close();
                    }

                } finally {
                    sail.shutDown();
                }

            } finally {
                store.destroy();
            }
        }

        // Verify the service was notified just once.
        assertEquals("nstarted", 1, serviceFactory.nstarted.get());

    } finally {

        // De-register.
        ServiceRegistry.getInstance().remove(serviceURI1);

    }

    // Verify not registered.
    assertNull(ServiceRegistry.getInstance().get(serviceURI1));

}
 
Example 6
Source File: AbstractTestNanoSparqlClient.java    From database with GNU General Public License v2.0 4 votes vote down vote up
protected Server newFixture(final String lnamespace) throws Exception {

	   final IIndexManager indexManager = getIndexManager();
		
		final Properties properties = getProperties();

		// Create the triple store instance.
        createTripleStore(indexManager, lnamespace, properties);
        
        // Open an unisolated connection on that namespace and figure out what
        // mode the namespace is using.
        {
            final BigdataSail sail = new BigdataSail(lnamespace, indexManager);
            try {
                sail.initialize();
                final BigdataSailConnection con = sail.getUnisolatedConnection();
                try {
                    final AbstractTripleStore tripleStore = con.getTripleStore();
        if (tripleStore.isStatementIdentifiers()) {
			testMode = TestMode.sids;
        } else if (tripleStore.isQuads()) {
            testMode = TestMode.quads;
        } else {
            testMode = TestMode.triples;
        }
                } finally {
                    con.close();
                }
            } finally {
                sail.shutDown();
            }
        }

        final Map<String, String> initParams = new LinkedHashMap<String, String>();
        {

            initParams.put(ConfigParams.NAMESPACE, lnamespace);

            initParams.put(ConfigParams.CREATE, "false");
            
        }
        // Start server for that kb instance.
        final Server fixture = NanoSparqlServer.newInstance(0/* port */,
                indexManager, initParams);

        fixture.start();
		
        return fixture;
	}
 
Example 7
Source File: NSSEmbeddedExample.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Start and run an {@link NanoSparqlServer} instance from embedded code.
 * 
 * @param args
 *            ignored.
 *            
 * @throws Exception
 */
public static void main(final String[] args) throws Exception {

    final int port = 0; // random port.

    /*
     * Create or re-open a durable database instance using default
     * configuration properties. There are other constructors that allow you
     * to take more control over this process.
     */
    final BigdataSail sail = new BigdataSail();

    sail.initialize();

    try {

        final IIndexManager indexManager = sail.getDatabase()
                .getIndexManager();

        final Map<String, String> initParams = new LinkedHashMap<String, String>();

        new Thread(new NSSEmbeddedExample(port, indexManager, initParams))
                .run();

    } finally {

        sail.shutDown();

    }

}