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();
}
}
use of org.springframework.beans.factory.BeanFactory in project grails-core by grails.
the class ClosureClassIgnoringComponentScanBeanDefinitionParser method createScanner.
@Override
protected ClassPathBeanDefinitionScanner createScanner(XmlReaderContext readerContext, boolean useDefaultFilters) {
final ClassPathBeanDefinitionScanner scanner = super.createScanner(readerContext, useDefaultFilters);
BeanDefinitionRegistry beanDefinitionRegistry = readerContext.getRegistry();
GrailsPluginManager pluginManager = null;
if (beanDefinitionRegistry instanceof HierarchicalBeanFactory) {
HierarchicalBeanFactory beanFactory = (HierarchicalBeanFactory) beanDefinitionRegistry;
BeanFactory parent = beanFactory.getParentBeanFactory();
if (parent != null && parent.containsBean(GrailsPluginManager.BEAN_NAME)) {
pluginManager = parent.getBean(GrailsPluginManager.BEAN_NAME, GrailsPluginManager.class);
}
}
if (pluginManager != null) {
List<TypeFilter> typeFilters = pluginManager.getTypeFilters();
for (TypeFilter typeFilter : typeFilters) {
scanner.addIncludeFilter(typeFilter);
}
}
return scanner;
}
use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class SelectivePrototypeTargetSourceCreator method testCustomPrototypeTargetSource.
@Test
public void testCustomPrototypeTargetSource() throws Exception {
CountingTestBean.count = 0;
BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
ITestBean test = (ITestBean) bf.getBean("prototypeTest");
assertTrue(AopUtils.isAopProxy(test));
Advised advised = (Advised) test;
assertTrue(advised.getTargetSource() instanceof PrototypeTargetSource);
assertEquals("Rod", test.getName());
// Check that references survived prototype creation
assertEquals("Kerry", test.getSpouse().getName());
assertEquals("Only 2 CountingTestBeans instantiated", 2, CountingTestBean.count);
CountingTestBean.count = 0;
}
use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class SelectivePrototypeTargetSourceCreator method testCommonInterceptorAndAdvisor.
/**
* Check that we can provide a common interceptor that will
* appear in the chain before "specific" interceptors,
* which are sourced from matching advisors
*/
@Test
public void testCommonInterceptorAndAdvisor() throws Exception {
BeanFactory bf = new ClassPathXmlApplicationContext(COMMON_INTERCEPTORS_CONTEXT, CLASS);
ITestBean test1 = (ITestBean) bf.getBean("test1");
assertTrue(AopUtils.isAopProxy(test1));
Lockable lockable1 = (Lockable) test1;
NopInterceptor nop1 = (NopInterceptor) bf.getBean("nopInterceptor");
NopInterceptor nop2 = (NopInterceptor) bf.getBean("pointcutAdvisor", Advisor.class).getAdvice();
ITestBean test2 = (ITestBean) bf.getBean("test2");
Lockable lockable2 = (Lockable) test2;
// Locking should be independent; nop is shared
assertFalse(lockable1.locked());
assertFalse(lockable2.locked());
// equals 2 calls on shared nop, because it's first and sees calls
// against the Lockable interface introduced by the specific advisor
assertEquals(2, nop1.getCount());
assertEquals(0, nop2.getCount());
lockable1.lock();
assertTrue(lockable1.locked());
assertFalse(lockable2.locked());
assertEquals(5, nop1.getCount());
assertEquals(0, nop2.getCount());
PackageVisibleMethod packageVisibleMethod = (PackageVisibleMethod) bf.getBean("packageVisibleMethod");
assertEquals(5, nop1.getCount());
assertEquals(0, nop2.getCount());
packageVisibleMethod.doSomething();
assertEquals(6, nop1.getCount());
assertEquals(1, nop2.getCount());
assertTrue(packageVisibleMethod instanceof Lockable);
Lockable lockable3 = (Lockable) packageVisibleMethod;
lockable3.lock();
assertTrue(lockable3.locked());
lockable3.unlock();
assertFalse(lockable3.locked());
}
use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class SelectivePrototypeTargetSourceCreator method testWithOptimizedProxy.
@Test
public void testWithOptimizedProxy() throws Exception {
BeanFactory beanFactory = new ClassPathXmlApplicationContext(OPTIMIZED_CONTEXT, CLASS);
ITestBean testBean = (ITestBean) beanFactory.getBean("optimizedTestBean");
assertTrue(AopUtils.isAopProxy(testBean));
CountingBeforeAdvice beforeAdvice = (CountingBeforeAdvice) beanFactory.getBean("countingAdvice");
testBean.setAge(23);
testBean.getAge();
assertEquals("Incorrect number of calls to proxy", 2, beforeAdvice.getCalls());
}
Aggregations