This repository has been archived by the owner on Jun 19, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fefd82
commit e1596fa
Showing
18 changed files
with
1,186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# ignore .svn metadata files | ||
.svn | ||
# ignore Maven generated target folders | ||
target | ||
# ignore eclipse files | ||
.project | ||
.classpath | ||
.settings | ||
.scala_dependencies | ||
# ignore IDEA files | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea | ||
atlassian-ide-plugin.xml | ||
maven-ant-tasks.jar | ||
test-output | ||
# log files | ||
*.log | ||
# vim files | ||
*.swp | ||
# generated rhq plugin xml | ||
rhq-plugin.xml | ||
# generated schema | ||
core/src/main/resources/schema | ||
# Compiled python files | ||
*.pyc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0"?> | ||
<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> | ||
|
||
<parent> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-parent</artifactId> | ||
<version>4.1.0.FINAL</version> | ||
</parent> | ||
|
||
<groupId>org.infinispan.archetypes</groupId> | ||
<artifactId>infinispan-archetypes</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
|
||
<name>Infinispan Archetypes</name> | ||
<description>Archetypes for the Infinispan project</description> | ||
<packaging>pom</packaging> | ||
<url>http://community.jboss.org/wiki/InfinispanMavenArchetypes</url> | ||
|
||
<modules> | ||
<module>sampleproject</module> | ||
<module>testcase</module> | ||
</modules> | ||
</project> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-parent</artifactId> | ||
<version>4.1.0.FINAL</version> | ||
</parent> | ||
|
||
<groupId>org.infinispan.archetypes</groupId> | ||
<artifactId>sample-project</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<name>Infinispan Sample Project Archetype</name> | ||
<description>Builds a skeleton sample project using Infinispan.</description> | ||
|
||
<!-- these deps are here so that we can compile the sample classes --> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-core</artifactId> | ||
<version>5.0.0-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
15 changes: 15 additions & 0 deletions
15
sampleproject/src/main/resources/META-INF/maven/archetype-metadata.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<archetype-descriptor xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" | ||
name="Infinispan Project Archetype" partial="false"> | ||
<fileSets> | ||
<fileSet filtered="true" packaged="true" encoding="UTF-8"> | ||
<directory>src/main/java</directory> | ||
</fileSet> | ||
|
||
<fileSet filtered="false" packaged="false" encoding="UTF-8"> | ||
<directory>src/main/resources</directory> | ||
</fileSet> | ||
</fileSets> | ||
|
||
</archetype-descriptor> |
102 changes: 102 additions & 0 deletions
102
sampleproject/src/main/resources/archetype-resources/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>${groupId}</groupId> | ||
<artifactId>${artifactId}</artifactId> | ||
<packaging>jar</packaging> | ||
<version>${version}</version> | ||
<name>A sample project using Infinispan</name> | ||
<url>http://www.myorganization.org</url> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-core</artifactId> | ||
<version>${infinispan.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<!-- enforce java 1.6 and maven 2.1.0 --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-enforcer-plugin</artifactId> | ||
<version>1.0-beta-1</version> | ||
<executions> | ||
<execution> | ||
<id>enforce-java</id> | ||
<goals> | ||
<goal>enforce</goal> | ||
</goals> | ||
<configuration> | ||
<rules> | ||
<requireJavaVersion> | ||
<version>[1.6,)</version> | ||
</requireJavaVersion> | ||
<requireMavenVersion> | ||
<version>[2.1.0,)</version> | ||
</requireMavenVersion> | ||
</rules> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<!-- by default, compile to JDK 1.6 compatibility --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3.1</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<repositories> | ||
<repository> | ||
<id>JBoss.org Public Repository</id> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
<url>http://repository.jboss.org/nexus/content/groups/public/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<profiles> | ||
<profile> | ||
<!-- This profile is used to run the sample Application.java file. Remove this in any production usage. --> | ||
<id>run</id> | ||
<activation> | ||
<activeByDefault>false</activeByDefault> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.1</version> | ||
<executions> | ||
<execution> | ||
<phase>process-classes</phase> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<mainClass>${groupId}.Application</mainClass> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
123 changes: 123 additions & 0 deletions
123
sampleproject/src/main/resources/archetype-resources/src/main/java/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package ${groupId}; | ||
|
||
import org.infinispan.Cache; | ||
import org.infinispan.notifications.Listener; | ||
import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated; | ||
import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified; | ||
import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved; | ||
import org.infinispan.notifications.cachelistener.annotation.CacheEntryVisited; | ||
import org.infinispan.notifications.cachelistener.event.CacheEntryEvent; | ||
import org.infinispan.notifications.cachelistener.event.CacheEntryVisitedEvent; | ||
import org.infinispan.notifications.cachemanagerlistener.event.Event; | ||
import org.infinispan.util.concurrent.NotifyingFuture; | ||
|
||
import java.util.Arrays; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Sample application code. For more examples visit http://community.jboss.org/wiki/5minutetutorialonInfinispan | ||
*/ | ||
public class Application { | ||
|
||
public void basicUse() { | ||
System.out.println("\n\n1. Demonstrating basic usage of Infinispan. This cache stores arbitrary Strings."); | ||
Cache<String, String> cache = SampleCacheContainer.getCache(); | ||
|
||
System.out.println(" Storing value 'World' under key 'Hello'"); | ||
String oldValue = cache.put("Hello", "World"); | ||
System.out.printf(" Done. Saw old value as '%s'\n", oldValue); | ||
|
||
System.out.println(" Replacing 'World' with 'Mars'."); | ||
boolean worked = cache.replace("Hello", "World", "Mars"); | ||
System.out.printf(" Successful? %s\n", worked); | ||
|
||
assert oldValue == null; | ||
assert worked == true; | ||
} | ||
|
||
public void lifespans() throws InterruptedException { | ||
System.out.println("\n\n2. Demonstrating usage of Infinispan with expirable entries."); | ||
Cache<String, Float> stocksCache = SampleCacheContainer.getCache("stock tickers"); | ||
System.out.println(" Storing key 'RHT' for 10 seconds."); | ||
stocksCache.put("RHT", 45.0f, 10, TimeUnit.SECONDS); | ||
System.out.printf(" Checking for existence of key. Is it there? %s\n", stocksCache.containsKey("RHT")); | ||
System.out.println(" Sleeping for 10 seconds..."); | ||
Thread.sleep(10000); | ||
System.out.printf(" Checking for existence of key. Is it there? %s\n", stocksCache.containsKey("RHT")); | ||
assert stocksCache.get("RHT") == null; | ||
} | ||
|
||
public void asyncOperations() { | ||
System.out.println("\n\n3. Demonstrating asynchronous operations - where writes can be done in a non-blocking fashion."); | ||
Cache<String, Integer> wineCache = SampleCacheContainer.getCache("wine cache"); | ||
|
||
System.out.println(" Put #1"); | ||
NotifyingFuture<Integer> f1 = wineCache.putAsync("Pinot Noir", 300); | ||
System.out.println(" Put #1"); | ||
NotifyingFuture<Integer> f2 = wineCache.putAsync("Merlot", 120); | ||
System.out.println(" Put #1"); | ||
NotifyingFuture<Integer> f3 = wineCache.putAsync("Chardonnay", 180); | ||
|
||
// now poll the futures to make sure any remote calls have completed! | ||
for (NotifyingFuture<Integer> f: Arrays.asList(f1, f2, f3)) { | ||
try { | ||
System.out.println(" Checking future... "); | ||
f.get(); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Operation failed!", e); | ||
} | ||
} | ||
System.out.println(" Everything stored!"); | ||
|
||
// TIP: For more examples on using the asynchronous API, visit http://community.jboss.org/wiki/AsynchronousAPI | ||
} | ||
|
||
public void registeringListeners() { | ||
System.out.println("\n\n4. Demonstrating use of listeners."); | ||
Cache<Integer, String> anotherCache = SampleCacheContainer.getCache("another"); | ||
System.out.println(" Attaching listener"); | ||
MyListener l = new MyListener(); | ||
anotherCache.addListener(l); | ||
|
||
System.out.println(" Put #1"); | ||
anotherCache.put(1, "One"); | ||
System.out.println(" Put #2"); | ||
anotherCache.put(2, "Two"); | ||
System.out.println(" Put #3"); | ||
anotherCache.put(3, "Three"); | ||
|
||
// TIP: For more examples on using listeners visit http://community.jboss.org/wiki/ListenersandNotifications | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
System.out.println("\n\n\n ******************************** \n\n\n"); | ||
System.out.println("Hello. This is a sample application making use of Infinispan."); | ||
Application a = new Application(); | ||
a.basicUse(); | ||
a.lifespans(); | ||
a.asyncOperations(); | ||
a.registeringListeners(); | ||
System.out.println("Sample complete."); | ||
System.out.println("\n\n\n ******************************** \n\n\n"); | ||
} | ||
|
||
@Listener | ||
public class MyListener { | ||
|
||
@CacheEntryCreated | ||
@CacheEntryModified | ||
@CacheEntryRemoved | ||
public void printDetailsOnChange(CacheEntryEvent e) { | ||
System.out.printf("Thread %s has modified an entry in the cache named %s under key %s!\n", | ||
Thread.currentThread().getName(), e.getCache().getName(), e.getKey()); | ||
} | ||
|
||
@CacheEntryVisited | ||
public void pribtDetailsOnVisit(CacheEntryVisitedEvent e) { | ||
System.out.printf("Thread %s has visited an entry in the cache named %s under key %s!\n", | ||
Thread.currentThread().getName(), e.getCache().getName(), e.getKey()); | ||
} | ||
} | ||
} | ||
|
69 changes: 69 additions & 0 deletions
69
sampleproject/src/main/resources/archetype-resources/src/main/java/SampleCacheContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package ${groupId}; | ||
|
||
import org.infinispan.Cache; | ||
import org.infinispan.manager.DefaultCacheManager; | ||
import org.infinispan.manager.EmbeddedCacheManager; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* This sample cache container acts as a factory and a mechanism with which to create and configure an embedded cache | ||
* manager, and to hold this cache manager such that other code can access it. | ||
* | ||
* Variants of this pattern include storing the EmbeddedCacheManager in JNDI or as a bean in JMX, or even using CDI | ||
* or some other dependency injection framework to hold the cache manager (and even cache) references and inject them | ||
* as needed into various bits of application code. | ||
*/ | ||
public class SampleCacheContainer { | ||
|
||
// ************************************************************************************************************ | ||
// This should point to the Infinispan configuration file. Either an absolute path or the name of a config | ||
// file in your classpath could be used. See http://community.jboss.org/wiki/Configuringcache for more details. | ||
// ************************************************************************************************************ | ||
|
||
// This skeleton project ships with 4 different Infinispan configurations. Uncomment the one most appropriate to you. | ||
private static final String INFINISPAN_CONFIGURATION = "infinispan-local.xml"; | ||
// private static final String INFINISPAN_CONFIGURATION = "infinispan-clustered-tcp.xml"; | ||
// private static final String INFINISPAN_CONFIGURATION = "infinispan-clustered-udp.xml"; | ||
// private static final String INFINISPAN_CONFIGURATION = "infinispan-clustered-ec2.xml"; | ||
|
||
private static final EmbeddedCacheManager CACHE_MANAGER; | ||
|
||
static { | ||
try { | ||
CACHE_MANAGER = new DefaultCacheManager(INFINISPAN_CONFIGURATION); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Unable to configure Infinispan", e); | ||
} | ||
} | ||
|
||
/** | ||
* Retrieves the default cache. | ||
* @param <K> type used as keys in this cache | ||
* @param <V> type used as values in this cache | ||
* @return a cache | ||
*/ | ||
public static <K, V> Cache<K, V> getCache() { | ||
return CACHE_MANAGER.getCache(); | ||
} | ||
|
||
/** | ||
* Retrieves a named cache. | ||
* @param cacheName name of cache to retrieve | ||
* @param <K> type used as keys in this cache | ||
* @param <V> type used as values in this cache | ||
* @return a cache | ||
*/ | ||
public static <K, V> Cache<K, V> getCache(String cacheName) { | ||
if (cacheName == null) throw new NullPointerException("Cache name cannot be null!"); | ||
return CACHE_MANAGER.getCache(cacheName); | ||
} | ||
|
||
/** | ||
* Retrieves the embedded cache manager. | ||
* @return a cache manager | ||
*/ | ||
public static EmbeddedCacheManager getCacheContainer() { | ||
return CACHE_MANAGER; | ||
} | ||
} |
Oops, something went wrong.