@Test public void testNullTargetBeans() { LoadBalanceProxyFactoryBean loadBalanceProxyFactoryBean = newLoadBalanceProxyFactoryBean(Greet.class, null); try { loadBalanceProxyFactoryBean.afterPropertiesSet(); Assert.fail("loadBalanceProxyFactoryBean with null 'targetBeans' property should throw exception."); } catch (Exception e) { Assert.assertNotNull("exception should not null.", e); } }
@SuppressWarnings("unchecked") public void afterPropertiesSet() throws Exception { if (getServiceInterface() == null) { throw new IllegalArgumentException("Property 'serviceInterfaces' is required"); } if (targetBeans == null) { throw new IllegalArgumentException("Property 'targetFactoryBeans' is required"); } for (Map.Entry<String, Object> entry : targetBeans.entrySet()) { Object o = entry.getValue(); if (!getServiceInterface().isAssignableFrom(o.getClass())) { throw new IllegalArgumentException("target facotry bean class '" + entry.getKey() + "' must implement serviceInterface"); } if (!isAssignableFrom(getExtraServiceInterfaces(), o.getClass())) { throw new IllegalArgumentException("target facotry bean class '" + entry.getKey() + "' must implement all the extraInterfaces "); } } ProxyFactory pf = new ProxyFactory(getServiceInterface(), this); if (getExtraServiceInterfaces() != null) { for (Class clazz : getExtraServiceInterfaces()) { pf.addInterface(clazz); } } this.serviceProxy = pf.getProxy(getBeanClassLoader()); if (loadBalanceStrategy == null) { Map<String, Integer> lbFactors = new HashMap<String, Integer>(); for (String key : targetBeans.keySet()) { lbFactors.put(key, DEFAULT_LB_FACTOR); } loadBalanceStrategy = new RoundRobinLoadBalanceStrategy(lbFactors); } else { Set<String> targets = loadBalanceStrategy.getTargets(); if (targets == null) { targets = new HashSet<String>(); } for (String key : targets) { if (!targetBeans.containsKey(key)) { LOGGER.log(Level.SEVERE, "the target key '" + key + "' of loadBalanceStrategy is invalid"); loadBalanceStrategy.removeTarget(key); } } } targetBeans = Collections.synchronizedMap(targetBeans); if (!isFailOver()) { LOGGER.log(Level.WARNING, "LoadBalanceProxy is shut down failover action due to not set FailOverInterceptor"); } }
LoadBalanceProxyFactoryBean extends ServiceMultiInterfaceAccessor implements BeanClassLoaderAware,
        FactoryBean, InitializingBean, MethodInterceptor, DisposableBean, BeanNameAware { @SuppressWarnings("unchecked") public void afterPropertiesSet() throws Exception { if (getServiceInterface() == null) { throw new IllegalArgumentException("Property 'serviceInterfaces' is required"); } if (targetBeans == null) { throw new IllegalArgumentException("Property 'targetFactoryBeans' is required"); } for (Map.Entry<String, Object> entry : targetBeans.entrySet()) { Object o = entry.getValue(); if (!getServiceInterface().isAssignableFrom(o.getClass())) { throw new IllegalArgumentException("target facotry bean class '" + entry.getKey() + "' must implement serviceInterface"); } if (!isAssignableFrom(getExtraServiceInterfaces(), o.getClass())) { throw new IllegalArgumentException("target facotry bean class '" + entry.getKey() + "' must implement all the extraInterfaces "); } } ProxyFactory pf = new ProxyFactory(getServiceInterface(), this); if (getExtraServiceInterfaces() != null) { for (Class clazz : getExtraServiceInterfaces()) { pf.addInterface(clazz); } } this.serviceProxy = pf.getProxy(getBeanClassLoader()); if (loadBalanceStrategy == null) { Map<String, Integer> lbFactors = new HashMap<String, Integer>(); for (String key : targetBeans.keySet()) { lbFactors.put(key, DEFAULT_LB_FACTOR); } loadBalanceStrategy = new RoundRobinLoadBalanceStrategy(lbFactors); } else { Set<String> targets = loadBalanceStrategy.getTargets(); if (targets == null) { targets = new HashSet<String>(); } for (String key : targets) { if (!targetBeans.containsKey(key)) { LOGGER.log(Level.SEVERE, "the target key '" + key + "' of loadBalanceStrategy is invalid"); loadBalanceStrategy.removeTarget(key); } } } targetBeans = Collections.synchronizedMap(targetBeans); if (!isFailOver()) { LOGGER.log(Level.WARNING, "LoadBalanceProxy is shut down failover action due to not set FailOverInterceptor"); } } }
LoadBalanceProxyFactoryBean extends ServiceMultiInterfaceAccessor implements BeanClassLoaderAware,
        FactoryBean, InitializingBean, MethodInterceptor, DisposableBean, BeanNameAware { @SuppressWarnings("unchecked") public void afterPropertiesSet() throws Exception { if (getServiceInterface() == null) { throw new IllegalArgumentException("Property 'serviceInterfaces' is required"); } if (targetBeans == null) { throw new IllegalArgumentException("Property 'targetFactoryBeans' is required"); } for (Map.Entry<String, Object> entry : targetBeans.entrySet()) { Object o = entry.getValue(); if (!getServiceInterface().isAssignableFrom(o.getClass())) { throw new IllegalArgumentException("target facotry bean class '" + entry.getKey() + "' must implement serviceInterface"); } if (!isAssignableFrom(getExtraServiceInterfaces(), o.getClass())) { throw new IllegalArgumentException("target facotry bean class '" + entry.getKey() + "' must implement all the extraInterfaces "); } } ProxyFactory pf = new ProxyFactory(getServiceInterface(), this); if (getExtraServiceInterfaces() != null) { for (Class clazz : getExtraServiceInterfaces()) { pf.addInterface(clazz); } } this.serviceProxy = pf.getProxy(getBeanClassLoader()); if (loadBalanceStrategy == null) { Map<String, Integer> lbFactors = new HashMap<String, Integer>(); for (String key : targetBeans.keySet()) { lbFactors.put(key, DEFAULT_LB_FACTOR); } loadBalanceStrategy = new RoundRobinLoadBalanceStrategy(lbFactors); } else { Set<String> targets = loadBalanceStrategy.getTargets(); if (targets == null) { targets = new HashSet<String>(); } for (String key : targets) { if (!targetBeans.containsKey(key)) { LOGGER.log(Level.SEVERE, "the target key '" + key + "' of loadBalanceStrategy is invalid"); loadBalanceStrategy.removeTarget(key); } } } targetBeans = Collections.synchronizedMap(targetBeans); if (!isFailOver()) { LOGGER.log(Level.WARNING, "LoadBalanceProxy is shut down failover action due to not set FailOverInterceptor"); } }  }
LoadBalanceProxyFactoryBean extends ServiceMultiInterfaceAccessor implements BeanClassLoaderAware,
        FactoryBean, InitializingBean, MethodInterceptor, DisposableBean, BeanNameAware { @SuppressWarnings("unchecked") public void afterPropertiesSet() throws Exception { if (getServiceInterface() == null) { throw new IllegalArgumentException("Property 'serviceInterfaces' is required"); } if (targetBeans == null) { throw new IllegalArgumentException("Property 'targetFactoryBeans' is required"); } for (Map.Entry<String, Object> entry : targetBeans.entrySet()) { Object o = entry.getValue(); if (!getServiceInterface().isAssignableFrom(o.getClass())) { throw new IllegalArgumentException("target facotry bean class '" + entry.getKey() + "' must implement serviceInterface"); } if (!isAssignableFrom(getExtraServiceInterfaces(), o.getClass())) { throw new IllegalArgumentException("target facotry bean class '" + entry.getKey() + "' must implement all the extraInterfaces "); } } ProxyFactory pf = new ProxyFactory(getServiceInterface(), this); if (getExtraServiceInterfaces() != null) { for (Class clazz : getExtraServiceInterfaces()) { pf.addInterface(clazz); } } this.serviceProxy = pf.getProxy(getBeanClassLoader()); if (loadBalanceStrategy == null) { Map<String, Integer> lbFactors = new HashMap<String, Integer>(); for (String key : targetBeans.keySet()) { lbFactors.put(key, DEFAULT_LB_FACTOR); } loadBalanceStrategy = new RoundRobinLoadBalanceStrategy(lbFactors); } else { Set<String> targets = loadBalanceStrategy.getTargets(); if (targets == null) { targets = new HashSet<String>(); } for (String key : targets) { if (!targetBeans.containsKey(key)) { LOGGER.log(Level.SEVERE, "the target key '" + key + "' of loadBalanceStrategy is invalid"); loadBalanceStrategy.removeTarget(key); } } } targetBeans = Collections.synchronizedMap(targetBeans); if (!isFailOver()) { LOGGER.log(Level.WARNING, "LoadBalanceProxy is shut down failover action due to not set FailOverInterceptor"); } }  void setFailOverEvent(FailOverEvent failOverEvent); void setTargetBeans(Map<String, Object> targetFactoryBeans); synchronized void addTargetBean(String key, Object targetBean); void setLoadBalanceStrategy(LoadBalanceStrategy loadBalanceStrategy); FailOverInterceptor getFailOverInterceptor(); void setFailOverInterceptor(FailOverInterceptor failOverInterceptor); boolean isFailOver(); @SuppressWarnings("unchecked") void afterPropertiesSet(); Object getObject(); Class getObjectType(); boolean isSingleton(); void setBeanClassLoader(ClassLoader classLoader); Object invoke(MethodInvocation invocation); Object invokeWithMaxTry(MethodInvocation invocation, int maxTry); Map<String, FactoryBeanInvokeInfo> getFailedFactoryBeans(); synchronized void recoverFactoryBean(String key); synchronized boolean hasFactoryBeanFailed(); void destroy(); void cleanResource(boolean needFreeThreadPool); void setStrategyInterceptor(StrategyInterceptor strategyInterceptor); void setRecoverInterval(long recoverInterval); long getRecoverInterval(); void setHeartBeat(boolean heartBeat); void setBeanName(String beanName); }
LoadBalanceProxyFactoryBean extends ServiceMultiInterfaceAccessor implements BeanClassLoaderAware,
        FactoryBean, InitializingBean, MethodInterceptor, DisposableBean, BeanNameAware { @SuppressWarnings("unchecked") public void afterPropertiesSet() throws Exception { if (getServiceInterface() == null) { throw new IllegalArgumentException("Property 'serviceInterfaces' is required"); } if (targetBeans == null) { throw new IllegalArgumentException("Property 'targetFactoryBeans' is required"); } for (Map.Entry<String, Object> entry : targetBeans.entrySet()) { Object o = entry.getValue(); if (!getServiceInterface().isAssignableFrom(o.getClass())) { throw new IllegalArgumentException("target facotry bean class '" + entry.getKey() + "' must implement serviceInterface"); } if (!isAssignableFrom(getExtraServiceInterfaces(), o.getClass())) { throw new IllegalArgumentException("target facotry bean class '" + entry.getKey() + "' must implement all the extraInterfaces "); } } ProxyFactory pf = new ProxyFactory(getServiceInterface(), this); if (getExtraServiceInterfaces() != null) { for (Class clazz : getExtraServiceInterfaces()) { pf.addInterface(clazz); } } this.serviceProxy = pf.getProxy(getBeanClassLoader()); if (loadBalanceStrategy == null) { Map<String, Integer> lbFactors = new HashMap<String, Integer>(); for (String key : targetBeans.keySet()) { lbFactors.put(key, DEFAULT_LB_FACTOR); } loadBalanceStrategy = new RoundRobinLoadBalanceStrategy(lbFactors); } else { Set<String> targets = loadBalanceStrategy.getTargets(); if (targets == null) { targets = new HashSet<String>(); } for (String key : targets) { if (!targetBeans.containsKey(key)) { LOGGER.log(Level.SEVERE, "the target key '" + key + "' of loadBalanceStrategy is invalid"); loadBalanceStrategy.removeTarget(key); } } } targetBeans = Collections.synchronizedMap(targetBeans); if (!isFailOver()) { LOGGER.log(Level.WARNING, "LoadBalanceProxy is shut down failover action due to not set FailOverInterceptor"); } }  void setFailOverEvent(FailOverEvent failOverEvent); void setTargetBeans(Map<String, Object> targetFactoryBeans); synchronized void addTargetBean(String key, Object targetBean); void setLoadBalanceStrategy(LoadBalanceStrategy loadBalanceStrategy); FailOverInterceptor getFailOverInterceptor(); void setFailOverInterceptor(FailOverInterceptor failOverInterceptor); boolean isFailOver(); @SuppressWarnings("unchecked") void afterPropertiesSet(); Object getObject(); Class getObjectType(); boolean isSingleton(); void setBeanClassLoader(ClassLoader classLoader); Object invoke(MethodInvocation invocation); Object invokeWithMaxTry(MethodInvocation invocation, int maxTry); Map<String, FactoryBeanInvokeInfo> getFailedFactoryBeans(); synchronized void recoverFactoryBean(String key); synchronized boolean hasFactoryBeanFailed(); void destroy(); void cleanResource(boolean needFreeThreadPool); void setStrategyInterceptor(StrategyInterceptor strategyInterceptor); void setRecoverInterval(long recoverInterval); long getRecoverInterval(); void setHeartBeat(boolean heartBeat); void setBeanName(String beanName);  }