List of usage examples for org.springframework.data.solr.server SolrClientFactory getSolrClient
SolrClient getSolrClient();
From source file:org.springframework.data.rest.webmvc.solr.SolrInfrastructureConfig.java
/** * {@link SpringJUnit4ClassRunner} executes {@link ClassRule}s before the actual shutdown of the * {@link ApplicationContext}. This causes the {@link TemporaryFolder} to vanish before Solr can gracefully shutdown. * <br />/*from w w w .ja v a 2 s . c o m*/ * To prevent error messages popping up we register a {@link CloseHook} re adding the index directory and removing it * after {@link SolrCore#close()}. * * @param factory */ private void attachCloseHook(SolrClientFactory factory) { EmbeddedSolrServer server = (EmbeddedSolrServer) factory.getSolrClient(); for (SolrCore core : server.getCoreContainer().getCores()) { core.addCloseHook(new CloseHook() { private String path; @Override public void preClose(SolrCore core) { CoreDescriptor cd = core.getCoreDescriptor(); if (cd == null) { return; } File tmp = new File(core.getIndexDir()).getParentFile(); if (tmp.exists()) { return; } try { File indexFile = new File(tmp, "index"); indexFile.mkdirs(); this.path = indexFile.getPath(); } catch (Exception e) { e.printStackTrace(); } } @Override public void postClose(SolrCore core) { if (!StringUtils.hasText(this.path)) { return; } File tmp = new File(this.path); if (tmp.exists() && tmp.getPath().startsWith(FileUtils.getTempDirectoryPath())) { try { FileUtils.deleteDirectory(tmp); } catch (IOException e) { e.printStackTrace(); } } } }); } }