use of com.alipay.sofa.ark.container.registry.ServiceMetadataImpl in project sofa-ark by alipay.
the class RegistryServiceImpl method publishService.
@Override
public <T> ServiceReference<T> publishService(Class<T> ifClass, T implObject, ServiceProvider serviceProvider) {
ServiceMetadata serviceMetadata = new ServiceMetadataImpl(ifClass.getName(), ifClass, serviceProvider);
if (!services.containsKey(serviceMetadata.getServiceName())) {
services.putIfAbsent(serviceMetadata.getServiceName(), new CopyOnWriteArrayList<ServiceReference<?>>());
}
List<ServiceReference<?>> serviceReferences = services.get(serviceMetadata.getServiceName());
for (ServiceReference<?> serviceReference : serviceReferences) {
if (serviceMetadata.equals(serviceReference.getServiceMetadata())) {
LOGGER.warn(String.format("Service: %s publish by: %s already exist", serviceMetadata.getServiceName(), serviceProvider));
return (ServiceReference<T>) serviceReference;
}
}
ServiceReference<T> serviceReference = new ServiceReferenceImpl<>(serviceMetadata, implObject);
LOGGER.info(String.format("Service: %s publish by: %s succeed", serviceMetadata.getServiceName(), serviceProvider));
serviceReferences.add(serviceReference);
return serviceReference;
}
Aggregations