Search in sources :

Example 1 with ResourceIdProvider

use of com.sequenceiq.flow.core.ResourceIdProvider in project cloudbreak by hortonworks.

the class ComponentTestConfig method resourceIdProvider.

@Bean
public ResourceIdProvider resourceIdProvider() {
    AtomicLong idSeq = new AtomicLong(0);
    ConcurrentMap<String, Long> crnIdMap = new ConcurrentHashMap<>();
    ConcurrentMap<String, Long> nameIdMap = new ConcurrentHashMap<>();
    return new ResourceIdProvider() {

        @Override
        public Long getResourceIdByResourceCrn(String resourceCrn) {
            return crnIdMap.computeIfAbsent(resourceCrn, r -> idSeq.incrementAndGet());
        }

        @Override
        public Long getResourceIdByResourceName(String resourceName) {
            return nameIdMap.computeIfAbsent(resourceName, r -> idSeq.incrementAndGet());
        }
    };
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ResourceIdProvider(com.sequenceiq.flow.core.ResourceIdProvider) Bean(org.springframework.context.annotation.Bean) ConversionServiceFactoryBean(org.springframework.context.support.ConversionServiceFactoryBean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Aggregations

ResourceIdProvider (com.sequenceiq.flow.core.ResourceIdProvider)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Bean (org.springframework.context.annotation.Bean)1 ConversionServiceFactoryBean (org.springframework.context.support.ConversionServiceFactoryBean)1 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)1