Skip to content

Commit

Permalink
add function service
Browse files Browse the repository at this point in the history
  • Loading branch information
Li Wang committed Jun 16, 2015
1 parent a66f440 commit 610b564
Show file tree
Hide file tree
Showing 15 changed files with 556 additions and 0 deletions.
27 changes: 27 additions & 0 deletions FunctionService/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions FunctionService/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
29 changes: 29 additions & 0 deletions FunctionService/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>FunctionService</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
4 changes: 4 additions & 0 deletions FunctionService/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
5 changes: 5 additions & 0 deletions FunctionService/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7
4 changes: 4 additions & 0 deletions FunctionService/.settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
52 changes: 52 additions & 0 deletions FunctionService/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.pivotal</groupId>
<artifactId>FunctionService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>FunctionService</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.gemstone.gemfire</groupId>
<artifactId>gemfire</artifactId>
<version>8.1.0</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
<repository>
<id>gemstone-repository</id>
<name>GemFire Repository</name>
<url>http://dist.gemstone.com/maven/release/</url>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
29 changes: 29 additions & 0 deletions FunctionService/src/main/java/io/pivotal/app/PreLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.pivotal.app;

import io.pivotal.domain.Customer;
import io.pivotal.service.CustomerLoader;

import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.Region;

public class PreLoader {
public static void main(String[] args) {
// Create cache
Cache cache = new CacheFactory()
.set("log-level", "error")
.set("cache-xml-file", "config/cache.xml").create();

// Get the customer region
Region<Integer, Customer> customers = cache.getRegion("Customer");
System.out.println("Got the Customer Region: " + customers);

// Load 20 customers into region
CustomerLoader customerLoader = new CustomerLoader(customers);
customerLoader.bulkInsertion(20);

// Close cache
cache.close();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.pivotal.app;


public class SizeFunctionExecution
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
25 changes: 25 additions & 0 deletions FunctionService/src/main/java/io/pivotal/app/StartPeer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.pivotal.app;

import java.io.IOException;

import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;

public class StartPeer {

public static void main(String[] args) throws InterruptedException, IOException {
// Create cache
Cache cache = new CacheFactory()
.set("log-level", "error")
.set("name", args[0])
.set("cache-xml-file", "config/cache.xml").create();

System.out.println(args[0] + " started.");

// Waiting for other process
Thread.sleep(10000);

// Close cache
cache.close();
}
}
49 changes: 49 additions & 0 deletions FunctionService/src/main/java/io/pivotal/domain/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.pivotal.domain;

public class Customer {

private Integer customerNumber;
private String firstName;
private String lastName;

public Customer() {
}

public Customer(int customerNumber, String firstName, String lastName) {
super();
this.customerNumber = new Integer(customerNumber);
this.firstName = firstName;
this.lastName = lastName;
}

public Integer getCustomerNumber() {
return customerNumber;
}

public void setCustomerNumber(Integer customerNumber) {
this.customerNumber = customerNumber;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

@Override
public String toString() {
return "Customer [customerNumber=" + customerNumber + ", firstName="
+ firstName + ", lastName=" + lastName + "]";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.pivotal.service;

import io.pivotal.domain.Customer;
import io.pivotal.util.CustomerFactory;

import com.gemstone.gemfire.cache.Region;

public class CustomerLoader {

Region<Integer, Customer> customerRegion = null;
CustomerFactory customerFactory = null;

public CustomerLoader(Region<Integer, Customer> customerRegion) {
this.customerRegion = customerRegion;
this.customerFactory = new CustomerFactory();
}

public void bulkInsertion(int n) {

for (int i = 0; i < n; i++) {
Customer customer = customerFactory.generateCustomer(i+1);
customerRegion.put(i + 1, customer);
}

System.out.println("Inserted " + n + " records.");
}


}
Loading

0 comments on commit 610b564

Please sign in to comment.