Fixup documentation and samples.

This commit is contained in:
John Blum
2017-07-26 01:35:27 -07:00
parent e3cc3e7388
commit 04168ef1b3
28 changed files with 1110 additions and 1291 deletions

View File

@@ -36,7 +36,7 @@ import org.springframework.data.gemfire.config.xml.GemfireConstants;
import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration;
import org.springframework.util.Assert;
public class GemFireClientServerReadyBeanPostProcessor implements BeanPostProcessor {
public class ClientServerReadyBeanPostProcessor implements BeanPostProcessor {
private static final long DEFAULT_TIMEOUT = TimeUnit.SECONDS.toMillis(60);
@@ -55,16 +55,17 @@ public class GemFireClientServerReadyBeanPostProcessor implements BeanPostProces
);
}
@Value("${spring.session.data.gemfire.port:${application.gemfire.client-server.port}}")
@Value("${spring.session.data.geode.cache.server.port:${application.geode.client-server.port:40404}}")
private int port;
@Value("${application.gemfire.client-server.host:localhost}")
@Value("${application.geode.client-server.host:localhost}")
private String host;
private final AtomicBoolean checkGemFireServerIsRunning = new AtomicBoolean(true);
private final AtomicReference<Pool> gemfirePool = new AtomicReference<Pool>(null);
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (shouldCheckWhetherGemFireServerIsRunning(bean, beanName)) {
try {
validateCacheClientNotified();
@@ -79,17 +80,20 @@ public class GemFireClientServerReadyBeanPostProcessor implements BeanPostProces
}
private boolean shouldCheckWhetherGemFireServerIsRunning(Object bean, String beanName) {
return (isGemFireRegion(bean, beanName)
? this.checkGemFireServerIsRunning.compareAndSet(true, false)
: whenGemFirePool(bean, beanName));
}
private boolean isGemFireRegion(Object bean, String beanName) {
return (GemFireHttpSessionConfiguration.DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME.equals(beanName)
|| bean instanceof Region);
}
private boolean whenGemFirePool(Object bean, String beanName) {
if (bean instanceof Pool) {
this.gemfirePool.compareAndSet(null, (Pool) bean);
}
@@ -98,24 +102,26 @@ public class GemFireClientServerReadyBeanPostProcessor implements BeanPostProces
}
private void validateCacheClientNotified() throws InterruptedException {
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));
"Apache Geode Cache Server failed to start on host [%s] and port [%d]", this.host, this.port));
}
@SuppressWarnings("all")
private void validateCacheClientSubscriptionQueueConnectionEstablished() throws InterruptedException {
boolean cacheClientSubscriptionQueueConnectionEstablished = false;
Pool pool = defaultIfNull(this.gemfirePool.get(),
GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME, GEMFIRE_DEFAULT_POOL_NAME);
if (pool instanceof PoolImpl) {
long timeout = (System.currentTimeMillis() + DEFAULT_TIMEOUT);
while (System.currentTimeMillis() < timeout
&& !((PoolImpl) pool).isPrimaryUpdaterAlive()) {
while (System.currentTimeMillis() < timeout && !((PoolImpl) pool).isPrimaryUpdaterAlive()) {
synchronized (pool) {
TimeUnit.MILLISECONDS.timedWait(pool, 500L);
@@ -127,13 +133,14 @@ public class GemFireClientServerReadyBeanPostProcessor implements BeanPostProces
((PoolImpl) pool).isPrimaryUpdaterAlive();
}
Assert.state(cacheClientSubscriptionQueueConnectionEstablished, String.format(
"Cache client subscription queue connection not established; GemFire Pool was [%s];"
+ " GemFire Pool configuration was [locators = %s, servers = %s]",
Assert.state(cacheClientSubscriptionQueueConnectionEstablished,
String.format("Cache client subscription queue connection not established; Geode Pool was [%s];"
+ " Geode Pool configuration was [locators = %s, servers = %s]",
pool, pool.getLocators(), pool.getServers()));
}
private Pool defaultIfNull(Pool pool, String... poolNames) {
for (String poolName : poolNames) {
pool = (pool != null ? pool : PoolManager.find(poolName));
}
@@ -145,4 +152,3 @@ public class GemFireClientServerReadyBeanPostProcessor implements BeanPostProces
return bean;
}
}
// tag::end[]

View File

@@ -20,7 +20,6 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
@SuppressWarnings("resource")
// tag::class[]
@Configuration // <1>
@ImportResource("META-INF/spring/session-server.xml") // <2>

View File

@@ -1,2 +1,2 @@
application.gemfire.client-server.host=localhost
application.gemfire.client-server.port=40404
application.geode.client-server.host=localhost
application.geode.client-server.port=40404

View File

@@ -13,17 +13,13 @@
">
<!-- tag::beans[] -->
<!--1-->
<context:annotation-config/>
<!--2-->
<context:property-placeholder location="classpath:META-INF/spring/application.properties"/>
<!--3-->
<!--1-->
<util:properties id="gemfireProperties">
<prop key="name">GemFireClientServerHttpSessionXmlSample</prop>
<prop key="mcast-port">0</prop>
<!--<prop key="log-file">gemfire-server.log</prop>-->
<prop key="name">SpringSessionSampleXmlGemFireClientServer</prop>
<prop key="log-level">${spring.session.data.gemfire.log-level:warning}</prop>
<!--
<prop key="jmx-manager">true</prop>
@@ -31,16 +27,16 @@
-->
</util:properties>
<!--4-->
<!--2-->
<gfe:cache properties-ref="gemfireProperties"/>
<!--5-->
<!--3-->
<gfe:cache-server auto-startup="true"
bind-address="${application.gemfire.client-server.host:localhost}"
host-name-for-clients="${application.gemfire.client-server.host:localhost}"
port="${spring.session.data.gemfire.port:${application.gemfire.client-server.port:40404}}"/>
bind-address="${application.geode.client-server.host:localhost}"
host-name-for-clients="${application.geode.client-server.host:localhost}"
port="${spring.session.data.geode.cache.server.port:${application.geode.client-server.port:40404}}"/>
<!--6-->
<!--4-->
<bean class="org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration"
p:maxInactiveIntervalInSeconds="30"/>
<!-- end::beans[] -->

View File

@@ -13,36 +13,27 @@
">
<!-- tag::beans[] -->
<!--1-->
<context:annotation-config/>
<!--2-->
<context:property-placeholder location="classpath:META-INF/spring/application.properties"/>
<!--3-->
<bean class="sample.GemFireClientServerReadyBeanPostProcessor"/>
<bean class="sample.ClientServerReadyBeanPostProcessor"/>
<!--4-->
<!--1-->
<util:properties id="gemfireProperties">
<!--<prop key="log-file">gemfire-client.log</prop>-->
<prop key="log-level">${spring.session.data.gemfire.log-level:warning}</prop>
<prop key="log-level">${spring.session.data.geode.log-level:warning}</prop>
</util:properties>
<!--5-->
<!--2-->
<gfe:client-cache properties-ref="gemfireProperties" pool-name="gemfirePool"/>
<!--6-->
<gfe:pool keep-alive="false"
ping-interval="5000"
read-timeout="15000"
retry-attempts="1"
subscription-enabled="true"
thread-local-connections="false">
<gfe:server host="${application.gemfire.client-server.host}"
port="${spring.session.data.gemfire.port:${application.gemfire.client-server.port}}"/>
<!--3-->
<gfe:pool ping-interval="5000" read-timeout="15000" retry-attempts="1" subscription-enabled="true">
<gfe:server host="${application.geode.client-server.host}"
port="${spring.session.data.geode.cache.server.port:${application.geode.client-server.port:40404}}"/>
</gfe:pool>
<!--7-->
<!--4-->
<bean class="org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration"
p:maxInactiveIntervalInSeconds="30" p:poolName="DEFAULT"/>
<!-- end::beans[] -->