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;
}
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;
}
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);
}
}
}
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);
}
}
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();
}
Aggregations