Backport GemFire improvements
This commit is contained in:
@@ -71,8 +71,6 @@ public class AbstractGemFireIntegrationTests {
|
||||
protected static final boolean GEMFIRE_QUERY_DEBUG = Boolean
|
||||
.getBoolean("spring.session.data.gemfire.query.debug");
|
||||
|
||||
protected static final int DEFAULT_GEMFIRE_SERVER_PORT = CacheServer.DEFAULT_PORT;
|
||||
|
||||
protected static final long DEFAULT_WAIT_DURATION = TimeUnit.SECONDS.toMillis(20);
|
||||
protected static final long DEFAULT_WAIT_INTERVAL = 500L;
|
||||
|
||||
@@ -82,7 +80,7 @@ public class AbstractGemFireIntegrationTests {
|
||||
protected static final String DEFAULT_PROCESS_CONTROL_FILENAME = "process.ctl";
|
||||
|
||||
protected static final String GEMFIRE_LOG_FILE_NAME = System
|
||||
.getProperty("spring.session.data.gemfire.log-file", "server.log");
|
||||
.getProperty("spring.session.data.gemfire.log-file", "gemfire-server.log");
|
||||
|
||||
@Autowired
|
||||
protected Cache gemfireCache;
|
||||
|
||||
@@ -48,9 +48,10 @@ task runGemFireServer() {
|
||||
String classpath = sourceSets.main.runtimeClasspath.collect { it }.join(File.pathSeparator)
|
||||
|
||||
String[] commandLine = ['java', '-server', '-ea', '-classpath', classpath,
|
||||
"-Dgemfire.cache.server.port=$port",
|
||||
"-Dgemfire.log-level=" + System.getProperty('gemfire.log.level', 'warning'),
|
||||
'sample.server.GemFireServer']
|
||||
"-Dgemfire.cache.server.port=$port",
|
||||
//"-Dgemfire.log-file=gemfire-server.log",
|
||||
"-Dgemfire.log-level=" + System.getProperty('gemfire.log.level', 'config'),
|
||||
'sample.server.GemFireServer']
|
||||
|
||||
//println commandLine
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import com.gemstone.gemfire.cache.client.Pool;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.management.membership.ClientMembership;
|
||||
import com.gemstone.gemfire.management.membership.ClientMembershipEvent;
|
||||
import com.gemstone.gemfire.management.membership.ClientMembershipListenerAdapter;
|
||||
@@ -40,10 +40,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
import org.springframework.data.gemfire.client.PoolFactoryBean;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpoint;
|
||||
import org.springframework.data.gemfire.util.CollectionUtils;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession;
|
||||
import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -64,6 +64,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession
|
||||
* @see org.springframework.stereotype.Controller
|
||||
* @see com.gemstone.gemfire.cache.client.ClientCache
|
||||
* @see com.gemstone.gemfire.cache.client.Pool
|
||||
* @since 1.2.1
|
||||
*/
|
||||
// tag::class[]
|
||||
@@ -72,11 +73,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
@Controller
|
||||
public class Application {
|
||||
|
||||
static final long DEFAULT_WAIT_DURATION = TimeUnit.SECONDS.toMillis(60);
|
||||
static final long DEFAULT_TIMEOUT = TimeUnit.SECONDS.toMillis(60);
|
||||
|
||||
static final CountDownLatch latch = new CountDownLatch(1);
|
||||
static final CountDownLatch LATCH = new CountDownLatch(1);
|
||||
|
||||
static final String DEFAULT_GEMFIRE_LOG_LEVEL = "warning";
|
||||
static final String DEFAULT_GEMFIRE_LOG_LEVEL = "config";
|
||||
static final String INDEX_TEMPLATE_VIEW_NAME = "index";
|
||||
static final String PING_RESPONSE = "PONG";
|
||||
static final String REQUEST_COUNT_ATTRIBUTE_NAME = "requestCount";
|
||||
@@ -94,6 +95,7 @@ public class Application {
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
gemfireProperties.setProperty("name", applicationName());
|
||||
//gemfireProperties.setProperty("log-file", "gemfire-client.log");
|
||||
gemfireProperties.setProperty("log-level", logLevel());
|
||||
|
||||
return gemfireProperties;
|
||||
@@ -109,37 +111,46 @@ public class Application {
|
||||
}
|
||||
|
||||
@Bean
|
||||
ClientCacheFactoryBean gemfireCache() { // <3>
|
||||
ClientCacheFactoryBean gemfireCache(
|
||||
@Value("${gemfire.cache.server.host:localhost}") String host,
|
||||
@Value("${gemfire.cache.server.port:12480}") int port) { // <3>
|
||||
|
||||
ClientCacheFactoryBean gemfireCache = new ClientCacheFactoryBean();
|
||||
|
||||
gemfireCache.setClose(true);
|
||||
gemfireCache.setProperties(gemfireProperties());
|
||||
|
||||
// GemFire Pool settings <4>
|
||||
gemfireCache.setKeepAlive(false);
|
||||
gemfireCache.setPingInterval(TimeUnit.SECONDS.toMillis(5));
|
||||
gemfireCache.setReadTimeout(intValue(TimeUnit.SECONDS.toMillis(15)));
|
||||
gemfireCache.setRetryAttempts(1);
|
||||
gemfireCache.setSubscriptionEnabled(true);
|
||||
gemfireCache.setThreadLocalConnections(false);
|
||||
gemfireCache.setServers(Collections.singletonList(newConnectionEndpoint(host, port)));
|
||||
|
||||
registerClientMembershipListener(); // <5>
|
||||
|
||||
return gemfireCache;
|
||||
}
|
||||
|
||||
@Bean
|
||||
PoolFactoryBean gemfirePool(
|
||||
@Value("${gemfire.cache.server.host:localhost}") String host,
|
||||
@Value("${gemfire.cache.server.port:12480}") int port) { // <4>
|
||||
|
||||
PoolFactoryBean gemfirePool = new PoolFactoryBean();
|
||||
|
||||
gemfirePool.setKeepAlive(false);
|
||||
gemfirePool.setPingInterval(TimeUnit.SECONDS.toMillis(5));
|
||||
gemfirePool.setReadTimeout(Long.valueOf(TimeUnit.SECONDS.toMillis(15)).intValue());
|
||||
gemfirePool.setRetryAttempts(1);
|
||||
gemfirePool.setSubscriptionEnabled(true);
|
||||
gemfirePool.setThreadLocalConnections(false);
|
||||
gemfirePool.setServers(Collections.singleton(newConnectionEndpoint(host, port)));
|
||||
|
||||
return gemfirePool;
|
||||
int intValue(Number number) {
|
||||
return number.intValue();
|
||||
}
|
||||
|
||||
ConnectionEndpoint newConnectionEndpoint(String host, int port) {
|
||||
return new ConnectionEndpoint(host, port);
|
||||
}
|
||||
|
||||
void registerClientMembershipListener() {
|
||||
ClientMembership.registerClientMembershipListener(new ClientMembershipListenerAdapter() {
|
||||
@Override
|
||||
public void memberJoined(ClientMembershipEvent event) {
|
||||
LATCH.countDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Bean
|
||||
BeanPostProcessor gemfireCacheServerReadyBeanPostProcessor(
|
||||
@Value("${gemfire.cache.server.host:localhost}") final String host,
|
||||
@@ -147,30 +158,15 @@ public class Application {
|
||||
|
||||
return new BeanPostProcessor() {
|
||||
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (GemFireHttpSessionConfiguration.DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME.equals(beanName)
|
||||
|| bean instanceof Region) {
|
||||
|
||||
if ("gemfirePool".equals(beanName)) {
|
||||
ClientMembership.registerClientMembershipListener(
|
||||
new ClientMembershipListenerAdapter() {
|
||||
@Override
|
||||
public void memberJoined(ClientMembershipEvent event) {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return bean;
|
||||
}
|
||||
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
|
||||
if (bean instanceof Pool && "gemfirePool".equals(beanName)) {
|
||||
try {
|
||||
Assert.state(latch.await(DEFAULT_WAIT_DURATION, TimeUnit.MILLISECONDS),
|
||||
String.format("GemFire Cache Server failed to start on host [%1$s] and port [%2$d]",
|
||||
host, port));
|
||||
boolean didNotTimeout = LATCH.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
|
||||
|
||||
Assert.state(didNotTimeout, String.format(
|
||||
"GemFire Cache Server failed to start on host [%s] and port [%d]", host, port));
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
@@ -179,6 +175,10 @@ public class Application {
|
||||
|
||||
return bean;
|
||||
}
|
||||
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,7 @@ import org.springframework.session.data.gemfire.config.annotation.web.http.Enabl
|
||||
* @see org.springframework.boot.SpringApplication
|
||||
* @see org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
* @see org.springframework.context.annotation.Bean
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.
|
||||
* EnableGemFireHttpSession
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession
|
||||
* @see com.gemstone.gemfire.cache.Cache
|
||||
* @since 1.2.1
|
||||
*/
|
||||
@@ -47,7 +46,7 @@ import org.springframework.session.data.gemfire.config.annotation.web.http.Enabl
|
||||
@EnableGemFireHttpSession(maxInactiveIntervalInSeconds = 20) // <1>
|
||||
public class GemFireServer {
|
||||
|
||||
static final String DEFAULT_GEMFIRE_LOG_LEVEL = "warning";
|
||||
static final String DEFAULT_GEMFIRE_LOG_LEVEL = "config";
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication springApplication = new SpringApplication(GemFireServer.class);
|
||||
@@ -65,6 +64,7 @@ public class GemFireServer {
|
||||
|
||||
gemfireProperties.setProperty("name", applicationName());
|
||||
gemfireProperties.setProperty("mcast-port", "0");
|
||||
//gemfireProperties.setProperty("log-file", "gemfire-server.log");
|
||||
gemfireProperties.setProperty("log-level", logLevel());
|
||||
//gemfireProperties.setProperty("jmx-manager", "true");
|
||||
//gemfireProperties.setProperty("jmx-manager-start", "true");
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Properties;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.gemstone.gemfire.cache.client.Pool;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.management.membership.ClientMembership;
|
||||
import com.gemstone.gemfire.management.membership.ClientMembershipEvent;
|
||||
import com.gemstone.gemfire.management.membership.ClientMembershipListenerAdapter;
|
||||
@@ -40,14 +40,14 @@ import org.springframework.util.Assert;
|
||||
@EnableGemFireHttpSession(maxInactiveIntervalInSeconds = 30, poolName = "DEFAULT") // <1>
|
||||
public class ClientConfig {
|
||||
|
||||
static final long DEFAULT_WAIT_DURATION = TimeUnit.SECONDS.toMillis(20);
|
||||
static final long DEFAULT_TIMEOUT = TimeUnit.SECONDS.toMillis(60);
|
||||
|
||||
static final CountDownLatch latch = new CountDownLatch(1);
|
||||
static final CountDownLatch LATCH = new CountDownLatch(1);
|
||||
|
||||
static final String DEFAULT_GEMFIRE_LOG_LEVEL = "warning";
|
||||
|
||||
@Bean
|
||||
static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
|
||||
static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
|
||||
return new PropertySourcesPlaceholderConfigurer();
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ public class ClientConfig {
|
||||
|
||||
@Bean
|
||||
ClientCacheFactoryBean gemfireCache(
|
||||
@Value("${spring.session.data.gemfire.host:" + ServerConfig.SERVER_HOST + "}") String host,
|
||||
@Value("${spring.session.data.gemfire.port:" + ServerConfig.SERVER_PORT + "}") int port) { // <3>
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactory = new ClientCacheFactoryBean();
|
||||
@@ -80,49 +81,49 @@ public class ClientConfig {
|
||||
// GemFire Pool settings <4>
|
||||
clientCacheFactory.setKeepAlive(false);
|
||||
clientCacheFactory.setPingInterval(TimeUnit.SECONDS.toMillis(5));
|
||||
clientCacheFactory.setReadTimeout(2000); // 2 seconds
|
||||
clientCacheFactory.setReadTimeout(intValue(TimeUnit.SECONDS.toMillis(15)));
|
||||
clientCacheFactory.setRetryAttempts(1);
|
||||
clientCacheFactory.setSubscriptionEnabled(true);
|
||||
clientCacheFactory.setThreadLocalConnections(false);
|
||||
clientCacheFactory.setServers(Collections.singletonList(newConnectionEndpoint(host, port)));
|
||||
|
||||
clientCacheFactory.setServers(Collections.singletonList(
|
||||
newConnectionEndpoint(ServerConfig.SERVER_HOST, port)));
|
||||
registerClientMembershipListener(); // <5>
|
||||
|
||||
return clientCacheFactory;
|
||||
}
|
||||
|
||||
int intValue(Number number) {
|
||||
return number.intValue();
|
||||
}
|
||||
|
||||
ConnectionEndpoint newConnectionEndpoint(String host, int port) {
|
||||
return new ConnectionEndpoint(host, port);
|
||||
}
|
||||
|
||||
void registerClientMembershipListener() {
|
||||
ClientMembership.registerClientMembershipListener(
|
||||
new ClientMembershipListenerAdapter() {
|
||||
@Override
|
||||
public void memberJoined(ClientMembershipEvent event) {
|
||||
LATCH.countDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Bean
|
||||
BeanPostProcessor gemfireCacheServerReadyBeanPostProcessor() { // <5>
|
||||
BeanPostProcessor gemfireCacheServerReadyBeanPostProcessor(
|
||||
@Value("${spring.session.data.gemfire.host:" + ServerConfig.SERVER_HOST + "}") final String host,
|
||||
@Value("${spring.session.data.gemfire.port:" + ServerConfig.SERVER_PORT + "}") final int port) { // <5>
|
||||
|
||||
return new BeanPostProcessor() {
|
||||
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
|
||||
if ("gemfirePool".equals(beanName)) {
|
||||
ClientMembership.registerClientMembershipListener(
|
||||
new ClientMembershipListenerAdapter() {
|
||||
@Override
|
||||
public void memberJoined(ClientMembershipEvent event) {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return bean;
|
||||
}
|
||||
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
|
||||
if (bean instanceof Pool && "gemfirePool".equals(beanName)) {
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof Region) {
|
||||
try {
|
||||
Assert.state(latch.await(DEFAULT_WAIT_DURATION, TimeUnit.MILLISECONDS),
|
||||
String.format("GemFire Cache Server failed to start on host [%1$s] and port [%2$d]",
|
||||
ServerConfig.SERVER_HOST, ServerConfig.SERVER_PORT));
|
||||
boolean didNotTimeout = LATCH.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
|
||||
|
||||
Assert.state(didNotTimeout, String.format(
|
||||
"GemFire Cache Server failed to start on host [%s] and port [%d]", host, port));
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
@@ -131,6 +132,10 @@ public class ClientConfig {
|
||||
|
||||
return bean;
|
||||
}
|
||||
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
};
|
||||
}
|
||||
// end::class[]
|
||||
|
||||
@@ -19,7 +19,7 @@ package sample;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.gemstone.gemfire.cache.client.Pool;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.management.membership.ClientMembership;
|
||||
import com.gemstone.gemfire.management.membership.ClientMembershipEvent;
|
||||
import com.gemstone.gemfire.management.membership.ClientMembershipListenerAdapter;
|
||||
@@ -31,9 +31,9 @@ import org.springframework.util.Assert;
|
||||
|
||||
public class GemFireCacheServerReadyBeanPostProcessor implements BeanPostProcessor {
|
||||
|
||||
static final long DEFAULT_WAIT_DURATION = TimeUnit.SECONDS.toMillis(20);
|
||||
static final long DEFAULT_TIMEOUT = TimeUnit.SECONDS.toMillis(60);
|
||||
|
||||
static final CountDownLatch latch = new CountDownLatch(1);
|
||||
static final CountDownLatch LATCH = new CountDownLatch(1);
|
||||
|
||||
@Value("${spring.session.data.gemfire.port:${application.gemfire.client-server.port}}")
|
||||
int port;
|
||||
@@ -42,27 +42,21 @@ public class GemFireCacheServerReadyBeanPostProcessor implements BeanPostProcess
|
||||
String host;
|
||||
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
if ("gemfirePool".equals(beanName)) {
|
||||
if ("gemfireCache".equals(beanName)) {
|
||||
ClientMembership.registerClientMembershipListener(
|
||||
new ClientMembershipListenerAdapter() {
|
||||
@Override
|
||||
public void memberJoined(ClientMembershipEvent event) {
|
||||
latch.countDown();
|
||||
LATCH.countDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return bean;
|
||||
}
|
||||
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
|
||||
if (bean instanceof Pool && "gemfirePool".equals(beanName)) {
|
||||
else if (bean instanceof Region) {
|
||||
try {
|
||||
Assert.state(latch.await(DEFAULT_WAIT_DURATION, TimeUnit.MILLISECONDS),
|
||||
String.format("GemFire Cache Server failed to start on host [%1$s] and port [%2$d]",
|
||||
this.host, this.port));
|
||||
boolean didNotTimeout = LATCH.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
|
||||
|
||||
Assert.state(didNotTimeout, String.format(
|
||||
"GemFire Cache Server failed to start on host [%s] and port [%d]", this.host, this.port));
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
@@ -71,5 +65,9 @@ public class GemFireCacheServerReadyBeanPostProcessor implements BeanPostProcess
|
||||
|
||||
return bean;
|
||||
}
|
||||
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
// tag::end[]
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<!--6-->
|
||||
<gfe:pool keep-alive="false"
|
||||
ping-interval="5000"
|
||||
read-timeout="5000"
|
||||
read-timeout="15000"
|
||||
retry-attempts="1"
|
||||
subscription-enabled="true"
|
||||
thread-local-connections="false">
|
||||
|
||||
@@ -244,11 +244,10 @@ public class ClientServerGemFireOperationsSessionRepositoryIntegrationTests
|
||||
static class SpringSessionGemFireClientConfiguration {
|
||||
|
||||
@Bean
|
||||
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
|
||||
static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
|
||||
return new PropertySourcesPlaceholderConfigurer();
|
||||
}
|
||||
|
||||
@Bean
|
||||
Properties gemfireProperties() {
|
||||
Properties gemfireProperties = new Properties();
|
||||
gemfireProperties.setProperty("log-level", GEMFIRE_LOG_LEVEL);
|
||||
@@ -308,7 +307,8 @@ public class ClientServerGemFireOperationsSessionRepositoryIntegrationTests
|
||||
}
|
||||
}
|
||||
|
||||
@EnableGemFireHttpSession(regionName = SPRING_SESSION_GEMFIRE_REGION_NAME, maxInactiveIntervalInSeconds = MAX_INACTIVE_INTERVAL_IN_SECONDS)
|
||||
@EnableGemFireHttpSession(regionName = SPRING_SESSION_GEMFIRE_REGION_NAME,
|
||||
maxInactiveIntervalInSeconds = MAX_INACTIVE_INTERVAL_IN_SECONDS)
|
||||
static class SpringSessionGemFireServerConfiguration {
|
||||
|
||||
static final int MAX_CONNECTIONS = 50;
|
||||
|
||||
Reference in New Issue
Block a user