Em vez de usar a interface BackingMap para programaticamente configurar os atributos de BackingMap
a serem usados pelos Evictor TTL, é possível usar um arquivo XML para configurar cada instância de BackingMap. O código a seguir demonstra como configurar tais atributos para três mapas BackingMap diferentes:
Antes de Iniciar
Antes de começar, decida sobre o tipo de evictor que será usado:
- Evictor TTL baseado em tempo padrão: O evictor padrão usa uma política
de despejo tempo de vida (TTL) para cada instância BackingMap.
- Um um mecanismo de evictor conectável: Evictors conectáveis geralmente usam uma política de despejo com base no número de entradas em vez de no tempo.
A maior parte das configurações de evictor deve ser feita
antes de inicializar o ObjectGrid.
Procedimento
- Para configurar o evictor TTL padrão, inclua o atributo ttlEvictorType no arquivo descritor XML do ObjectGrid.
O exemplo a seguir mostra que a instância map1 de BackingMap usa um tipo de evictor NONE TTL. A instância BackingMap map2 usa um tipo de evictor TTL LAST_ACCESS_TIME ou LAST_UPDATE_TIME. Especifique apenas uma ou outras dessas configurações. A instância BackingMap map2 tem um valor de tempo de vida de 1800 segundos, ou 30 minutos. A instância map3 de BackingMap é definida para
utilizar um tipo de evictor CREATION_TIME TTL e tem um valor de
time-to-live de 1200 segundos ou 20 minutos.
Figura 1. Ativar o Evictor TimeToLive com XML<?xml version="1.0" encoding="UTF-8"?>
<objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ibm.com/ws/objectgrid/config ../objectGrid.xsd"
xmlns="http://ibm.com/ws/objectgrid/config">
<objectGrids>
<objectGrid name="grid1">
<backingMap name="map1" ttlEvictorType="NONE" />
<backingMap name="map2" ttlEvictorType="LAST_ACCESS_TIME|LAST_UPDATE_TIME"
timeToLive="1800" />
<backingMap name="map3" ttlEvictorType="CREATION_TIME" timeToLive="1200" />
</objectgrid>
</objectGrids>
- Para configurar um evictor conectável, use o seguinte exemplo.
Figura 2. Conectando um Evictor Usando XML<?xml version="1.0" encoding="UTF-8"?>
<objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ibm.com/ws/objectgrid/config ../objectGrid.xsd"
xmlns="http://ibm.com/ws/objectgrid/config">
<objectGrids>
<objectGrid name="grid">
<backingMap name="map1" ttlEvictorType="NONE" pluginCollectionRef="LRU" />
<backingMap name="map2" ttlEvictorType="NONE" pluginCollectionRef="LFU" />
</objectGrid>
</objectGrids>
<backingMapPluginCollections>
<backingMapPlugincollection id="LRU">
<bean id="Evictor" className="com.ibm.websphere.objectgrid.plugins.builtins.LRUEvictor">
<property name="maxSize" type="int" value="1000" description="set max size for each LRU queue" />
<property name="sleepTime" type="int" value="15" description="evictor thread sleep time" />
<property name="numberOfLRUQueues" type="int" value="53" description="set number of LRU queues" />
</bean>
</backingMapPluginCollection>
<backingMapPluginCollection id="LFU">
<bean id="Evictor" className="com.ibm.websphere.objectgrid.plugins.builtins.LFUEvictor">
<property name="maxSize" type="int" value="2000" description="set max size for each LFU heap" />
<property name="sleepTime" type="int" value="15" description="evictor thread sleep time" />
<property name="numberOfHeaps" type="int" value="211" description="set number of LFU heaps" />
</bean>
</backingMapPluginCollection>
</backingMapPluginCollections>
</objectGridConfig>