• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java HotSwappableTargetSource类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



HotSwappableTargetSource类属于org.springframework.aop.target包,在下文中一共展示了HotSwappableTargetSource类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: makeSpringAOPToStringTrigger

import org.springframework.aop.target.HotSwappableTargetSource; //导入依赖的package包/类
public static Object makeSpringAOPToStringTrigger ( Object o ) throws Exception {
    return makeToStringTrigger(o, x -> {
        return new HotSwappableTargetSource(x);
    });
}
 
开发者ID:mbechler,项目名称:marshalsec,代码行数:6,代码来源:ToStringUtil.java


示例6: 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


示例7: getTargetSource

import org.springframework.aop.target.HotSwappableTargetSource; //导入依赖的package包/类
public HotSwappableTargetSource getTargetSource() {
    return targetSource;
}
 
开发者ID:alibaba,项目名称:cobarclient,代码行数:4,代码来源:PassiveEventHotSwappableAdvice.java


示例8: setTargetSource

import org.springframework.aop.target.HotSwappableTargetSource; //导入依赖的package包/类
public void setTargetSource(HotSwappableTargetSource targetSource) {
    this.targetSource = targetSource;
}
 
开发者ID:alibaba,项目名称:cobarclient,代码行数:4,代码来源:PassiveEventHotSwappableAdvice.java


示例9: createHADataSource

import org.springframework.aop.target.HotSwappableTargetSource; //导入依赖的package包/类
public DataSource createHADataSource(CobarDataSourceDescriptor descriptor) throws Exception {
    DataSource activeDataSource = descriptor.getTargetDataSource();
    DataSource standbyDataSource = descriptor.getStandbyDataSource();
    if (activeDataSource == null && standbyDataSource == null) {
        throw new IllegalArgumentException("must have at least one data source active.");
    }
    if (activeDataSource == null || standbyDataSource == null) {
        logger.warn("only one data source is available for use, so no HA support.");
        if (activeDataSource == null) {
            return standbyDataSource;
        }
        return activeDataSource;
    }

    HotSwappableTargetSource targetSource = new HotSwappableTargetSource(activeDataSource);
    ProxyFactory pf = new ProxyFactory();
    pf.setInterfaces(new Class[] { DataSource.class });
    pf.setTargetSource(targetSource);
    
    
    if (isPositiveFailoverEnable()) {
        DataSource targetDetectorDataSource = descriptor.getTargetDetectorDataSource();
        DataSource standbyDetectorDataSource = descriptor.getStandbyDetectorDataSource();
        if (targetDetectorDataSource == null || standbyDetectorDataSource == null) {
            throw new IllegalArgumentException(
                    "targetDetectorDataSource or standbyDetectorDataSource can't be null if positive failover is enabled.");
        }
        // 1. create active monitoring job for failover event
        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
        ExecutorService jobExecutor = Executors.newFixedThreadPool(1);
        jobExecutorRegistry.add(jobExecutor);
        FailoverMonitorJob job = new FailoverMonitorJob(jobExecutor);
        //    1.1  inject dependencies
        job.setHotSwapTargetSource(targetSource);
        job.setMasterDataSource(activeDataSource);
        job.setStandbyDataSource(standbyDataSource);
        job.setMasterDetectorDataSource(targetDetectorDataSource);
        job.setStandbyDetectorDataSource(standbyDetectorDataSource);
        job.setCurrentDetectorDataSource(targetDetectorDataSource);
        job.setDetectingRequestTimeout(getDetectingTimeoutThreshold());
        job.setDetectingSQL(getDetectingSql());
        job.setRecheckInterval(recheckInterval);
        job.setRecheckTimes(recheckTimes);
        //    1.2  start scheduling and keep reference for canceling and shutdown
        ScheduledFuture<?> future = scheduler.scheduleWithFixedDelay(job, initialDelay,
                monitorPeriod, TimeUnit.MILLISECONDS);
        schedulerFutures.put(future, scheduler);
    }

    if (isPassiveFailoverEnable()) {
        // 2. create data source proxy with passive event advice
        PassiveEventHotSwappableAdvice advice = new PassiveEventHotSwappableAdvice();
        advice.setRetryInterval(recheckInterval);
        advice.setRetryTimes(recheckTimes);
        advice.setDetectingSql(detectingSql);
        advice.setTargetSource(targetSource);
        advice.setMainDataSource(activeDataSource);
        advice.setStandbyDataSource(standbyDataSource);
        pf.addAdvice(advice);
    }

    return (DataSource) pf.getProxy();
}
 
开发者ID:alibaba,项目名称:cobarclient,代码行数:64,代码来源:FailoverHotSwapDataSourceCreator.java


示例10: getHotSwapTargetSource

import org.springframework.aop.target.HotSwappableTargetSource; //导入依赖的package包/类
public HotSwappableTargetSource getHotSwapTargetSource() {
    return hotSwapTargetSource;
}
 
开发者ID:alibaba,项目名称:cobarclient,代码行数:4,代码来源:FailoverMonitorJob.java


示例11: setHotSwapTargetSource

import org.springframework.aop.target.HotSwappableTargetSource; //导入依赖的package包/类
public void setHotSwapTargetSource(HotSwappableTargetSource hotSwapTargetSource) {
    this.hotSwapTargetSource = hotSwapTargetSource;
}
 
开发者ID:alibaba,项目名称:cobarclient,代码行数:4,代码来源:FailoverMonitorJob.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CreationReference类代码示例发布时间:2022-05-22
下一篇:
Java XLineBreakpointImpl类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap