Search in sources :

Example 6 with AutowireCapableBeanFactory

use of org.springframework.beans.factory.config.AutowireCapableBeanFactory in project grails-core by grails.

the class AbstractGrailsPluginManager method doRuntimeConfiguration.

/**
     * Base implementation that simply goes through the list of plugins and calls doWithRuntimeConfiguration on each
     * @param springConfig The RuntimeSpringConfiguration instance
     */
public void doRuntimeConfiguration(RuntimeSpringConfiguration springConfig) {
    ApplicationContext context = springConfig.getUnrefreshedApplicationContext();
    AutowireCapableBeanFactory autowireCapableBeanFactory = context.getAutowireCapableBeanFactory();
    if (autowireCapableBeanFactory instanceof ConfigurableListableBeanFactory) {
        ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) autowireCapableBeanFactory;
        ConversionService existingConversionService = beanFactory.getConversionService();
        ConverterRegistry converterRegistry;
        if (existingConversionService == null) {
            GenericConversionService conversionService = new GenericConversionService();
            converterRegistry = conversionService;
            beanFactory.setConversionService(conversionService);
        } else {
            converterRegistry = (ConverterRegistry) existingConversionService;
        }
        converterRegistry.addConverter(new Converter<NavigableMap.NullSafeNavigator, Object>() {

            @Override
            public Object convert(NavigableMap.NullSafeNavigator source) {
                return null;
            }
        });
    }
    checkInitialised();
    for (GrailsPlugin plugin : pluginList) {
        if (plugin.supportsCurrentScopeAndEnvironment() && plugin.isEnabled(context.getEnvironment().getActiveProfiles())) {
            plugin.doWithRuntimeConfiguration(springConfig);
        }
    }
}
Also used : NavigableMap(org.grails.config.NavigableMap) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) ApplicationContext(org.springframework.context.ApplicationContext) ConverterRegistry(org.springframework.core.convert.converter.ConverterRegistry) GrailsPlugin(grails.plugins.GrailsPlugin) ConversionService(org.springframework.core.convert.ConversionService) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) ConfigObject(groovy.util.ConfigObject) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) GenericConversionService(org.springframework.core.convert.support.GenericConversionService)

Example 7 with AutowireCapableBeanFactory

use of org.springframework.beans.factory.config.AutowireCapableBeanFactory in project otter by alibaba.

the class OtterDownStreamHandlerIntergration method testSimple.

@Test
public void testSimple() {
    final OtterDownStreamHandler handler = new OtterDownStreamHandler();
    handler.setPipelineId(388L);
    handler.setDetectingIntervalInSeconds(1);
    ((AutowireCapableBeanFactory) TestedObject.getSpringBeanFactory()).autowireBeanProperties(handler, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
    final CountDownLatch count = new CountDownLatch(1);
    ExecutorService executor = Executors.newFixedThreadPool(1);
    executor.submit(new Runnable() {

        public void run() {
            int times = 50;
            handler.before(Arrays.asList(buildEvent()));
            while (--times > 0) {
                try {
                    Thread.sleep(50000);
                } catch (InterruptedException e) {
                }
                handler.before(Arrays.asList(buildEvent()));
            }
            count.countDown();
        }
    });
    try {
        count.await();
    } catch (InterruptedException e) {
    }
}
Also used : OtterDownStreamHandler(com.alibaba.otter.node.etl.select.selector.canal.OtterDownStreamHandler) ExecutorService(java.util.concurrent.ExecutorService) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test) BaseOtterTest(com.alibaba.otter.node.etl.BaseOtterTest)

Example 8 with AutowireCapableBeanFactory

use of org.springframework.beans.factory.config.AutowireCapableBeanFactory in project Settler by EmhyrVarEmreis.

the class AutowiringSpringBeanJobFactory method createJobInstance.

@Override
protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {
    Object job = super.createJobInstance(bundle);
    AutowireCapableBeanFactory autowireCapableBeanFactory = applicationContext.getAutowireCapableBeanFactory();
    autowireCapableBeanFactory.autowireBean(job);
    job = autowireCapableBeanFactory.initializeBean(job, job.getClass().getName());
    return job;
}
Also used : AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory)

Example 9 with AutowireCapableBeanFactory

use of org.springframework.beans.factory.config.AutowireCapableBeanFactory in project cloudstack by apache.

the class ModuleBasedFilter method init.

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    String module = filterConfig.getInitParameter("module");
    CloudStackSpringContext context = (CloudStackSpringContext) filterConfig.getServletContext().getAttribute(CloudStackSpringContext.CLOUDSTACK_CONTEXT_SERVLET_KEY);
    if (context == null)
        return;
    ApplicationContext applicationContext = context.getApplicationContextForWeb(module);
    if (applicationContext != null) {
        AutowireCapableBeanFactory factory = applicationContext.getAutowireCapableBeanFactory();
        if (factory != null) {
            factory.autowireBean(this);
            enabled = true;
        }
    }
}
Also used : CloudStackSpringContext(org.apache.cloudstack.spring.module.factory.CloudStackSpringContext) ApplicationContext(org.springframework.context.ApplicationContext) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory)

Example 10 with AutowireCapableBeanFactory

use of org.springframework.beans.factory.config.AutowireCapableBeanFactory in project cloudstack by apache.

the class ComponentContext method initComponentsLifeCycle.

public static void initComponentsLifeCycle() {
    if (!s_initializeBeans)
        return;
    AutowireCapableBeanFactory beanFactory = s_appContext.getAutowireCapableBeanFactory();
    Map<String, ComponentMethodInterceptable> interceptableComponents = getApplicationContext().getBeansOfType(ComponentMethodInterceptable.class);
    for (Map.Entry<String, ComponentMethodInterceptable> entry : interceptableComponents.entrySet()) {
        Object bean = getTargetObject(entry.getValue());
        beanFactory.configureBean(bean, entry.getKey());
    }
    Map<String, ComponentLifecycle> lifecycleComponents = getApplicationContext().getBeansOfType(ComponentLifecycle.class);
    Map<String, ComponentLifecycle>[] classifiedComponents = new Map[ComponentLifecycle.MAX_RUN_LEVELS];
    for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
        classifiedComponents[i] = new HashMap<String, ComponentLifecycle>();
    }
    for (Map.Entry<String, ComponentLifecycle> entry : lifecycleComponents.entrySet()) {
        classifiedComponents[entry.getValue().getRunLevel()].put(entry.getKey(), entry.getValue());
    }
    // Run the SystemIntegrityCheckers first
    Map<String, SystemIntegrityChecker> integrityCheckers = getApplicationContext().getBeansOfType(SystemIntegrityChecker.class);
    for (Entry<String, SystemIntegrityChecker> entry : integrityCheckers.entrySet()) {
        s_logger.info("Running SystemIntegrityChecker " + entry.getKey());
        try {
            entry.getValue().check();
        } catch (Throwable e) {
            s_logger.error("System integrity check failed. Refuse to startup", e);
            System.exit(1);
        }
    }
    // configuration phase
    Map<String, String> avoidMap = new HashMap<String, String>();
    for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
        for (Map.Entry<String, ComponentLifecycle> entry : classifiedComponents[i].entrySet()) {
            ComponentLifecycle component = entry.getValue();
            String implClassName = ComponentContext.getTargetClass(component).getName();
            s_logger.info("Configuring " + implClassName);
            if (avoidMap.containsKey(implClassName)) {
                s_logger.info("Skip configuration of " + implClassName + " as it is already configured");
                continue;
            }
            try {
                component.configure(component.getName(), component.getConfigParams());
            } catch (ConfigurationException e) {
                s_logger.error("Unhandled exception", e);
                throw new RuntimeException("Unable to configure " + implClassName, e);
            }
            avoidMap.put(implClassName, implClassName);
        }
    }
    // starting phase
    avoidMap.clear();
    for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
        for (Map.Entry<String, ComponentLifecycle> entry : classifiedComponents[i].entrySet()) {
            ComponentLifecycle component = entry.getValue();
            String implClassName = ComponentContext.getTargetClass(component).getName();
            s_logger.info("Starting " + implClassName);
            if (avoidMap.containsKey(implClassName)) {
                s_logger.info("Skip configuration of " + implClassName + " as it is already configured");
                continue;
            }
            try {
                component.start();
                if (getTargetObject(component) instanceof ManagementBean)
                    registerMBean((ManagementBean) getTargetObject(component));
            } catch (Exception e) {
                s_logger.error("Unhandled exception", e);
                throw new RuntimeException("Unable to start " + implClassName, e);
            }
            avoidMap.put(implClassName, implClassName);
        }
    }
}
Also used : ManagementBean(com.cloud.utils.mgmt.ManagementBean) HashMap(java.util.HashMap) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) ConfigurationException(javax.naming.ConfigurationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ConfigurationException(javax.naming.ConfigurationException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)10 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)2 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)2 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)2 ApplicationContext (org.springframework.context.ApplicationContext)2 BaseOtterTest (com.alibaba.otter.node.etl.BaseOtterTest)1 OtterDownStreamHandler (com.alibaba.otter.node.etl.select.selector.canal.OtterDownStreamHandler)1 ManagementBean (com.cloud.utils.mgmt.ManagementBean)1 GrailsPlugin (grails.plugins.GrailsPlugin)1 ConfigObject (groovy.util.ConfigObject)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 ConfigurationException (javax.naming.ConfigurationException)1 CloudStackSpringContext (org.apache.cloudstack.spring.module.factory.CloudStackSpringContext)1