Search in sources :

Example 6 with SofaRuntimeManager

use of com.alipay.sofa.runtime.spi.component.SofaRuntimeManager in project sofa-boot by sofastack.

the class SofaEventHandlerTest method testDynamicProxyFinder.

@Test
public void testDynamicProxyFinder() throws Exception {
    SofaFramework.registerSofaRuntimeManager(sofaRuntimeManager);
    new MockUp<DynamicJvmServiceProxyFinder>() {

        @Mock
        public Biz getBiz(SofaRuntimeManager sofaRuntimeManager) {
            return biz;
        }
    };
    new Expectations() {

        {
            biz.getIdentity();
            result = "MockName:MockVersion";
            biz.getBizState();
            result = BizState.ACTIVATED;
            sofaRuntimeManager.getAppClassLoader();
            result = ctx.getClassLoader().getParent();
        }
    };
    new Expectations() {

        {
            sofaRuntimeManager.getComponentManager();
            result = ((SofaRuntimeContext) ctx.getBean("sofaRuntimeContext")).getComponentManager();
            contract.getInterfaceType();
            result = SampleService.class;
            contract.getUniqueId();
            result = "";
            contract.getBinding(JvmBinding.JVM_BINDING_TYPE);
            result = new JvmBinding();
            invocation.getArguments();
            result = new Object[] {};
            invocation.getMethod();
            result = SampleService.class.getMethod("service");
        }
    };
    DynamicJvmServiceProxyFinder.getDynamicJvmServiceProxyFinder().setHasFinishStartup(true);
    ServiceProxy serviceProxy = DynamicJvmServiceProxyFinder.getDynamicJvmServiceProxyFinder().findServiceProxy(ctx.getClassLoader(), contract);
    try {
        Assert.assertTrue(SofaEventHandlerTest.class.getName().equals(serviceProxy.invoke(invocation)));
    } catch (Throwable throwable) {
        throw new RuntimeException("testDynamicProxyFinder case failed.", throwable);
    }
}
Also used : Expectations(mockit.Expectations) ServiceProxy(com.alipay.sofa.runtime.spi.service.ServiceProxy) DefaultSampleService(com.alipay.sofa.runtime.test.beans.service.DefaultSampleService) SampleService(com.alipay.sofa.runtime.test.beans.facade.SampleService) MockUp(mockit.MockUp) SofaRuntimeManager(com.alipay.sofa.runtime.spi.component.SofaRuntimeManager) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Test(org.junit.Test)

Example 7 with SofaRuntimeManager

use of com.alipay.sofa.runtime.spi.component.SofaRuntimeManager in project sofa-boot by sofastack.

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;
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) ServiceComponent(com.alipay.sofa.runtime.service.component.ServiceComponent) SofaRuntimeManager(com.alipay.sofa.runtime.spi.component.SofaRuntimeManager)

Example 8 with SofaRuntimeManager

use of com.alipay.sofa.runtime.spi.component.SofaRuntimeManager in project sofa-boot by sofastack.

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);
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) ServiceComponent(com.alipay.sofa.runtime.service.component.ServiceComponent) SofaRuntimeManager(com.alipay.sofa.runtime.spi.component.SofaRuntimeManager) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Example 9 with SofaRuntimeManager

use of com.alipay.sofa.runtime.spi.component.SofaRuntimeManager in project sofa-boot by sofastack.

the class DynamicJvmServiceProxyFinder method afterBizUninstall.

public void afterBizUninstall(Biz biz) {
    if (!SofaRuntimeProperties.isDynamicJvmServiceCacheEnable()) {
        return;
    }
    for (SofaRuntimeManager runtimeManager : SofaFramework.getRuntimeSet()) {
        if (runtimeManager.getAppClassLoader().equals(biz.getBizClassLoader())) {
            for (ComponentInfo componentInfo : runtimeManager.getComponentManager().getComponents()) {
                if (componentInfo instanceof ServiceComponent) {
                    ServiceComponent serviceComponent = (ServiceComponent) componentInfo;
                    String uniqueName = getUniqueName(serviceComponent.getService());
                    JvmServiceTargetHabitat jvmServiceTargetHabitat = jvmServiceTargetHabitats.get(uniqueName);
                    if (jvmServiceTargetHabitat != null) {
                        jvmServiceTargetHabitat.removeServiceComponent(biz.getBizVersion());
                    }
                }
            }
        }
    }
}
Also used : ServiceComponent(com.alipay.sofa.runtime.service.component.ServiceComponent) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) SofaRuntimeManager(com.alipay.sofa.runtime.spi.component.SofaRuntimeManager)

Example 10 with SofaRuntimeManager

use of com.alipay.sofa.runtime.spi.component.SofaRuntimeManager in project sofa-boot by alipay.

the class ModelCreatingStage method doProcess.

@Override
protected void doProcess() throws Exception {
    ApplicationRuntimeModel application = new ApplicationRuntimeModel();
    application.setAppName(appName);
    SofaRuntimeManager sofaRuntimeManager = applicationContext.getBean(SofaRuntimeManager.class);
    application.setSofaRuntimeContext(sofaRuntimeManager.getSofaRuntimeContext());
    application.setModuleDeploymentValidator(new DefaultModuleDeploymentValidator());
    getAllDeployments(application);
    applicationContext.getBeanFactory().registerSingleton(SofaBootConstants.APPLICATION, application);
}
Also used : DefaultModuleDeploymentValidator(com.alipay.sofa.isle.deployment.impl.DefaultModuleDeploymentValidator) SofaRuntimeManager(com.alipay.sofa.runtime.spi.component.SofaRuntimeManager) ApplicationRuntimeModel(com.alipay.sofa.isle.ApplicationRuntimeModel)

Aggregations

SofaRuntimeManager (com.alipay.sofa.runtime.spi.component.SofaRuntimeManager)33 StandardSofaRuntimeManager (com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager)15 ClientFactoryImpl (com.alipay.sofa.runtime.client.impl.ClientFactoryImpl)11 ClientFactoryInternal (com.alipay.sofa.runtime.spi.client.ClientFactoryInternal)11 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)10 Bean (org.springframework.context.annotation.Bean)10 ReferenceClientImpl (com.alipay.sofa.runtime.service.client.ReferenceClientImpl)9 ServiceClientImpl (com.alipay.sofa.runtime.service.client.ServiceClientImpl)9 ServiceComponent (com.alipay.sofa.runtime.service.component.ServiceComponent)8 Biz (com.alipay.sofa.ark.spi.model.Biz)6 Test (org.junit.Test)6 ComponentHealthChecker (com.alipay.sofa.healthcheck.impl.ComponentHealthChecker)4 JvmBinding (com.alipay.sofa.runtime.service.binding.JvmBinding)4 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)4 SofaRuntimeContext (com.alipay.sofa.runtime.spi.component.SofaRuntimeContext)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 ApplicationRuntimeModel (com.alipay.sofa.isle.ApplicationRuntimeModel)2 DefaultModuleDeploymentValidator (com.alipay.sofa.isle.deployment.impl.DefaultModuleDeploymentValidator)2