SGF-749 - Remove samples.

This commit is contained in:
John Blum
2018-05-17 17:07:49 -07:00
parent 0fb69a35d2
commit c181a8a3a5
13 changed files with 0 additions and 589 deletions

View File

@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[2.3.2.201003220227-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
</configs>
<configSets>
</configSets>
</beansProjectDescription>

View File

@@ -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'

View File

@@ -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

View File

@@ -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<Object, Object> {
private static final Log log = LogFactory.getLog(CacheLogger.class);
@Override
public void afterCreate(EntryEvent<Object, Object> event) {
log.info("Added " + messageLog(event) + " to the cache");
}
@Override
public void afterDestroy(EntryEvent<Object, Object> event) {
log.info("Removed " + messageLog(event) + " from the cache");
}
@Override
public void afterUpdate(EntryEvent<Object, Object> event) {
log.info("Updated " + messageLog(event) + " in the cache");
}
private String messageLog(EntryEvent<Object, Object> event) {
Object key = event.getKey();
Object value = event.getNewValue();
if (event.getOperation().isUpdate()) {
return "[" + key + "] from [" + event.getOldValue() + "] to [" + event.getNewValue() + "]";
}
return "[" + key + "=" + value + "]";
}
}

View File

@@ -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<String>() {
public String doInGemfire(Region reg) throws GemFireCheckedException, GemFireException {
Region<String, String> 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<Entry<String, String>> entrySet = region.entrySet();
if (entrySet.size() == 0)
return "[]";
StringBuilder sb = new StringBuilder();
for (Entry<String, String> 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";
}
});
}
}

View File

@@ -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<String, String> 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);
}
}
}

View File

@@ -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();
}
}

View File

@@ -1,14 +0,0 @@
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<import resource="cache-context.xml"/>
<!-- find beans by scanning the classpath -->
<context:component-scan base-package="org.springframework.data.gemfire.samples.helloworld"/>
</beans>

View File

@@ -1,28 +0,0 @@
<?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:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:gfe="http://www.springframework.org/schema/gemfire"
xsi:schemaLocation="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
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd">
<!-- Pivotal GemFire cache bean -->
<gfe:cache properties-ref="props" />
<util:properties id="props" location="cache.properties"/>
<!-- Pivotal GemFire transaction manager -->
<gfe:transaction-manager />
<!-- hello world region -->
<!-- since no name is given, the region will be named after the bean -->
<gfe:replicated-region id="myWorld">
<gfe:cache-listener>
<bean class="org.springframework.data.gemfire.samples.helloworld.CacheLogger"/>
</gfe:cache-listener>
</gfe:replicated-region>
<bean id="gemfireTemplate" class="org.springframework.data.gemfire.GemfireTemplate" p:region-ref="myWorld"/>
</beans>

View File

@@ -1,2 +0,0 @@
log-level=warning
name=Spring GemFire World

View File

@@ -1,17 +0,0 @@
Supported commands are:
get <key> - retrieves an entry (by key) from the grid
put <key> <value> - puts a new entry into the grid
remove <key> - 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 <key> - indicates if the given key is contained by the grid
containsValue <value> - indicates if the given value is contained by the grid
query <query> - executes a query on the grid
help - this info
exit - this node exists

View File

@@ -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[] {});
}
}

View File

@@ -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.