Search in sources :

Example 1 with ServiceMetadataImpl

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;
}
Also used : ServiceMetadataImpl(com.alipay.sofa.ark.container.registry.ServiceMetadataImpl) ServiceMetadata(com.alipay.sofa.ark.spi.registry.ServiceMetadata) ServiceReference(com.alipay.sofa.ark.spi.registry.ServiceReference) ServiceReferenceImpl(com.alipay.sofa.ark.container.registry.ServiceReferenceImpl)

Aggregations

ServiceMetadataImpl (com.alipay.sofa.ark.container.registry.ServiceMetadataImpl)1 ServiceReferenceImpl (com.alipay.sofa.ark.container.registry.ServiceReferenceImpl)1 ServiceMetadata (com.alipay.sofa.ark.spi.registry.ServiceMetadata)1 ServiceReference (com.alipay.sofa.ark.spi.registry.ServiceReference)1