Search in sources :

Example 1 with ClientFactoryInternal

use of com.alipay.sofa.runtime.spi.client.ClientFactoryInternal in project sofa-boot by sofastack.

the class ComponentManagerImpl method shutdown.

@Override
public void shutdown() {
    if (SofaRuntimeProperties.isSkipAllComponentShutdown(appClassLoader)) {
        return;
    }
    List<ComponentInfo> elems = new ArrayList<>(registry.values());
    // shutdown spring contexts first
    List<ComponentInfo> springContextComponents = elems.stream().filter(componentInfo -> componentInfo instanceof SpringContextComponent).collect(Collectors.toList());
    for (ComponentInfo ri : springContextComponents) {
        try {
            unregister(ri);
        } catch (Throwable t) {
            SofaLogger.error(ErrorCode.convert("01-03001", ri.getName()), t);
        }
    }
    if (!springContextComponents.isEmpty()) {
        elems.removeAll(springContextComponents);
    }
    if (SofaRuntimeProperties.isSkipCommonComponentShutdown(appClassLoader)) {
        return;
    }
    // shutdown remaining components
    for (ComponentInfo ri : elems) {
        try {
            unregister(ri);
        } catch (Throwable t) {
            SofaLogger.error(ErrorCode.convert("01-03001", ri.getName()), t);
        }
    }
    try {
        if (registry != null) {
            registry.clear();
        }
        if (resolvedRegistry != null) {
            resolvedRegistry.clear();
        }
        clientFactoryInternal = null;
    } catch (Throwable t) {
        SofaLogger.error(ErrorCode.convert("01-03000"), t);
    }
}
Also used : ClientFactoryInternal(com.alipay.sofa.runtime.spi.client.ClientFactoryInternal) Collection(java.util.Collection) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SpringContextComponent(com.alipay.sofa.runtime.spring.SpringContextComponent) HashMap(java.util.HashMap) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) List(java.util.List) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentStatus(com.alipay.sofa.runtime.model.ComponentStatus) ComponentType(com.alipay.sofa.runtime.model.ComponentType) Map(java.util.Map) SofaLogger(com.alipay.sofa.runtime.log.SofaLogger) ErrorCode(com.alipay.sofa.boot.error.ErrorCode) SofaRuntimeProperties(com.alipay.sofa.runtime.SofaRuntimeProperties) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) ArrayList(java.util.ArrayList) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) SpringContextComponent(com.alipay.sofa.runtime.spring.SpringContextComponent)

Example 2 with ClientFactoryInternal

use of com.alipay.sofa.runtime.spi.client.ClientFactoryInternal in project sofa-boot by sofastack.

the class SofaRuntimeAutoConfiguration method sofaRuntimeManager.

@Bean
@ConditionalOnMissingBean
public static SofaRuntimeManager sofaRuntimeManager(Environment environment, BindingConverterFactory bindingConverterFactory, BindingAdapterFactory bindingAdapterFactory) {
    ClientFactoryInternal clientFactoryInternal = new ClientFactoryImpl();
    SofaRuntimeManager sofaRuntimeManager = new StandardSofaRuntimeManager(environment.getProperty("spring.application.name"), 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;
}
Also used : ClientFactoryImpl(com.alipay.sofa.runtime.client.impl.ClientFactoryImpl) ClientFactoryInternal(com.alipay.sofa.runtime.spi.client.ClientFactoryInternal) ReferenceClientImpl(com.alipay.sofa.runtime.service.client.ReferenceClientImpl) StandardSofaRuntimeManager(com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager) ServiceClientImpl(com.alipay.sofa.runtime.service.client.ServiceClientImpl) SofaRuntimeManager(com.alipay.sofa.runtime.spi.component.SofaRuntimeManager) StandardSofaRuntimeManager(com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with ClientFactoryInternal

use of com.alipay.sofa.runtime.spi.client.ClientFactoryInternal in project sofa-boot by sofastack.

the class SofaStartupIsleAutoConfiguration method sofaRuntimeManager.

@Bean(destroyMethod = "")
@ConditionalOnMissingBean
public static SofaRuntimeManager sofaRuntimeManager() {
    ClientFactoryInternal clientFactoryInternal = new ClientFactoryImpl();
    SofaRuntimeManager sofaRuntimeManager = new StandardSofaRuntimeManager("IsleStageCostTest", Thread.currentThread().getContextClassLoader(), clientFactoryInternal);
    SofaFramework.registerSofaRuntimeManager(sofaRuntimeManager);
    return sofaRuntimeManager;
}
Also used : ClientFactoryImpl(com.alipay.sofa.runtime.client.impl.ClientFactoryImpl) ClientFactoryInternal(com.alipay.sofa.runtime.spi.client.ClientFactoryInternal) StandardSofaRuntimeManager(com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager) SofaRuntimeManager(com.alipay.sofa.runtime.spi.component.SofaRuntimeManager) StandardSofaRuntimeManager(com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 4 with ClientFactoryInternal

use of com.alipay.sofa.runtime.spi.client.ClientFactoryInternal in project sofa-boot by alipay.

the class ComponentManagerImpl method shutdown.

@Override
public void shutdown() {
    if (SofaRuntimeProperties.isSkipAllComponentShutdown(appClassLoader)) {
        return;
    }
    List<ComponentInfo> elems = new ArrayList<>(registry.values());
    // shutdown spring contexts first
    List<ComponentInfo> springContextComponents = elems.stream().filter(componentInfo -> componentInfo instanceof SpringContextComponent).collect(Collectors.toList());
    for (ComponentInfo ri : springContextComponents) {
        try {
            unregister(ri);
        } catch (Throwable t) {
            SofaLogger.error(ErrorCode.convert("01-03001", ri.getName()), t);
        }
    }
    if (!springContextComponents.isEmpty()) {
        elems.removeAll(springContextComponents);
    }
    if (SofaRuntimeProperties.isSkipCommonComponentShutdown(appClassLoader)) {
        return;
    }
    // shutdown remaining components
    for (ComponentInfo ri : elems) {
        try {
            unregister(ri);
        } catch (Throwable t) {
            SofaLogger.error(ErrorCode.convert("01-03001", ri.getName()), t);
        }
    }
    try {
        if (registry != null) {
            registry.clear();
        }
        if (resolvedRegistry != null) {
            resolvedRegistry.clear();
        }
        clientFactoryInternal = null;
    } catch (Throwable t) {
        SofaLogger.error(ErrorCode.convert("01-03000"), t);
    }
}
Also used : ClientFactoryInternal(com.alipay.sofa.runtime.spi.client.ClientFactoryInternal) Collection(java.util.Collection) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SpringContextComponent(com.alipay.sofa.runtime.spring.SpringContextComponent) HashMap(java.util.HashMap) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) List(java.util.List) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentStatus(com.alipay.sofa.runtime.model.ComponentStatus) ComponentType(com.alipay.sofa.runtime.model.ComponentType) Map(java.util.Map) SofaLogger(com.alipay.sofa.runtime.log.SofaLogger) ErrorCode(com.alipay.sofa.boot.error.ErrorCode) SofaRuntimeProperties(com.alipay.sofa.runtime.SofaRuntimeProperties) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) ArrayList(java.util.ArrayList) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) SpringContextComponent(com.alipay.sofa.runtime.spring.SpringContextComponent)

Example 5 with ClientFactoryInternal

use of com.alipay.sofa.runtime.spi.client.ClientFactoryInternal in project sofa-boot by alipay.

the class SofaStartupIsleAutoConfiguration method sofaRuntimeManager.

@Bean(destroyMethod = "")
@ConditionalOnMissingBean
public static SofaRuntimeManager sofaRuntimeManager() {
    ClientFactoryInternal clientFactoryInternal = new ClientFactoryImpl();
    SofaRuntimeManager sofaRuntimeManager = new StandardSofaRuntimeManager("IsleStageCostTest", Thread.currentThread().getContextClassLoader(), clientFactoryInternal);
    SofaFramework.registerSofaRuntimeManager(sofaRuntimeManager);
    return sofaRuntimeManager;
}
Also used : ClientFactoryImpl(com.alipay.sofa.runtime.client.impl.ClientFactoryImpl) ClientFactoryInternal(com.alipay.sofa.runtime.spi.client.ClientFactoryInternal) StandardSofaRuntimeManager(com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager) SofaRuntimeManager(com.alipay.sofa.runtime.spi.component.SofaRuntimeManager) StandardSofaRuntimeManager(com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

ClientFactoryInternal (com.alipay.sofa.runtime.spi.client.ClientFactoryInternal)13 ClientFactoryImpl (com.alipay.sofa.runtime.client.impl.ClientFactoryImpl)11 StandardSofaRuntimeManager (com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager)11 SofaRuntimeManager (com.alipay.sofa.runtime.spi.component.SofaRuntimeManager)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 ComponentManager (com.alipay.sofa.runtime.spi.component.ComponentManager)3 ErrorCode (com.alipay.sofa.boot.error.ErrorCode)2 SofaRuntimeProperties (com.alipay.sofa.runtime.SofaRuntimeProperties)2 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)2 ComponentName (com.alipay.sofa.runtime.api.component.ComponentName)2 SofaLogger (com.alipay.sofa.runtime.log.SofaLogger)2 ComponentStatus (com.alipay.sofa.runtime.model.ComponentStatus)2 ComponentType (com.alipay.sofa.runtime.model.ComponentType)2 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)2 SpringContextComponent (com.alipay.sofa.runtime.spring.SpringContextComponent)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2