use of com.alipay.sofa.runtime.spi.component.SofaRuntimeManager in project sofa-boot by alipay.
the class RuntimeConfiguration method sofaRuntimeManager.
@Bean
@ConditionalOnMissingBean
public static SofaRuntimeManager sofaRuntimeManager(Environment environment, BindingConverterFactory bindingConverterFactory, BindingAdapterFactory bindingAdapterFactory) {
String appName = environment.getProperty(SofaBootConstants.APP_NAME_KEY);
ClientFactoryInternal clientFactoryInternal = new ClientFactoryImpl();
SofaRuntimeManager sofaRuntimeManager = new StandardSofaRuntimeManager(appName, Thread.currentThread().getContextClassLoader(), clientFactoryInternal);
sofaRuntimeManager.getComponentManager().registerComponentClient(ReferenceClient.class, new ReferenceClientImpl(sofaRuntimeManager.getSofaRuntimeContext(), bindingConverterFactory, bindingAdapterFactory));
sofaRuntimeManager.getComponentManager().registerComponentClient(ServiceClient.class, new ServiceClientImpl(sofaRuntimeManager.getSofaRuntimeContext(), bindingConverterFactory, bindingAdapterFactory));
SofaFramework.registerSofaRuntimeManager(sofaRuntimeManager);
return sofaRuntimeManager;
}
use of com.alipay.sofa.runtime.spi.component.SofaRuntimeManager in project sofa-boot by alipay.
the class HealthCheckerProcessorParallelTest method testComponentHealthCheckerFailedFirst.
@Test
public void testComponentHealthCheckerFailedFirst() {
SofaRuntimeManager manager = new StandardSofaRuntimeManager("testComponentHealthCheckerFailedFirst", Thread.currentThread().getContextClassLoader(), null);
manager.getComponentManager().register(new TestComponent("component1", true));
manager.getComponentManager().register(new TestComponent("component2", true));
manager.getComponentManager().register(new TestComponent("component3", false));
manager.getComponentManager().register(new TestComponent("component4", true));
manager.getComponentManager().register(new TestComponent("component5", false));
ComponentHealthChecker componentHealthChecker = new ComponentHealthChecker(new SofaRuntimeContext(manager, manager.getComponentManager(), null));
int i = 0;
for (Map.Entry<String, Object> entry : componentHealthChecker.isHealthy().getDetails().entrySet()) {
if (i < 2) {
Assert.assertEquals(entry.getValue().toString(), "failed");
} else {
Assert.assertEquals(entry.getValue().toString(), "passed");
}
++i;
}
}
use of com.alipay.sofa.runtime.spi.component.SofaRuntimeManager in project sofa-boot by alipay.
the class MultiApplicationHealthIndicator method health.
@Override
public Health health() {
boolean allPassed = true;
Health.Builder builder = new Health.Builder();
for (SofaRuntimeManager sofaRuntimeManager : SofaFramework.getRuntimeSet()) {
Biz biz = DynamicJvmServiceProxyFinder.getBiz(sofaRuntimeManager);
if (biz == null) {
continue;
}
if (!sofaRuntimeManager.isLivenessHealth()) {
allPassed = false;
builder.withDetail(String.format("Biz: %s health check", biz.getIdentity()), "failed");
} else {
builder.withDetail(String.format("Biz: %s health check", biz.getIdentity()), "passed");
}
}
if (allPassed) {
return builder.up().build();
} else {
return builder.down().build();
}
}
use of com.alipay.sofa.runtime.spi.component.SofaRuntimeManager in project sofa-boot by alipay.
the class DynamicJvmServiceProxyFinder method findServiceProxy.
public ServiceProxy findServiceProxy(ClassLoader clientClassloader, Contract contract) {
ServiceComponent serviceComponent = findServiceComponent(clientClassloader, contract);
if (serviceComponent == null) {
return null;
}
SofaRuntimeManager sofaRuntimeManager = serviceComponent.getContext().getSofaRuntimeManager();
Biz biz = getBiz(sofaRuntimeManager);
if (biz == null) {
return null;
}
JvmBinding referenceJvmBinding = (JvmBinding) contract.getBinding(JvmBinding.JVM_BINDING_TYPE);
JvmBinding serviceJvmBinding = (JvmBinding) serviceComponent.getService().getBinding(JvmBinding.JVM_BINDING_TYPE);
boolean serialize;
if (serviceJvmBinding != null) {
serialize = referenceJvmBinding.getJvmBindingParam().isSerialize() || serviceJvmBinding.getJvmBindingParam().isSerialize();
} else {
// Service provider don't intend to publish JVM service, serialize is considered to be true in this case
serialize = true;
}
return new DynamicJvmServiceInvoker(clientClassloader, sofaRuntimeManager.getAppClassLoader(), serviceComponent.getService().getTarget(), contract, biz.getIdentity(), serialize);
}
use of com.alipay.sofa.runtime.spi.component.SofaRuntimeManager in project sofa-boot by alipay.
the class DynamicJvmServiceProxyFinder method findServiceComponent.
public ServiceComponent findServiceComponent(ClassLoader clientClassloader, Contract contract) {
ServiceComponent serviceComponent = null;
if (hasFinishStartup && SofaRuntimeProperties.isDynamicJvmServiceCacheEnable()) {
serviceComponent = cacheSearching(contract);
if (serviceComponent != null) {
return serviceComponent;
}
}
String interfaceType = contract.getInterfaceType().getCanonicalName();
String uniqueId = contract.getUniqueId();
for (SofaRuntimeManager sofaRuntimeManager : SofaFramework.getRuntimeSet()) {
if (sofaRuntimeManager.getAppClassLoader().equals(clientClassloader)) {
continue;
}
String version = ReplayContext.get();
if (ReplayContext.PLACEHOLDER.equals(version)) {
version = null;
}
Biz biz = getBiz(sofaRuntimeManager);
// if null , check next
if (biz == null) {
continue;
}
// https://github.com/sofastack/sofa-boot/issues/532
if (hasFinishStartup && biz.getBizState() != BizState.DEACTIVATED && biz.getBizState() != BizState.ACTIVATED) {
continue;
}
// if specified version , but version do not match ,check next
if (version != null && !version.equals(biz.getBizVersion())) {
continue;
}
// https://github.com/sofastack/sofa-boot/issues/532
if (hasFinishStartup && version == null && biz.getBizState() != BizState.ACTIVATED) {
continue;
}
// match biz
serviceComponent = findServiceComponent(uniqueId, interfaceType, sofaRuntimeManager.getComponentManager());
if (serviceComponent != null) {
return serviceComponent;
}
}
return null;
}
Aggregations