use of com.alipay.sofa.runtime.api.binding.BindingType in project sofa-boot by alipay.
the class ReferenceAnnotationBeanPostProcessor method createReferenceProxy.
private Object createReferenceProxy(SofaReference sofaReferenceAnnotation, Class<?> interfaceType) {
Reference reference = new ReferenceImpl(sofaReferenceAnnotation.uniqueId(), interfaceType, InterfaceMode.annotation, sofaReferenceAnnotation.jvmFirst());
BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(new BindingType(sofaReferenceAnnotation.binding().bindingType()));
if (bindingConverter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00200", sofaReferenceAnnotation.binding().bindingType()));
}
BindingConverterContext bindingConverterContext = new BindingConverterContext();
bindingConverterContext.setInBinding(true);
bindingConverterContext.setApplicationContext(applicationContext);
bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
Binding binding = bindingConverter.convert(sofaReferenceAnnotation, sofaReferenceAnnotation.binding(), bindingConverterContext);
reference.addBinding(binding);
return ReferenceRegisterHelper.registerReference(reference, bindingAdapterFactory, sofaRuntimeContext, applicationContext);
}
use of com.alipay.sofa.runtime.api.binding.BindingType in project sofa-boot by alipay.
the class ServiceBeanFactoryPostProcessor method getSofaServiceBinding.
private List<Binding> getSofaServiceBinding(SofaService sofaServiceAnnotation, SofaServiceBinding[] sofaServiceBindings) {
List<Binding> bindings = new ArrayList<>();
for (SofaServiceBinding sofaServiceBinding : sofaServiceBindings) {
BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(new BindingType(sofaServiceBinding.bindingType()));
if (bindingConverter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00200", sofaServiceBinding.bindingType()));
}
BindingConverterContext bindingConverterContext = new BindingConverterContext();
bindingConverterContext.setInBinding(false);
bindingConverterContext.setApplicationContext(applicationContext);
bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
Binding binding = bindingConverter.convert(sofaServiceAnnotation, sofaServiceBinding, bindingConverterContext);
bindings.add(binding);
}
return bindings;
}
use of com.alipay.sofa.runtime.api.binding.BindingType in project sofa-boot by alipay.
the class SofaBindingTest method testBindingType.
@Test
public void testBindingType() {
Assert.assertTrue(new BindingType("jvm").equals(new BindingType("jvm")));
Assert.assertFalse(new BindingType("jvm").equals(new BindingType("bolt")));
Assert.assertFalse(new BindingType("jvm").equals(null));
Assert.assertFalse(new BindingType("jvm").equals("jvm"));
HashMap<BindingType, String> map = new HashMap<>();
map.put(new BindingType("jvm"), "jvm");
map.put(new BindingType("bolt"), "bolt");
map.put(new BindingType("rest"), "rest");
Assert.assertEquals(map.get(new BindingType("jvm")), "jvm");
Assert.assertEquals(map.get(new BindingType("bolt")), "bolt");
Assert.assertEquals(map.get(new BindingType("rest")), "rest");
Assert.assertEquals(map.get("jvm"), null);
Assert.assertEquals(map.get(null), null);
}
use of com.alipay.sofa.runtime.api.binding.BindingType in project sofa-boot by alipay.
the class SofaServiceAndReferenceTest method testSofaServiceWithMultipleBindings.
@Test
public void testSofaServiceWithMultipleBindings() {
Map<String, Object> properties = new HashMap<>();
properties.put("spring.application.name", "SofaServiceAndReferenceTest");
SpringApplication springApplication = new SpringApplication(MultipleBindingsSofaServiceConfiguration.class, RuntimeConfiguration.class);
springApplication.setWebApplicationType(WebApplicationType.NONE);
springApplication.setDefaultProperties(properties);
ApplicationContext ctx = springApplication.run();
ServiceFactoryBean bean = ctx.getBean(ServiceFactoryBean.class);
Assert.assertEquals(2, bean.getBindings().size());
Assert.assertEquals(new BindingType("jvm"), bean.getBindings().get(0).getBindingType());
Assert.assertEquals(new BindingType("jvm"), bean.getBindings().get(1).getBindingType());
}
use of com.alipay.sofa.runtime.api.binding.BindingType in project sofa-boot by sofastack.
the class ServiceBeanFactoryPostProcessor method getSofaReferenceBinding.
/**
* get sofa reference binding annotated on parameter. At present, only jvm sofa reference is supported .
* @param sofaReferenceAnnotation
* @param sofaReferenceBinding
* @return
*/
private List<Binding> getSofaReferenceBinding(SofaReference sofaReferenceAnnotation, SofaReferenceBinding sofaReferenceBinding) {
if (!JvmBinding.XmlConstants.BINDING_TYPE.equals(sofaReferenceBinding.bindingType())) {
throw new ServiceRuntimeException(ErrorCode.convert("01-02005"));
}
List<Binding> bindings = new ArrayList<>();
BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(new BindingType(sofaReferenceBinding.bindingType()));
if (bindingConverter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00200", sofaReferenceBinding.bindingType()));
}
BindingConverterContext bindingConverterContext = new BindingConverterContext();
bindingConverterContext.setInBinding(true);
bindingConverterContext.setApplicationContext(applicationContext);
bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
Binding binding = bindingConverter.convert(sofaReferenceAnnotation, sofaReferenceBinding, bindingConverterContext);
bindings.add(binding);
return bindings;
}
Aggregations