use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by sofastack.
the class ServiceComponent method activateBinding.
private void activateBinding() {
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));
}
Object outBindingResult;
SofaLogger.info(" <<Out Binding [{}] Begins - {}.", binding.getBindingType(), service);
try {
outBindingResult = bindingAdapter.outBinding(service, binding, target, getContext());
} catch (Throwable t) {
allPassed = false;
binding.setHealthy(false);
SofaLogger.error(ErrorCode.convert("01-00004", binding.getBindingType(), service), t);
continue;
}
if (!Boolean.FALSE.equals(outBindingResult)) {
SofaLogger.info(" <<Out Binding [{}] Ends - {}.", binding.getBindingType(), service);
} else {
binding.setHealthy(false);
SofaLogger.info(" <<Out Binding [{}] Fails, Don't publish service - {}.", binding.getBindingType(), service);
}
}
if (!allPassed) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00005", service));
}
}
SofaLogger.info("Register Service - {}", service);
}
use of com.alipay.sofa.runtime.spi.binding.Binding in project sofa-boot by sofastack.
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);
}
Aggregations