Search in sources :

Example 1 with CloudFactory

use of org.springframework.cloud.CloudFactory in project pivotal-cla by pivotalsoftware.

the class SessionConfig method cloudRedisConnectionFactory.

@Profile(GitHubClaProfiles.CLOUDFOUNDRY)
@Bean
public RedisConnectionFactory cloudRedisConnectionFactory() {
    CloudFactory cloudFactory = new CloudFactory();
    Cloud cloud = cloudFactory.getCloud();
    RedisConnectionFactory connectionFactory = cloud.getSingletonServiceConnector(RedisConnectionFactory.class, null);
    if (connectionFactory instanceof LettuceConnectionFactory) {
        ((LettuceConnectionFactory) connectionFactory).setShutdownTimeout(0);
    }
    return connectionFactory;
}
Also used : CloudFactory(org.springframework.cloud.CloudFactory) Cloud(org.springframework.cloud.Cloud) LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) Profile(org.springframework.context.annotation.Profile) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with CloudFactory

use of org.springframework.cloud.CloudFactory in project spring-cloud-connectors by spring-cloud.

the class CloudPropertiesFactoryBean method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    ConfigurableListableBeanFactory listableBeanFactory = (ConfigurableListableBeanFactory) beanFactory;
    if (cloud == null) {
        if (listableBeanFactory.getBeansOfType(CloudFactory.class).isEmpty()) {
            listableBeanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME, new CloudFactory());
        }
        CloudFactory cloudFactory = listableBeanFactory.getBeansOfType(CloudFactory.class).values().iterator().next();
        cloud = cloudFactory.getCloud();
    }
}
Also used : CloudFactory(org.springframework.cloud.CloudFactory) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 3 with CloudFactory

use of org.springframework.cloud.CloudFactory in project spring-cloud-connectors by spring-cloud.

the class AbstractCloudServiceConnectorFactory method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) getBeanFactory();
    if (cloud == null) {
        if (beanFactory.getBeansOfType(CloudFactory.class).isEmpty()) {
            beanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME, new CloudFactory());
        }
        CloudFactory cloudFactory = beanFactory.getBeansOfType(CloudFactory.class).values().iterator().next();
        cloud = cloudFactory.getCloud();
    }
    if (!StringUtils.hasText(serviceId)) {
        List<? extends ServiceInfo> infos = cloud.getServiceInfos(serviceConnectorType);
        if (infos.size() != 1) {
            throw new CloudException("Expected 1 service matching " + serviceConnectorType.getName() + " type, but found " + infos.size());
        }
        serviceId = infos.get(0).getId();
    }
    super.afterPropertiesSet();
}
Also used : CloudFactory(org.springframework.cloud.CloudFactory) CloudException(org.springframework.cloud.CloudException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 4 with CloudFactory

use of org.springframework.cloud.CloudFactory in project spring-cloud-connectors by spring-cloud.

the class CloudScanHelper method initializeCloud.

private void initializeCloud(BeanDefinitionRegistry registry) {
    if (cloud != null) {
        return;
    }
    ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) registry;
    if (beanFactory.getBeansOfType(CloudFactory.class).isEmpty()) {
        beanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME, new CloudFactory());
    }
    CloudFactory cloudFactory = beanFactory.getBeansOfType(CloudFactory.class).values().iterator().next();
    cloud = cloudFactory.getCloud();
}
Also used : CloudFactory(org.springframework.cloud.CloudFactory) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Aggregations

CloudFactory (org.springframework.cloud.CloudFactory)4 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)3 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Cloud (org.springframework.cloud.Cloud)1 CloudException (org.springframework.cloud.CloudException)1 Bean (org.springframework.context.annotation.Bean)1 Profile (org.springframework.context.annotation.Profile)1 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)1 LettuceConnectionFactory (org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory)1