Guest User

Untitled

a guest
Nov 9th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. package io.pivotal.config;
  2.  
  3. import java.util.Properties;
  4.  
  5. import org.apache.geode.pdx.ReflectionBasedAutoSerializer;
  6. import org.springframework.cloud.Cloud;
  7. import org.springframework.cloud.CloudFactory;
  8. import org.springframework.context.annotation.Bean;
  9. import org.springframework.data.gemfire.cache.config.EnableGemfireCaching;
  10. import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
  11. import org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer;
  12. import org.springframework.data.gemfire.config.annotation.EnableContinuousQueries;
  13. import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions;
  14. import org.springframework.data.gemfire.config.annotation.EnableSecurity;
  15. import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories;
  16.  
  17. import io.pivotal.model.Pizza;
  18.  
  19. @ClientCacheApplication(name = "GemFireSpringPizzaStoreApplication", durableClientId = "5",
  20. readyForEvents = true, subscriptionEnabled = true)
  21. @EnableContinuousQueries(poolName = "DEFAULT")
  22. @EnableEntityDefinedRegions(basePackageClasses = Pizza.class)
  23. @EnableGemfireCaching
  24. @EnableGemfireRepositories("io.pivotal.repository.gemfire")
  25. @EnableSecurity
  26. public class GemfireConfiguration {
  27.  
  28. //private static final String SECURITY_CLIENT = "security-client-auth-init";
  29. private static final String SECURITY_USERNAME = "security-username";
  30. private static final String SECURITY_PASSWORD = "security-password";
  31.  
  32. @Bean
  33. ClientCacheConfigurer clientCacheSecurityConfigurer() {
  34.  
  35. return (beanName, clientCacheFactoryBean) -> {
  36.  
  37. Cloud cloud = new CloudFactory().getCloud();
  38. ServiceInfo serviceInfo = (ServiceInfo) cloud.getServiceInfos().get(0);
  39. Properties gemfireProperties = clientCacheFactoryBean.getProperties();
  40.  
  41. gemfireProperties.setProperty(SECURITY_USERNAME, serviceInfo.getUsername());
  42. gemfireProperties.setProperty(SECURITY_PASSWORD, serviceInfo.getPassword());
  43.  
  44. clientCacheFactoryBean.setPdxSerializer(
  45. new ReflectionBasedAutoSerializer("io.pivotal.model.Pizza", "io.pivotal.model.Name"));
  46. };
  47. }
  48.  
  49. /*
  50. @Bean
  51. public ClientCache gemfireCache() {
  52.  
  53. Cloud cloud = new CloudFactory().getCloud();
  54. ServiceInfo serviceInfo = (ServiceInfo) cloud.getServiceInfos().get(0);
  55. ClientCacheFactory factory = new ClientCacheFactory();
  56.  
  57. for (URI locator : serviceInfo.getLocators()) {
  58. factory.addPoolLocator(locator.getHost(), locator.getPort());
  59. }
  60.  
  61. factory.set(SECURITY_CLIENT, "io.pivotal.config.UserAuthInitialize.create");
  62. factory.set(SECURITY_USERNAME, serviceInfo.getUsername());
  63. factory.set(SECURITY_PASSWORD, serviceInfo.getPassword());
  64. factory.setPdxSerializer(new ReflectionBasedAutoSerializer("io.pivotal.model.Pizza", "io.pivotal.model.Name"));
  65. factory.setPoolSubscriptionEnabled(true); // to enable CQ
  66.  
  67. return factory.create();
  68. }
  69. */
  70.  
  71. /*
  72. @Bean
  73. public ClientCache gemfireCache() {
  74.  
  75. ClientCacheFactory factory = new ClientCacheFactory();
  76.  
  77. factory.addPoolLocator("10.74.37.200", 55221);
  78. factory.addPoolLocator("10.74.37.201", 55221);
  79. factory.addPoolLocator("10.74.37.202", 55221);
  80. factory.set(SECURITY_CLIENT, "io.pivotal.config.UserAuthInitialize.create");
  81. factory.set(SECURITY_USERNAME, "cluster_operator");
  82. factory.set(SECURITY_PASSWORD, "no4h3dBA1UHN5ZubeXmA");
  83. factory.setPdxSerializer(new ReflectionBasedAutoSerializer("io.pivotal.model.Pizza"));
  84. factory.setPoolSubscriptionEnabled(true); // to enable CQ
  85.  
  86. return factory.create();
  87. }
  88. */
  89.  
  90. /*
  91. @Bean
  92. public GemfireCacheManager cacheManager(ClientCache gemfireCache) {
  93. GemfireCacheManager cacheManager = new GemfireCacheManager();
  94. cacheManager.setCache(gemfireCache);
  95. return cacheManager;
  96. }
  97. */
  98.  
  99. /*
  100. @Bean(name = "Pizza")
  101. ClientRegionFactoryBean<Long, Pizza> orderRegion(@Autowired ClientCache gemfireCache) {
  102. ClientRegionFactoryBean<Long, Pizza> orderRegion = new ClientRegionFactoryBean<>();
  103.  
  104. orderRegion.setCache(gemfireCache);
  105. orderRegion.setClose(false);
  106. orderRegion.setShortcut(ClientRegionShortcut.PROXY);
  107. orderRegion.setLookupEnabled(true);
  108.  
  109. return orderRegion;
  110. }
  111. */
  112.  
  113. /*
  114. @Bean(name = "Name")
  115. ClientRegionFactoryBean<Long, Name> nameRegion(@Autowired ClientCache gemfireCache) {
  116. ClientRegionFactoryBean<Long, Name> nameRegion = new ClientRegionFactoryBean<>();
  117.  
  118. nameRegion.setCache(gemfireCache);
  119. nameRegion.setClose(false);
  120. nameRegion.setShortcut(ClientRegionShortcut.PROXY);
  121. nameRegion.setLookupEnabled(true);
  122.  
  123. return nameRegion;
  124. }
  125. */
  126. }
Add Comment
Please, Sign In to add comment