com.avanza.astrix.beans.api.AstrixFtProxiedFactory Maven / Gradle / Ivy
/*
* Copyright 2014 Avanza Bank AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.avanza.astrix.beans.api;
import java.util.Arrays;
import com.avanza.astrix.beans.core.AstrixBeanKey;
import com.avanza.astrix.beans.core.BeanInvocationDispatcher;
import com.avanza.astrix.beans.core.BeanProxy;
import com.avanza.astrix.beans.core.ReactiveTypeConverter;
import com.avanza.astrix.beans.factory.AstrixBeans;
import com.avanza.astrix.beans.factory.StandardFactoryBean;
import com.avanza.astrix.beans.ft.BeanFaultToleranceFactory;
import com.avanza.astrix.beans.publish.PublishedAstrixBean;
import com.avanza.astrix.core.util.ReflectionUtil;
final class AstrixFtProxiedFactory implements StandardFactoryBean {
private final StandardFactoryBean target;
private final BeanFaultToleranceFactory faultToleranceProxyFactory;
private final PublishedAstrixBean beanDefinition;
private final ReactiveTypeConverter asyncTypeConverter;
public AstrixFtProxiedFactory(StandardFactoryBean target,
BeanFaultToleranceFactory faultToleranceProxyFactory,
PublishedAstrixBean beanDefinition,
ReactiveTypeConverter asyncTypeConverter) {
this.target = target;
this.faultToleranceProxyFactory = faultToleranceProxyFactory;
this.beanDefinition = beanDefinition;
this.asyncTypeConverter = asyncTypeConverter;
}
@Override
public T create(AstrixBeans beans) {
T rawBean = target.create(beans);
BeanProxy ftProxy = faultToleranceProxyFactory.createFaultToleranceProxy(beanDefinition.getBeanKey());
BeanInvocationDispatcher beanProxyDispather = new BeanInvocationDispatcher(Arrays.asList(ftProxy), asyncTypeConverter, rawBean);
return ReflectionUtil.newProxy(getBeanKey().getBeanType(), beanProxyDispather);
}
@Override
public AstrixBeanKey getBeanKey() {
return target.getBeanKey();
}
}