List of usage examples for org.apache.solr.core CoreContainer shutdown
public void shutdown()
From source file:io.redlink.solrlib.embedded.EmbeddedCoreContainer.java
License:Apache License
@Override public final void shutdown() throws IOException { Preconditions.checkState(Objects.nonNull(this.coreContainer), "Not initialized!"); try {// w w w .j av a2 s .co m final CoreContainer cc = this.coreContainer; this.coreContainer = null; cc.shutdown(); } catch (final Exception t) { log.error("Unexpected Error during CoreContainer.shutdown(): {}", t.getMessage()); throw t; } if (deleteOnShutdown) { log.debug("Cleaning up solr-home {}", solrHome); PathUtils.deleteRecursive(solrHome); } }
From source file:org.apache.jackrabbit.oak.plugins.index.solr.server.EmbeddedSolrServerProvider.java
License:Apache License
private SolrServer createSolrServer() throws Exception { log.info("creating new embedded solr server with config: {}", solrServerConfiguration); String solrHomePath = solrServerConfiguration.getSolrHomePath(); String coreName = solrServerConfiguration.getCoreName(); EmbeddedSolrServerConfiguration.HttpConfiguration httpConfiguration = solrServerConfiguration .getHttpConfiguration();/* ww w.ja v a 2s . c o m*/ if (solrHomePath != null && coreName != null) { checkSolrConfiguration(solrHomePath, coreName); if (httpConfiguration != null) { if (log.isInfoEnabled()) { log.info("starting embedded Solr server with http bindings"); } ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(JettySolrRunner.class.getClassLoader()); Integer httpPort = httpConfiguration.getHttpPort(); String context = httpConfiguration.getContext(); JettySolrRunner jettySolrRunner = null; try { jettySolrRunner = new JettySolrRunner(solrHomePath, context, httpPort, "solrconfig.xml", "schema.xml", true); if (log.isInfoEnabled()) { log.info("Jetty runner instantiated"); } jettySolrRunner.start(true); if (log.isInfoEnabled()) { log.info("Jetty runner started"); } } catch (Exception t) { if (log.isErrorEnabled()) { log.error("an error has occurred while starting Solr Jetty", t); } } finally { if (jettySolrRunner != null && !jettySolrRunner.isRunning()) { try { jettySolrRunner.stop(); if (log.isInfoEnabled()) { log.info("Jetty runner stopped"); } } catch (Exception e) { if (log.isErrorEnabled()) { log.error("error while stopping the Jetty runner", e); } } } Thread.currentThread().setContextClassLoader(classLoader); } if (log.isInfoEnabled()) { log.info("starting HTTP Solr server"); } return new HttpWithJettySolrServer( SolrServerConfigurationDefaults.LOCAL_BASE_URL + ':' + httpPort + context + '/' + coreName, jettySolrRunner); } else { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(CoreContainer.class.getClassLoader()); CoreContainer coreContainer = new CoreContainer(solrHomePath); try { if (!coreContainer.isLoaded(coreName)) { coreContainer.load(); } } catch (Exception e) { log.error("cannot load core {}, shutting down embedded Solr..", coreName, e); try { coreContainer.shutdown(); } catch (Exception se) { log.error("could not shutdown embedded Solr", se); } return null; } finally { Thread.currentThread().setContextClassLoader(classLoader); } EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, coreName); if (server.ping().getStatus() == 0) { return server; } else { throw new IOException("the embedded Solr server is not alive"); } } } else { throw new Exception("SolrServer configuration proprties not set"); } }
From source file:org.opencms.search.solr.TestSolrConfiguration.java
License:Open Source License
/** * Tests shutting down Solr.<p>/* w w w . j a v a 2 s . co m*/ * * @throws Throwable */ public void testShutDown() throws Throwable { echo("Testing Solr shutdown"); CmsSolrIndex index = new CmsSolrIndex(AllTests.INDEX_TEST); index.setProject("Offline"); index.setLocale(Locale.GERMAN); index.setRebuildMode(CmsSearchIndex.REBUILD_MODE_AUTO); index.setFieldConfigurationName("solr_fields"); index.addSourceName("solr_source2"); OpenCms.getSearchManager().addSearchIndex(index); OpenCms.getSearchManager().rebuildIndex(AllTests.INDEX_TEST, new CmsShellReport(Locale.ENGLISH)); for (int i = 0; i < 250; i++) { index.search(getCmsObject(), "q=*:*"); } // shut down CoreContainer container = ((EmbeddedSolrServer) index.m_solr).getCoreContainer(); for (SolrCore core : container.getCores()) { echo("Open count for core: " + core.getName() + ": " + core.getOpenCount()); } container.shutdown(); // wait for a moment Thread.sleep(500); // success ? CmsFileUtil.purgeDirectory(new File(index.getPath())); assertTrue( "The index folder must be deleted, otherwise some index lock may have prevent a successful purge.", !new File(index.getPath()).exists()); }
From source file:org.si4t.solr.SolrIndexDispatcher.java
License:Apache License
public void destroyServers() { for (Entry<String, CoreContainer> entry : _solrContainers.entrySet()) { CoreContainer c = entry.getValue(); if (c != null) { log.info("Shutting down CoreContainer for searcher: " + entry.getKey()); c.shutdown(); }//www . j a va 2 s . c om } for (Entry<String, HttpClient> clients : _httpClients.entrySet()) { HttpClient client = clients.getValue(); if (client != null) { log.info("Closing down HttpClient for url: " + clients.getKey()); client.getConnectionManager().shutdown(); } } }