Java Code Examples for org.eclipse.rdf4j.repository.Repository#shutDown()
The following examples show how to use
org.eclipse.rdf4j.repository.Repository#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: LocalRepositoryManagerIntegrationTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testRestartManagerWithoutTransaction() throws Exception { Repository rep = subject.getRepository(TEST_REPO); assertNotNull("Expected repository to exist.", rep); assertTrue("Expected repository to be initialized.", rep.isInitialized()); try (RepositoryConnection conn = rep.getConnection()) { conn.add(conn.getValueFactory().createIRI("urn:sesame:test:subject"), RDF.TYPE, OWL.ONTOLOGY); assertEquals(1, conn.size()); } finally { rep.shutDown(); subject.shutDown(); } subject = new LocalRepositoryManager(datadir); subject.initialize(); Repository rep2 = subject.getRepository(TEST_REPO); assertNotNull("Expected repository to exist.", rep2); assertTrue("Expected repository to be initialized.", rep2.isInitialized()); try (RepositoryConnection conn2 = rep2.getConnection()) { assertEquals(1, conn2.size()); } finally { rep2.shutDown(); subject.shutDown(); } }
Example 2
Source File: RepositoryManager.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Shuts down all initialized repositories, including the SYSTEM repository. * * @see #refresh() */ public void shutDown() { synchronized (initializedRepositories) { updateInitializedRepositories(); for (Repository repository : initializedRepositories.values()) { try { if (repository.isInitialized()) { repository.shutDown(); } } catch (RepositoryException e) { logger.error("Repository shut down failed", e); } } initializedRepositories.clear(); initialized = false; } }
Example 3
Source File: AbstractNQuadsParserTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public TestSuite createTestSuite() throws Exception { // Create test suite TestSuite suite = new TestSuite(this.getClass().getName()); // Add the manifest for W3C test cases to a repository and query it Repository w3cRepository = new SailRepository(new MemoryStore()); w3cRepository.initialize(); RepositoryConnection w3cCon = w3cRepository.getConnection(); InputStream inputStream = this.getClass().getResourceAsStream(TEST_W3C_MANIFEST_URL); w3cCon.add(inputStream, TEST_W3C_MANIFEST_URI_BASE, RDFFormat.TURTLE); parsePositiveNQuadsSyntaxTests(suite, TEST_W3C_FILE_BASE_PATH, TEST_W3C_TEST_URI_BASE, w3cCon); parseNegativeNQuadsSyntaxTests(suite, TEST_W3C_FILE_BASE_PATH, TEST_W3C_TEST_URI_BASE, w3cCon); w3cCon.close(); w3cRepository.shutDown(); return suite; }
Example 4
Source File: TriGParserTestCase.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public TestSuite createTestSuite() throws Exception { // Create test suite TestSuite suite = new TestSuite(TriGParserTestCase.class.getName()); // Add the manifest for W3C test cases to a repository and query it Repository w3cRepository = new SailRepository(new MemoryStore()); w3cRepository.initialize(); RepositoryConnection w3cCon = w3cRepository.getConnection(); InputStream inputStream = this.getClass().getResourceAsStream(TEST_W3C_MANIFEST_URL); w3cCon.add(inputStream, TEST_W3C_MANIFEST_URI_BASE, RDFFormat.TURTLE); parsePositiveTriGSyntaxTests(suite, TEST_W3C_FILE_BASE_PATH, TESTS_W3C_BASE_URL, TEST_W3C_TEST_URI_BASE, w3cCon); parseNegativeTriGSyntaxTests(suite, TEST_W3C_FILE_BASE_PATH, TESTS_W3C_BASE_URL, TEST_W3C_TEST_URI_BASE, w3cCon); parsePositiveTriGEvalTests(suite, TEST_W3C_FILE_BASE_PATH, TESTS_W3C_BASE_URL, TEST_W3C_TEST_URI_BASE, w3cCon); parseNegativeTriGEvalTests(suite, TEST_W3C_FILE_BASE_PATH, TESTS_W3C_BASE_URL, TEST_W3C_TEST_URI_BASE, w3cCon); w3cCon.close(); w3cRepository.shutDown(); return suite; }
Example 5
Source File: RepositoryManager.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected void updateInitializedRepositories() { synchronized (initializedRepositories) { Iterator<Repository> iter = initializedRepositories.values().iterator(); while (iter.hasNext()) { Repository next = iter.next(); if (!next.isInitialized()) { iter.remove(); try { next.shutDown(); } catch (RepositoryException e) { } } } } }
Example 6
Source File: SPARQLServerBaseTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Load a dataset. Note: the repositories are cleared before loading data * * @param rep * @param datasetFile * @throws RDFParseException * @throws RepositoryException * @throws IOException */ protected void loadDataSet(Repository rep, String datasetFile) throws RDFParseException, RepositoryException, IOException { log.debug("loading dataset..."); InputStream dataset = SPARQLServerBaseTest.class.getResourceAsStream(datasetFile); boolean needToShutdown = false; if (!rep.isInitialized()) { rep.init(); needToShutdown = true; } RepositoryConnection con = rep.getConnection(); try { con.clear(); con.add(dataset, "", Rio.getParserFormatForFileName(datasetFile).get()); } finally { dataset.close(); con.close(); if (needToShutdown) { rep.shutDown(); } } log.debug("dataset loaded."); }
Example 7
Source File: FedXWithRemoteRepositoryManager.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static void main(String[] args) throws Exception { // connection URL of a RDF4J server which manages the repositories String serverUrl = "http://localhost:8080/rdf4j-server"; RepositoryManager repoManager = new RemoteRepositoryManager(serverUrl); // assumes that remote repositories exist Repository localRepo = FedXFactory.newFederation() .withRepositoryResolver(repoManager) .withResolvableEndpoint("my-repository-1") .withResolvableEndpoint("my-repository-2") .create(); localRepo.init(); try (RepositoryConnection conn = localRepo.getConnection()) { try (RepositoryResult<Statement> repoResult = conn.getStatements(null, RDF.TYPE, FOAF.PERSON)) { repoResult.forEach(st -> System.out.println(st)); } } localRepo.shutDown(); repoManager.shutDown(); }
Example 8
Source File: LocalRepositoryManagerIntegrationTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.repository.subject.LocalRepositoryManager#getRepository(java.lang.String)} . * * @throws RepositoryException if a problem occurs accessing the repository * @throws RepositoryConfigException if a problem occurs accessing the repository */ @Test public void testGetRepository() throws RepositoryConfigException, RepositoryException { Repository rep = subject.getRepository(TEST_REPO); assertNotNull("Expected repository to exist.", rep); assertTrue("Expected repository to be initialized.", rep.isInitialized()); rep.shutDown(); rep = subject.getRepository(TEST_REPO); assertNotNull("Expected repository to exist.", rep); assertTrue("Expected repository to be initialized.", rep.isInitialized()); }
Example 9
Source File: RepositoryManager.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Removes the configuration for the specified repository from the manager's system repository if such a * configuration is present. Returns <tt>true</tt> if the system repository actually contained the specified * repository configuration. * * @param repositoryID The ID of the repository whose configuration needs to be removed. * @throws RepositoryException If the manager failed to update it's system repository. * @throws RepositoryConfigException If the manager doesn't know how to remove a configuration due to inconsistent * configuration data in the system repository. For example, this happens when * there are multiple existing configurations with the concerning ID. * @deprecated since 2.0. Use {@link #removeRepository(String repositoryID)} instead. */ @Deprecated public boolean removeRepositoryConfig(String repositoryID) throws RepositoryException, RepositoryConfigException { logger.debug("Removing repository configuration for {}.", repositoryID); boolean isRemoved = hasRepositoryConfig(repositoryID); synchronized (initializedRepositories) { // update SYSTEM repository if there is one for 2.2 compatibility Repository systemRepository = getSystemRepository(); if (systemRepository != null) { RepositoryConfigUtil.removeRepositoryConfigs(systemRepository, repositoryID); } if (isRemoved) { logger.debug("Shutdown repository {} after removal of configuration.", repositoryID); Repository repository = initializedRepositories.remove(repositoryID); if (repository != null && repository.isInitialized()) { repository.shutDown(); } try { cleanUpRepository(repositoryID); } catch (IOException e) { throw new RepositoryException("Unable to clean up resources for removed repository " + repositoryID, e); } } } return isRemoved; }
Example 10
Source File: RepositoryManager.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
void refreshRepository(String repositoryID, Repository repository) { logger.debug("Refreshing repository {}...", repositoryID); try { if (repository.isInitialized()) { repository.shutDown(); } } catch (RepositoryException e) { logger.error("Failed to shut down repository", e); } cleanupIfRemoved(repositoryID); }
Example 11
Source File: Demo2.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(String[] args) throws Exception { if (System.getProperty("log4j.configuration") == null) { System.setProperty("log4j.configuration", "file:local/log4j.properties"); } File dataConfig = new File("local/LifeScience-FedX-SPARQL.ttl"); Repository repo = FedXFactory.createFederation(dataConfig); repo.init(); String q = "SELECT ?Drug ?IntDrug ?IntEffect WHERE { " + "?Drug <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Drug> . " + "?y <http://www.w3.org/2002/07/owl#sameAs> ?Drug . " + "?Int <http://www4.wiwiss.fu-berlin.de/drugbank/resource/drugbank/interactionDrug1> ?y . " + "?Int <http://www4.wiwiss.fu-berlin.de/drugbank/resource/drugbank/interactionDrug2> ?IntDrug . " + "?Int <http://www4.wiwiss.fu-berlin.de/drugbank/resource/drugbank/text> ?IntEffect . }"; try (RepositoryConnection conn = repo.getConnection()) { TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, q); try (TupleQueryResult res = query.evaluate()) { while (res.hasNext()) { System.out.println(res.next()); } } } repo.shutDown(); System.out.println("Done."); System.exit(0); }
Example 12
Source File: LockRemover.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Try to remove lock from repository * * @param repo * @param consoleIO * @return true if lock was removed * @throws IOException * @throws RepositoryException */ public static boolean tryToRemoveLock(Repository repo, ConsoleIO consoleIO) throws IOException, RepositoryException { boolean lockRemoved = false; LockManager lockManager = new DirectoryLockManager(repo.getDataDir()); if (lockManager.isLocked() && consoleIO .askProceed("WARNING: The lock from another process on this repository needs to be removed", true)) { repo.shutDown(); lockRemoved = lockManager.revokeLock(); repo.initialize(); } return lockRemoved; }
Example 13
Source File: RepositoryManager.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Removes the specified repository by deleting its configuration from the manager's system repository if such a * configuration is present, and removing any persistent data associated with the repository. Returns <tt>true</tt> * if the system repository actually contained the specified repository configuration. <strong>NB this operation can * not be undone!</strong> * * @param repositoryID The ID of the repository that needs to be removed. * @throws RepositoryException If the manager failed to update its system repository. * @throws RepositoryConfigException If the manager doesn't know how to remove a repository due to inconsistent * configuration data in the system repository. For example, this happens when * there are multiple existing configurations with the concerning ID. */ public boolean removeRepository(String repositoryID) throws RepositoryException, RepositoryConfigException { logger.debug("Removing repository {}.", repositoryID); boolean isRemoved = hasRepositoryConfig(repositoryID); synchronized (initializedRepositories) { // update SYSTEM repository if there is one for 2.2 compatibility Repository systemRepository = getSystemRepository(); if (systemRepository != null) { RepositoryConfigUtil.removeRepositoryConfigs(systemRepository, repositoryID); } if (isRemoved) { logger.debug("Shutdown repository {} after removal of configuration.", repositoryID); Repository repository = initializedRepositories.remove(repositoryID); if (repository != null && repository.isInitialized()) { repository.shutDown(); } try { cleanUpRepository(repositoryID); } catch (IOException e) { throw new RepositoryException("Unable to clean up resources for removed repository " + repositoryID, e); } } } return isRemoved; }
Example 14
Source File: ConnectionManager.java From semagrow with Apache License 2.0 | 5 votes |
public void shutdown() { for (Repository repo : repoMap.values()) { if (repo.isInitialized()) try { repo.shutDown(); } catch (RepositoryException e) { logger.warn("Failed to shutdown repo {}", repo); } } }
Example 15
Source File: LocalRepositoryManagerIntegrationTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testRestartManagerWithTransaction() throws Exception { Repository rep = subject.getRepository(TEST_REPO); assertNotNull("Expected repository to exist.", rep); assertTrue("Expected repository to be initialized.", rep.isInitialized()); try (RepositoryConnection conn = rep.getConnection()) { conn.begin(); conn.add(conn.getValueFactory().createIRI("urn:sesame:test:subject"), RDF.TYPE, OWL.ONTOLOGY); conn.commit(); assertEquals(1, conn.size()); } finally { rep.shutDown(); subject.shutDown(); } subject = new LocalRepositoryManager(datadir); subject.initialize(); Repository rep2 = subject.getRepository(TEST_REPO); assertNotNull("Expected repository to exist.", rep2); assertTrue("Expected repository to be initialized.", rep2.isInitialized()); try (RepositoryConnection conn2 = rep2.getConnection()) { assertEquals(1, conn2.size()); } finally { rep2.shutDown(); subject.shutDown(); } }
Example 16
Source File: SPARQLEmbeddedServer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void stop() throws Exception { Repository systemRepo = new HTTPRepository(Protocol.getRepositoryLocation(getServerUrl(), SystemRepository.ID)); RepositoryConnection con = systemRepo.getConnection(); try { con.clear(); } finally { con.close(); systemRepo.shutDown(); } jetty.stop(); System.clearProperty("org.mortbay.log.class"); }
Example 17
Source File: QueryPlanLogDemo.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void main(String[] args) throws Exception { FedXConfig config = new FedXConfig().withEnableMonitoring(true).withLogQueryPlan(true); Repository repo = FedXFactory.newFederation() .withSparqlEndpoint("http://dbpedia.org/sparql") .withSparqlEndpoint("https://query.wikidata.org/sparql") .withConfig(config) .create(); repo.init(); String q = "PREFIX wd: <http://www.wikidata.org/entity/> " + "PREFIX wdt: <http://www.wikidata.org/prop/direct/> " + "SELECT * WHERE { " + " ?country a <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheEuropeanUnion> ." + " ?country <http://www.w3.org/2002/07/owl#sameAs> ?countrySameAs . " + " ?countrySameAs wdt:P2131 ?gdp ." + "}"; try (RepositoryConnection conn = repo.getConnection()) { TupleQuery query = repo.getConnection().prepareTupleQuery(QueryLanguage.SPARQL, q); try (TupleQueryResult res = query.evaluate()) { int count = 0; while (res.hasNext()) { res.next(); count++; } System.out.println("# Done, " + count + " results"); } System.out.println("# Optimized Query Plan:"); System.out.println(QueryPlanLog.getQueryPlan()); } repo.shutDown(); System.out.println("Done."); System.exit(0); }
Example 18
Source File: FedXInRDF4JWorkbenchTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testFederation() throws Exception { assumeSparqlEndpoint(); // load some data into endpoint1 and endpoint2 loadDataSet(server.getRepository(1), "/tests/medium/data1.ttl"); loadDataSet(server.getRepository(2), "/tests/medium/data2.ttl"); final String repositoryId = "my-federation"; final SPARQLEmbeddedServer rdf4jServer = (SPARQLEmbeddedServer) server; final File dataDir = rdf4jServer.getDataDir(); String repoPath = "server/repositories"; if (PlatformFactory.getPlatform().dataDirPreserveCase()) { repoPath = "Server/repositories"; } final File repositoriesDir = new File(dataDir, repoPath); // preparation: add configuration files to the repository File fedXDataDir = new File(repositoriesDir, repositoryId); fedXDataDir.mkdirs(); FileUtils.copyFile(toFile("/tests/rdf4jserver/config.ttl"), new File(fedXDataDir, "config.ttl")); String fedXSparqlUrl = rdf4jServer.getRepositoryUrl(repositoryId); SPARQLRepository repo = new SPARQLRepository(fedXSparqlUrl); repo.init(); try (RepositoryConnection conn = repo.getConnection()) { // simple check: make sure that expected data is present Assertions.assertEquals(30, conn.size()); } repo.shutDown(); // temporary workaround: shutdown the federation repository explicitly here to // avoid a long running test. This is because the federation keeps an open // connection to other endpoints hosted in the same server, and the shutdown // sequence is arbitrary. Repository fedx = rdf4jServer.getRepositoryResolver().getRepository(repositoryId); fedx.shutDown(); }
Example 19
Source File: FedXInRDF4JWorkbenchTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testFederation_WithDataConfig() throws Exception { assumeSparqlEndpoint(); // load some data into endpoint1 and endpoint2 loadDataSet(server.getRepository(1), "/tests/medium/data1.ttl"); loadDataSet(server.getRepository(2), "/tests/medium/data2.ttl"); final String repositoryId = "my-federation"; final SPARQLEmbeddedServer rdf4jServer = (SPARQLEmbeddedServer) server; final File dataDir = rdf4jServer.getDataDir(); String repoPath = "server/repositories"; if (PlatformFactory.getPlatform().dataDirPreserveCase()) { repoPath = "Server/repositories"; } final File repositoriesDir = new File(dataDir, repoPath); // preparation: add configuration files to the repository File fedXDataDir = new File(repositoriesDir, repositoryId); fedXDataDir.mkdirs(); FileUtils.copyFile(toFile("/tests/rdf4jserver/config-withDataConfig.ttl"), new File(fedXDataDir, "config.ttl")); FileUtils.copyFile(toFile("/tests/rdf4jserver/dataConfig.ttl"), new File(fedXDataDir, "dataConfig.ttl")); String fedXSparqlUrl = rdf4jServer.getRepositoryUrl(repositoryId); SPARQLRepository repo = new SPARQLRepository(fedXSparqlUrl); repo.init(); try (RepositoryConnection conn = repo.getConnection()) { // simple check: make sure that expected data is present Assertions.assertEquals(30, conn.size()); } repo.shutDown(); // temporary workaround: shutdown the federation repository explicitly here to // avoid a long running test. This is because the federation keeps an open // connection to other endpoints hosted in the same server, and the shutdown // sequence is arbitrary. Repository fedx = rdf4jServer.getRepositoryResolver().getRepository(repositoryId); fedx.shutDown(); }
Example 20
Source File: CustomGraphQueryInferencerTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected void runTest(final CustomGraphQueryInferencer inferencer) throws RepositoryException, RDFParseException, IOException, MalformedQueryException, UpdateExecutionException { // Initialize Repository sail = new SailRepository(inferencer); sail.initialize(); RepositoryConnection connection = sail.getConnection(); try { connection.begin(); connection.clear(); connection.add(new StringReader(initial), BASE, RDFFormat.TURTLE); // Test initial inferencer state Collection<Value> watchPredicates = inferencer.getWatchPredicates(); assertThat(watchPredicates).hasSize(testData.predCount); Collection<Value> watchObjects = inferencer.getWatchObjects(); assertThat(watchObjects).hasSize(testData.objCount); Collection<Value> watchSubjects = inferencer.getWatchSubjects(); assertThat(watchSubjects).hasSize(testData.subjCount); ValueFactory factory = connection.getValueFactory(); if (resourceFolder.startsWith(PREDICATE)) { assertThat(watchPredicates.contains(factory.createIRI(BASE, "brotherOf"))).isTrue(); assertThat(watchPredicates.contains(factory.createIRI(BASE, "parentOf"))).isTrue(); } else { IRI bob = factory.createIRI(BASE, "Bob"); IRI alice = factory.createIRI(BASE, "Alice"); assertThat(watchSubjects).contains(bob, alice); assertThat(watchObjects).contains(bob, alice); } // Test initial inferencing results assertThat(Iterations.asSet(connection.getStatements(null, null, null, true))) .hasSize(testData.initialCount); // Test results after removing some statements connection.prepareUpdate(QueryLanguage.SPARQL, delete).execute(); assertThat(Iterations.asSet(connection.getStatements(null, null, null, true))) .hasSize(testData.countAfterRemove); // Tidy up. Storage gets re-used for subsequent tests, so must clear here, // in order to properly clear out any inferred statements. connection.clear(); connection.commit(); } finally { connection.close(); } sail.shutDown(); }