当前位置: 首页>>代码示例>>Java>>正文


Java HotSwappableTargetSource.swap方法代码示例

本文整理汇总了Java中org.springframework.aop.target.HotSwappableTargetSource.swap方法的典型用法代码示例。如果您正苦于以下问题:Java HotSwappableTargetSource.swap方法的具体用法?Java HotSwappableTargetSource.swap怎么用?Java HotSwappableTargetSource.swap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.aop.target.HotSwappableTargetSource的用法示例。


在下文中一共展示了HotSwappableTargetSource.swap方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDynamicTargetSource

import org.springframework.aop.target.HotSwappableTargetSource; //导入方法依赖的package包/类
/**
 * Test that we can set the target to a dynamic TargetSource.
 */
@Test
public void testDynamicTargetSource() throws NoSuchMethodException {
	// Install facade
	CallCountingTransactionManager txMan = new CallCountingTransactionManager();
	PlatformTransactionManagerFacade.delegate = txMan;

	TestBean tb = (TestBean) factory.getBean("hotSwapped");
	assertEquals(666, tb.getAge());
	int newAge = 557;
	tb.setAge(newAge);
	assertEquals(newAge, tb.getAge());

	TestBean target2 = new TestBean();
	target2.setAge(65);
	HotSwappableTargetSource ts = (HotSwappableTargetSource) factory.getBean("swapper");
	ts.swap(target2);
	assertEquals(target2.getAge(), tb.getAge());
	tb.setAge(newAge);
	assertEquals(newAge, target2.getAge());

	assertEquals(0, txMan.inflight);
	assertEquals(2, txMan.commits);
	assertEquals(0, txMan.rollbacks);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:28,代码来源:BeanFactoryTransactionTests.java

示例2: testDynamicTargetSource

import org.springframework.aop.target.HotSwappableTargetSource; //导入方法依赖的package包/类
/**
 * Test that we can set the target to a dynamic TargetSource.
 */
public void testDynamicTargetSource() throws NoSuchMethodException {
	// Install facade
	CallCountingTransactionManager txMan = new CallCountingTransactionManager();
	PlatformTransactionManagerFacade.delegate = txMan;

	TestBean tb = (TestBean) factory.getBean("hotSwapped");
	assertEquals(666, tb.getAge());
	int newAge = 557;
	tb.setAge(newAge);
	assertEquals(newAge, tb.getAge());

	TestBean target2 = new TestBean();
	target2.setAge(65);
	HotSwappableTargetSource ts = (HotSwappableTargetSource) factory.getBean("swapper");
	ts.swap(target2);
	assertEquals(target2.getAge(), tb.getAge());
	tb.setAge(newAge);
	assertEquals(newAge, target2.getAge());

	assertEquals(0, txMan.inflight);
	assertEquals(2, txMan.commits);
	assertEquals(0, txMan.rollbacks);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:27,代码来源:BeanFactoryTransactionTests.java

示例3: aopTarget

import org.springframework.aop.target.HotSwappableTargetSource; //导入方法依赖的package包/类
public static void aopTarget() {
	ApplicationContext app = iocInit("");
	try {
		// SingletonTargetSource
		Object proxy = app.getBean("singleProxy");
		Object obj1 = ((Advised) proxy).getTargetSource().getTarget();
		Object obj2 = ((Advised) proxy).getTargetSource().getTarget();
		System.out.println("SingletonTargetSource:" + (obj1 == obj2));

		// PrototypeTargetSource
		proxy = app.getBean("prototypeProxy");
		obj1 = ((Advised) proxy).getTargetSource().getTarget();
		obj2 = ((Advised) proxy).getTargetSource().getTarget();
		System.out.println("PrototypeTargetSource:" + (obj1 == obj2));

		// HotSwappableTargetSource
		proxy = app.getBean("hotswapProxy");
		obj1 = ((Advised) proxy).getTargetSource().getTarget();
		HotSwappableTargetSource hsts = (HotSwappableTargetSource) app
				.getBean("hotswapTarget");
		Object oldObj = hsts.swap(new ITester() {
			@Override
			public void testSoftware() {
			}

			@Override
			public boolean isBusyAsTester() {
				return false;
			}
		});
		obj2 = ((Advised) proxy).getTargetSource().getTarget();
		System.out.println(oldObj == obj1);
		System.out.println(oldObj == obj2);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:bdceo,项目名称:bd-codes,代码行数:38,代码来源:FXmain.java

示例4: afterPropertiesSet

import org.springframework.aop.target.HotSwappableTargetSource; //导入方法依赖的package包/类
public void afterPropertiesSet() throws Exception {
   // run this when the bean is loaded

   // auto set the name if it is not set
   if (sakaiComponentName == null || "".equals(sakaiComponentName)) {
      Class<?>[] interfaces = getProxiedInterfaces();
      if (interfaces.length > 0) {
         sakaiComponentName = interfaces[0].getName();
         log.info("Autogenerating component name from interface: " + sakaiComponentName);
      }
   }

   // get the component from the Sakai CM if it is in there
   Object obj = ComponentManager.get(sakaiComponentName);

   /*
    * If the obj is null, that means this is the first time we have loaded
    * the component, so we will add it to the Component Manager. If this
    * component is already available from the component manager, then we
    * will simply update it's proxy target.
    */
   if (obj == null) {
      this.setTargetSource(new HotSwappableTargetSource(localSakaiComponentBean));  
      ComponentManager.loadComponent(sakaiComponentName, this);
   }
   else {
      try {
         Method getTargetSource = obj.getClass().getMethod("getTargetSource");              
         HotSwappableTargetSource hsts = (HotSwappableTargetSource) getTargetSource.invoke(obj);
         hsts.swap(localSakaiComponentBean);
      } catch (Exception e) {
         log.error("Unable to update reloadable SakaiComponent: " + sakaiComponentName, e);
      }
   }
   log.info("Added component proxy from webapp to component manager: " + sakaiComponentName);
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:37,代码来源:ReloadableComponentProxy.java

示例5: testExistingProxyChangesTarget

import org.springframework.aop.target.HotSwappableTargetSource; //导入方法依赖的package包/类
@Test
public void testExistingProxyChangesTarget() throws Throwable {
	TestBean tb1 = new TestBean();
	tb1.setAge(33);

	TestBean tb2 = new TestBean();
	tb2.setAge(26);
	tb2.setName("Juergen");
	TestBean tb3 = new TestBean();
	tb3.setAge(37);
	ProxyFactory pc = new ProxyFactory(tb1);
	NopInterceptor nop = new NopInterceptor();
	pc.addAdvice(nop);
	ITestBean proxy = (ITestBean) createProxy(pc);
	assertEquals(nop.getCount(), 0);
	assertEquals(tb1.getAge(), proxy.getAge());
	assertEquals(nop.getCount(), 1);
	// Change to a new static target
	pc.setTarget(tb2);
	assertEquals(tb2.getAge(), proxy.getAge());
	assertEquals(nop.getCount(), 2);

	// Change to a new dynamic target
	HotSwappableTargetSource hts = new HotSwappableTargetSource(tb3);
	pc.setTargetSource(hts);
	assertEquals(tb3.getAge(), proxy.getAge());
	assertEquals(nop.getCount(), 3);
	hts.swap(tb1);
	assertEquals(tb1.getAge(), proxy.getAge());
	tb1.setName("Colin");
	assertEquals(tb1.getName(), proxy.getName());
	assertEquals(nop.getCount(), 5);

	// Change back, relying on casting to Advised
	Advised advised = (Advised) proxy;
	assertSame(hts, advised.getTargetSource());
	SingletonTargetSource sts = new SingletonTargetSource(tb2);
	advised.setTargetSource(sts);
	assertEquals(tb2.getName(), proxy.getName());
	assertSame(sts, advised.getTargetSource());
	assertEquals(tb2.getAge(), proxy.getAge());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:43,代码来源:AbstractAopProxyTests.java


注:本文中的org.springframework.aop.target.HotSwappableTargetSource.swap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。