spring-projects / spring-data-geode

Spring Data support for Apache Geode
Apache License 2.0
51 stars 39 forks source link

Add @ClientCacheApplication and @EnablePool annotation attribute and property support for socketConnectTimeout [DATAGEODE-335] #384

Closed spring-projects-issues closed 4 years ago

spring-projects-issues commented 4 years ago

John Blum opened DATAGEODE-335 and commented

Currently, the @ClientCacheApplication annotation as well as the @EnablePool annotation from SDG are missing a configuration attribute and associated property (e.g. spring.data.gemfire.pool.socket-connect-timeout) for socketConnectTimeout, which is part of the GemFire/Geode API in the ClientCacheFactory class as well as the PoolFactory interface.

This property (and setter) have been appropriately added to the ClientCacheFactoryBean as well as the PoolFactoryBean SDG classes.

Therefore, the socketConnectTimeout configuration setting should be appropriately added to the @ClientCacheApplication and @EnablePool annotations as both an attribute and property in SDG, respectively


Affects: 2.1.17 (Lovelace SR17), 2.2.7 (Moore SR7), 2.3 RC2 (Neumann)

Backported to: 2.2.8 (Moore SR8), 2.1.18 (Lovelace SR18)

spring-projects-issues commented 4 years ago

John Blum commented

Users have asked how to configure the socketConnectTimeout property (using the appropriate SDG FactoryBean setter method, i.e. setSocketConnectTimeout(:int), with either the ClientCacheFactoryBean when configuring the "DEFAULT" Pool or using the PoolFactoryBean when configuring a "named" Pool) dynamically?

By way of example, if you users are using SDG's Annotation-based configuration model, then users could do the following:

@ClientCacheApplication
@EnablePools(pools = {
  @EnablePool(name = "PoolOne"),
  @EnablePool(name = "PoolTwo"),
  @EnablePool(name = "PoolThree")
})
class GeodeConfiguration {

  @Bean
  ClientCacheConfigurer defaultPoolSocketConnectTimeoutConfigurer(
      @Value("${some.external.property:5000}") int timeout) {

    return (beanName, clientCacheFactoryBean) ->  clientCacheFatoryBean.setSocketConnectTimeout(timeout);
  }

  @Bean
  PoolConfigurer namedPoolSocketConnectTimeoutConfigurer(@Value("${some.external.property:5000}") int timeout) {

    return (beanName, poolFactoryBean) -> {

      // Only configure the 'socketConnectTimeout' for "PoolOne" and "PoolTwo"
      // NOT for "PoolThree"
      if (Arrays.asList("PoolOne", "PoolTwo").contains(beanName)) {
        poolFactoryBean.setSocketConnectTimeout(timeout);
      }
    };
  }
}

However, if the user is directly using the SDG API in Spring container Java-based configuration with the SDG FactoryBeans, and specifically, the ClientCachFactoryBean and (possibly) PoolFactoryBeans, then the following would be equivalent to the above:

@Configuration
class GeodeConfiguration {

  @Bean
  ClientCacheFactoryBean gemfireCache(@Value("${some.external.proeprty:5000}") int timeout) {

    ClientCacheFactoryBean gemfireCache = new ClientCacheFactoryBean();

    gemfireCache.setSocketConnectTimeout(timeout);
    ...

    return gemfireCache;
  }

  @Bean("PoolOne")
  PoolFactoryBean poolOne(@Value("${some.external.property:5000}") int timeout) {

    PoolFactoryBean pool = new PoolFactoryBean();

    pool.setSocketConnectTimeout(timeout);
    ...

    return pool;
  }

  @Bean("PoolTwo")
  PoolFactoryBean poolTwo(@Value("${some.external.property:5000}") int timeout) {

    PoolFactoryBean pool = new PoolFactoryBean();

    pool.setSocketConnectTimeout(timeout);
    ...

    return pool;
  }

  @Bean("PoolThree")
  PoolFactoryBean poolThree(@Value() {

    PoolFactoryBean pool = new PoolFactoryBean();

    ...

    return pool;
  }
}