The document introduces the Infinispan data grid platform. It discusses how Infinispan can be used as a distributed in-memory cache and data grid. It covers key Infinispan features like clustering, persistence, transactions, querying and map-reduce capabilities. It also provides examples of using Infinispan for session clustering and as a state store for Storm processing.
5. Data Grid
Distributed Cache with persistence
–
–
–
–
–
Performance Boost
Dynamic provisioning
Fast access to data (in memory) - optionally write-through
Elasticity
Fault tolerance
Data Grid
– Evolution of distributed caches
– Well-known pattern to boost data access performance and
scalability
– Clustered by nature
6. Cache vs. Data Grid
JSR 107 - Temporary Caching for the Java Platform
– read, write, expiry, write-through, distributed-manner
– JBoss Cache
JSR 347 - Data Grids for the Java Platform
– query, consistency, map-reducing standard way
– Infinispan
8. Infinispan
Distributed In-memory key/value Data Grid/ Cache
org.infinispan.Cache Interface
Distributed as Library and Server (from 5.3)
High availability
Elastic
Manageable
Open source
DefaultCacheManager manager = new DefaultCacheManager();
// Cache<Integer, Ticket> cache = manager.getCache();
Cache<Integer, Ticket> cache = manager.getCache(“myCache”);
9. Architecture: Library
Library Mode - standalone
Infinispan
App
JVM
JCP-107 Style Cache
just cache with advantages: expiry, j2ee transaction
10. Architecture: Library (Clustered)
Use as library
Library Mode - clustered
Infinispan
– More features
– Richer APIs
– Programmatic/
Declarative
configuration
– Extendable/
embeddable
– Faster (API call)
App
JVM
Infinispan
App
Cluster
JVM
Infinispan
App
JVM
Application doesn’t know it’s on cluster
11. Architecture: Server
Server Mode - clustered
Use as server
Infinispan
JVM
App
App
Infinispan
Cluster
JVM
Infinispan
App
JVM
– Remote
Memcached, R
EST, Hot Rod,
WebSocket
– Data tier shared
by multi-apps
– App doesn’t affe
ct cluster
– Non-java clients
C++, .NET, Rub
y, Python, Java
14. Clustering
Peer-to-Peer
– No central master, no single point of failure, no single bottle
neck
JGroups
– Reliable multicast communication library, nodes discovery,
sharing data, performing cluster scaling
Consistent Hash
– Hash based data distribution
– How it finds where data locates
Linear in nature: throughput, capacity
Cluster Mode
20. Listener
Listener on CacheManager
– Node join/ leave, Cache start/ stop
Cache
– CRUD, Eviction/ Passivation
– Rehashing/ Transaction completion
@Listener
public class SimpleListener {
@CacheEntryCreated
public void dataAdded(CacheEntryCreatedEvent event) {
if (event.isPre()) {
System.out.println("Before creating the entry:" + event.getKey());
} else {
System.out.println("After creating the entry:" + event.getKey());
}
…
}
DefaultCacheManager manager = new DefaultCacheManager();
manager.addListener(listener);
Cache<Integer, Ticket> cache = manager.getCache();
cache.addListener(listener);
21. Asynchronous APIs
put() and get() and remove() are synchronous
– They wait for RPC and Locks (and maybe cache stores)
The asynchronous API returns NotifyingFuture
– Events are fired on completion of the operation
NotifyingFuture<String> future = c.removeAsync(key);
future.attachListener(new FutureListener<String>() {
@Override
public void futureDone(Future<String> future) {
try {
future.get();
System.out.printf ("The entry stored under key %s has been removed.", key);
} catch (ExecutionException e) {
System.out.printf("Failed to remove %s!", key);
}
}
});
22. Key Features: Persistence
Used for durability
Cache Store - Persistence Storage
– File System, Cloud, Remote, JDBC, JPA, LevelDB, Cassandra,
– HBase, MongoDB, BerkeleyDB, JDBM, REST
CacheLoader, CacheStore(CacheWriter from 6.0)
Write-through, write-behind
Passivation, activation
Store chain
Shared store
26. Distributed Execution
Executes codes on distributed nodes
Through a standard JDK ExecutorService interface
Use DistributedCallable extends
java.util.concurrent.Callable
27. Key Features: Map/Reduce
Based on Distributed Execution Framework
Mapper, Reducer, Collator, MapReduceTask
public interface Mapper<KIn, VIn, KOut, VOut> extends Serializable {
void map(KIn key, VIn value, Collector<KOut, VOut> collector);
}
public interface Reducer<KOut, VOut> extends Serializable {
VOut reduce(KOut reducedKey, Iterator<VOut> iter);
}
public interface Callator<KOut, Vout, R> {
R collate(Map<KOut, VOut>);
}
30. Spring Integration
Infinispan provider for Spring cache abstraction
infinispan-spring.jar
<cache:annotation-driven cache-manager="operationCacheManager"/>
<bean id="operationCacheManager"
class="org.infinispan.spring.provider.SpringEmbeddedCacheManagerFactoryBean"
p:configurationFileLocation="classpath:infinispan-config.xml" />
@Cacheable(value = "secureLayerContextCache", key="#contextId")
public SecureLayerContext getSecureLayerContext(String contextId) {
return null;
}
@CachePut(value = "secureLayerContextCache", key="#contextId")
public SecureLayerContext setSecureLayerContext(String contextId,
SecureLayerContext secureLayerContext) {
return secureLayerContext;
}
@CacheEvict(value = "secureLayerContextCache", key="#contextId")
public void removeSecureLayerContext(String contextId) {
// Intentionally blank
}
31. Infinispan on Jboss AS 7
Used for session clustering, Hibernate L2 cache
Application gets cache with JNDI name using
@Resource
XML Configuration in server configuration file
<cache-container name="web" aliases="standard-session-cache" default-cache="repl">
<transport lock-timeout="60000" />
<replicated-cache name="repl" mode="ASYNC" batching="true">
<file-store />
</replicated-cache>
</cache-container>
32. JDG
Red Hat JBoss Data Grid
Infinispan-based
JON
All the benefits of
subscription, including
Red Hat world class
support and services
33. Radar Gun
Data grid and distributed cache benchmarking
framework
Built to test Infinispan and other distributed data grid
platforms
https://github.com/radargun/radargun
35. Case Study: Session Clustering
Store session information into cache
in Spring MVC Interceptor
36. Case Study: Session Clustering
Store session information into cache
in Spring Security Filter
-
-
SecurityContextRepository를 구현한
CacheSecurityContextRepository 작성
loadContext, saveContext를 오버라이드하여
인피니스팬 사용
Spring cache abstraction 사용