use of com.alipay.sofa.runtime.spi.component.DefaultImplementation in project sofa-boot by sofastack.
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();
}
use of com.alipay.sofa.runtime.spi.component.DefaultImplementation 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