Vous êtes sur la page 1sur 22

JBoss Cache

Helves H. Domingues MAC 5863 - Sistemas de Middleware Avanados Prof. Francisco Reverbel

Agenda

Viso Geral TreeCache / Demonstrao POJOCache / Demonstrao Cache Loaders Configuraes

JBoss Cache

Consiste em dois mdulos

TreeCache

Dados em estrutura de rvore Replicao, transao Utiliza JGroups Acima do TreeCache Replicao de objetos POJO Utiliza AOP

PojoCache

Verso Atual

JBoss Cache 1.4.0 Jalapeno Integrado ao JBoss App. Server como MBean service. Standalone Pode rodar em qualquer Java EE Server ( WebLogic e WebSphere) e tambm em um processo Java fora de um servidor de applicao.

Aplicaes

JBoss Cache como segundo nvel de cache para o Hibernate Replicao de objetos de sesso em um cluster Cpia local de dados caros:

Banco de dados ( acesso mais lento ) Dados calculados ( faz um clculo ) Parte de conjunto muito grande Dados remotos, onde o trfego lento

Organizao dos dados


a

Full Qualified Name ( Fqn ) = /a/d/f

TreeCache API

put (Fqn path,Object key, Object value) put (Fqn path,Object key, Map data) Object get (Fqn path,Object key) remove(Fqn path) remove(Fqn path, Object key)

TreeCache Exemplo 1 / Demonstrao


import org.jboss.cache.*; TreeCache tree = new TreeCache(); PropertyConfigurator config = new PropertyConfigurator(); config.configure(tree, "META-INF/replSync-service.xml"); tree.startService(); tree.put("/a/b/c", "chave", "valor1");

POJOCache API

putObject (Fqn path,Object pojo) Object getObject (Fqn path) removeObject(Fqn path) O objeto que ser posto no cache:

@org.jboss.cache.aop.annotation.InstanceOfPojoCacheable

POJOCache Interceptadores

1
CacheInterceptor

2 3 5 4 POJO Cache

Objeto

POJOCache Exemplo 2 / Demonstrao


// Import necessrios TreeCache tree = new PojoCache(); PropertyConfigurator config = new PropertyConfigurator(); config.configure(tree, "META-INF/replSync-service.xml"); Person joe = new Person(); joe.setName("Joao Batista"); joe.setAge(31); Address addr = new Address(); addr.setCity("Sao Paulo"); addr.setStreet("Bosque Saude, 56"); addr.setZip(04136-222); joe.setAddress(addr); tree.startService(); tree.putObject("/aop/joe", joe);

POJOCache com Transao Exemplo 3 / Demonstrao


//-- Import necessrios DummyTransactionManager.getInstance(); Properties prop = new Properties(); prop.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.cache.tra nsaction.DummyContextFactory"); UserTransaction tx = (UserTransaction)new InitialContext(prop).lookup("UserTransaction"); PojoCache tree = new PojoCache(); PropertyConfigurator config = new PropertyConfigurator(); config.configure(tree, "META-INF/replSync-service.xml"); //-- Criao do Person e Address, etc tree.startService(); tree.putObject("/aop/joe", joe); tx.begin(); joe.setAge(41); tx.commit();

POJOCache com CacheLoader Exemplo 4 / Demonstrao


//-- Import necessrios //-- o mesmo do exemplo anterior config.configure(tree, "META-INF/oodb-service.xml"); tree.startService(); if(!tree.exists("/aop/joe")) { print("Criando um entrada no cache"); //-- Cria Person e Addres.. } else { print("O Cache ja tem a entrada /aop/joe"); }

Cenrios CacheLoaders Repositrio compartilhado

Replicao

CacheLoader

CacheLoader

Repositrio

Cenrios CacheLoaders Repositrio nico

Replicao

CacheLoader

Repositrio

Cenrios CacheLoaders Repositrios isolados

Replicao

CacheLoader

CacheLoader

Repositrio

Repositrio

Configurao JBoss Cache Modo de replicao

CacheMode

Sem replicao

LOCAL REPL_SYNC REPL_ASYNC INVALIDATE_SYNC INVALIDATE_ASYNC

Com replicao

Com invalidao

Configurao JBoss Cache Transao

IsolationLevel

SERIALIZABLE REPEATABLE_READ (default) READ_COMMITTED READ_UNCOMMITTED NONE OPTIMISTIC PESSIMISTIC (default)

NodeLockingScheme

Configurao JBoss Cache Replicao entre um subgrupo


buddyReplicationEnabled

TRUE/FALSE numBuddies = 5 ignoreColocatedBuddies = true

buddyLocatorProperties

buddyPoolName

Configurao JBoss Cache Invalidao de Cache Eviction Policy


EvictionPolicyClass

LRUPolicy, LFUPolicy, MRUPolicy e FIFOPolicy maxNodes, minNodes timeToLiveSeconds maxAgeSeconds

Region ( fqn de um n )

wakeUpIntervalSeconds

Configurao JBoss Cache Cache Loaders

Modo de operao

passivation= true/false preload=(fqn do n) shared=true/false class location (onde est o repositrio) async=true/false purgeOnStartup=true/false ignoreModifications=true/false

Para cada cache Loaders


JBoss Cache Dvidas/Perguntas


Helves H. Domingues MAC 5863 - Sistemas de Middleware Avanados Prof. Francisco Reverbel