Java Code Examples for org.eclipse.rdf4j.repository.Repository#isInitialized()
The following examples show how to use
org.eclipse.rdf4j.repository.Repository#isInitialized() .
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: 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 2
Source File: RepositoryManager.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Gets the SYSTEM repository. * * @deprecated Repository configuration is no longer stored in a centralized system repository, instead using a file * <code>config.ttl</code> per repository, stored in that repository's datadir. */ @Deprecated public Repository getSystemRepository() { if (!isInitialized()) { throw new IllegalStateException("Repository Manager is not initialized"); } synchronized (initializedRepositories) { Repository systemRepository = initializedRepositories.get(SystemRepository.ID); if (systemRepository != null && systemRepository.isInitialized()) { return systemRepository; } systemRepository = createSystemRepository(); if (systemRepository != null) { initializedRepositories.put(SystemRepository.ID, systemRepository); } return systemRepository; } }
Example 3
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 4
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 5
Source File: ConnectionManager.java From semagrow with Apache License 2.0 | 6 votes |
public RepositoryConnection getConnection(URL endpoint) throws RepositoryException { Repository repo = null; if (!repoMap.containsKey(endpoint)) { repo = new SPARQLRepository(endpoint.toString()); repoMap.put(endpoint,repo); } else { repo = repoMap.get(endpoint); } if (!repo.isInitialized()) repo.initialize(); RepositoryConnection conn = repo.getConnection(); logger.info("Open [{}] (currently open={})", conn, countconn); synchronized(this) { countconn++; } return conn; }
Example 6
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 7
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 8
Source File: RepositoryManager.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Gets the repository that is known by the specified ID from this manager. * * @param identity A repository ID. * @return An initialized Repository object, or <tt>null</tt> if no repository was known for the specified ID. * @throws RepositoryConfigException If no repository could be created due to invalid or incomplete configuration * data. */ @Override public Repository getRepository(String identity) throws RepositoryConfigException, RepositoryException { synchronized (initializedRepositories) { updateInitializedRepositories(); Repository result = initializedRepositories.get(identity); if (result != null && !result.isInitialized()) { // repository exists but has been shut down. throw away the old // object so we can re-read from the config. initializedRepositories.remove(identity); result = null; } if (result == null && SystemRepository.ID.equals(identity)) { result = getSystemRepository(); } if (result == null) { // First call (or old object thrown away), create and initialize the // repository. result = createRepository(identity); if (result != null) { initializedRepositories.put(identity, result); } } return result; } }
Example 9
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 10
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); } } }