Search in sources :

Example 1 with ComponentName

use of com.alipay.sofa.runtime.api.component.ComponentName in project sofa-boot by alipay.

the class ReferenceComponent method getServiceTarget.

/**
 * get service target
 *
 * @return service target
 */
private Object getServiceTarget() {
    Object serviceTarget = null;
    ComponentName componentName = ComponentNameFactory.createComponentName(ServiceComponent.SERVICE_COMPONENT_TYPE, reference.getInterfaceType(), reference.getUniqueId());
    ComponentInfo componentInfo = sofaRuntimeContext.getComponentManager().getComponentInfo(componentName);
    if (componentInfo != null) {
        serviceTarget = componentInfo.getImplementation().getTarget();
    }
    return serviceTarget;
}
Also used : ComponentName(com.alipay.sofa.runtime.api.component.ComponentName)

Example 2 with ComponentName

use of com.alipay.sofa.runtime.api.component.ComponentName in project sofa-boot by alipay.

the class ComponentManagerImpl method _register.

private ComponentInfo _register(ComponentInfo ci) {
    ComponentName name = ci.getName();
    if (isRegistered(name)) {
        SofaLogger.error("Component was already registered: {0}", name);
        return getComponentInfo(name);
    }
    try {
        ci.register();
    } catch (Exception e) {
        SofaLogger.error(e, "Failed to register component: {0}", ci.getName());
        return null;
    }
    SofaLogger.info("Registering component: {0}", ci.getName());
    try {
        ComponentInfo old = registry.putIfAbsent(ci.getName(), ci);
        if (old != null) {
            SofaLogger.error("Component was already registered: {0}", name);
            return old;
        }
        if (ci.resolve()) {
            _typeRegistry(ci);
            ci.activate();
        }
    } catch (Exception e) {
        ci.exception(e);
        SofaLogger.error(e, "Failed to create the component {0}", ci.getName());
    }
    return ci;
}
Also used : ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Example 3 with ComponentName

use of com.alipay.sofa.runtime.api.component.ComponentName in project sofa-boot by alipay.

the class ReferenceClientImpl method removeReference.

@Override
public <T> void removeReference(ReferenceParam<T> referenceParam) {
    Reference reference = getReferenceFromReferenceParam(referenceParam);
    ComponentName referenceComponentName = ComponentNameFactory.createComponentName(ReferenceComponent.REFERENCE_COMPONENT_TYPE, reference.getInterfaceType(), reference.getUniqueId() + "#" + ReferenceRegisterHelper.generateBindingHashCode(reference));
    Collection<ComponentInfo> referenceComponents = sofaRuntimeContext.getComponentManager().getComponentInfosByType(ReferenceComponent.REFERENCE_COMPONENT_TYPE);
    for (ComponentInfo referenceComponent : referenceComponents) {
        if (referenceComponent.getName().equals(referenceComponentName)) {
            sofaRuntimeContext.getComponentManager().unregister(referenceComponent);
        }
    }
}
Also used : Reference(com.alipay.sofa.runtime.service.component.Reference) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo)

Example 4 with ComponentName

use of com.alipay.sofa.runtime.api.component.ComponentName in project sofa-boot by alipay.

the class ComponentManagerImpl method _typeRegistry.

protected void _typeRegistry(ComponentInfo componentInfo) {
    ComponentName name = componentInfo.getName();
    if (name != null) {
        ComponentType type = name.getType();
        Map<ComponentName, ComponentInfo> typesRi = resolvedRegistry.get(type);
        if (typesRi == null) {
            resolvedRegistry.putIfAbsent(type, new HashMap<ComponentName, ComponentInfo>());
            typesRi = resolvedRegistry.get(type);
        }
        typesRi.put(name, componentInfo);
    }
}
Also used : ComponentType(com.alipay.sofa.runtime.model.ComponentType) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo)

Example 5 with ComponentName

use of com.alipay.sofa.runtime.api.component.ComponentName in project sofa-boot by alipay.

the class ComponentManagerImpl method unregister.

public void unregister(ComponentInfo componentInfo) throws ServiceRuntimeException {
    ComponentName componentName = componentInfo.getName();
    registry.remove(componentName);
    if (componentName != null) {
        ComponentType componentType = componentName.getType();
        Map<ComponentName, ComponentInfo> typesRi = resolvedRegistry.get(componentType);
        typesRi.remove(componentName);
    }
    componentInfo.unregister();
}
Also used : ComponentType(com.alipay.sofa.runtime.model.ComponentType) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo)

Aggregations

ComponentName (com.alipay.sofa.runtime.api.component.ComponentName)5 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)4 ComponentType (com.alipay.sofa.runtime.model.ComponentType)2 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)1 Reference (com.alipay.sofa.runtime.service.component.Reference)1