Infinispan - NoSQL für den Enterprise Java Alltag...02.09.2013 3 © 2013 Orientation in Objects...
Transcript of Infinispan - NoSQL für den Enterprise Java Alltag...02.09.2013 3 © 2013 Orientation in Objects...
02.09.2013
1
Orientation in Objects GmbH
Weinheimer Str. 6868309 Mannheim
Infinispan - NoSQL für den Enterprise Java
Alltag
1.1
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Gliederung
• NoSQL und Java EE
• Infinispan
• Integrationsszenarien
• Ausblick
2
02.09.2013
2
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Gliederung
• NoSQL und Java EE
• Infinispan
• Integrationsszenarien
• Ausblick
3
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
NoSQL vs. Java EE
• NoSQL– Datenspeicher ohne festgelegte Tabellenschemata– skalieren horizontal– keine strenge Spezifikation( viele gut diskutierte/erprobte Konzepte)– viele Implementierungen auf verschiedenen Konzepten basierend
• Java EE– strenge Spezifikation einer Softwarearchitektur – transaktionsbasierte Ausführung von Java-Komponenten– auf transkaktionsbasiertem Konzept beruhende Teilstandards
• JTA/JCA/JPA/JMS/JDBC
– Horizontale Skalierung als Konzept für High Availability• Antwortzeiten• Ausfall von Knoten
– (insbesondere gedacht für Web-Anwendungen)
4
02.09.2013
3
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
CAP Theorem und JTA
5
ConsistencyConsistency
AvailabilityAvailabilityPartion
TolerancePartion
Tolerance
n.a.
BASE
JTA JTA
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Data Grid vs. Distributed DBMS
6
ConsistencyConsistency
AvailabilityAvailabilityPartion
TolerancePartion
Tolerance
n.a.
BASE
Data Grid
DistributedDBMS
02.09.2013
4
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
JSR 107(347) Elastic Data Grid für Java EE
7
Servlet
Node 1
JSF
Node 3
EJB
Node 2
AppserverAppserverJSR 107
Node 1
JSR 107
Node 3
JSR 107
Node 2
Data GridData Grid
Secondary Store
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
JSR 107 API - Standard für einen Distributed HashTable
• Distributed HashTable– javax.cache.Cache
• ähnlich java.util.ConcurrentMap
• Managementschnittstellen– javax.cache.CacheManager– javax.cache..CacheListener
• Annotationen z.B.– @CacheResult,@CacheKeyParam,@CacheRemoveEntry..
8
02.09.2013
5
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
javax.cache.CacheLoader
9
JEEApplication
CacheCache
1. Get
• Secondary Store
CacheLoaderCacheLoader
2. load
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
javax.cache.CacheWriter
10
JEEApplication
CacheCache
1. Put
• Secondary Store
CacheWriterCacheWriter
2. store
02.09.2013
6
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Expiration
11
CacheCache
I
Y
XM
F
D
put
get
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Gliederung
• NoSQL und Java EE
• Infinispan
• Integrationsszenarien
• Ausblick
12
02.09.2013
7
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Infinispan
• Key-Value-Store– Distributed HashTable(JSR 107/347)– Transactional (JTA)– Low-latency (RAM)– Optional persist to disk
• Open Source Data Grid Plattform (LGPL)– JBoss/Red Hat
• Java and Scala
• Nicht nur für die JVM gedacht
• in verschiedenen Modi einsetzbar– Embedded– Client/Server(Data Grid)
13
ConsistencyConsistency
AvailabilityAvailabilityPartion
TolerancePartion
Tolerance
n.a.
BASE
Infinispan DistributedDBs
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Demo
14
02.09.2013
8
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Local Embedded Mode
15
SecondaryStore
2. Read
JEE
Application
CacheCache
Data Access
UI
1. get4. Read
0./3. Query
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Local Embedded Mode II
• Code in der gleiche VM wie infinispan
• wenig Konfigurationsarbeit
– Mit default EinstellungenDefaultCacheManager cacheManager = new DefaultCacheManager();
Cache<String, String> cache = cacheManager.getCache();
– Mit eigenen Einstellungen z.B: Clustereinstellungen
DefaultCacheManager cacheManager = newDefaultCacheManager(„cluster.xml");
Cache<String, String> cache = cacheManager.getCache();
16
02.09.2013
9
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Infinispan und Java EE Clustering
17
JEE
Application
CacheCache
Data Access
UI
1. get5. get
0./4. Query
JEE
Application
CacheCache
Data Access
UI
1.x Store A1 2. Read A
0. Update
• Secondary Store
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Clustered Embedded Mode
18
JEE
Application
CacheCache
Data Access
UI
2. get5. put
0./4. Query
JEE
Application
CacheCache
Data Access
UI
n.
• Secondary Store
JEE
Application
CacheCache
Data Access
UI
n+k.
3./6. load/Store
02.09.2013
10
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Demo
19
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
JEEApplication
CacheCache
Data Access
JEEApplication
CacheCache
Data Access
2. Put
0. query
Replication
20
JEEApplication
CacheCache
Data Access
1. Store
• Secondary Store
Replicate Replicate
02.09.2013
11
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
JEEApplication
CacheCache
Data Access
4. get
3. query
Invalidation
21
JEEApplication
CacheCache
Data Access
JEEApplication
CacheCache
Data Access
1. Put
0. query
• Secondary Store
Invalidate Invalidate
2. Store
5. load
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
JEEApplication
CacheCache
Data Access
2. get
0. query
Distribution [numOwner=2]
22
JEEApplication
CacheCache
Data Access
JEEApplication
CacheCache
Data Access
1. Read
• Secondary Store
Copy
02.09.2013
12
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Client/Server Mode
23
Load/Store
Non JavaApplication
Plenty
JVM
CacheCache
• Secondary Store
memcachedJVM
CacheCache
JEEApplication
Data Access
JSEApplication
Data Access
Hotrod
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Demo
24
02.09.2013
13
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Client/Server Mode II
• Starten des Servers erfordert die Angabe des Protokolls– bin/clustered.sh -Djboss.socket.binding.port-offset=xxx -
Djboss.node.name=nodeX
• org.infinispan.client.hotrod.RemoteCacheManagerRemoteCacheManager rcm = new
RemoteCacheManager("192.168.3.120");
RemoteCache remoteCace = rcm.getCache();
String key = "hello";
remoteCace.put(key, "world");
25
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Client/Server Remoting
RemoteEndpoint
Protokoll Smart Routing
LoadBalancing
Memcached Text - VordefinierteListe
ReSTful Text - http Loadbalancer
HotRod Binary + DynamischeTopologie
26
JVM
CacheCache
JEEApplicationApplication
Data Access
GroovyApplicationApplication
Data Access
02.09.2013
14
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
CacheStore
27
JEEApplication
CacheCache
1. Put
• Secondary Store
CacheStoreCacheStore
2. store
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Eviction
28
CacheCache
I
Y
XM FDput
get
MemorymeterStrategiez.B. LRU
02.09.2013
15
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Storage JPA Cache Store
• Implementierung mit JPA 2
• Speicherung mit applikationsspezifischem Datenmodell
• Key muss Primärschlüssel der Entität sein– @Id, @EmbeddedId
• Keine generierten Ids
Cache<String, User> usersCache = cacheManager.getCache("myJPACache"); // configured for User entity class
usersCache.put("raytsang", new User());
Cache<Integer, Teacher> teachersCache = cacheManager.getCache("myJPACache"); // cannot do this whenthis cache is configured to use a JPA cache store
teachersCache.put(1, new Teacher());
29
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Storage JPA Cache Store
<namedCache name="vehicleCache">
<loaders passivation="false" shared="true" preload="true">
<jpaStore
persistenceUnitName="org.infinispan.loaders.jpa.configurationTest"
entityClassName="org.infinispan.loaders.jpa.entity.User"
/>
</loaders>
</namedCache>
30
02.09.2013
16
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Gliederung
• NoSQL und Java EE
• Infinispan
• Integrationsszenarien
• Ausblick
31
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
DI-Container Integration
32
DI Container
Rem
oteC
onne
ctor
Ser
vice
Tran
sact
ionI
nter
epto
r
Cac
he
DA
O
Cac
heS
tore
02.09.2013
17
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Spring Integration
• Spring 3.1 Cache Abstraktion
• Infinispan Provider
• Integration mit Spring DI für CacheManager und Cache
<bean id="cacheManager"
class="org.infinispan.spring.provider.SpringEmbeddedCacheManagerFactoryBean"
p:configurationFileLocation="classpath:META-INF/oio-infinispan-config.xml">
</bean>
• Aktivieren des Cache– <cache:annotation-driven />
33
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Spring Integration
• Cache Annotation@Cacheable("nachrichtenCache")
public List<Nachricht> findAlleUngeleseneNachrichten () {… }
@Cacheable("nachrichtenCache", key=#"projektId ")
public List<Nachricht> findNachrichtenFuerProjekt(Bi gIntegerprojektId) {… }
• Deklarative Eviction@CacheEvict(value = "nachrichtenCache", allEntries = true)
public void nachrichtMarkieren(BigInteger nachrichtId, booleanungelesen) {… }
34
02.09.2013
18
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
CDI
• Konfiguration und Injizierung des Infinispan Cache– Cache Injizierung
@Inject
private Cache<String, String> cache;
@Inject
RemoteCache<String, String> remoteCache;
• Partielle Unterstützung vom JSR 107 Annotationen
35
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
CDI
• Eigene Cache [email protected]
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.
METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface NachrichtenCache {}
public class CacheCreator {@ConfigureCache("nachrichtencache") // cache name.
@NachrichtenCache // cache qualifier.
@Produces
public Configuration specialCacheCfg() {
return new ConfigurationBuilder()
.eviction()
.strategy(EvictionStrategy.LRU)
.maxEntries(10)
.build();
}
}
36
02.09.2013
19
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
CDI
• Injizierung des eigenen Caches
public class MyCDIComponent {
@Inject @NachrichtenCache
Cache<String, String> nachrichtenCache;
}
37
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Demo
38
02.09.2013
20
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
OR/M Integration
39
Java Virtual Machine
Anwendung
Transient
Transient
TransientTransient
Transient
PersistenceManager
1.Level Cache
Connection
DB
InstanzInstanz
Instanz
2.Level Cache
Entity Cache
InstanzInstanz
InstanzInstanz
QueryFacility
Transaction
QueryCache
TimestampCache
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Hibernate 2nd Level Cache
• Entity Cache– Key der Primärschlüssel– Cache lokal(default) oder repliziert – Replizierter Cache nicht empfohlen
• Query Cache– Key ist query-name und Parameter Hash– Cache lokal(default) oder repliziert
• Timestamps Cache– asynchrone Replikation(default)– keine eviction/expiration
40
02.09.2013
21
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Hibernate second level cache
• JTA Transaktion Manager– Hibernate soll/muss JTA Manager nutzen.
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/>
<property name="hibernate.cache.infinispan.cfg" value="/oio-infinispan-config.xml"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTSStandaloneTransactionManagerLookup"/>
41
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Gliederung
• NoSQL und Java EE
• Infinispan
• Integrationsszenarien
• Ausblick
42
02.09.2013
22
Infinispan - NoSQL für den Enterprise Java Alltag© 2013 Orientation in Objects GmbH
Infinispan Ausblick
• Map/Reduce Support
• Versioned Entries
• Support Eventual Consistency (7.0 ?)
• Optimierungen:– Transaktionen– Locking– RPC
43
Orientation in Objects GmbH
Weinheimer Str. 6868309 Mannheim
??
? ?
????
Fragen ?
44
02.09.2013
23
Orientation in Objects GmbH
Weinheimer Str. 6868309 Mannheim
Vielen Dank für ihre Aufmerksamkeit !