List of usage examples for org.apache.solr.client.solrj.embedded JettySolrRunner stop
public void stop() throws Exception
From source file:com.shaie.solr.MiniSolrCloudCluster.java
License:Apache License
/** Stops the Solr identified by the given {@code nodeId}. */ public void stopSolr(String nodeId) { final JettySolrRunner solrRunner = getJettySolrRunner(nodeId); try {//from w w w.jav a 2 s .c o m solrRunner.stop(); solrRunners.remove(nodeId); } catch (final Exception e) { throw Throwables.propagate(e); } }
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();/*from w w w . ja va 2s . com*/ 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"); } }