@Test public void testUnregisterService() { dsm.startup(); String name = "myNewService"; dsm.registerService(name, "AZ"); String service = dsm.getServiceByName(name, String.class); assertNotNull(service); assertEquals("AZ", service); dsm.unregisterService(name); }
@Override public void unregisterService(String name) { checkRunning(); if (name == null) { throw new IllegalArgumentException("name cannot be null"); } if (applicationContext.containsBean(name)) { try { Object beanInstance = applicationContext.getBean(name); try { applicationContext.getBeanFactory().destroyBean(name, beanInstance); } catch (NoSuchBeanDefinitionException e) { for (final Method method : beanInstance.getClass().getMethods()) { if (method.isAnnotationPresent(PreDestroy.class)) { try { method.invoke(beanInstance); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { log.warn("Failed to call declared @PreDestroy method of {} service", name, ex); } } } } } catch (BeansException e) { } } }
DSpaceServiceManager implements ServiceManagerSystem { @Override public void unregisterService(String name) { checkRunning(); if (name == null) { throw new IllegalArgumentException("name cannot be null"); } if (applicationContext.containsBean(name)) { try { Object beanInstance = applicationContext.getBean(name); try { applicationContext.getBeanFactory().destroyBean(name, beanInstance); } catch (NoSuchBeanDefinitionException e) { for (final Method method : beanInstance.getClass().getMethods()) { if (method.isAnnotationPresent(PreDestroy.class)) { try { method.invoke(beanInstance); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { log.warn("Failed to call declared @PreDestroy method of {} service", name, ex); } } } } } catch (BeansException e) { } } } }
DSpaceServiceManager implements ServiceManagerSystem { @Override public void unregisterService(String name) { checkRunning(); if (name == null) { throw new IllegalArgumentException("name cannot be null"); } if (applicationContext.containsBean(name)) { try { Object beanInstance = applicationContext.getBean(name); try { applicationContext.getBeanFactory().destroyBean(name, beanInstance); } catch (NoSuchBeanDefinitionException e) { for (final Method method : beanInstance.getClass().getMethods()) { if (method.isAnnotationPresent(PreDestroy.class)) { try { method.invoke(beanInstance); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { log.warn("Failed to call declared @PreDestroy method of {} service", name, ex); } } } } } catch (BeansException e) { } } } DSpaceServiceManager(DSpaceConfigurationService configurationService); protected  DSpaceServiceManager(DSpaceConfigurationService configurationService,
            String... springXmlConfigFiles); }
DSpaceServiceManager implements ServiceManagerSystem { @Override public void unregisterService(String name) { checkRunning(); if (name == null) { throw new IllegalArgumentException("name cannot be null"); } if (applicationContext.containsBean(name)) { try { Object beanInstance = applicationContext.getBean(name); try { applicationContext.getBeanFactory().destroyBean(name, beanInstance); } catch (NoSuchBeanDefinitionException e) { for (final Method method : beanInstance.getClass().getMethods()) { if (method.isAnnotationPresent(PreDestroy.class)) { try { method.invoke(beanInstance); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { log.warn("Failed to call declared @PreDestroy method of {} service", name, ex); } } } } } catch (BeansException e) { } } } DSpaceServiceManager(DSpaceConfigurationService configurationService); protected  DSpaceServiceManager(DSpaceConfigurationService configurationService,
            String... springXmlConfigFiles); boolean isRunning(); ListableBeanFactory getBeanFactory(); @Override ClassPathXmlApplicationContext getApplicationContext(); void notifyServiceManagerReady(); @Override void shutdown(); @Override void startup(); @Override void registerService(String name, Object service); @Override void registerServiceNoAutowire(String name, Object service); @SuppressWarnings("unchecked") @Override T registerServiceClass(String name, Class<T> type); @Override void unregisterService(String name); @SuppressWarnings("unchecked") @Override T getServiceByName(String name, Class<T> type); @SuppressWarnings("unchecked") @Override List<T> getServicesByType(Class<T> type); @Override List<String> getServicesNames(); @Override boolean isServiceExists(String name); @Override Map<String, Object> getServices(); @Override void pushConfig(Map<String, Object> properties); static String[] getSpringPaths(boolean testMode, String[] configPaths,
                                          DSpaceConfigurationService configurationService); }
DSpaceServiceManager implements ServiceManagerSystem { @Override public void unregisterService(String name) { checkRunning(); if (name == null) { throw new IllegalArgumentException("name cannot be null"); } if (applicationContext.containsBean(name)) { try { Object beanInstance = applicationContext.getBean(name); try { applicationContext.getBeanFactory().destroyBean(name, beanInstance); } catch (NoSuchBeanDefinitionException e) { for (final Method method : beanInstance.getClass().getMethods()) { if (method.isAnnotationPresent(PreDestroy.class)) { try { method.invoke(beanInstance); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { log.warn("Failed to call declared @PreDestroy method of {} service", name, ex); } } } } } catch (BeansException e) { } } } DSpaceServiceManager(DSpaceConfigurationService configurationService); protected  DSpaceServiceManager(DSpaceConfigurationService configurationService,
            String... springXmlConfigFiles); boolean isRunning(); ListableBeanFactory getBeanFactory(); @Override ClassPathXmlApplicationContext getApplicationContext(); void notifyServiceManagerReady(); @Override void shutdown(); @Override void startup(); @Override void registerService(String name, Object service); @Override void registerServiceNoAutowire(String name, Object service); @SuppressWarnings("unchecked") @Override T registerServiceClass(String name, Class<T> type); @Override void unregisterService(String name); @SuppressWarnings("unchecked") @Override T getServiceByName(String name, Class<T> type); @SuppressWarnings("unchecked") @Override List<T> getServicesByType(Class<T> type); @Override List<String> getServicesNames(); @Override boolean isServiceExists(String name); @Override Map<String, Object> getServices(); @Override void pushConfig(Map<String, Object> properties); static String[] getSpringPaths(boolean testMode, String[] configPaths,
                                          DSpaceConfigurationService configurationService); static final String CONFIG_PATH; static final String CORE_RESOURCE_PATH; static final String ADDON_RESOURCE_PATH; }