diff --git a/samples/hello-world/.springBeans b/samples/hello-world/.springBeans deleted file mode 100644 index 4dff6476..00000000 --- a/samples/hello-world/.springBeans +++ /dev/null @@ -1,13 +0,0 @@ - - - 1 - - - - - - - - - - diff --git a/samples/hello-world/build.gradle b/samples/hello-world/build.gradle deleted file mode 100644 index 0ed78060..00000000 --- a/samples/hello-world/build.gradle +++ /dev/null @@ -1,37 +0,0 @@ -description = 'Spring Data for Pivotal GemFire Samples - Hello World' - -apply plugin: 'base' -apply plugin: 'idea' -apply plugin: 'java' -apply plugin: 'eclipse' -apply plugin: 'application' - -[compileJava, compileTestJava]*.options*.compilerArgs = ["-Xlint:-serial"] - -repositories { - // Public Spring artefacts - maven { url "http://repo.springsource.org/libs-snapshot" } - mavenLocal() -} - -dependencies { - compile "org.springframework.data:spring-data-gemfire:$version" - compile "javax.inject:javax.inject:1" - compile "javax.annotation:jsr250-api:1.0" - - runtime "log4j:log4j:$log4jVersion" - runtime "org.slf4j:slf4j-log4j12:$slf4jVersion" - - testCompile "junit:junit:$junitVersion" - testCompile "org.springframework:spring-test:$springVersion" -} - - -run { - main = "org.springframework.data.gemfire.samples.helloworld.Main" - classpath = sourceSets.main.runtimeClasspath - standardInput = System.in - systemProperties['java.net.preferIPv4Stack'] = 'true' -} - -defaultTasks 'run' diff --git a/samples/hello-world/readme.txt b/samples/hello-world/readme.txt deleted file mode 100644 index ef0dfc70..00000000 --- a/samples/hello-world/readme.txt +++ /dev/null @@ -1,28 +0,0 @@ -====================== -== Hello World Demo == -====================== - -1. MOTIVATION - -As the name implies, this is a simple demo that illustrates the configuration -and interaction with the GemFire through the Spring container. - -The demo starts and configures the GemFire grid and open up a basic shell for -executing commands against the grid. -Multiple nodes can be started which will share and exchange information transparently. - -2. BUILD AND DEPLOYMENT - -This directory contains the source files. -For building, JDK 1.5+ are required - -To build the sample, use the following command: - -*nix/BSD OS: -# ../../gradlew -q - -Windows OS: -# ..\..\gradlew -q - -If you have Gradle installed and available in your classpath, you can simply type: -# gradle -q diff --git a/samples/hello-world/src/main/java/org/springframework/data/gemfire/samples/helloworld/CacheLogger.java b/samples/hello-world/src/main/java/org/springframework/data/gemfire/samples/helloworld/CacheLogger.java deleted file mode 100644 index 6528e6ef..00000000 --- a/samples/hello-world/src/main/java/org/springframework/data/gemfire/samples/helloworld/CacheLogger.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2010 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.samples.helloworld; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.apache.geode.cache.EntryEvent; -import org.apache.geode.cache.util.CacheListenerAdapter; - -/** - * Listener that logs entry operations to the configured logger. - * - * @author Costin Leau - */ -public class CacheLogger extends CacheListenerAdapter { - - private static final Log log = LogFactory.getLog(CacheLogger.class); - - @Override - public void afterCreate(EntryEvent event) { - log.info("Added " + messageLog(event) + " to the cache"); - } - - @Override - public void afterDestroy(EntryEvent event) { - log.info("Removed " + messageLog(event) + " from the cache"); - } - - @Override - public void afterUpdate(EntryEvent event) { - log.info("Updated " + messageLog(event) + " in the cache"); - } - - private String messageLog(EntryEvent event) { - Object key = event.getKey(); - Object value = event.getNewValue(); - - if (event.getOperation().isUpdate()) { - return "[" + key + "] from [" + event.getOldValue() + "] to [" + event.getNewValue() + "]"; - } - return "[" + key + "=" + value + "]"; - } -} diff --git a/samples/hello-world/src/main/java/org/springframework/data/gemfire/samples/helloworld/CommandProcessor.java b/samples/hello-world/src/main/java/org/springframework/data/gemfire/samples/helloworld/CommandProcessor.java deleted file mode 100644 index 26830685..00000000 --- a/samples/hello-world/src/main/java/org/springframework/data/gemfire/samples/helloworld/CommandProcessor.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright 2010 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.samples.helloworld; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.Scanner; -import java.util.Set; -import java.util.Map.Entry; -import java.util.regex.Pattern; - -import javax.annotation.Resource; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.data.gemfire.GemfireCallback; -import org.springframework.data.gemfire.GemfireTemplate; -import org.springframework.stereotype.Component; - -import org.apache.geode.GemFireCheckedException; -import org.apache.geode.GemFireException; -import org.apache.geode.cache.Region; - -/** - * Entity processing and interpreting shell commands. - * - * @author Costin Leau - */ -@Component -public class CommandProcessor { - - private static final Pattern COM = Pattern.compile("query|exit|help|size|clear|keys|values|map|containsKey|containsValue|get|remove|put"); - - private static final Log log = LogFactory.getLog(CommandProcessor.class); - - private static String help = initHelp(); - private static String EMPTY = ""; - - boolean threadActive; - private Thread thread; - - @Resource - private GemfireTemplate template; - - void start() { - if (thread == null) { - threadActive = true; - thread = new Thread(new Task(), "cmd-processor"); - thread.start(); - } - } - - void stop() throws Exception { - threadActive = false; - thread.join(3 * 100); - } - - void awaitCommands() throws Exception { - thread.join(); - } - - private class Task implements Runnable { - - public void run() { - System.out.println("Hello World!"); - System.out.println("Want to interact with the world ? ..."); - System.out.println(help); - System.out.print("-> "); - System.out.flush(); - - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - - try { - while (threadActive) { - if (br.ready()) { - try { - System.out.println(process(br.readLine())); - } catch (Exception ex) { - System.out.println("Error executing last command " + ex.getMessage()); - ex.printStackTrace(); - } - - System.out.print("-> "); - System.out.flush(); - } - } - } catch (IOException ioe) { - // just ignore any exceptions - log.error("Caught exception while processing commands ", ioe); - } - } - } - - private static String initHelp() { - try { - InputStream stream = CommandProcessor.class.getResourceAsStream("help.txt"); - byte[] buffer = new byte[stream.available() > 0 ? stream.available() : 300]; - - BufferedInputStream bf = new BufferedInputStream(stream); - bf.read(buffer); - return new String(buffer); - } catch (IOException io) { - throw new IllegalStateException("Cannot read help file"); - } - } - - String process(final String line) { - final Scanner sc = new Scanner(line); - - return template.execute(new GemfireCallback() { - - public String doInGemfire(Region reg) throws GemFireCheckedException, GemFireException { - Region region = reg; - - if (!sc.hasNext(COM)) { - return "Invalid command - type 'help' for supported operations"; - } - String command = sc.next(); - String arg1 = (sc.hasNext() ? sc.next() : null); - String arg2 = (sc.hasNext() ? sc.next() : null); - - // query shortcut - if ("query".equalsIgnoreCase(command)) { - String query = line.trim().substring(command.length()); - return region.query(query).toString(); - } - - // parse commands w/o arguments - if ("exit".equalsIgnoreCase(command)) { - threadActive = false; - return "Node exiting..."; - } - if ("help".equalsIgnoreCase(command)) { - return help; - } - if ("size".equalsIgnoreCase(command)) { - return EMPTY + region.size(); - } - if ("clear".equalsIgnoreCase(command)) { - region.clear(); - return "Clearing grid.."; - } - if ("keys".equalsIgnoreCase(command)) { - return region.keySet().toString(); - } - if ("values".equalsIgnoreCase(command)) { - return region.values().toString(); - } - - if ("map".equalsIgnoreCase(command)) { - Set> entrySet = region.entrySet(); - if (entrySet.size() == 0) - return "[]"; - - StringBuilder sb = new StringBuilder(); - for (Entry entry : entrySet) { - sb.append("["); - sb.append(entry.getKey()); - sb.append("="); - sb.append(entry.getValue()); - sb.append("] "); - } - return sb.toString(); - } - - // commands w/ 1 arg - if ("containsKey".equalsIgnoreCase(command)) { - return EMPTY + region.containsKey(arg1); - } - if ("containsValue".equalsIgnoreCase(command)) { - return EMPTY + region.containsValue(arg1); - } - if ("get".equalsIgnoreCase(command)) { - return region.get(arg1); - } - if ("remove".equalsIgnoreCase(command)) { - return region.remove(arg1); - } - - // commands w/ 2 args - - if ("put".equalsIgnoreCase(command)) { - return region.put(arg1, arg2); - } - - sc.close(); - return "unknown command - run 'help' for available commands"; - } - }); - } -} diff --git a/samples/hello-world/src/main/java/org/springframework/data/gemfire/samples/helloworld/HelloWorld.java b/samples/hello-world/src/main/java/org/springframework/data/gemfire/samples/helloworld/HelloWorld.java deleted file mode 100644 index e51d8f59..00000000 --- a/samples/hello-world/src/main/java/org/springframework/data/gemfire/samples/helloworld/HelloWorld.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2010 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.samples.helloworld; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.annotation.Resource; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.stereotype.Component; - -import org.apache.geode.cache.Region; - -/** - * Main bean for interacting with the cache from the console. - * - * @author Costin Leau - */ -@Component -public class HelloWorld { - - private static final Log log = LogFactory.getLog(HelloWorld.class); - - // inject the region - @Resource(name = "myWorld") - private Region region; - - @Resource - private CommandProcessor processor; - - @PostConstruct - void start() { - log.info("Member " + region.getCache().getDistributedSystem().getDistributedMember().getId() - + " connecting to region [" + region.getName() + "]"); - processor.start(); - } - - @PreDestroy - void stop() throws Exception { - log.info("Member " + region.getCache().getDistributedSystem().getDistributedMember().getId() - + " disconnecting from region [" + region.getName() + "]"); - processor.stop(); - } - - public void greetWorld() { - try { - processor.awaitCommands(); - } catch (Exception ex) { - throw new IllegalStateException("Cannot greet world", ex); - } - } -} diff --git a/samples/hello-world/src/main/java/org/springframework/data/gemfire/samples/helloworld/Main.java b/samples/hello-world/src/main/java/org/springframework/data/gemfire/samples/helloworld/Main.java deleted file mode 100644 index cba3d340..00000000 --- a/samples/hello-world/src/main/java/org/springframework/data/gemfire/samples/helloworld/Main.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2010 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.samples.helloworld; - -import org.springframework.context.support.AbstractApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -/** - * Hello World startup class. - * - * Bootstraps the Spring container which in turns starts Pivotal GemFire and the actual application. - * - * Accepts as optional parameters location of one (or multiple) application contexts that will - * be used for configuring the Spring container. See the reference documentation for more - * {@link http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/resources.html information}. - * - * Note that in most (if not all) managed environments writing such a class is not needed - * as Spring already provides the required integration. - * - * @see org.springframework.web.context.ContextLoaderListener - * @author Costin Leau - */ -public class Main { - - private static final String[] CONFIGS = new String[] { "app-context.xml" }; - - /** - * @param args - */ - public static void main(String[] args) { - String[] res = (args != null && args.length > 0 ? args : CONFIGS); - AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(res); - // shutdown the context along with the VM - ctx.registerShutdownHook(); - - // call greet world to prevent the thread from ending - HelloWorld bean = ctx.getBean(HelloWorld.class); - bean.greetWorld(); - } -} diff --git a/samples/hello-world/src/main/resources/app-context.xml b/samples/hello-world/src/main/resources/app-context.xml deleted file mode 100644 index 34d6ebe4..00000000 --- a/samples/hello-world/src/main/resources/app-context.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - diff --git a/samples/hello-world/src/main/resources/cache-context.xml b/samples/hello-world/src/main/resources/cache-context.xml deleted file mode 100644 index 55847bc4..00000000 --- a/samples/hello-world/src/main/resources/cache-context.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/hello-world/src/main/resources/cache.properties b/samples/hello-world/src/main/resources/cache.properties deleted file mode 100644 index 769bd33b..00000000 --- a/samples/hello-world/src/main/resources/cache.properties +++ /dev/null @@ -1,2 +0,0 @@ -log-level=warning -name=Spring GemFire World diff --git a/samples/hello-world/src/main/resources/org/springframework/data/gemfire/samples/helloworld/help.txt b/samples/hello-world/src/main/resources/org/springframework/data/gemfire/samples/helloworld/help.txt deleted file mode 100644 index 28afdd02..00000000 --- a/samples/hello-world/src/main/resources/org/springframework/data/gemfire/samples/helloworld/help.txt +++ /dev/null @@ -1,17 +0,0 @@ -Supported commands are: - -get - retrieves an entry (by key) from the grid -put - puts a new entry into the grid -remove - removes an entry (by key) from the grid -size - returns the size of the grid -clear - removes all mapping in the grid -map - returns the keys and associated values contained by the grid -keys - returns the keys contained by the grid -values - returns the values contained by the grid -containsKey - indicates if the given key is contained by the grid -containsValue - indicates if the given value is contained by the grid - -query - executes a query on the grid - -help - this info -exit - this node exists \ No newline at end of file diff --git a/samples/hello-world/src/test/java/org/springframework/data/gemfire/samples/helloworld/BasicTest.java b/samples/hello-world/src/test/java/org/springframework/data/gemfire/samples/helloworld/BasicTest.java deleted file mode 100644 index 2f66cfba..00000000 --- a/samples/hello-world/src/test/java/org/springframework/data/gemfire/samples/helloworld/BasicTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2010 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.samples.helloworld; - -import org.junit.Test; - - -public class BasicTest { - - @Test - public void testBasic() throws Exception { - //Main.main(new String[] {}); - } -} - diff --git a/samples/readme.txt b/samples/readme.txt deleted file mode 100644 index 4f598f03..00000000 --- a/samples/readme.txt +++ /dev/null @@ -1,34 +0,0 @@ -Spring GemFire Samples ----------------------- -NOTE: Spring Data GemFire Sample code has been moved to https://github.com/SpringSource/spring-gemfire-examples ------------------------------------------------------------------------------------------------------------------ -This folder contains various various demo applications and samples for Spring GemFire. - -Please see each folder for detailed instructions (readme.txt). - -As a general rule, each demo provides an integration tests that bootstraps -the GemFire platform, installs the demo and its dependencies and interacts with -the application. - -SAMPLES OVERVIEW ----------------- - -* hello-world -A simple demo for configuring and interacting with the GemFire grid. - - -BUILDING AND DEPLOYMENT ------------------------ - -All demos require JDK 1.5+. - -Each module should be run from its top folder using gradle wrapper: - -# ../../gradlew - -RUNNING UNDER LINUX -------------------- - -If you experience network problems under Linux, try passing "-Djava.net.preferIPv4Stack=true" to the command -(note this is passed automatically when using the provided script). -See https://jira.springsource.org/browse/SGF-28 for more information. \ No newline at end of file