Permalink
Browse files

used lookup tag and gemfire template

  • Loading branch information...
1 parent 2010456 commit 0cba8ca71a805bddd19f32c370582f5078b990d4 @d4v3r d4v3r committed May 4, 2012
View
35 vfgf-quickstart/src/main/java/quickstart/DataExpiration.java
@@ -4,10 +4,10 @@
import javax.annotation.Resource;
+import org.springframework.data.gemfire.GemfireTemplate;
import org.springframework.stereotype.Component;
import com.gemstone.gemfire.cache.ExpirationAttributes;
-import com.gemstone.gemfire.cache.Region;
/**
* Each data region can be configured to expire entries that have not been
@@ -22,20 +22,21 @@
@Component
public class DataExpiration {
- @Resource(name = "exampleRegion")
- private Region<String, String> exampleRegion;
+ @Resource(name = "exampleRegionTemplate")
+ private GemfireTemplate exampleRegionTemplate;
public void run() throws Exception {
System.out.println("This example shows entry expiration.");
System.out.println();
// Get the EntryIdleTimeout setting from the region attributes
- ExpirationAttributes expirationAttr = exampleRegion.getAttributes()
- .getEntryIdleTimeout();
+ ExpirationAttributes expirationAttr = exampleRegionTemplate.getRegion()
+ .getAttributes().getEntryIdleTimeout();
System.out.println();
- System.out.println("The region \"" + exampleRegion.getFullPath()
+ System.out.println("The region \""
+ + exampleRegionTemplate.getRegion().getFullPath()
+ "\" is configured to");
System.out.println(expirationAttr.getAction()
+ " any cache entry that is idle for ");
@@ -45,15 +46,15 @@ public void run() throws Exception {
System.out.println();
System.out.println("Putting entry: key1 => value1");
- exampleRegion.put("key1", "value1");
+ exampleRegionTemplate.put("key1", "value1");
System.out.println("Putting entry: key2 => value2");
- exampleRegion.put("key2", "value2");
+ exampleRegionTemplate.put("key2", "value2");
System.out.println("Putting entry: key3 => value3");
- exampleRegion.put("key3", "value3");
+ exampleRegionTemplate.put("key3", "value3");
System.out.println();
System.out.println("The cache now contains:");
- printRegionContents(exampleRegion);
+ printRegionContents(exampleRegionTemplate);
System.out.println();
System.out
@@ -62,12 +63,12 @@ public void run() throws Exception {
// Get key1 to prevent it from expiring
System.out.println("Getting entry: key1 => "
- + exampleRegion.get("key1"));
+ + exampleRegionTemplate.get("key1"));
// Update key2 to prevent it from expiring
System.out.println("Putting entry: key2 => value2000");
System.out.println();
- exampleRegion.put("key2", "value2000");
+ exampleRegionTemplate.put("key2", "value2000");
System.out
.println("Next, the listener should report on an expiration action... ");
@@ -77,16 +78,18 @@ public void run() throws Exception {
Thread.sleep((idleTime / 2) * 1000);
System.out.println("After the expiration timeout, the cache contains:");
- printRegionContents(exampleRegion);
+ printRegionContents(exampleRegionTemplate);
}
- private static void printRegionContents(Region<?, ?> region) {
- Object[] keys = region.keySet().toArray();
+ private static void printRegionContents(
+ GemfireTemplate exampleRegionTemplate) {
+ Object[] keys = exampleRegionTemplate.getRegion().keySet().toArray();
Arrays.sort(keys);
for (Object key : keys) {
- System.out.println(" " + key + " => " + region.get(key));
+ System.out.println(" " + key + " => "
+ + exampleRegionTemplate.get(key));
}
}
}
View
24 vfgf-quickstart/src/main/resources/data-expiration-cache-context.xml
@@ -7,26 +7,12 @@
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd">
<!-- GemFire cache bean -->
- <gfe:cache properties-ref="props" />
+ <gfe:cache properties-ref="props" cache-xml-location="xml/DataExpiration.xml"/>
+
<util:properties id="props" location="cache.properties" />
- <bean id="exampleRegion" class="org.springframework.data.gemfire.RegionFactoryBean"
- p:cache-ref="gemfire-cache">
- <property name="cacheListeners">
- <array>
- <bean class="quickstart.SimpleCacheListener" />
- </array>
- </property>
- <property name="attributes">
- <bean class="org.springframework.data.gemfire.RegionAttributesFactoryBean">
- <property name="entryIdleTimeout">
- <bean class="com.gemstone.gemfire.cache.ExpirationAttributes">
- <constructor-arg value="10" />
- <constructor-arg value="DESTROY" />
- </bean>
- </property>
- </bean>
- </property>
- </bean>
+ <gfe:lookup-region id="exampleRegion" name="exampleRegion"/>
+
+ <bean id="exampleRegionTemplate" class="org.springframework.data.gemfire.GemfireTemplate" p:region-ref="exampleRegion"/>
</beans>
View
22 vfgf-quickstart/src/main/resources/xml/DataExpiration.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!DOCTYPE cache PUBLIC
+ "-//GemStone Systems, Inc.//GemFire Declarative Caching 6.5//EN"
+ "http://www.gemstone.com/dtd/cache6_5.dtd">
+
+<!--
+ | DataExpiration.xml
+ |
+ | Configures a region with entry idle time expiration.
+ -->
+<cache>
+ <region name="exampleRegion">
+ <region-attributes>
+ <entry-idle-time>
+ <expiration-attributes timeout="10" action="destroy" />
+ </entry-idle-time>
+ <cache-listener>
+ <class-name>quickstart.SimpleCacheListener</class-name>
+ </cache-listener>
+ </region-attributes>
+ </region>
+</cache>

0 comments on commit 0cba8ca

Please sign in to comment.