@Override protected void init() { try { LogSummaryAppenderUtils.registerLogSummaryAppender(); super.init(); this.dataSource = platform.getDataSource(); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(parameterService.getAllParameters()); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(springContext); ctx.addBeanFactoryPostProcessor(configurer); List<String> extensionLocations = new ArrayList<String>(); extensionLocations.add("classpath:/symmetric-ext-points.xml"); if (registerEngine) { extensionLocations.add("classpath:/symmetric-jmx.xml"); } String xml = parameterService.getString(ParameterConstants.EXTENSIONS_XML); File file = new File(parameterService.getTempDirectory(), "extension.xml"); FileUtils.deleteQuietly(file); if (isNotBlank(xml)) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); // the "parse" method also validates XML, will throw an exception if misformatted builder.parse(new InputSource(new StringReader(xml))); FileUtils.write(file, xml, false); extensionLocations.add("file:" + file.getAbsolutePath()); } catch (Exception e) { log.error("Invalid " + ParameterConstants.EXTENSIONS_XML + " parameter."); } } try { ctx.setConfigLocations(extensionLocations.toArray(new String[extensionLocations.size()])); ctx.refresh(); this.springContext = ctx; ((ClientExtensionService) this.extensionService).setSpringContext(springContext); this.extensionService.refresh(); } catch (Exception ex) { log.error( "Failed to initialize the extension points. Please fix the problem and restart the server.", ex); } } catch (RuntimeException ex) { destroy(); throw ex; } }
@Override public synchronized void stop() { if (this.springContext instanceof AbstractApplicationContext) { AbstractApplicationContext ctx = (AbstractApplicationContext) this.springContext; try { if (ctx.isActive()) { ctx.stop(); } } catch (Exception ex) { } } super.stop(); }
@Override public synchronized void destroy() { super.destroy(); if (springContext instanceof AbstractApplicationContext) { try { ((AbstractApplicationContext) springContext).destroy(); } catch (Exception ex) { } } springContext = null; if (dataSource != null && dataSource instanceof BasicDataSource) { try { ((BasicDataSource) dataSource).close(); } catch (SQLException e) { } } }