Created
November 6, 2017 22:37
-
-
Save jxblum/c31f7de7a0336a62f3dc71e3ef895d08 to your computer and use it in GitHub Desktop.
GemFire configuration using SDG Annotation-based configuration.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.pivotal.config; | |
import java.util.Properties; | |
import org.apache.geode.pdx.ReflectionBasedAutoSerializer; | |
import org.springframework.cloud.Cloud; | |
import org.springframework.cloud.CloudFactory; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.data.gemfire.cache.config.EnableGemfireCaching; | |
import org.springframework.data.gemfire.config.annotation.ClientCacheApplication; | |
import org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer; | |
import org.springframework.data.gemfire.config.annotation.EnableContinuousQueries; | |
import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions; | |
import org.springframework.data.gemfire.config.annotation.EnableSecurity; | |
import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; | |
import io.pivotal.model.Pizza; | |
@ClientCacheApplication(name = "GemFireSpringPizzaStoreApplication", durableClientId = "5", | |
readyForEvents = true, subscriptionEnabled = true) | |
@EnableContinuousQueries(poolName = "DEFAULT") | |
@EnableEntityDefinedRegions(basePackageClasses = Pizza.class) | |
@EnableGemfireCaching | |
@EnableGemfireRepositories("io.pivotal.repository.gemfire") | |
@EnableSecurity | |
public class GemfireConfiguration { | |
//private static final String SECURITY_CLIENT = "security-client-auth-init"; | |
private static final String SECURITY_USERNAME = "security-username"; | |
private static final String SECURITY_PASSWORD = "security-password"; | |
@Bean | |
ClientCacheConfigurer clientCacheSecurityConfigurer() { | |
return (beanName, clientCacheFactoryBean) -> { | |
Cloud cloud = new CloudFactory().getCloud(); | |
ServiceInfo serviceInfo = (ServiceInfo) cloud.getServiceInfos().get(0); | |
Properties gemfireProperties = clientCacheFactoryBean.getProperties(); | |
gemfireProperties.setProperty(SECURITY_USERNAME, serviceInfo.getUsername()); | |
gemfireProperties.setProperty(SECURITY_PASSWORD, serviceInfo.getPassword()); | |
clientCacheFactoryBean.setPdxSerializer( | |
new ReflectionBasedAutoSerializer("io.pivotal.model.Pizza", "io.pivotal.model.Name")); | |
}; | |
} | |
/* | |
@Bean | |
public ClientCache gemfireCache() { | |
Cloud cloud = new CloudFactory().getCloud(); | |
ServiceInfo serviceInfo = (ServiceInfo) cloud.getServiceInfos().get(0); | |
ClientCacheFactory factory = new ClientCacheFactory(); | |
for (URI locator : serviceInfo.getLocators()) { | |
factory.addPoolLocator(locator.getHost(), locator.getPort()); | |
} | |
factory.set(SECURITY_CLIENT, "io.pivotal.config.UserAuthInitialize.create"); | |
factory.set(SECURITY_USERNAME, serviceInfo.getUsername()); | |
factory.set(SECURITY_PASSWORD, serviceInfo.getPassword()); | |
factory.setPdxSerializer(new ReflectionBasedAutoSerializer("io.pivotal.model.Pizza", "io.pivotal.model.Name")); | |
factory.setPoolSubscriptionEnabled(true); // to enable CQ | |
return factory.create(); | |
} | |
*/ | |
/* | |
@Bean | |
public ClientCache gemfireCache() { | |
ClientCacheFactory factory = new ClientCacheFactory(); | |
factory.addPoolLocator("10.74.37.200", 55221); | |
factory.addPoolLocator("10.74.37.201", 55221); | |
factory.addPoolLocator("10.74.37.202", 55221); | |
factory.set(SECURITY_CLIENT, "io.pivotal.config.UserAuthInitialize.create"); | |
factory.set(SECURITY_USERNAME, "cluster_operator"); | |
factory.set(SECURITY_PASSWORD, "no4h3dBA1UHN5ZubeXmA"); | |
factory.setPdxSerializer(new ReflectionBasedAutoSerializer("io.pivotal.model.Pizza")); | |
factory.setPoolSubscriptionEnabled(true); // to enable CQ | |
return factory.create(); | |
} | |
*/ | |
/* | |
@Bean | |
public GemfireCacheManager cacheManager(ClientCache gemfireCache) { | |
GemfireCacheManager cacheManager = new GemfireCacheManager(); | |
cacheManager.setCache(gemfireCache); | |
return cacheManager; | |
} | |
*/ | |
/* | |
@Bean(name = "Pizza") | |
ClientRegionFactoryBean<Long, Pizza> orderRegion(@Autowired ClientCache gemfireCache) { | |
ClientRegionFactoryBean<Long, Pizza> orderRegion = new ClientRegionFactoryBean<>(); | |
orderRegion.setCache(gemfireCache); | |
orderRegion.setClose(false); | |
orderRegion.setShortcut(ClientRegionShortcut.PROXY); | |
orderRegion.setLookupEnabled(true); | |
return orderRegion; | |
} | |
*/ | |
/* | |
@Bean(name = "Name") | |
ClientRegionFactoryBean<Long, Name> nameRegion(@Autowired ClientCache gemfireCache) { | |
ClientRegionFactoryBean<Long, Name> nameRegion = new ClientRegionFactoryBean<>(); | |
nameRegion.setCache(gemfireCache); | |
nameRegion.setClose(false); | |
nameRegion.setShortcut(ClientRegionShortcut.PROXY); | |
nameRegion.setLookupEnabled(true); | |
return nameRegion; | |
} | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment