Search in sources :

Example 26 with BeanFactory

use of org.springframework.beans.factory.BeanFactory in project ignite by apache.

the class GridTestMain method main.

/**
     * Main method.
     *
     * @param args Parameters.
     * @throws IgniteCheckedException If failed.
     */
public static void main(String[] args) throws Exception {
    BeanFactory ctx = new ClassPathXmlApplicationContext("org/apache/ignite/loadtests/colocation/spring-colocation.xml");
    // Initialize Spring factory.
    try (Ignite g = G.start((IgniteConfiguration) ctx.getBean("grid.cfg"))) {
        final IgniteCache<GridTestKey, Long> cache = g.cache("partitioned");
        assert cache != null;
        // Uncomment if you plan to load cache using AccentureCacheStore.
        // generateAndLoad();
        // Uncomment if you plan to load cache from cache store.
        // Note that you could also do this automatically from lifecycle bean.
        // To configure lifecycle bean, uncomment 'lifecycleBeans' property in
        // spring-accenture.xml file.
        loadFromStore(cache);
        X.println("Number of entries in cache: " + cache.size());
        colocateJobs();
    //localPoolRun();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BeanFactory(org.springframework.beans.factory.BeanFactory) Ignite(org.apache.ignite.Ignite)

Example 27 with BeanFactory

use of org.springframework.beans.factory.BeanFactory in project ignite by apache.

the class SpringCacheManagerContextInjectionTest method testBeanInjectionUsingConfiguration.

/**
     * @throws Exception If failed.
     */
public void testBeanInjectionUsingConfiguration() throws Exception {
    BeanFactory factory = new AnnotationConfigApplicationContext(TestCfgConfiguration.class);
    TestInjectionLifecycleBean bean1 = (TestInjectionLifecycleBean) factory.getBean("bean1");
    TestInjectionLifecycleBean bean2 = (TestInjectionLifecycleBean) factory.getBean("bean2");
    bean1.checkState();
    bean2.checkState();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) BeanFactory(org.springframework.beans.factory.BeanFactory) TestInjectionLifecycleBean(org.apache.ignite.TestInjectionLifecycleBean)

Example 28 with BeanFactory

use of org.springframework.beans.factory.BeanFactory in project ignite by apache.

the class GridSpringCacheManagerMultiJvmSelfTest method testSyncCache.

/**
     * @throws Exception If failed.
     */
public void testSyncCache() throws Exception {
    IgniteEx loc = startGrid(0);
    final int threads = 4;
    final int entries = 100_000;
    final int remoteNum = 2;
    final CountDownLatch latch = new CountDownLatch(1);
    List<IgniteInternalFuture<Integer>> futures = new ArrayList<>(remoteNum);
    for (int i = 0; i < remoteNum; i++) {
        final int gridIdx = i + 1;
        final IgniteEx remote = startGrid(gridIdx);
        IgniteInternalFuture<Integer> calledCntFut = GridTestUtils.runAsync(new Callable<Integer>() {

            @Override
            public Integer call() throws Exception {
                latch.await();
                return executeRemotely((IgniteProcessProxy) remote, new TestIgniteCallable<Integer>() {

                    @Override
                    public Integer call(Ignite ignite) throws Exception {
                        BeanFactory factory = new ClassPathXmlApplicationContext("org/apache/ignite/cache/spring/spring-caching" + gridIdx + ".xml");
                        final GridSpringDynamicCacheTestService dynamicSvc = (GridSpringDynamicCacheTestService) factory.getBean("dynamicTestService");
                        final CyclicBarrier barrier = new CyclicBarrier(threads);
                        GridTestUtils.runMultiThreaded(new Callable() {

                            @Override
                            public Object call() throws Exception {
                                for (int i = 0; i < entries; i++) {
                                    barrier.await();
                                    assertEquals("value" + i, dynamicSvc.cacheableSync(i));
                                    assertEquals("value" + i, dynamicSvc.cacheableSync(i));
                                }
                                return null;
                            }
                        }, threads, "get-sync");
                        return dynamicSvc.called();
                    }
                });
            }
        });
        futures.add(calledCntFut);
    }
    latch.countDown();
    int totalCalledCnt = 0;
    for (IgniteInternalFuture<Integer> future : futures) totalCalledCnt += future.get();
    IgniteCache<Object, Object> cache = loc.cache("dynamicCache");
    assertEquals(entries, cache.size());
    assertEquals(entries, totalCalledCnt);
    for (int i = 0; i < entries; i++) assertEquals("value" + i, cache.get(i));
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Callable(java.util.concurrent.Callable) CyclicBarrier(java.util.concurrent.CyclicBarrier) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) IgniteEx(org.apache.ignite.internal.IgniteEx) BeanFactory(org.springframework.beans.factory.BeanFactory) Ignite(org.apache.ignite.Ignite) IgniteProcessProxy(org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy)

Example 29 with BeanFactory

use of org.springframework.beans.factory.BeanFactory in project ignite by apache.

the class SpringTransactionManagerContextInjectionTest method testBeanInjectionUsingConfig.

/**
     * @throws Exception If failed.
     */
public void testBeanInjectionUsingConfig() throws Exception {
    BeanFactory factory = new AnnotationConfigApplicationContext(TestCfgConfiguration.class);
    TestInjectionLifecycleBean bean1 = (TestInjectionLifecycleBean) factory.getBean("bean1");
    TestInjectionLifecycleBean bean2 = (TestInjectionLifecycleBean) factory.getBean("bean2");
    bean1.checkState();
    bean2.checkState();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) BeanFactory(org.springframework.beans.factory.BeanFactory) TestInjectionLifecycleBean(org.apache.ignite.TestInjectionLifecycleBean)

Example 30 with BeanFactory

use of org.springframework.beans.factory.BeanFactory in project sakuli by ConSol.

the class BeanLoader method loadMultipleBeans.

/**
     * @param classDef class definition of the expected beans
     * @param <T>      generic type of the returned {@link List}.
     * @return all available beans of type {@code <T>}. If no beans are available, the method returns an empty List.
     */
public static <T> java.util.Map<String, T> loadMultipleBeans(Class<T> classDef) {
    BeanFactory beanFactory = getBeanFactory();
    Map<String, T> beans = null;
    if (beanFactory instanceof ListableBeanFactory) {
        beans = ((ListableBeanFactory) beanFactory).getBeansOfType(classDef);
    }
    return beans != null ? beans : Collections.emptyMap();
}
Also used : BeanFactory(org.springframework.beans.factory.BeanFactory) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory)

Aggregations

BeanFactory (org.springframework.beans.factory.BeanFactory)62 Test (org.junit.Test)28 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)17 ITestBean (org.springframework.tests.sample.beans.ITestBean)11 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)10 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)10 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)8 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)7 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)7 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)5 FactoryBean (org.springframework.beans.factory.FactoryBean)4 SmartFactoryBean (org.springframework.beans.factory.SmartFactoryBean)4 CallCountingTransactionManager (org.springframework.tests.transaction.CallCountingTransactionManager)4 DataSource (javax.sql.DataSource)3 Ignite (org.apache.ignite.Ignite)3 TestInjectionLifecycleBean (org.apache.ignite.TestInjectionLifecycleBean)3 BeansException (org.springframework.beans.BeansException)3 BeanNotOfRequiredTypeException (org.springframework.beans.factory.BeanNotOfRequiredTypeException)3 HierarchicalBeanFactory (org.springframework.beans.factory.HierarchicalBeanFactory)3