use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by alipay.
the class ServiceFactoryBean method doAfterPropertiesSet.
@Override
protected void doAfterPropertiesSet() {
if (!apiType && hasSofaServiceAnnotation()) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00103", beanId, ref.getClass()));
}
Implementation implementation = new DefaultImplementation();
implementation.setTarget(ref);
service = buildService();
// default add jvm binding and service jvm binding should set serialize as true
if (bindings.size() == 0) {
JvmBindingParam jvmBindingParam = new JvmBindingParam().setSerialize(true);
bindings.add(new JvmBinding().setJvmBindingParam(jvmBindingParam));
}
for (Binding binding : bindings) {
service.addBinding(binding);
}
ComponentInfo componentInfo = new ServiceComponent(implementation, service, bindingAdapterFactory, sofaRuntimeContext);
componentInfo.setApplicationContext(applicationContext);
sofaRuntimeContext.getComponentManager().register(componentInfo);
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by alipay.
the class ServiceComponent method deactivate.
@Override
public void deactivate() throws ServiceRuntimeException {
Object target = service.getTarget();
if (target == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00000"));
}
if (service.hasBinding()) {
boolean allPassed = true;
Set<Binding> bindings = service.getBindings();
for (Binding binding : bindings) {
BindingAdapter<Binding> bindingAdapter = this.bindingAdapterFactory.getBindingAdapter(binding.getBindingType());
if (bindingAdapter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00001", binding.getBindingType(), service));
}
SofaLogger.info(" <<Pre un-out Binding [{}] Begins - {}.", binding.getBindingType(), service);
try {
bindingAdapter.preUnoutBinding(service, binding, target, getContext());
} catch (Throwable t) {
allPassed = false;
SofaLogger.error(ErrorCode.convert("01-00006", binding.getBindingType(), service), t);
continue;
}
SofaLogger.info(" <<Pre un-out Binding [{}] Ends - {}.", binding.getBindingType(), service);
}
if (!allPassed) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00007", service));
}
}
super.deactivate();
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by alipay.
the class XsdTimeoutTest method testReferenceTimeout.
@Test
public void testReferenceTimeout() {
Collection<ComponentInfo> c = sofaRuntimeContext.getComponentManager().getComponentInfosByType(ReferenceComponent.REFERENCE_COMPONENT_TYPE);
for (ComponentInfo componentInfo : c) {
if (componentInfo instanceof ReferenceComponent) {
ReferenceComponent referenceComponent = (ReferenceComponent) componentInfo;
if (!referenceComponent.getReference().getInterfaceType().equals(WhateverInterface.class)) {
continue;
}
Binding binding = referenceComponent.getReference().getBinding(RpcBindingType.BOLT_BINDING_TYPE);
if (binding instanceof RpcBinding) {
RpcBinding rpcBinding = (RpcBinding) binding;
Assert.assertEquals((long) rpcBinding.getRpcBindingParam().getTimeout(), 10000);
}
}
}
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by alipay.
the class ReferenceClientImpl method getReferenceFromReferenceParam.
@SuppressWarnings("unchecked")
private <T> Reference getReferenceFromReferenceParam(ReferenceParam<T> referenceParam) {
BindingParam bindingParam = referenceParam.getBindingParam();
Reference reference = new ReferenceImpl(referenceParam.getUniqueId(), referenceParam.getInterfaceType(), InterfaceMode.api, referenceParam.isJvmFirst(), null);
if (bindingParam == null) {
// default add jvm binding and reference jvm binding should set serialize as false
JvmBindingParam jvmBindingParam = new JvmBindingParam();
jvmBindingParam.setSerialize(false);
reference.addBinding(new JvmBinding().setJvmBindingParam(jvmBindingParam));
} else {
BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(bindingParam.getBindingType());
if (bindingConverter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00200", bindingParam.getBindingType()));
}
BindingConverterContext bindingConverterContext = new BindingConverterContext();
bindingConverterContext.setInBinding(true);
bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
Binding binding = bindingConverter.convert(bindingParam, bindingConverterContext);
reference.addBinding(binding);
}
return reference;
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by alipay.
the class ReferenceComponent method activate.
@Override
public void activate() throws ServiceRuntimeException {
if (reference.hasBinding()) {
Binding candidate = null;
Set<Binding> bindings = reference.getBindings();
if (bindings.size() == 1) {
candidate = bindings.iterator().next();
} else if (bindings.size() > 1) {
Object backupProxy = null;
for (Binding binding : bindings) {
if (JvmBinding.JVM_BINDING_TYPE.getType().equals(binding.getName())) {
candidate = binding;
} else {
// Under normal RPC reference (local-first/jvm-first is not set to false) binding,
// backup proxy is the RPC proxy, which will be invoked if Jvm service is not found
backupProxy = createProxy(reference, binding);
}
}
if (candidate != null) {
((JvmBinding) candidate).setBackupProxy(backupProxy);
}
}
Object proxy = null;
if (candidate != null) {
proxy = createProxy(reference, candidate);
}
this.implementation = new DefaultImplementation();
implementation.setTarget(proxy);
}
super.activate();
latch.countDown();
}
Aggregations