Permalink
Browse files

Significantly reworked project structure and examples for Spring Data…

… GemFire 1.2.0
  • Loading branch information...
dturanski committed Aug 30, 2012
1 parent 8b43260 commit cfbc48e1f22f5636a330ad3e5aabe20448d2885e
Showing 305 changed files with 8,228 additions and 5,569 deletions.
View
@@ -1,5 +1,15 @@
+tutorial/
+example/
+more-examples/
+.settings
+.project
+.classpath
+.springBeans
+.gradle
#Compile source#
*.class
+build
+vf.*
#Packages#
############
View
@@ -0,0 +1,65 @@
+description = 'Spring Data GemFire Basic Examples'
+
+project('replicated') {
+ description = 'Spring Data GemFire Replicated Region (p2p) Example'
+ dependencies {
+ compile project(':spring-gemfire-examples-common')
+ }
+}
+
+project('replicated-cs') {
+
+ description = 'Spring Data GemFire Replicated Region (Client Server) Example'
+ dependencies {
+ compile project(':spring-gemfire-examples-common')
+ }
+}
+
+
+project('partitioned') {
+ description = 'Spring Data GemFire Partitioned Region Example'
+ dependencies {
+ compile project(':spring-gemfire-examples-common')
+ compile "org.springframework:spring-beans:$springVersion"
+ }
+}
+
+project('persistence'){
+ description = 'Spring Data GemFire Persistence Example'
+ dependencies {
+ compile project(':spring-gemfire-examples-common')
+ compile "org.springframework:spring-beans:$springVersion"
+ }
+}
+
+project('write-through'){
+ description = 'Spring Data GemFire Write Through'
+ dependencies {
+ compile project(':spring-gemfire-examples-common')
+ compile "org.springframework:spring-beans:$springVersion"
+ }
+}
+
+project('write-behind'){
+ description = 'Spring Data GemFire Write Behind Example'
+ dependencies {
+ compile project(':spring-gemfire-examples-common')
+ compile "org.springframework:spring-beans:$springVersion"
+ }
+}
+
+project('transaction'){
+ description = 'Spring Data GemFire Transaction Example'
+ dependencies {
+ compile project(':spring-gemfire-examples-common')
+ compile "org.springframework:spring-beans:$springVersion"
+ }
+}
+
+project('function'){
+ description = 'Spring Data GemFire Function Execution Example'
+ dependencies {
+ compile project(':spring-gemfire-examples-common')
+ compile "org.springframework:spring-beans:$springVersion"
+ }
+}
@@ -0,0 +1,34 @@
+Partitioned Region Example
+==========================
+
+This demonstrates using Spring Data GemFire to create a partitioned region. The demonstration contains a Client and a Server. The partitioned region will cause entries to be distributed among the active servers. This demonstration is designed for two server instances.
+
+To run this example, open a command window, go to the the spring-gemfire-examples root directory, and type:
+
+ gradle -q run-partitioned -PmainClass=Server
+
+Open a second command window and repeat the above command
+
+When both servers are running, open a third window, and type:
+ gradle -q run-partitioned -PmainClass=Client
+
+Or to run from your IDE, execute one of the following tasks once.
+
+ gradle eclipse
+ gradle idea
+
+Then import the project into your IDE and run the above classes
+
+# Details
+
+When the Client runs, it will create 100 Orders. These will be evenly distributed across the two servers as indicated by the log messages. Notice the key values for each entry show a more or less random pattern.
+
+# Custom Partitioning
+
+The example also includes a custom PartitionResolver (CountryPartitionResolver) that allows the application to control how entries are co-located. In this example, the order shipping address is either in the US or the UK. In fact, all the odd number orders go to UK, and the evens go to US. The Spring configuration file server/cache-config is configured with 3 Spring profiles, "default", "UK", and "US". In the "US" profile, the region is configured with a fixed partition named "US" and likewise the "UK" profile contains the "UK" partition. Both profiles are configured with the CountryPartitionResolver which routes orders to corresponding partition. So try this:
+
+In the server command windows, run the servers again, but each with a different active profile:
+ gradle -q run-partitioned -PmainClass=Server -PjavaArgs=US
+ gradle -q run-partitioned -PmainClass=Server -PjavaArgs=UK
+
+Run the client again. This time, you will observe that all the odd numbered orders go to "UK" and the evens go to "US"
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:gfe="http://www.springframework.org/schema/gemfire"
+ xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+
+ <util:properties id="gemfire-props">
+ <prop key="log-level">warning</prop>
+ </util:properties>
+
+ <gfe:client-cache properties-ref="gemfire-props"/>
+
+ <gfe:client-region id="Order" data-policy="empty"/>
+
+ <gfe:pool>
+ <gfe:server host="localhost" port="40404"/>
+ <gfe:server host="localhost" port="40405"/>
+ <gfe:server host="localhost" port="40406"/>
+ </gfe:pool>
+
+</beans>
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:gfe="http://www.springframework.org/schema/gemfire"
+ xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+
+ <beans>
+ <util:properties id="gemfire-props">
+ <prop key="log-level">warning</prop>
+ </util:properties>
+
+ <gfe:cache properties-ref="gemfire-props" />
+
+ <!-- Note the SpEL expression here used to dynamically configure an available
+ port in the given range -->
+ <gfe:cache-server port="#{portGenerator.generatePort(40404,40406)}" />
+
+ <bean id="portGenerator"
+ class="org.springframework.data.gemfire.examples.util.ServerPortGenerator" />
+ </beans>
+
+ <!-- Here we are using Spring environment profiles to provide alternate region configurations. -->
+
+ <beans profile="default">
+ <gfe:partitioned-region id="Order">
+ <gfe:cache-listener>
+ <bean
+ class="org.springframework.data.gemfire.examples.util.LoggingCacheListener" />
+ </gfe:cache-listener>
+ </gfe:partitioned-region>
+ </beans>
+
+<!-- A partitioned region with fixed partition named 'UK'. -->
+ <beans profile="UK">
+ <gfe:partitioned-region id="Order">
+
+ <gfe:cache-listener>
+ <bean
+ class="org.springframework.data.gemfire.examples.util.LoggingCacheListener" />
+ </gfe:cache-listener>
+
+ <gfe:partition-resolver>
+ <bean
+ class="org.springframework.data.gemfire.examples.CountryPartitionResolver" />
+ </gfe:partition-resolver>
+
+ <gfe:fixed-partition partition-name="UK"/>
+
+ </gfe:partitioned-region>
+ </beans>
+
+<!-- A partitioned region with fixed partition named 'US'. -->
+ <beans profile="US">
+ <gfe:partitioned-region id="Order">
+
+ <gfe:cache-listener>
+ <bean
+ class="org.springframework.data.gemfire.examples.util.LoggingCacheListener" />
+ </gfe:cache-listener>
+
+ <gfe:partition-resolver>
+ <bean
+ class="org.springframework.data.gemfire.examples.CountryPartitionResolver" />
+ </gfe:partition-resolver>
+
+ <gfe:fixed-partition partition-name="US"/>
+
+ </gfe:partitioned-region>
+ </beans>
+</beans>
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:gfe="http://www.springframework.org/schema/gemfire"
+ xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+
+ <util:properties id="gemfire-props">
+ <prop key="log-level">warning</prop>
+ </util:properties>
+
+ <gfe:client-cache properties-ref="gemfire-props"/>
+
+ <gfe:client-region id="Order" data-policy="empty"/>
+
+ <gfe:pool>
+ <gfe:server host="localhost" port="40404"/>
+ <gfe:server host="localhost" port="40405"/>
+ <gfe:server host="localhost" port="40406"/>
+ </gfe:pool>
+
+</beans>
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:gfe="http://www.springframework.org/schema/gemfire"
+ xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+
+ <beans>
+ <util:properties id="gemfire-props">
+ <prop key="log-level">warning</prop>
+ </util:properties>
+
+ <gfe:cache properties-ref="gemfire-props" />
+
+ <!-- Note the SpEL expression here used to dynamically configure an available
+ port in the given range -->
+ <gfe:cache-server port="#{portGenerator.generatePort(40404,40406)}" />
+
+ <bean id="portGenerator"
+ class="org.springframework.data.gemfire.examples.util.ServerPortGenerator" />
+ </beans>
+
+ <!-- Here we are using Spring environment profiles to provide alternate region configurations. -->
+
+ <beans profile="default">
+ <gfe:partitioned-region id="Order">
+ <gfe:cache-listener>
+ <bean
+ class="org.springframework.data.gemfire.examples.util.LoggingCacheListener" />
+ </gfe:cache-listener>
+ </gfe:partitioned-region>
+ </beans>
+
+<!-- A partitioned region with fixed partition named 'UK'. -->
+ <beans profile="UK">
+ <gfe:partitioned-region id="Order">
+
+ <gfe:cache-listener>
+ <bean
+ class="org.springframework.data.gemfire.examples.util.LoggingCacheListener" />
+ </gfe:cache-listener>
+
+ <gfe:partition-resolver>
+ <bean
+ class="org.springframework.data.gemfire.examples.CountryPartitionResolver" />
+ </gfe:partition-resolver>
+
+ <gfe:fixed-partition partition-name="UK"/>
+
+ </gfe:partitioned-region>
+ </beans>
+
+<!-- A partitioned region with fixed partition named 'US'. -->
+ <beans profile="US">
+ <gfe:partitioned-region id="Order">
+
+ <gfe:cache-listener>
+ <bean
+ class="org.springframework.data.gemfire.examples.util.LoggingCacheListener" />
+ </gfe:cache-listener>
+
+ <gfe:partition-resolver>
+ <bean
+ class="org.springframework.data.gemfire.examples.CountryPartitionResolver" />
+ </gfe:partition-resolver>
+
+ <gfe:fixed-partition partition-name="US"/>
+
+ </gfe:partitioned-region>
+ </beans>
+</beans>
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.gemfire.examples;
+
+import java.io.IOException;
+import java.util.Random;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.data.gemfire.examples.domain.Address;
+import org.springframework.data.gemfire.examples.domain.Order;
+
+import com.gemstone.gemfire.cache.Region;
+
+public class Client {
+
+
+ @SuppressWarnings("unchecked")
+
+ public static void main(String args[]) throws IOException {
+
+ ApplicationContext context = new ClassPathXmlApplicationContext("client/cache-config.xml");
+ Region<Long,Order> region = context.getBean(Region.class);
+
+ //Create some orders
+ Random rand = new Random(100);
+ for (long orderId = 1; orderId <= 100; orderId++) {
+ Address shipTo = new Address("Some Street","Some City",(orderId%2 == 0)?"US":"UK");
+ Order order = new Order(orderId, rand.nextLong(),shipTo);
+ region.put(orderId, order, order);
+ }
+
+ }
+}
Oops, something went wrong.

0 comments on commit cfbc48e

Please sign in to comment.