JBoss Cache SVN: r7033 - in core/trunk/src: test/java/org/jboss/cache/config and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-30 12:57:53 -0400 (Thu, 30 Oct 2008)
New Revision: 7033
Added:
core/trunk/src/test/resources/configs/conf2x/zeroTTL.xml
Modified:
core/trunk/src/main/resources/config2to3.xslt
core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTransformerTest.java
core/trunk/src/test/resources/configs/conf2x/optimistically-locked-cache.xml
Log:
Updated to take into account new meanings of 0 in eviction config and translate old 0's to -1's to denote no limit.
Modified: core/trunk/src/main/resources/config2to3.xslt
===================================================================
--- core/trunk/src/main/resources/config2to3.xslt 2008-10-30 04:53:19 UTC (rev 7032)
+++ core/trunk/src/main/resources/config2to3.xslt 2008-10-30 16:57:53 UTC (rev 7033)
@@ -373,7 +373,14 @@
<xsl:value-of select="substring-before($attr/@name,'Seconds')"/>
</xsl:attribute>
<xsl:attribute name="value">
- <xsl:value-of select="concat($attr,'000')"/>
+ <xsl:choose>
+ <xsl:when test="$attr = '0'">
+ <xsl:value-of select="-1"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="concat($attr,'000')"/>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
@@ -381,7 +388,17 @@
<xsl:value-of select="string($attr/@name)"/>
</xsl:attribute>
<xsl:attribute name="value">
- <xsl:value-of select="$attr"/>
+ <xsl:choose>
+ <xsl:when test="$attr/@name = 'maxNodes' and $attr = '0'">
+ <xsl:value-of select="-1"/>
+ </xsl:when>
+ <xsl:when test="$attr/@name = 'minNodes' and $attr = '0'">
+ <xsl:value-of select="-1"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$attr"/>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
Modified: core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTransformerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTransformerTest.java 2008-10-30 04:53:19 UTC (rev 7032)
+++ core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTransformerTest.java 2008-10-30 16:57:53 UTC (rev 7033)
@@ -3,6 +3,7 @@
import org.jboss.cache.config.parsing.ConfigFilesConvertor;
import org.jboss.cache.config.parsing.XmlConfigurationParser;
import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
+import org.jboss.cache.eviction.LRUAlgorithmConfig;
import org.testng.annotations.Test;
import java.io.ByteArrayInputStream;
@@ -17,7 +18,7 @@
* <li> it parses the file with 2.x parser
* <li> it parses the transform with a 3.x parser
* <li> checks that the two resulting <tt>Configuration</tt> objects are equal.
- * </ol>
+ * </ol>
*
* @author Mircea.Markus(a)jboss.com
* @since 3.0
@@ -86,7 +87,7 @@
"default-test-config2x.xml",
"eviction-enabled-cache.xml",
"optimistically-locked-cache.xml",
- "policyPerRegion-eviction.xml" ,
+ "policyPerRegion-eviction.xml",
};
for (String file : fileNames)
{
@@ -106,6 +107,38 @@
}
}
+ public void testUnlimitedValues() throws Exception
+ {
+ // in 3.x, unlimited values in eviction are denoted by -1 and not 0!
+ String fileName = getFileName("/zeroTTL.xml");
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ convertor.parse(fileName, baos, XSLT_FILE);
+ System.out.println("result = \n" + baos);
+
+ XmlConfigurationParser newParser = new XmlConfigurationParser();
+ XmlConfigurationParser2x oldParser = new XmlConfigurationParser2x();
+
+ Configuration newConfig = newParser.parseStream(new ByteArrayInputStream(baos.toByteArray()));
+ Configuration oldConfig = oldParser.parseFile(fileName);
+
+ for (EvictionRegionConfig erc : oldConfig.getEvictionConfig().getEvictionRegionConfigs())
+ {
+ correctUnlimitedValues(erc);
+ }
+ correctUnlimitedValues(oldConfig.getEvictionConfig().getDefaultEvictionRegionConfig());
+
+ assert oldConfig.equals(newConfig);
+ }
+
+ private void correctUnlimitedValues(EvictionRegionConfig erc)
+ {
+ LRUAlgorithmConfig eac = (LRUAlgorithmConfig) erc.getEvictionAlgorithmConfig();
+ if (eac.getMaxAge() == 0) eac.setMaxAge(-1);
+ if (eac.getMaxNodes() == 0) eac.setMaxNodes(-1);
+ if (eac.getMinTimeToLive() == 0) eac.setMinTimeToLive(-1);
+ if (eac.getTimeToLive() == 0) eac.setTimeToLive(-1);
+ }
+
private String getFileName(String s)
{
return BASE_DIR + File.separator + s;
Modified: core/trunk/src/test/resources/configs/conf2x/optimistically-locked-cache.xml
===================================================================
--- core/trunk/src/test/resources/configs/conf2x/optimistically-locked-cache.xml 2008-10-30 04:53:19 UTC (rev 7032)
+++ core/trunk/src/test/resources/configs/conf2x/optimistically-locked-cache.xml 2008-10-30 16:57:53 UTC (rev 7033)
@@ -66,13 +66,13 @@
<region name="/_default_">
<attribute name="maxNodes">10</attribute>
- <attribute name="timeToLiveSeconds">0</attribute>
- <attribute name="maxAgeSeconds">0</attribute>
+ <attribute name="timeToLiveSeconds">8</attribute>
+ <attribute name="maxAgeSeconds">5</attribute>
</region>
<region name="/testingRegion">
<attribute name="maxNodes">10</attribute>
- <attribute name="timeToLiveSeconds">0</attribute>
- <attribute name="maxAgeSeconds">0</attribute>
+ <attribute name="timeToLiveSeconds">1</attribute>
+ <attribute name="maxAgeSeconds">2</attribute>
</region>
<region name="/timeBased">
<attribute name="maxNodes">10</attribute>
Added: core/trunk/src/test/resources/configs/conf2x/zeroTTL.xml
===================================================================
--- core/trunk/src/test/resources/configs/conf2x/zeroTTL.xml (rev 0)
+++ core/trunk/src/test/resources/configs/conf2x/zeroTTL.xml 2008-10-30 16:57:53 UTC (rev 7033)
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<server>
+
+ <mbean code="org.jboss.cache.jmx.CacheJmxWrapper"
+ name="jboss.cache:service=Cache">
+
+ <depends>jboss:service=Naming</depends>
+ <depends>jboss:service=TransactionManager</depends>
+
+ <attribute name="TransactionManagerLookupClass">org.jboss.cache.transaction.GenericTransactionManagerLookup
+ </attribute>
+
+ <attribute name="IsolationLevel">REPEATABLE_READ</attribute>
+
+ <attribute name="CacheMode">LOCAL</attribute>
+
+ <attribute name="LockAcquisitionTimeout">15000</attribute>
+
+ <attribute name="EvictionPolicyConfig">
+ <config>
+ <attribute name="wakeUpIntervalSeconds">10</attribute>
+ <attribute name="eventQueueSize">200000</attribute>
+ <attribute name="policyClass">org.jboss.cache.eviction.LRUPolicy</attribute>
+
+ <!-- Cache wide default -->
+ <region name="/_default_">
+ <attribute name="maxNodes">5000</attribute>
+ <attribute name="minTimeToLiveSeconds">0</attribute>
+ </region>
+ <region name="/org/jboss/data">
+ <attribute name="minTimeToLiveSeconds">1000</attribute>
+ <attribute name="maxNodes">0</attribute>
+ </region>
+ </config>
+ </attribute>
+ </mbean>
+</server>
16 years, 2 months
JBoss Cache SVN: r7032 - enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES.
by jbosscache-commits@lists.jboss.org
Author: mospina
Date: 2008-10-30 00:53:19 -0400 (Thu, 30 Oct 2008)
New Revision: 7032
Modified:
enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Architecture.po
enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Compatibility.po
enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Introduction.po
enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Jboss_integration.po
Log:
translation in progress
Modified: enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Architecture.po
===================================================================
--- enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Architecture.po 2008-10-30 01:39:47 UTC (rev 7031)
+++ enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Architecture.po 2008-10-30 04:53:19 UTC (rev 7032)
@@ -1,30 +1,32 @@
+# translation of Architecture.po to
# Language /tmp/mike/JBEAP420/Cache translations for JBEAP package.
-# Copyright (C) 2007 Free Software Foundation, Inc.
+# Copyright (C) 2007, 2008 Free Software Foundation, Inc.
# Automatically generated, 2007.
#
msgid ""
msgstr ""
-"Project-Id-Version: JBEAP 420\n"
+"Project-Id-Version: Architecture\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2008-09-21 04:43+0000\n"
-"PO-Revision-Date: 2001-02-09 01:25+0100\n"
-"Last-Translator: Automatically generated\n"
-"Language-Team: none\n"
+"PO-Revision-Date: 2008-10-30 08:36+1000\n"
+"Last-Translator: Angela Garcia\n"
+"Language-Team: <en(a)li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: KBabel 1.11.4\n"
#. Tag: title
#: Architecture.xml:5
#, no-c-format
msgid "Architecture"
-msgstr ""
+msgstr "Arquitectura"
#. Tag: title
#: Architecture.xml:7
#, no-c-format
msgid "Schematic TreeCache architecture"
-msgstr ""
+msgstr "Arquitectura TreeCache esquemática"
#. Tag: para
#: Architecture.xml:14
@@ -36,6 +38,8 @@
"underlying group communication subsystem is done using <ulink url=\"http://"
"www.jgroups.org\">JGroups</ulink>."
msgstr ""
+"La arquitectura se puede ver arriba. El ejemplo muestra dos MV Java, cada una ha creado una instancia de <literal>TreeCache</literal>. Estas máquinas virtuales se pueden encontrar en la misma máquina o en dos máquinas diferentes. La configuración del subsistema de comunicación del grupo subyacente se realiza utilizando <ulink url=\"http://"
+"www.jgroups.org\">JGroups</ulink>."
#. Tag: para
#: Architecture.xml:17
@@ -48,4 +52,5 @@
"the end of a transaction (at commit time). When a new cache is created, it "
"can optionally acquire the contents from one of the existing caches on "
"startup."
-msgstr ""
+msgstr "Cualquier modificación (vea la API a continuación) en un caché será replicada al otro caché<footnote><para> Observe que puede tener más de dos cachés en un clúster. </para> </footnote> y viceversa. Dependiendo de la configuración transaccional, esta replicación ocurrirá ya sea después de cada modificación o al final de una transacción (en el momento de guardar los cambios). Cuando se crea un nuevo caché, opcionalmente puede adquirir el contenido de uno de los cachés existentes al arrancar. "
+
Modified: enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Compatibility.po
===================================================================
--- enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Compatibility.po 2008-10-30 01:39:47 UTC (rev 7031)
+++ enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Compatibility.po 2008-10-30 04:53:19 UTC (rev 7032)
@@ -8,7 +8,7 @@
"Project-Id-Version: Compatibility\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2008-09-21 04:43+0000\n"
-"PO-Revision-Date: 2008-10-17 14:24+1000\n"
+"PO-Revision-Date: 2008-10-30 13:47+1000\n"
"Last-Translator: Angela Garcia\n"
"Language-Team: <en(a)li.org>\n"
"MIME-Version: 1.0\n"
@@ -35,7 +35,7 @@
"state transfer messages. Note however that interoperability requires use of "
"the same JGroups version in all nodes in the cluster. In most cases, the "
"version of JGroups used by a version of JBoss Cache can be upgraded."
-msgstr ""
+msgstr "Mientras que esto no está completamente garantizado, generalmente hablando dentro de una versión importante, se supone que los lanzamientos de JBoss Cache son compatibles e interoperables. Compatibles es decir que debería ser posible actualizar una aplicación de una versión a otra simplemente con reemplazar las jars. Interoperable en otras palabras que si dos versiones diferentes de JBoss Cache se utilizan en el mismo clúster deben poder intercambiar los mensajes de replicación y de transferencia de estado. Sin embargo, observe que la interoperabilidad requiere el uso de la misma versión de JGroups en todos los nodos en el clúster. En la mayoría de los casos, se puede actualizar la versión de JGroups que una versión de JBoss Cache utiliza."
#. Tag: para
#: Compatibility.xml:9
@@ -50,6 +50,8 @@
"please recompile before upgrading to 1.2.4.SP2 in order to be sure you have "
"no issues."
msgstr ""
+"En los lanzamientos 1.2.4 y 1.2.4.SP1 se perdió la interoperabilidad y la compatibilidad API con los lanzamientos anteriores. El propósito principal del lanzamiento 1.2.4.SP2 era el reestablecer la interoperabilidad y la compatibilidad API. Sin embargo, observe que el restaurar la compatibilidad API con lanzamientos anteriores significaba que "
+"1.2.4.SP2 no es completamente compatible API con los otros dos lanzamientos 1.2.4. Si ha construido aplicaciones por encima de 1.2.4 o 1.2.4.SP1, recompile antes de actualizar a 1.2.4.SP2 con el fin de asegurarse de que no hay problemas."
#. Tag: para
#: Compatibility.xml:12
@@ -65,6 +67,8 @@
"JBoss Cache by using more efficient wire formats while still providing a "
"means to preserve interoperability."
msgstr ""
+"Desde 1.2.4.SP2, se añadió un nuevo atributo de configuración "
+"<literal>ReplicationVersion</literal>. Es necesario configurar este atributo con el fin de permitir la interoperabilidad con lanzamientos anteriores. El valor se debe configurar con el nombre del lanzamiento de la versión con la cual se desea la interoperabilidad, por ejemplo, \"1.2.3\". Si este atributo se configura, el formato de cable de los mensajes de replicación y de transferencia de estado cumplirán con los requerimientos asumidos por el lanzamiento indicado. Este mecanismo nos permite mejorar JBoss Cache utilizando formatos de cable más eficientes al mismo tiempo proporcionando un medio para preservar la interoperabilidad."
#. Tag: para
#: Compatibility.xml:15
@@ -80,4 +84,6 @@
"caches, a workaround is to set system property <literal>jboss.cache."
"fqn.123compatible</literal> to <literal>true</literal>."
msgstr ""
+"En casos muy raros múltiples y diferentes instancias de JBoss Cache pueden estar operando en cada nodo en un clúster, pero no todas necesitarán interoperar con una versión caché 1.2.3 y por lo tanto algunos cachés no serán configurados con <literal>ReplicationVersion</literal> establecido como 1.2.3. Esto puede llegar a causar problemas con la serialización de objetos Fqn. Si está utilizando esta clase de configuración y está teniendo problemas y no quiere configurar <literal>ReplicationVersion</literal> como <literal>1.2.3</literal> en todos los cachés, una solución opcional es configurar la propiedad del sistema <literal>jboss.cache."
+"fqn.123compatible</literal> como <literal>true</literal>."
Modified: enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Introduction.po
===================================================================
--- enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Introduction.po 2008-10-30 01:39:47 UTC (rev 7031)
+++ enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Introduction.po 2008-10-30 04:53:19 UTC (rev 7032)
@@ -1,30 +1,32 @@
+# translation of Introduction.po to
# Language /tmp/mike/JBEAP420/Cache translations for JBEAP package.
-# Copyright (C) 2007 Free Software Foundation, Inc.
+# Copyright (C) 2007, 2008 Free Software Foundation, Inc.
# Automatically generated, 2007.
#
msgid ""
msgstr ""
-"Project-Id-Version: JBEAP 420\n"
+"Project-Id-Version: Introduction\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2008-09-21 04:44+0000\n"
-"PO-Revision-Date: 2001-02-09 01:25+0100\n"
-"Last-Translator: Automatically generated\n"
-"Language-Team: none\n"
+"PO-Revision-Date: 2008-10-30 11:59+1000\n"
+"Last-Translator: Angela Garcia\n"
+"Language-Team: <en(a)li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: KBabel 1.11.4\n"
#. Tag: title
#: Introduction.xml:5
#, no-c-format
msgid "Introduction"
-msgstr ""
+msgstr "Introducción"
#. Tag: title
#: Introduction.xml:7
#, no-c-format
msgid "What is a TreeCache?"
-msgstr ""
+msgstr "¿Qué es un TreeCache?"
#. Tag: para
#: Introduction.xml:8
@@ -36,6 +38,8 @@
"including - in certain versions - clustering JNDI, HTTP and EJB sessions, "
"and clustering JMS."
msgstr ""
+"Un <literal>TreeCache</literal> es un caché transaccional, replicado y con estructura de árbol de JBoss Cache. <literal>TreeCache</literal> es la columna vertebral para muchos de los servicios fundamentales de clúster de JBoss Application Server, "
+"incluyendo - en ciertas versiones - clústers JNDI, HTTP y sesiones EJB y clústers JMS."
#. Tag: para
#: Introduction.xml:11
@@ -46,13 +50,13 @@
"data store, may be embedded in other J2EE compliant application servers such "
"as BEA WebLogic or IBM WebSphere, servlet containers such as Tomcat, or even "
"in Java applications that do not run from within an application server."
-msgstr ""
+msgstr "Además de esto, <literal>TreeCache</literal> se puede utilizar como un caché autónomo transaccional y replicado o incluso un almacenamiento de datos orientado a objetos, es posible que se encuentre incluido en otros servidores de aplicaciones que cumplen con los requerimientos de J2EE tal como BEA WebLogic o IBM WebSphere, contenedores servlet como Tomcat o incluso en aplicaciones Java que no ejecutan desde dentro de un servidor de aplicaciones."
#. Tag: title
#: Introduction.xml:17
#, no-c-format
msgid "TreeCache Basics"
-msgstr ""
+msgstr "Conceptos básicos sobre TreeCache"
#. Tag: para
#: Introduction.xml:18
@@ -65,7 +69,7 @@
"node is found. It can also be accessed by giving a fully qualified name "
"(FQN), which consists of the concatenation of all node names from the root "
"to the node in question."
-msgstr ""
+msgstr "La estructura de un <literal>TreeCache</literal> es un árbol con nodos. Cada nodo tiene un nombre y cero o más hijos. Un nodo sólo puede tener un padre; actualmente no hay soporte para gráficas. Se puede llegar hasta un nodo navegando desde la raíz recursivamente a través de los hijos hasta encontrar el nodo requerido. También se puede acceder proporcionando un nobre de clase completamente calificado (FQN - fully qualified name), el cual consiste de la concatenación de todos los nombres de nodos desde la raíz hasta el nodo en cuestión."
#. Tag: para
#: Introduction.xml:21
@@ -79,6 +83,8 @@
"not a requirement for <literal>PojoCache</literal>, where reflection and "
"aspect-oriented programming is used to replicate any type."
msgstr ""
+"Un <literal>TreeCache</literal> puede tener múltiples raices permitiendo que un número de árboles diferentes estén presentes en una sóla instancia de caché. Observe que un árbol de un nivel es esencialmente un <literal>HashMap</literal>. Cada nodo "
+"en el árbol tiene un mapa de claves y valores. Para un caché replicado, todas las claves y valores tienen que ser <literal>Serializable</literal>. La serializabilidad no es un requerimiento para <literal>PojoCache</literal>, en donde se utiliza la reflección y la programación orientada a aspectos para replicar cualquier tipo."
#. Tag: para
#: Introduction.xml:24
@@ -89,7 +95,7 @@
"replicated trees propagate any changes to all other replicated trees in the "
"same cluster. A cluster may span different hosts on a network or just "
"different JVMs on a single host."
-msgstr ""
+msgstr "Un <literal>TreeCache</literal> puede ser local o replicado. Los árboles locales sólo existen dentro de la MV Java en donde son creados, mientras que los árboles replicados propagan cualquier cambio en los otros árboles replicados en el mismo clúster. Un clúster puede abarcar diferentes hosts en una red o simplemente diferentes MVJ en un sólo host."
#. Tag: para
#: Introduction.xml:27
@@ -110,6 +116,11 @@
"literal>, but is a vital requirement for <literal>PojoCache</literal> (as we "
"will see in the separate <literal>PojoCache</literal> documentation)."
msgstr ""
+"La primera versión de <literal>TreeCache</literal> era esencialmente un sólo "
+"<literal>HashMap</literal> que replicaba. Sin embargo,esa decisión se tomó para que fuera con un caché con estructura de árbol ya que (a) es más flexible y eficiente y (b) un árbol siempre se puede reducir a un mapa, de esa manera ofreciendo ambas posibilidades. El argumento sobre la eficiencia se originó principalmente por la preocupación sobre el costo de la replicación y era que un valor puede ser en sí mismo un objeto sofisticado, con la agrupación apuntando a otros objetos o un "
+"objeto que contiene muchos campos. Por lo tanto un pequeño cambio en el objeto dispararía que se serializara todo el objeto (posiblemente el cierre transitivo sobre la gráfica del objeto) para ser serializado y propagado a los otros nodos en el clúster. "
+"Con un árbol, sólo los nodos modificados en el árbol tendrán que ser serializados y propagados. Esto no es necesariamente una preocupación para <literal>TreeCache</"
+"literal>, pero es un requerimiento vital para <literal>PojoCache</literal> (como lo vamos a ver en la documentación <literal>PojoCache</literal> que viene por separado)."
#. Tag: para
#: Introduction.xml:30
@@ -124,7 +135,7 @@
"replication traffic and overhead. For example, if a caller makes 100 "
"modifications and then rolls back the transaction, we will not replicate "
"anything, resulting in no network traffic."
-msgstr ""
+msgstr "Cuando se realiza un cambio al <literal>TreeCache</literal> y ese cambio se realiza en el contexto de una transacción entonces postergamos la replicación de cambios hasta que la transacción guarda los cambios de manera exitosa. Todas las modificaciones se guardan en una lista asociada con la transacción para el que realiza la llamada. Cuando la transacción guarda los cambios entonces replicamos los cambios. De otra manera (cuando se deshacen los cambios) simplemente deshacemos los cambios localmente y liberamos cualquier bloqueo lo cual resulta en cero tráfico de replicación y sobrecostos. Por ejemplo, si alguien que realiza una llamada realiza 100 modificaciones y luego deshace la transacción entonces no vamos a replicar nada lo cual hace que no haya tráfico de red. "
#. Tag: para
#: Introduction.xml:33
@@ -137,7 +148,7 @@
"transaction can be thought of as analogous as running with auto-commit "
"switched on in JDBC terminology, where each operation is committed "
"automatically."
-msgstr ""
+msgstr "Si el que realiza la llamada no tiene una transacción asociada con este (y el nivel de aislamiento no es NONE - lo veremos más adelante) entonces vamos a replicar justo después de cada modificación, por ejemplo, en el caso anterior enviaríamos 100 mensajes más un mensaje adicional por el deshacer los cambios. En este sentido, el ejecutar sin una transacción se puede considerar como analogo a ejecutar con el auto-commit prendido en terminología JDBC, en donde cada operación se guarda de manera automática. "
#. Tag: para
#: Introduction.xml:36
@@ -148,7 +159,7 @@
"Several <literal>TransactionManagerLookup</literal> implementations are "
"provided for popular transaction managers, including a "
"<literal>DummyTransactionManager</literal> for testing."
-msgstr ""
+msgstr "Hay una API para conectar diferentes administradores de transacciones: todo lo que necesita es obtener la transacción asociada con el hilo del que realiza la llamada. Se proporcionan varias implementaciones <literal>TransactionManagerLookup</literal> para administradores de transacciones populares, incluyendo un <literal>DummyTransactionManager</literal> para pruebas. "
#. Tag: para
#: Introduction.xml:39
@@ -164,6 +175,9 @@
"an object for which we do not yet have a lock (this would result in too high "
"an overhead for messaging)."
msgstr ""
+"Finalmente utilizamos el bloqueo pesimista del caché por defecto, con el bloqueo optimista como una opción configurable. Con el bloqueo pesimista podemos configurar la política de bloqueo local correspondiente a los niveles de aislamiento de transacciones de estilo de base de datos, por ejemplo, SERIALIZABLE, REPEATABLE, READ_COMMITTED, "
+"READ_UNCOMMITTED y NONE. Más adelante abordaremos los niveles de aislamiento de transacciones. Observe que el nivel de aislamiento a través del clúster es READ-"
+"UNCOMMITTED por defecto ya que no adquirimos un bloqueo a nivel de clúster al tocar un objeto para el cual aún no tenemos un bloqueo (esto resultaría en un sobrecosto para mensajería). "
#. Tag: para
#: Introduction.xml:42
@@ -176,4 +190,5 @@
"cluster-wide, for the minor performance penalty incurred when validating "
"workspace data at commit time, and the occasional transaction commit failure "
"due to validation failures at commit time."
-msgstr ""
+msgstr "Con el bloqueo optimista, los niveles de aislamiento se ignoran ya que cada transacción mantiene efectivamente una copia de los datos con los que trabaja y luego trata de fusionarse en la estructura de árbol cuando la transacción se completa. Esto resulta en un grado casi serializable de integridad de datos, aplicado a nivel del clúster, para la penalidad de rendimiento menor en la que se incurrió al validar datos de espacio de trabajo en el momento de guardar los cambios y falla al tratar de guardar los cambios de la transacción debido a fallas en la validación en el momento de guardar los cambios. "
+
Modified: enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Jboss_integration.po
===================================================================
--- enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Jboss_integration.po 2008-10-30 01:39:47 UTC (rev 7031)
+++ enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Jboss_integration.po 2008-10-30 04:53:19 UTC (rev 7032)
@@ -8,7 +8,7 @@
"Project-Id-Version: Jboss_integration\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2008-09-21 04:44+0000\n"
-"PO-Revision-Date: 2008-10-17 12:13+1000\n"
+"PO-Revision-Date: 2008-10-30 14:34+1000\n"
"Last-Translator: Angela Garcia\n"
"Language-Team: <en(a)li.org>\n"
"MIME-Version: 1.0\n"
@@ -20,7 +20,7 @@
#: Jboss_integration.xml:5
#, no-c-format
msgid "Running JBoss Cache within JBoss Application Server"
-msgstr ""
+msgstr "Ejecución de JBoss Cache dentro de JBoss Application Server"
#. Tag: para
#: Jboss_integration.xml:6
@@ -33,6 +33,11 @@
"course, JBoss Cache can also be deployed as a SAR, or even as part of a WAR, "
"EJB or EAR."
msgstr ""
+"Si se ejecuta JBoss Cache en JBoss AS entonces JBoss Cache puede ser desplegado como un "
+"MBean. Los pasos a continuación ilustran como lograr esto. No desplegamos JBoss "
+"Cache como un Service Archive (SAR), sino como un JAR (<literal>jboss-cache.jar</"
+"literal> en el directorio lib) y un archivo XML definiendo el MBean. JBoss Cache también puede desplegarse como un SAR o incluso como parte de un WAR, "
+"EJB o EAR."
#. Tag: para
#: Jboss_integration.xml:9
@@ -43,6 +48,8 @@
"configuration file in XML format has to be copied to the /deploy directory. "
"The XML file format is the same as discussed in the Configuration chapter."
msgstr ""
+"Primero se tiene que copiar el archivo <literal>jboss-cache.jar</literal> al directorio lib /"
+"y se tiene que re-iniciar JBoss AS. Después hay que copiar un archivo de configuración normal de JBoss Cache en formato XML en el directorio /deploy. El formato del archivo XML es el mismo que discutimos en el capítulo sobre configuración."
#. Tag: para
#: Jboss_integration.xml:12
@@ -50,7 +57,7 @@
msgid ""
"In order to be used from a client such as a servlet in the Tomcat web "
"container inside the same JBoss container, JMX can be used:"
-msgstr ""
+msgstr "Se puede utilizar JMX con el fin de utilizarlo desde un cliente tal como un servlet en el contenedor web Tomcat dentro del mismo contenedor JBoss: "
#. Tag: programlisting
#: Jboss_integration.xml:15
@@ -78,12 +85,14 @@
"invoked against the generated interface. The name used to look up the MBean "
"is the same as defined in the configuration file."
msgstr ""
+"La clase MBeanServerLocator es una ayuda para encontrar el servidor JBoss MBean dentro de la MV actual. El método estático create() crea un proxy dinámico a la interfaz dada y utiliza JMX para despachar dinámicamente los métodos "
+"invocados frente a la interfaz generada. El nombre utilizado para buscar el MBean es el mismo que el definido en el archivo de configuración."
#. Tag: title
#: Jboss_integration.xml:20
#, no-c-format
msgid "Running as an MBean"
-msgstr ""
+msgstr "Ejecución como un MBean"
#. Tag: para
#: Jboss_integration.xml:21
@@ -93,6 +102,8 @@
"JNDI using JrmpProxyFactory, just like any other MBean. Below is an example "
"of how to do this:"
msgstr ""
+"Si se ejecuta JBoss Cache dentro de JBoss AS (como un MBean) podemos enlazarlo a "
+"JNDI utilizando JrmpProxyFactory, como cualquier otro MBean. "
#. Tag: programlisting
#: Jboss_integration.xml:22
@@ -160,4 +171,6 @@
"under which the MBean will be bound, and <literal>ExportedInterface</"
"literal> is the interface name of the MBean."
msgstr ""
+"El atributo <literal>InvokerName</literal> necesita apuntar a un MBean invocador de JBoss válido. <literal>TargetName</literal> es el nombre JMX del MBean que necesita enlazarse a JNDI. <literal>JndiName</literal> es el nombre bajo el cual el MBean se vinculará y <literal>ExportedInterface</"
+"literal> es el nombre de la interfaz del MBean."
16 years, 2 months
JBoss Cache SVN: r7031 - core/trunk/src/test/java/org/jboss/cache/passivation.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-29 21:39:47 -0400 (Wed, 29 Oct 2008)
New Revision: 7031
Modified:
core/trunk/src/test/java/org/jboss/cache/passivation/ReplAndStateTransferWithPassivationTest.java
Log:
better tests
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/ReplAndStateTransferWithPassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/ReplAndStateTransferWithPassivationTest.java 2008-10-29 19:35:43 UTC (rev 7030)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/ReplAndStateTransferWithPassivationTest.java 2008-10-30 01:39:47 UTC (rev 7031)
@@ -74,6 +74,17 @@
doTest(NodeLockingScheme.PESSIMISTIC, true);
}
+ public void testStateTransferOfPassivatedPartialStateBRForceRemote() throws Exception
+ {
+ doTest(NodeLockingScheme.MVCC, false);
+ }
+
+ public void testStateTransferOfPassivatedPartialStateBRPessimisticForceRemote() throws Exception
+ {
+ doTest(NodeLockingScheme.PESSIMISTIC, false);
+ }
+
+
private void doPartialStateTransferTest(NodeLockingScheme nls) throws Exception
{
CacheSPI cache1=null, cache2=null;
@@ -85,8 +96,8 @@
nameSet.add("b");
nameSet.add("c");
- cache1 = (CacheSPI) new UnitTestCacheFactory().createCache(buildConf(nls, "cache1", true, false));
- cache2 = (CacheSPI) new UnitTestCacheFactory().createCache(buildConf(nls, "cache2", true, false));
+ cache1 = (CacheSPI) new UnitTestCacheFactory().createCache(buildConf(nls, "cache1", true, false, true));
+ cache2 = (CacheSPI) new UnitTestCacheFactory().createCache(buildConf(nls, "cache2", true, false, true));
Region r1 = cache1.getRegionManager().getRegion(subtree, true);
Region r2 = cache2.getRegionManager().getRegion(subtree, true);
@@ -126,7 +137,7 @@
nameSet.add(B.getLastElement());
nameSet.add(C.getLastElement());
- cache1 = new UnitTestCacheFactory().createCache(buildConf(nls, "cache1", false, useBR));
+ cache1 = new UnitTestCacheFactory().createCache(buildConf(nls, "cache1", false, useBR, true));
cache1.put(A, "k", "v");
cache1.put(B, "k", "v");
@@ -135,7 +146,7 @@
cache1.evict(A);
- cache2 = new UnitTestCacheFactory().createCache(buildConf(nls, "cache2", false, useBR));
+ cache2 = new UnitTestCacheFactory().createCache(buildConf(nls, "cache2", false, useBR, true));
if (useBR)
{
Set backupNameSet = new HashSet(nameSet);
@@ -155,7 +166,7 @@
}
}
- private Configuration buildConf(NodeLockingScheme nls, String n, boolean regionbased, boolean useBR) throws Exception
+ private Configuration buildConf(NodeLockingScheme nls, String n, boolean regionbased, boolean useBR, boolean brSearchSubtrees) throws Exception
{
Configuration c = new Configuration();
if (regionbased)
@@ -173,7 +184,7 @@
BuddyReplicationConfig brc = new BuddyReplicationConfig();
brc.setEnabled(true);
brc.setAutoDataGravitation(false);
- brc.setDataGravitationSearchBackupTrees(true);
+ brc.setDataGravitationSearchBackupTrees(brSearchSubtrees);
brc.setDataGravitationRemoveOnFind(true);
c.setBuddyReplicationConfig(brc);
}
16 years, 2 months
JBoss Cache SVN: r7030 - in pojo/trunk: src/main/java/org/jboss/cache/pojo/interceptors/dynamic and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-10-29 15:35:43 -0400 (Wed, 29 Oct 2008)
New Revision: 7030
Modified:
pojo/trunk/pom.xml
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/jmx/LegacyConfigurationTest.java
Log:
Fix PCACHE-77
JMX/Parsing updates that get all tests passing
Modified: pojo/trunk/pom.xml
===================================================================
--- pojo/trunk/pom.xml 2008-10-29 19:06:26 UTC (rev 7029)
+++ pojo/trunk/pom.xml 2008-10-29 19:35:43 UTC (rev 7030)
@@ -6,7 +6,7 @@
<properties>
<jbosscache-pojo-version>3.0.0-SNAPSHOT</jbosscache-pojo-version>
<jbosscache-core-version>3.0.0-SNAPSHOT</jbosscache-core-version>
- <jboss.aop.version>2.0.0.CR15</jboss.aop.version>
+ <jboss.aop.version>2.0.0.GA</jboss.aop.version>
</properties>
<parent>
<groupId>org.jboss.cache</groupId>
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java 2008-10-29 19:06:26 UTC (rev 7029)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java 2008-10-29 19:35:43 UTC (rev 7030)
@@ -125,9 +125,9 @@
{
pCache_.attach(fqn_, value, field.getName(), target);
}
+
+ util_.inMemorySubstitution(target, field, value);
}
-
- util_.inMemorySubstitution(target, field, value);
}
else if (invocation instanceof FieldReadInvocation)
{
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java 2008-10-29 19:06:26 UTC (rev 7029)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java 2008-10-29 19:35:43 UTC (rev 7030)
@@ -23,6 +23,7 @@
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Properties;
import java.util.Set;
import javax.management.AttributeChangeNotification;
@@ -41,13 +42,18 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheStatus;
+import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.RuntimeConfig;
+import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
import org.jboss.cache.config.parsing.JGroupsStackParser;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.config.parsing.element.BuddyElementParser;
import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.config.parsing.element.LoadersElementParser;
@@ -62,6 +68,8 @@
import org.jgroups.ChannelFactory;
import org.jgroups.jmx.JChannelFactoryMBean;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
@@ -489,7 +497,7 @@
BuddyReplicationConfig brc = null;
if (config != null)
{
- brc = buddyElementParser.parseBuddyElement(config);
+ brc = XmlConfigurationParser2x.parseBuddyReplicationConfig(config);
}
getConfiguration().setBuddyReplicationConfig(brc);
this.buddyReplConfig = config;
@@ -500,7 +508,7 @@
CacheLoaderConfig clc = null;
if (cache_loader_config != null)
{
- clc = loadersElementParser.parseLoadersElement(cache_loader_config);
+ clc = XmlConfigurationParser2x.parseCacheLoaderConfig(cache_loader_config);
}
getConfiguration().setCacheLoaderConfig(clc);
this.cacheLoaderConfig = cache_loader_config;
@@ -550,7 +558,7 @@
EvictionConfig ec = null;
if (config != null)
{
- ec = evictionElementParser.parseEvictionElement(config);
+ ec = XmlConfigurationParser2x.parseEvictionConfig(config);
}
getConfiguration().setEvictionConfig(ec);
this.evictionConfig = config;
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/jmx/LegacyConfigurationTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/jmx/LegacyConfigurationTest.java 2008-10-29 19:06:26 UTC (rev 7029)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/jmx/LegacyConfigurationTest.java 2008-10-29 19:35:43 UTC (rev 7030)
@@ -46,10 +46,16 @@
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.config.Configuration.NodeLockingScheme;
import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.eviction.FIFOAlgorithm;
+import org.jboss.cache.eviction.FIFOAlgorithmConfig;
import org.jboss.cache.eviction.FIFOConfiguration;
import org.jboss.cache.eviction.FIFOPolicy;
+import org.jboss.cache.eviction.LRUAlgorithm;
+import org.jboss.cache.eviction.LRUAlgorithmConfig;
import org.jboss.cache.eviction.LRUConfiguration;
import org.jboss.cache.eviction.LRUPolicy;
+import org.jboss.cache.eviction.MRUAlgorithm;
+import org.jboss.cache.eviction.MRUAlgorithmConfig;
import org.jboss.cache.eviction.MRUConfiguration;
import org.jboss.cache.eviction.MRUPolicy;
import org.jboss.cache.loader.FileCacheLoader;
@@ -181,37 +187,33 @@
assertEquals("EvictionPolicyConfig", getEvictionPolicyConfig().toString(), wrapper.getEvictionPolicyConfig().toString());
EvictionConfig ec = c.getEvictionConfig();
- //assertEquals("EC queue size", 20000, ec.getDefaultEventQueueSize());
assertEquals("EC wakeup", 5, ec.getWakeupIntervalSeconds());
- assertEquals("EC default pol", LRUPolicy.class.getName(), ec.getDefaultEvictionPolicyClass());
- List<EvictionRegionConfig> ercs = ec.getEvictionRegionConfigs();
+ //assertEquals("EC default pol", LRUPolicy.class.getName(), ec.getDefaultEvictionPolicyClass());
+ assertEquals("EvictionPolicyConfig", getEvictionPolicyConfig().toString(), wrapper.getEvictionPolicyConfig().toString());
+ EvictionConfig ec1 = c.getEvictionConfig();
+ assertEquals("EC queue size", 1000, ec1.getDefaultEvictionRegionConfig().getEventQueueSize());
+ assertEquals("EC wakeup", 5000, ec1.getWakeupInterval());
+ assertEquals("EC default pol", LRUAlgorithm.class.getName(), ec1.getDefaultEvictionRegionConfig().getEvictionAlgorithmConfig().getEvictionAlgorithmClassName());
+ List<EvictionRegionConfig> ercs = ec1.getEvictionRegionConfigs();
EvictionRegionConfig erc = ercs.get(0);
- assertEquals("ERC0 name", "/_default_", erc.getRegionName());
- assertEquals("ERC0 queue size", 1000, erc.getEventQueueSize());
- LRUConfiguration lru = (LRUConfiguration) erc.getEvictionPolicyConfig();
- assertEquals("EPC0 pol", LRUPolicy.class.getName(), lru.getEvictionPolicyClass());
- assertEquals("EPC0 maxnodes", 5000, lru.getMaxNodes());
- assertEquals("EPC0 ttl", 1000, lru.getTimeToLiveSeconds());
- erc = ercs.get(1);
assertEquals("ERC1 name", "/org/jboss/data", erc.getRegionName());
assertEquals("ERC1 queue size", 20000, erc.getEventQueueSize());
- FIFOConfiguration fifo = (FIFOConfiguration) erc.getEvictionPolicyConfig();
- assertEquals("EPC1 pol", FIFOPolicy.class.getName(), fifo.getEvictionPolicyClass());
+ FIFOAlgorithmConfig fifo = (FIFOAlgorithmConfig) erc.getEvictionAlgorithmConfig();
+ assertEquals("EPC1 pol", FIFOAlgorithm.class.getName(), fifo.getEvictionAlgorithmClassName());
assertEquals("EPC1 maxnodes", 5000, fifo.getMaxNodes());
- erc = ercs.get(2);
+ erc = ercs.get(1);
assertEquals("ERC2 name", "/test", erc.getRegionName());
assertEquals("ERC2 queue size", 20000, erc.getEventQueueSize());
- MRUConfiguration mru = (MRUConfiguration) erc.getEvictionPolicyConfig();
- assertEquals("EPC2 pol", MRUPolicy.class.getName(), mru.getEvictionPolicyClass());
+ MRUAlgorithmConfig mru = (MRUAlgorithmConfig) erc.getEvictionAlgorithmConfig();
+ assertEquals("EPC2 pol", MRUAlgorithm.class.getName(), mru.getEvictionAlgorithmClassName());
assertEquals("EPC2 maxnodes", 10000, mru.getMaxNodes());
- erc = ercs.get(3);
+ erc = ercs.get(2);
assertEquals("ERC3 name", "/maxAgeTest", erc.getRegionName());
assertEquals("ERC3 queue size", 20000, erc.getEventQueueSize());
- lru = (LRUConfiguration) erc.getEvictionPolicyConfig();
- assertEquals("EPC3 pol", LRUPolicy.class.getName(), lru.getEvictionPolicyClass());
+ LRUAlgorithmConfig lru = (LRUAlgorithmConfig) erc.getEvictionAlgorithmConfig();
assertEquals("EPC3 maxnodes", 10000, lru.getMaxNodes());
- assertEquals("EPC3 maxage", 10, lru.getMaxAgeSeconds());
- assertEquals("EPC3 ttl", 8, lru.getTimeToLiveSeconds());
+ assertEquals("EPC3 maxage", 10000, lru.getMaxAge());
+ assertEquals("EPC3 ttl", 8000, lru.getTimeToLive());
}
@@ -239,120 +241,134 @@
protected static Element getBuddyReplicationConfig() throws Exception
{
- String xmlStr =
- " <buddy enabled=\"true\" poolName=\"testpool\" communicationTimeout=\"600000\">\n" +
- " <dataGravitation auto=\"false\" removeOnFind=\"false\" searchBackupTrees=\"false\"/>\n" +
- " <locator class=\"org.jboss.cache.buddyreplication.TestBuddyLocator\">\n" +
- " <properties>\n" +
- " numBuddies = 2\n" +
- " </properties>\n" +
- " </locator>\n" +
- " </buddy>";
- return XmlConfigHelper.stringToElementInCoreNS(xmlStr);
+ String xmlString = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled>\n" +
+ " <buddyCommunicationTimeout>600000</buddyCommunicationTimeout>\n" +
+ " <buddyLocatorClass>org.jboss.cache.buddyreplication.TestBuddyLocator</buddyLocatorClass>\n" +
+ " <buddyLocatorProperties>numBuddies = 2</buddyLocatorProperties>\n" +
+ " <buddyPoolName>testpool</buddyPoolName>" +
+ " <autoDataGravitation>false</autoDataGravitation>\n" +
+ " <dataGravitationRemoveOnFind>false</dataGravitationRemoveOnFind>\n" +
+ " <dataGravitationSearchBackupTrees>false</dataGravitationSearchBackupTrees>" +
+ "</config>";
+ return XmlConfigHelper.stringToElement(xmlString);
}
protected static Element getCacheLoaderConfig() throws Exception
{
- String xmlStr =
- " <loaders passivation=\"false\" shared=\"true\">\n" +
- " <preload>\n" +
- " <node fqn=\"/foo\"/>\n" +
- " </preload>\n" +
- " <loader class=\"org.jboss.cache.loader.FileCacheLoader\" async=\"false\" fetchPersistentState=\"true\"\n" +
- " ignoreModifications=\"true\" purgeOnStartup=\"true\">\n" +
- " <properties>\n" +
- " location=/tmp\n " +
- " </properties>\n" +
- " <singletonStore enabled=\"true\" /> \n" +
- " </loader>\n" +
- " <loader class=\"org.jboss.cache.loader.jdbm.JdbmCacheLoader\" async=\"true\" fetchPersistentState=\"false\"\n" +
- " ignoreModifications=\"false\" purgeOnStartup=\"false\">\n" +
- " <properties>\n" +
- " location=/home/bstansberry\n" +
- " </properties>\n" +
- " <singletonStore enabled=\"false\" /> \n" +
- " </loader>\n" +
- " </loaders>";
- return XmlConfigHelper.stringToElementInCoreNS(xmlStr);
+ String xml = "<config>\n" +
+ "<passivation>false</passivation>\n" +
+ "<preload>/foo</preload>\n" +
+ "<shared>true</shared>\n" +
+ "<cacheloader>\n" +
+ "<class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
+ "<properties>" +
+ " location=/tmp\n" +
+ "</properties>\n" +
+ "<async>false</async>\n" +
+ "<fetchPersistentState>true</fetchPersistentState>\n" +
+ "<ignoreModifications>true</ignoreModifications>\n" +
+ "<purgeOnStartup>true</purgeOnStartup>\n" +
+ "<singletonStore>" +
+ "<enabled>true</enabled>" +
+ "</singletonStore>" +
+ "</cacheloader>\n" +
+ "<cacheloader>\n" +
+ "<class>org.jboss.cache.loader.jdbm.JdbmCacheLoader</class>\n" +
+ "<properties>" +
+ " location=/home/bstansberry\n" +
+ "</properties>\n" +
+ "<async>true</async>\n" +
+ "<fetchPersistentState>false</fetchPersistentState>\n" +
+ "<ignoreModifications>false</ignoreModifications>\n" +
+ "<purgeOnStartup>false</purgeOnStartup>\n" +
+ "<singletonStore>" +
+ "<enabled>false</enabled>" +
+ "</singletonStore>" +
+ "</cacheloader>\n" +
+ "</config>";
+ return XmlConfigHelper.stringToElement(xml);
}
protected static Element getEvictionPolicyConfig() throws Exception
{
- String xmlStr =
- " <eviction wakeUpInterval=\"5000\" defaultPolicyClass=\"org.jboss.cache.eviction.LRUPolicy\" defaultEventQueueSize=\"20000\">\n" +
- " <default eventQueueSize=\"1000\">\n" +
- " <attribute name=\"maxNodes\">5000</attribute>\n" +
- " <attribute name=\"timeToLive\">1000000</attribute>\n" +
- " </default>\n" +
- "<region name=\"/org/jboss/data\" policyClass=\"org.jboss.cache.eviction.FIFOPolicy\">\n" +
- " <attribute name=\"maxNodes\">5000</attribute>\n" +
- "</region>\n" +
- "<region name=\"/test/\" policyClass=\"org.jboss.cache.eviction.MRUPolicy\">\n" +
- " <attribute name=\"maxNodes\">10000</attribute>\n" +
- "</region>\n" +
- "<region name=\"/maxAgeTest/\">\n" +
- " <attribute name=\"maxNodes\">10000</attribute>\n" +
- " <attribute name=\"timeToLiveSeconds\">8</attribute>\n" +
- " <attribute name=\"maxAgeSeconds\">10</attribute>\n" +
- "</region>\n" +
- " </eviction>";
- return XmlConfigHelper.stringToElementInCoreNS(xmlStr);
+ String xml = "<config>\n" +
+ "<attribute name=\"wakeUpIntervalSeconds\">5</attribute>\n" +
+ "<attribute name=\"eventQueueSize\">20000</attribute>\n" +
+ "<attribute name=\"policyClass\">org.jboss.cache.eviction.LRUPolicy</attribute>\n" +
+ "<region name=\"/_default_\" eventQueueSize=\"1000\">\n" +
+ " <attribute name=\"maxNodes\">5000</attribute>\n" +
+ " <attribute name=\"timeToLiveSeconds\">1000</attribute>\n" +
+ "</region>\n" +
+ "<region name=\"/org/jboss/data\" policyClass=\"org.jboss.cache.eviction.FIFOPolicy\">\n" +
+ " <attribute name=\"maxNodes\">5000</attribute>\n" +
+ "</region>\n" +
+ "<region name=\"/test/\" policyClass=\"org.jboss.cache.eviction.MRUPolicy\">\n" +
+ " <attribute name=\"maxNodes\">10000</attribute>\n" +
+ "</region>\n" +
+ "<region name=\"/maxAgeTest/\">\n" +
+ " <attribute name=\"maxNodes\">10000</attribute>\n" +
+ " <attribute name=\"timeToLiveSeconds\">8</attribute>\n" +
+ " <attribute name=\"maxAgeSeconds\">10</attribute>\n" +
+ "</region>\n" +
+ " </config>\n";
+ return XmlConfigHelper.stringToElement(xml);
}
protected static Element getClusterConfig() throws Exception
- {String xml =
- "<jgroupsConfig>\n" +
- "<UDP mcast_addr=\"228.10.10.10\"\n" +
- " mcast_port=\"45588\"\n" +
- " tos=\"8\"\n" +
- " ucast_recv_buf_size=\"20000000\"\n" +
- " ucast_send_buf_size=\"640000\"\n" +
- " mcast_recv_buf_size=\"25000000\"\n" +
- " mcast_send_buf_size=\"640000\"\n" +
- " loopback=\"false\"\n" +
- " discard_incompatible_packets=\"true\"\n" +
- " max_bundle_size=\"64000\"\n" +
- " max_bundle_timeout=\"30\"\n" +
- " use_incoming_packet_handler=\"true\"\n" +
- " ip_ttl=\"2\"\n" +
- " enable_bundling=\"false\"\n" +
- " enable_diagnostics=\"true\"\n" +
- " use_concurrent_stack=\"true\"\n" +
- " thread_naming_pattern=\"pl\"\n" +
- " thread_pool.enabled=\"true\"\n" +
- " thread_pool.min_threads=\"1\"\n" +
- " thread_pool.max_threads=\"25\"\n" +
- " thread_pool.keep_alive_time=\"30000\"\n" +
- " thread_pool.queue_enabled=\"true\"\n" +
- " thread_pool.queue_max_size=\"10\"\n" +
- " thread_pool.rejection_policy=\"Run\"\n" +
- " oob_thread_pool.enabled=\"true\"\n" +
- " oob_thread_pool.min_threads=\"1\"\n" +
- " oob_thread_pool.max_threads=\"4\"\n" +
- " oob_thread_pool.keep_alive_time=\"10000\"\n" +
- " oob_thread_pool.queue_enabled=\"true\"\n" +
- " oob_thread_pool.queue_max_size=\"10\"\n" +
- " oob_thread_pool.rejection_policy=\"Run\"/>\n" +
- " <PING timeout=\"2000\" num_initial_members=\"3\"/>\n" +
- " <MERGE2 max_interval=\"30000\" min_interval=\"10000\"/>\n" +
- " <FD_SOCK/>\n" +
- " <FD timeout=\"10000\" max_tries=\"5\" shun=\"true\"/>\n" +
- " <VERIFY_SUSPECT timeout=\"1500\"/>\n" +
- " <pbcast.NAKACK max_xmit_size=\"60000\"\n" +
- " use_mcast_xmit=\"false\" gc_lag=\"0\"\n" +
- " retransmit_timeout=\"300,600,1200,2400,4800\"\n" +
- " discard_delivered_msgs=\"true\"/>\n" +
- " <UNICAST timeout=\"300,600,1200,2400,3600\"/>\n" +
- " <pbcast.STABLE stability_delay=\"1000\" desired_avg_gossip=\"50000\"\n" +
- " max_bytes=\"400000\"/>\n" +
- " <pbcast.GMS print_local_addr=\"true\" join_timeout=\"5000\"\n" +
- " join_retry_timeout=\"2000\" shun=\"false\"\n" +
- " view_bundling=\"true\" view_ack_collection_timeout=\"5000\"/>\n" +
- " <FRAG2 frag_size=\"60000\"/>\n" +
- " <pbcast.STREAMING_STATE_TRANSFER use_reading_thread=\"true\"/>\n" +
- " <pbcast.FLUSH timeout=\"0\"/>\n" +
- "</jgroupsConfig>";
-return XmlConfigHelper.stringToElementInCoreNS(xml);
+ {
+ String xml =
+ "<config>\n" +
+ " <UDP mcast_addr=\"228.10.10.10\"\n" +
+ " mcast_port=\"45588\"\n" +
+ " tos=\"8\"\n" +
+ " ucast_recv_buf_size=\"20000000\"\n" +
+ " ucast_send_buf_size=\"640000\"\n" +
+ " mcast_recv_buf_size=\"25000000\"\n" +
+ " mcast_send_buf_size=\"640000\"\n" +
+ " loopback=\"false\"\n" +
+ " discard_incompatible_packets=\"true\"\n" +
+ " max_bundle_size=\"64000\"\n" +
+ " max_bundle_timeout=\"30\"\n" +
+ " use_incoming_packet_handler=\"true\"\n" +
+ " ip_ttl=\"2\"\n" +
+ " enable_bundling=\"false\"\n" +
+ " enable_diagnostics=\"true\"\n" +
+ " use_concurrent_stack=\"true\"\n" +
+ " thread_naming_pattern=\"pl\"\n" +
+ " thread_pool.enabled=\"true\"\n" +
+ " thread_pool.min_threads=\"1\"\n" +
+ " thread_pool.max_threads=\"25\"\n" +
+ " thread_pool.keep_alive_time=\"30000\"\n" +
+ " thread_pool.queue_enabled=\"true\"\n" +
+ " thread_pool.queue_max_size=\"10\"\n" +
+ " thread_pool.rejection_policy=\"Run\"\n" +
+ " oob_thread_pool.enabled=\"true\"\n" +
+ " oob_thread_pool.min_threads=\"1\"\n" +
+ " oob_thread_pool.max_threads=\"4\"\n" +
+ " oob_thread_pool.keep_alive_time=\"10000\"\n" +
+ " oob_thread_pool.queue_enabled=\"true\"\n" +
+ " oob_thread_pool.queue_max_size=\"10\"\n" +
+ " oob_thread_pool.rejection_policy=\"Run\"/>\n" +
+ " <PING timeout=\"2000\" num_initial_members=\"3\"/>\n" +
+ " <MERGE2 max_interval=\"30000\" min_interval=\"10000\"/>\n" +
+ " <FD_SOCK/>\n" +
+ " <FD timeout=\"10000\" max_tries=\"5\" shun=\"true\"/>\n" +
+ " <VERIFY_SUSPECT timeout=\"1500\"/>\n" +
+ " <pbcast.NAKACK max_xmit_size=\"60000\"\n" +
+ " use_mcast_xmit=\"false\" gc_lag=\"0\"\n" +
+ " retransmit_timeout=\"300,600,1200,2400,4800\"\n" +
+ " discard_delivered_msgs=\"true\"/>\n" +
+ " <UNICAST timeout=\"300,600,1200,2400,3600\"/>\n" +
+ " <pbcast.STABLE stability_delay=\"1000\" desired_avg_gossip=\"50000\"\n" +
+ " max_bytes=\"400000\"/>\n" +
+ " <pbcast.GMS print_local_addr=\"true\" join_timeout=\"5000\"\n" +
+ " join_retry_timeout=\"2000\" shun=\"false\"\n" +
+ " view_bundling=\"true\" view_ack_collection_timeout=\"5000\"/>\n" +
+ " <FRAG2 frag_size=\"60000\"/>\n" +
+ " <pbcast.STREAMING_STATE_TRANSFER use_reading_thread=\"true\"/>\n" +
+ " <pbcast.FLUSH timeout=\"0\"/>\n" +
+ "</config>";
+ return XmlConfigHelper.stringToElement(xml);
}
class MockInvocationHandler implements InvocationHandler
16 years, 2 months
JBoss Cache SVN: r7029 - in core/branches/flat/src: main/java/org/jboss/cache and 28 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-10-29 15:06:26 -0400 (Wed, 29 Oct 2008)
New Revision: 7029
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/EvictionManager.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionCacheConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/DefaultEvictionAction.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAction.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionCacheManager.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionCacheManagerImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionManagerImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/KeyEntry.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/BaseEvictionAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/BaseSortedEvictionAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/ElementSizeAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/ExpirationAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/NULL/
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/NULL/NullEvictionAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/NULL/NullEvictionAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/NULL/NullEvictionQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/SortedEvictionQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/fifo/
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/fifo/FIFOAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/fifo/FIFOAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/fifo/FIFOQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lfu/
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lfu/LFUAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lfu/LFUAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lfu/LFUQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lru/
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lru/LRUAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lru/LRUAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lru/LRUQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/EvictionListEntry.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/EvictionQueueList.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/MRUAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/MRUAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/MRUQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/EvictionManagerFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/EvictionInterceptor.java
Removed:
core/branches/flat/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionRegionConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseEvictionAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseSortedEvictionAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/DefaultEvictionActionPolicy.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionActionPolicy.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionListEntry.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueueList.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NodeEntry.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/SortedEvictionQueue.java
Modified:
core/branches/flat/src/main/docbook/userguide/en/modules/deployment.xml
core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java
core/branches/flat/src/main/java/org/jboss/cache/RPCManagerImpl.java
core/branches/flat/src/main/java/org/jboss/cache/Region.java
core/branches/flat/src/main/java/org/jboss/cache/RegionImpl.java
core/branches/flat/src/main/java/org/jboss/cache/RegionManagerImpl.java
core/branches/flat/src/main/java/org/jboss/cache/buddyreplication/Fqn2BuddyFqnVisitor.java
core/branches/flat/src/main/java/org/jboss/cache/commands/AbstractVisitor.java
core/branches/flat/src/main/java/org/jboss/cache/commands/Visitor.java
core/branches/flat/src/main/java/org/jboss/cache/commands/write/EvictCommand.java
core/branches/flat/src/main/java/org/jboss/cache/interceptors/BuddyRegionAwareEvictionInterceptor.java
core/branches/flat/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java
core/branches/flat/src/main/java/org/jboss/cache/interceptors/base/PrePostProcessingCommandInterceptor.java
core/branches/flat/src/main/java/org/jboss/cache/interceptors/base/SkipCheckChainedInterceptor.java
core/branches/flat/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
core/branches/flat/src/main/java/org/jboss/cache/remoting/jgroups/ChannelMessageListener.java
core/branches/flat/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java
core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
core/branches/flat/src/main/java/org/jboss/starobrno/CacheSPI.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/CommandsFactoryImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/EvictCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/element/EvictionElementParser.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionEvent.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionTimerTask.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/RemoveOnEvictActionPolicy.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/InterceptorChainFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/NonVolatile.java
core/branches/flat/src/main/java/org/jboss/starobrno/remoting/ChannelMessageListener.java
core/branches/flat/src/main/java/org/jboss/starobrno/remoting/RPCManagerImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/statetransfer/DefaultStateTransferManager.java
core/branches/flat/src/main/resources/config-samples/cacheloader-enabled.xml
core/branches/flat/src/main/resources/config-samples/eviction-enabled.xml
core/branches/flat/src/test/resources/configs/clonable-config.xml
core/branches/flat/src/test/resources/configs/local-lru-eviction.xml
core/branches/flat/src/test/resources/configs/local-passivation.xml
core/branches/flat/src/test/resources/configs/local-tx.xml
core/branches/flat/src/test/resources/configs/mixedPolicy-eviction.xml
core/branches/flat/src/test/resources/configs/parser-test-async.xml
core/branches/flat/src/test/resources/configs/parser-test.xml
core/branches/flat/src/test/resources/configs/policyPerRegion-eviction.xml
core/branches/flat/src/test/resources/configs/string-property-replaced.xml
core/branches/flat/src/test/resources/jbc2-registry-configs.xml
core/branches/flat/src/test/resources/jbc3-registry-configs.xml
core/branches/flat/src/test/resources/unit-test-cache-service.xml
Log:
ongoing eviction work
Modified: core/branches/flat/src/main/docbook/userguide/en/modules/deployment.xml
===================================================================
--- core/branches/flat/src/main/docbook/userguide/en/modules/deployment.xml 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/docbook/userguide/en/modules/deployment.xml 2008-10-29 19:06:26 UTC (rev 7029)
@@ -259,7 +259,7 @@
org.jboss.cache.eviction.LRUPolicy
</property>
<property name="wakeupIntervalSeconds">5</property>
- <property name="evictionRegionConfigs">
+ <property name="evictionCacheConfigs">
<list>
<bean name="ExampleDefaultEvictionRegionConfig"
class="org.jboss.cache.config.EvictionRegionConfig">
Modified: core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -24,6 +24,8 @@
import org.jboss.cache.annotations.Compat;
import org.jboss.cache.jmx.PlatformMBeanServerRegistration;
import org.jboss.starobrno.CacheDelegate;
+import org.jboss.starobrno.CacheSPI;
+import org.jboss.starobrno.Cache;
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.ConfigurationException;
import org.jboss.starobrno.config.parsing.XmlConfigurationParser;
@@ -107,7 +109,7 @@
{
try
{
- org.jboss.starobrno.CacheSPI<K, V> cache = createAndWire(configuration);
+ CacheSPI<K, V> cache = createAndWire(configuration);
if (start) cache.start();
return cache;
}
@@ -127,7 +129,7 @@
protected org.jboss.starobrno.CacheSPI<K, V> createAndWire(Configuration configuration) throws Exception
{
- org.jboss.starobrno.CacheSPI<K, V> spi = new CacheDelegate<K, V>();
+ CacheSPI<K, V> spi = new CacheDelegate<K, V>();
bootstrap(spi, configuration);
return spi;
}
@@ -135,14 +137,14 @@
/**
* Bootstraps this factory with a Configuration and a ComponentRegistry.
*/
- private void bootstrap(org.jboss.starobrno.CacheSPI spi, Configuration configuration)
+ private void bootstrap( CacheSPI spi, Configuration configuration)
{
// injection bootstrap stuff
componentRegistry = new ComponentRegistry(configuration, spi);
componentRegistry.registerDefaultClassLoader(defaultClassLoader);
this.configuration = configuration;
- componentRegistry.registerComponent(spi, org.jboss.starobrno.CacheSPI.class);
+ componentRegistry.registerComponent(spi, CacheSPI.class);
componentRegistry.registerComponent(new PlatformMBeanServerRegistration(), PlatformMBeanServerRegistration.class);
}
@@ -156,7 +158,7 @@
this.defaultClassLoader = loader;
}
- public org.jboss.starobrno.Cache<K, V> createCache(InputStream is) throws ConfigurationException
+ public Cache<K, V> createCache(InputStream is) throws ConfigurationException
{
XmlConfigurationParser parser = new XmlConfigurationParser();
Configuration c = null;
@@ -164,7 +166,7 @@
return createCache(c);
}
- public org.jboss.starobrno.Cache<K, V> createCache(InputStream is, boolean start) throws ConfigurationException
+ public Cache<K, V> createCache(InputStream is, boolean start) throws ConfigurationException
{
XmlConfigurationParser parser = new XmlConfigurationParser();
Configuration c = parser.parseStream(is);
Modified: core/branches/flat/src/main/java/org/jboss/cache/RPCManagerImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -370,7 +370,7 @@
{
boolean localTx = deadOwner.getAddress().equals(getLocalAddress());
// TODO: Fix me!!!
-// boolean broken = LockUtil.breakTransactionLock(node.getFqn(), lockManager, deadOwner, localTx, txTable, txManager);
+// boolean broken = LockUtil.breakTransactionLock(node.getKey(), lockManager, deadOwner, localTx, txTable, txManager);
boolean broken = true;
if (broken && trace) log.trace("Broke lock for node " + node.getFqn() + " held by " + deadOwner);
@@ -399,7 +399,7 @@
for (GlobalTransaction deadOwner : deadOwners)
{
boolean localTx = deadOwner.getAddress().equals(getLocalAddress());
-// boolean broken = LockUtil.breakTransactionLock(node.getFqn(), lockManager, deadOwner, localTx, txTable, txManager);
+// boolean broken = LockUtil.breakTransactionLock(node.getKey(), lockManager, deadOwner, localTx, txTable, txManager);
boolean broken = true; // TODO fix me!!
if (broken && trace) log.trace("Broke lock for node " + node.getFqn() + " held by " + deadOwner);
Modified: core/branches/flat/src/main/java/org/jboss/cache/Region.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/Region.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/Region.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -23,7 +23,7 @@
import org.jboss.cache.annotations.Compat;
import org.jboss.starobrno.config.Configuration;
-import org.jboss.starobrno.config.EvictionRegionConfig;
+import org.jboss.starobrno.config.EvictionCacheConfig;
import org.jboss.starobrno.eviction.EvictionEvent;
/**
@@ -141,14 +141,14 @@
/**
* Configures this region for eviction.
*
- * @param evictionRegionConfig configuration to set
+ * @param evictionCacheConfig configuration to set
*/
- void setEvictionRegionConfig(EvictionRegionConfig evictionRegionConfig);
+ void setEvictionRegionConfig(EvictionCacheConfig evictionCacheConfig);
/**
* @return the eviction region config, if any, set on the current region.
*/
- EvictionRegionConfig getEvictionRegionConfig();
+ EvictionCacheConfig getEvictionRegionConfig();
/**
* Registers an eviction event on the region's eviction event queue for later processing by
@@ -174,7 +174,7 @@
/**
* Marks a {@link org.jboss.cache.Node} as currently in use, by adding an event to the eviction queue.
* If there is an {@link org.jboss.cache.config.EvictionRegionConfig} associated with this region, and
- * it respects this event (e.g., {@link org.jboss.starobrno.eviction.LRUAlgorithm} does), then the {@link org.jboss.cache.Node} will not
+ * it respects this event (e.g., {@link org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm} does), then the {@link org.jboss.cache.Node} will not
* be evicted until {@link #unmarkNodeCurrentlyInUse(Fqn)} is invoked.
* <p/>
* This mechanism can be used to prevent eviction of data that the application
Modified: core/branches/flat/src/main/java/org/jboss/cache/RegionImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/RegionImpl.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/RegionImpl.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -26,9 +26,10 @@
import org.jboss.starobrno.util.Util;
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.EvictionAlgorithmConfig;
-import org.jboss.starobrno.config.EvictionRegionConfig;
-import org.jboss.starobrno.eviction.EvictionActionPolicy;
+import org.jboss.starobrno.config.EvictionCacheConfig;
+import org.jboss.starobrno.eviction.EvictionAction;
import org.jboss.starobrno.eviction.EvictionEvent;
+import org.jboss.starobrno.eviction.EvictionAlgorithm;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
@@ -48,8 +49,8 @@
private ClassLoader classLoader;
private BlockingQueue<EvictionEvent> evictionEventQueue = null;
private int capacityWarnThreshold = 0;
- private EvictionRegionConfig evictionRegionConfig;
- private org.jboss.starobrno.eviction.EvictionAlgorithm evictionAlgorithm;
+ private EvictionCacheConfig evictionCacheConfig;
+ private EvictionAlgorithm evictionAlgorithm;
/**
@@ -65,10 +66,10 @@
/**
* Constructs an eviction region from a policy and configuration, defined by an fqn and region manager.
*/
- public RegionImpl(EvictionRegionConfig config, Fqn fqn, RegionManager regionManager)
+ public RegionImpl(EvictionCacheConfig config, Fqn fqn, RegionManager regionManager)
{
this(fqn, regionManager);
- this.evictionRegionConfig = config;
+ this.evictionCacheConfig = config;
createQueue();
}
@@ -168,7 +169,7 @@
"; classloader=" + classLoader +
"; status=" + status +
"; eviction=" + (evictionAlgorithm != null) +
- "; timerThreadRegistered=" + (evictionAlgorithm != null && regionManager.getEvictionTimerTask().isRegionRegisteredForProcessing(this)) +
+ "; timerThreadRegistered=" + (evictionAlgorithm != null /*&& regionManager.getEvictionTimerTask().isRegionRegisteredForProcessing(this)*/) +
'}';
}
@@ -201,18 +202,18 @@
evictionEventQueue.clear();
}
- public void setEvictionRegionConfig(EvictionRegionConfig evictionRegionConfig)
+ public void setEvictionRegionConfig(EvictionCacheConfig evictionCacheConfig)
{
- this.evictionRegionConfig = evictionRegionConfig;
- evictionAlgorithm = createEvictionAlgorithm(evictionRegionConfig.getEvictionAlgorithmConfig(), evictionRegionConfig.getEvictionActionPolicyClassName());
- regionManager.getEvictionTimerTask().addRegionToProcess(this);
+ this.evictionCacheConfig = evictionCacheConfig;
+ evictionAlgorithm = createEvictionAlgorithm(evictionCacheConfig.getEvictionAlgorithmConfig(), evictionCacheConfig.getEvictionActionClassName());
+// regionManager.getEvictionTimerTask().addRegionToProcess(this);
if (evictionEventQueue == null) createQueue();
evictionAlgorithm.initialize();
}
- public EvictionRegionConfig getEvictionRegionConfig()
+ public EvictionCacheConfig getEvictionRegionConfig()
{
- return evictionRegionConfig;
+ return evictionCacheConfig;
}
public EvictionEvent registerEvictionEvent(Fqn fqn, EvictionEvent.Type eventType)
@@ -237,7 +238,7 @@
if (evictionEventQueue.size() > capacityWarnThreshold)
{
if (log.isWarnEnabled())
- log.warn("putNodeEvent(): eviction node event queue size is at 98% threshold value of capacity: " + evictionRegionConfig.getEventQueueSize() +
+ log.warn("putNodeEvent(): eviction node event queue size is at 98% threshold value of capacity: " + evictionCacheConfig.getEventQueueSize() +
" Region: " + fqn +
" You will need to reduce the wakeUpIntervalSeconds parameter.");
}
@@ -255,11 +256,11 @@
{
if (evictionEventQueue == null)
{
- if (evictionRegionConfig == null)
+ if (evictionCacheConfig == null)
{
throw new IllegalArgumentException("null eviction configuration");
}
- int size = evictionRegionConfig.getEventQueueSize();
+ int size = evictionCacheConfig.getEventQueueSize();
capacityWarnThreshold = (98 * size) / 100 - 100;
if (capacityWarnThreshold <= 0)
{
@@ -280,13 +281,13 @@
try
{
if (trace) log.trace("Instantiating " + evictionActionPolicyClass);
- EvictionActionPolicy actionPolicy = (EvictionActionPolicy) Util.getInstance(evictionActionPolicyClass);
- actionPolicy.setCache(regionManager.getCache());
+ EvictionAction evictionAction = (EvictionAction) Util.getInstance(evictionActionPolicyClass);
+// evictionAction.setCache(regionManager.getCache());
if (trace) log.trace("Instantiating " + algoConfig.getEvictionAlgorithmClassName());
org.jboss.starobrno.eviction.EvictionAlgorithm algorithm = (org.jboss.starobrno.eviction.EvictionAlgorithm) Util.getInstance(algoConfig.getEvictionAlgorithmClassName());
- algorithm.setEvictionActionPolicy(actionPolicy);
- algorithm.assignToRegion(fqn, regionManager.getCache(), algoConfig, regionManager.getConfiguration());
+ algorithm.setEvictionAction(evictionAction);
+// algorithm.assignToCache(fqn, regionManager.getCache(), algoConfig, regionManager.getConfiguration());
return algorithm;
}
catch (Exception e)
@@ -299,13 +300,13 @@
public Region copy(Fqn newRoot)
{
RegionImpl clone;
- clone = new RegionImpl(evictionRegionConfig, Fqn.fromRelativeFqn(newRoot, fqn), regionManager);
+ clone = new RegionImpl(evictionCacheConfig, Fqn.fromRelativeFqn(newRoot, fqn), regionManager);
clone.status = status;
// we also need to copy all of the eviction event nodes to the clone's queue
clone.createQueue();
for (EvictionEvent een : this.evictionEventQueue)
{
- clone.registerEvictionEvent(een.getFqn(), een.getEventType(), een.getElementDifference());
+// clone.registerEvictionEvent(een.getKey(), een.getEventType(), een.getElementDifference());
}
return clone;
}
Modified: core/branches/flat/src/main/java/org/jboss/cache/RegionManagerImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -32,9 +32,8 @@
import org.jboss.starobrno.util.concurrent.locks.ReentrantLockContainer;
import org.jboss.starobrno.CacheException;
import org.jboss.starobrno.config.Configuration;
-import org.jboss.starobrno.config.ConfigurationException;
import org.jboss.starobrno.config.EvictionConfig;
-import org.jboss.starobrno.config.EvictionRegionConfig;
+import org.jboss.starobrno.config.EvictionCacheConfig;
import org.jboss.starobrno.factories.annotations.Destroy;
import org.jboss.starobrno.factories.annotations.Inject;
import org.jboss.starobrno.factories.annotations.Start;
@@ -69,7 +68,7 @@
CacheSPI_Legacy<?, ?> cache;
private boolean usingEvictions;
private EvictionConfig evictionConfig;
- private final org.jboss.starobrno.eviction.EvictionTimerTask evictionTimerTask = new org.jboss.starobrno.eviction.EvictionTimerTask();
+ private final org.jboss.starobrno.eviction.EvictionTimerTask evictionTimerTask = null;//new org.jboss.starobrno.eviction.EvictionTimerTask();
private final LockContainer<Fqn> regionLocks = new ReentrantLockContainer<Fqn>(4);
protected Configuration configuration;
@@ -117,11 +116,11 @@
{
this.evictionConfig = configuration.getEvictionConfig();
// start with the default region
- EvictionRegionConfig defaultRegion = configuration.getEvictionConfig().getDefaultEvictionRegionConfig();
- if (defaultRegion.getEvictionAlgorithmConfig() != null) defaultRegion.getEvictionAlgorithmConfig().validate();
+ EvictionCacheConfig defaultCache = configuration.getEvictionConfig().getDefaultEvictionRegionConfig();
+ if (defaultCache.getEvictionAlgorithmConfig() != null) defaultCache.getEvictionAlgorithmConfig().validate();
// validate individual region configs now
- for (EvictionRegionConfig erc : configuration.getEvictionConfig().getEvictionRegionConfigs())
+ for (EvictionCacheConfig erc : configuration.getEvictionConfig().getEvictionCacheConfigs())
{
evictionConfig.applyDefaults(erc);
erc.validate();
@@ -290,7 +289,7 @@
if (isUsingEvictions() && r.getEvictionRegionConfig() != null)
{
- evictionTimerTask.removeRegionToProcess(r);
+// evictionTimerTask.removeRegionToProcess(r);
}
return true;
}
@@ -568,7 +567,7 @@
case ANY:
return true;
case EVICTION:
- return r.getEvictionRegionConfig() != null && evictionTimerTask.isRegionRegisteredForProcessing(r);
+ return r.getEvictionRegionConfig() != null /*&& evictionTimerTask.isRegionRegisteredForProcessing(r)*/;
case MARSHALLING:
return r.isActive() && r.getClassLoader() != null;
}
@@ -639,9 +638,9 @@
// we need to loop thru the regions and only select specific regions to rtn.
for (Region r : regionsRegistry.values())
{
- if ((type == EVICTION && r.getEvictionRegionConfig() != null && evictionTimerTask.isRegionRegisteredForProcessing(r)) ||
- (type == MARSHALLING && r.isActive() && r.getClassLoader() != null))
- regions.add(r);
+// if ((type == EVICTION && r.getEvictionCacheConfig() != null /*&& evictionTimerTask.isRegionRegisteredForProcessing(r))*/ ||
+// (type == MARSHALLING && r.isActive() && r.getClassLoader() != null))
+// regions.add(r);
}
}
else
@@ -665,7 +664,7 @@
// JBAS-1288
// Try to establish a default region if there isn't one already
// boolean needDefault;
- List<EvictionRegionConfig> ercs = evictionConfig.getEvictionRegionConfigs();
+ List<EvictionCacheConfig> ercs = evictionConfig.getEvictionCacheConfigs();
// Only add a default region if there are no regions. This is
// contrary to the idea that there *must* be a default region, but some
// unit tests fail w/ APPROACH 1, so for now we go with this approach.
@@ -677,24 +676,24 @@
// create regions for the regions defined in the evictionConfig.
// scan to be sure the _default_ region isn't added twice
boolean setDefault = false;
- for (EvictionRegionConfig erc : ercs)
+ for (EvictionCacheConfig erc : ercs)
{
- Fqn fqn = erc.getRegionFqn();
- if (trace) log.trace("Creating eviction region " + fqn);
-
- if (fqn.equals(DEFAULT_REGION) || fqn.isRoot())
- {
- if (setDefault)
- {
- throw new ConfigurationException("A default region for evictions has already been set for this cache");
- }
- if (trace) log.trace("Applying settings for default region to Fqn.ROOT");
- fqn = Fqn.ROOT;
- setDefault = true;
- }
- Region r = getRegion(fqn, true);
- evictionConfig.applyDefaults(erc);
- r.setEvictionRegionConfig(erc);
+// Fqn fqn = erc.getCacheName();
+// if (trace) log.trace("Creating eviction region " + fqn);
+//
+// if (fqn.equals(DEFAULT_REGION) || fqn.isRoot())
+// {
+// if (setDefault)
+// {
+// throw new ConfigurationException("A default region for evictions has already been set for this cache");
+// }
+// if (trace) log.trace("Applying settings for default region to Fqn.ROOT");
+// fqn = Fqn.ROOT;
+// setDefault = true;
+// }
+// Region r = getRegion(fqn, true);
+// evictionConfig.applyDefaults(erc);
+// r.setEvictionRegionConfig(erc);
}
}
Modified: core/branches/flat/src/main/java/org/jboss/cache/buddyreplication/Fqn2BuddyFqnVisitor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/buddyreplication/Fqn2BuddyFqnVisitor.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/buddyreplication/Fqn2BuddyFqnVisitor.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -117,7 +117,7 @@
}
@Override
- public Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
+ public Object visitEvictKeyCommand(InvocationContext ctx, EvictCommand command) throws Throwable
{
Fqn fqn = getBackupFqn(command.getFqn());
return factory.buildEvictFqnCommand(fqn);
Modified: core/branches/flat/src/main/java/org/jboss/cache/commands/AbstractVisitor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/commands/AbstractVisitor.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/commands/AbstractVisitor.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -78,7 +78,7 @@
return handleDefault(ctx, command);
}
- public Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
+ public Object visitEvictKeyCommand(InvocationContext ctx, EvictCommand command) throws Throwable
{
return handleDefault(ctx, command);
}
Modified: core/branches/flat/src/main/java/org/jboss/cache/commands/Visitor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/commands/Visitor.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/commands/Visitor.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -111,7 +111,7 @@
* @return response from the visit
* @throws Throwable in the event of problems.
*/
- Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable;
+ Object visitEvictKeyCommand(InvocationContext ctx, EvictCommand command) throws Throwable;
/**
* Visits a InvalidateCommand.
Modified: core/branches/flat/src/main/java/org/jboss/cache/commands/write/EvictCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/commands/write/EvictCommand.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/commands/write/EvictCommand.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -82,7 +82,7 @@
/**
* Evicts a node.
* <p/>
- * See {@link org.jboss.cache.interceptors.EvictionInterceptor#visitEvictFqnCommand(org.jboss.cache.InvocationContext , EvictCommand)}
+ * See {@link org.jboss.starobrno.interceptors.EvictionInterceptor#visitEvictKeyCommand(org.jboss.cache.InvocationContext , EvictCommand)}
* which is where the return value is used
*
* @return true if the node was removed from the tree or if it is resident. Returns false if the node still exists; i.e. was only data removed because it still has children.
@@ -175,7 +175,7 @@
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
{
- return visitor.visitEvictFqnCommand(ctx, this);
+ return visitor.visitEvictKeyCommand(ctx, this);
}
public int getCommandId()
Modified: core/branches/flat/src/main/java/org/jboss/cache/interceptors/BuddyRegionAwareEvictionInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/interceptors/BuddyRegionAwareEvictionInterceptor.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/interceptors/BuddyRegionAwareEvictionInterceptor.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -25,6 +25,7 @@
import org.jboss.cache.Region;
import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.interceptors.EvictionInterceptor;
/**
* A subclass of EvictionInterceptor that is aware of and able to deal with buddy regions.
@@ -42,29 +43,29 @@
this.buddyFqnTransformer = transformer;
}
- @Override
protected Region getRegion(Fqn fqn)
{
- Region r = super.getRegion(fqn);
- if (r != null)
- return r;
- else if (buddyFqnTransformer.isBackupFqn(fqn))
- {
- // try and grab a backup region, creating one if need be.
- Fqn actualFqn = buddyFqnTransformer.getActualFqn(fqn);
- Fqn backupRoot = buddyFqnTransformer.getBackupRootFromFqn(fqn);
-
- // the actual region could be a few levels higher than actualFqn
- Region actualRegion = regionManager.getRegion(actualFqn, Region.Type.EVICTION, false);
-
- if (actualRegion == null) return null;
-
- //create a new region for this backup
- Region newRegion = regionManager.getRegion(Fqn.fromRelativeFqn(backupRoot, actualRegion.getFqn()), Region.Type.EVICTION, true);
- newRegion.setEvictionRegionConfig(actualRegion.getEvictionRegionConfig());
-
- return newRegion;
- }
- else return null;
+// Region r = super.getRegion(fqn);
+// if (r != null)
+// return r;
+// else if (buddyFqnTransformer.isBackupFqn(fqn))
+// {
+// // try and grab a backup region, creating one if need be.
+// Fqn actualFqn = buddyFqnTransformer.getActualFqn(fqn);
+// Fqn backupRoot = buddyFqnTransformer.getBackupRootFromFqn(fqn);
+//
+// // the actual region could be a few levels higher than actualFqn
+// Region actualRegion = evictionCacheManager.getRegion(actualFqn, Region.Type.EVICTION, false);
+//
+// if (actualRegion == null) return null;
+//
+// //create a new region for this backup
+// Region newRegion = evictionCacheManager.getRegion(Fqn.fromRelativeFqn(backupRoot, actualRegion.getFqn()), Region.Type.EVICTION, true);
+// newRegion.configure(actualRegion.getEvictionCacheConfig());
+//
+// return newRegion;
+// }
+// else return null;
+ return null;
}
}
Deleted: core/branches/flat/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,257 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.cache.interceptors;
-
-import org.jboss.cache.DataContainer;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.InvocationContext;
-import org.jboss.cache.Region;
-import org.jboss.cache.RegionManager;
-import org.jboss.cache.commands.read.GetDataMapCommand;
-import org.jboss.cache.commands.read.GetKeyValueCommand;
-import org.jboss.cache.commands.read.GetNodeCommand;
-import org.jboss.cache.commands.write.ClearDataCommand;
-import org.jboss.cache.commands.write.EvictCommand;
-import org.jboss.cache.commands.write.PutDataMapCommand;
-import org.jboss.cache.commands.write.PutForExternalReadCommand;
-import org.jboss.cache.commands.write.PutKeyValueCommand;
-import org.jboss.cache.commands.write.RemoveKeyCommand;
-import org.jboss.cache.commands.write.RemoveNodeCommand;
-import org.jboss.cache.interceptors.base.CommandInterceptor;
-import static org.jboss.starobrno.eviction.EvictionEvent.Type.*;
-import org.jboss.starobrno.factories.annotations.Inject;
-
-/**
- * Eviction Interceptor.
- * <p/>
- * This interceptor is used to handle eviction events.
- *
- * @author Daniel Huang
- * @author Mircea.Markus(a)jboss.com
- * @version $Revision$
- */
-public class EvictionInterceptor extends CommandInterceptor
-{
- protected RegionManager regionManager;
-
- private DataContainer dataContainer;
-
- @Inject
- public void initialize(DataContainer dataContainer)
- {
- this.dataContainer = dataContainer;
- }
-
- /**
- * this method is for ease of unit testing. thus package access.
- * <p/>
- * Not to be attempted to be used anywhere else.
- */
- @Inject
- void setRegionManager(RegionManager regionManager)
- {
- this.regionManager = regionManager;
- }
-
- @Override
- public Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
- {
- Fqn fqn = command.getFqn();
- Object retVal = invokeNextInterceptor(ctx, command);
- // See if the node still exists; i.e. was only data removed
- // because it still has children.
- // If yes, put an ADD event in the queue so the node gets revisited
- boolean complete = (retVal != null && (Boolean) retVal);
- if (!complete)
- {
- Region r;
- if (fqn != null && (r = getRegion(fqn)) != null)
- {
- registerEvictionEventToRegionManager(fqn, ADD_NODE_EVENT, 0, r);
- }
- }
- return retVal;
- }
-
- @Override
- public Object visitPutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable
- {
- return visitPutKeyValueCommand(ctx, command);
- }
-
- @Override
- public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
- {
- Object retVal = invokeNextInterceptor(ctx, command);
- Region r;
- if (command.getFqn() != null && command.getKey() != null && (r = getRegion(command.getFqn())) != null)
- {
- registerEvictionEventToRegionManager(command.getFqn(), ADD_ELEMENT_EVENT, 1, r);
- }
- return retVal;
- }
-
- @Override
- public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
- {
- Object retVal = invokeNextInterceptor(ctx, command);
- Fqn fqn = command.getFqn();
- Region r;
- if (fqn != null && (r = getRegion(fqn)) != null)
- {
- if (command.getData() == null)
- {
- if (trace)
- {
- log.trace("Putting null data under fqn " + fqn + ".");
- }
- }
- else
- {
- int size;
- synchronized (command.getData())
- {
- size = command.getData().size();
- }
- registerEvictionEventToRegionManager(fqn, ADD_NODE_EVENT, size, r);
- }
- }
- return retVal;
- }
-
- @Override
- public Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
- {
- Object retVal = invokeNextInterceptor(ctx, command);
- if (retVal == null)
- {
- if (trace)
- {
- log.trace("No event added. Element does not exist");
- }
-
- }
- else
- {
- Fqn fqn = command.getFqn();
- Region r;
- if (fqn != null && command.getKey() != null && (r = getRegion(fqn)) != null)
- {
- registerEvictionEventToRegionManager(fqn, REMOVE_ELEMENT_EVENT, 1, r);
- }
- }
- return retVal;
- }
-
- @Override
- public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
- {
- Object retVal = invokeNextInterceptor(ctx, command);
- return handleGetNodeOrDataCommands(ctx, retVal, command.getFqn());
- }
-
- private Object handleGetNodeOrDataCommands(InvocationContext ctx, Object retVal, Fqn fqn)
- {
- if (retVal == null)
- {
- if (trace)
- {
- log.trace("No event added. Node does not exist");
- }
- }
- else
- {
- Region r;
- if (fqn != null && (r = getRegion(fqn)) != null)
- {
- registerEvictionEventToRegionManager(fqn, VISIT_NODE_EVENT, 0, r);
- }
- }
- return retVal;
- }
-
- @Override
- public Object visitGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable
- {
- Object retVal = invokeNextInterceptor(ctx, command);
- return handleGetNodeOrDataCommands(ctx, retVal, command.getFqn());
- }
-
- @Override
- public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
- {
- Object retVal = invokeNextInterceptor(ctx, command);
- Fqn fqn = command.getFqn();
- Region r;
- if (retVal == null)
- {
- if (trace)
- {
- log.trace("No event added. Element does not exist");
- }
- }
- else if (fqn != null && command.getKey() != null && (r = getRegion(fqn)) != null)
- {
- registerEvictionEventToRegionManager(fqn, VISIT_NODE_EVENT, 0, r);
- }
- return retVal;
- }
-
- @Override
- public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
- {
- Object retVal = invokeNextInterceptor(ctx, command);
- Region r;
- if (command.getFqn() != null && (r = getRegion(command.getFqn())) != null)
- {
- registerEvictionEventToRegionManager(command.getFqn(), REMOVE_NODE_EVENT, 0, r);
- }
- return retVal;
- }
-
- @Override
- public Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
- {
- Object retVal = invokeNextInterceptor(ctx, command);
- Region r;
- if (command.getFqn() != null && (r = getRegion(command.getFqn())) != null)
- {
- registerEvictionEventToRegionManager(command.getFqn(), REMOVE_NODE_EVENT, 0, r);
- }
- return retVal;
- }
-
- private void registerEvictionEventToRegionManager(Fqn fqn, org.jboss.starobrno.eviction.EvictionEvent.Type type, int elementDifference, Region region)
- {
- //we do not trigger eviction events for resident nodes
- if (dataContainer.isResident(fqn)) return;
-
- region.registerEvictionEvent(fqn, type, elementDifference);
-
- if (trace) log.trace("Registering event " + type + " on node " + fqn);
- }
-
- protected Region getRegion(Fqn fqn)
- {
- return regionManager.getRegion(fqn, Region.Type.EVICTION, false);
- }
-}
Modified: core/branches/flat/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -65,7 +65,7 @@
* store using the CacheLoader.
*/
@Override
- public Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
+ public Object visitEvictKeyCommand(InvocationContext ctx, EvictCommand command) throws Throwable
{
if (command.isRecursive())
{
Modified: core/branches/flat/src/main/java/org/jboss/cache/interceptors/base/PrePostProcessingCommandInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/interceptors/base/PrePostProcessingCommandInterceptor.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/interceptors/base/PrePostProcessingCommandInterceptor.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -154,7 +154,7 @@
}
@Override
- public final Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
+ public final Object visitEvictKeyCommand(InvocationContext ctx, EvictCommand command) throws Throwable
{
try
{
Modified: core/branches/flat/src/main/java/org/jboss/cache/interceptors/base/SkipCheckChainedInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/interceptors/base/SkipCheckChainedInterceptor.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/interceptors/base/SkipCheckChainedInterceptor.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -135,7 +135,7 @@
}
@Override
- public final Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
+ public final Object visitEvictKeyCommand(InvocationContext ctx, EvictCommand command) throws Throwable
{
if (skipInterception(ctx, command))
{
Modified: core/branches/flat/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -159,11 +159,11 @@
case GetKeyValueCommand.METHOD_ID:
case GetKeysCommand.METHOD_ID:
case ExistsCommand.METHOD_ID:
- fqn = ((DataCommand) cmd).getFqn();
+ fqn = ((DataCommand) cmd).getKey();
break;
case DataGravitationCleanupCommand.METHOD_ID:
- fqn = ((DataGravitationCleanupCommand) cmd).getFqn();
+ fqn = ((DataGravitationCleanupCommand) cmd).getKey();
break;
case AnnounceBuddyPoolNameCommand.METHOD_ID:
@@ -179,12 +179,12 @@
fqn = extractFqn(((ReplicateCommand) cmd).getModifications().get(0));
break;
case ClusteredGetCommand.METHOD_ID:
- fqn = ((ClusteredGetCommand) cmd).getDataCommand().getFqn();
+ fqn = ((ClusteredGetCommand) cmd).getDataCommand().getKey();
break;
default:
if (cmd instanceof DataCommand)
{
- fqn = ((DataCommand) cmd).getFqn();
+ fqn = ((DataCommand) cmd).getKey();
}
else
{
Modified: core/branches/flat/src/main/java/org/jboss/cache/remoting/jgroups/ChannelMessageListener.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/remoting/jgroups/ChannelMessageListener.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/remoting/jgroups/ChannelMessageListener.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -329,7 +329,7 @@
{
log.debug("Setting received partial state for subroot " + state_id);
Fqn subroot = Fqn.fromString(targetRoot);
-// Region region = regionManager.getRegion(subroot, false);
+// Region region = evictionCacheManager.getRegion(subroot, false);
// ClassLoader cl = null;
// if (region != null)
// {
@@ -378,7 +378,7 @@
log.debug("Setting received partial state for subroot " + stateId);
in = new MarshalledValueInputStream(istream);
Fqn subroot = Fqn.fromString(targetRoot);
-// Region region = regionManager.getRegion(subroot, false);
+// Region region = evictionCacheManager.getRegion(subroot, false);
// ClassLoader cl = null;
// if (region != null)
// {
Modified: core/branches/flat/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -190,13 +190,13 @@
{
if (curr == null) return;
ctx.setOriginLocal(false);
-// cache.getNotifier().notifyNodeCreated(curr.getFqn(), true, ctx);
-// cache.getNotifier().notifyNodeCreated(curr.getFqn(), false, ctx);
+// cache.getNotifier().notifyNodeCreated(curr.getKey(), true, ctx);
+// cache.getNotifier().notifyNodeCreated(curr.getKey(), false, ctx);
// AND notify that they have been modified!!
if (!curr.getKeys().isEmpty())
{
-// cache.getNotifier().notifyNodeModified(curr.getFqn(), true, NodeModifiedEvent.ModificationType.PUT_MAP, Collections.emptyMap(), ctx);
-// cache.getNotifier().notifyNodeModified(curr.getFqn(), false, NodeModifiedEvent.ModificationType.PUT_MAP, curr.getData(), ctx);
+// cache.getNotifier().notifyNodeModified(curr.getKey(), true, NodeModifiedEvent.ModificationType.PUT_MAP, Collections.emptyMap(), ctx);
+// cache.getNotifier().notifyNodeModified(curr.getKey(), false, NodeModifiedEvent.ModificationType.PUT_MAP, curr.getData(), ctx);
}
ctx.setOriginLocal(true);
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -57,4 +57,6 @@
public void endBatch(boolean successful);
List<Address> getMembers();
+
+ String getName();
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -44,11 +44,13 @@
import org.jboss.starobrno.factories.annotations.Inject;
import org.jboss.starobrno.factories.annotations.NonVolatile;
import org.jboss.starobrno.interceptors.InterceptorChain;
+import org.jboss.starobrno.interceptors.EvictionInterceptor;
import org.jboss.starobrno.interceptors.base.CommandInterceptor;
import org.jboss.starobrno.invocation.InvocationContextContainer;
import org.jboss.starobrno.notifications.Notifier;
import org.jboss.starobrno.transaction.GlobalTransaction;
import org.jboss.starobrno.transaction.TransactionTable;
+import org.jboss.starobrno.eviction.EvictionCacheManager;
import org.jgroups.Address;
import javax.transaction.Transaction;
@@ -73,9 +75,12 @@
protected ComponentRegistry componentRegistry;
protected TransactionManager transactionManager;
protected RPCManager rpcManager;
+ private String name;
+ private EvictionManager evictionManager;
@Inject
- private void injectDependencies(InvocationContextContainer invocationContextContainer,
+ private void injectDependencies(EvictionManager evictionManager,
+ InvocationContextContainer invocationContextContainer,
CommandsFactory commandsFactory,
InterceptorChain interceptorChain,
Configuration configuration,
@@ -94,6 +99,7 @@
this.transactionManager = transactionManager;
this.batchContainer = batchContainer;
this.rpcManager = rpcManager;
+ this.evictionManager = evictionManager;
}
public V putIfAbsent(K key, V value)
@@ -237,6 +243,10 @@
public void stop()
{
componentRegistry.stop();
+ if (config.isUsingEviction())
+ {
+ evictionManager.cacheStopped(getName());
+ }
}
private InvocationContext buildCtx()
@@ -294,6 +304,11 @@
throw new IllegalStateException();//todo Implement me properly
}
+ public EvictionManager getEvictionManager()
+ {
+ return evictionManager;
+ }
+
public RPCManager getRPCManager()
{
return rpcManager;
@@ -357,4 +372,19 @@
{
return rpcManager.getMembers();
}
+
+ public Object getDirect(Object key)
+ {
+ throw new UnsupportedOperationException("Not implemented");//todo please implement!
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/CacheSPI.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheSPI.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheSPI.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -164,6 +164,9 @@
*/
TransactionTable getTransactionTable();
+
+ EvictionManager getEvictionManager();
+
/**
* Gets a handle of the RPC manager.
* <p/>
@@ -239,4 +242,6 @@
* @see org.jboss.cache.factories.ComponentRegistry
*/
ComponentRegistry getComponentRegistry();
+
+ public Object getDirect(Object key);
}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/EvictionManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/EvictionManager.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/EvictionManager.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,38 @@
+package org.jboss.starobrno;
+
+import org.jboss.starobrno.eviction.EvictionCacheManager;
+import org.jboss.starobrno.factories.annotations.NonVolatile;
+import net.jcip.annotations.ThreadSafe;
+
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+@ThreadSafe
+@NonVolatile
+public interface EvictionManager
+{
+ /**
+ * Whenever a new cache is created this method should be called.
+ * If this cache does not have eviction enabled then this is a no-op.
+ * If the cache has eviction enabled then it is reistered for receivinge eviction information.
+ * If this is the first cache that requires eviction, the eviction theread will be started.
+ *
+ * @param cacheName
+ * @param cacheManager newly create cache.
+ */
+ public void cacheCreated(String cacheName, EvictionCacheManager cacheManager);
+
+
+ /**
+ * Whenever a cache will be stoped this method should be called.
+ * If the given cache doesn't have eviction enabled this is an no-op.
+ * If this is the only cache that has eviction enabled, then the eviction thread will be stopped.
+ * After calling this method the given cache will be unregistered from eviction events.
+ * @param chacheName
+ */
+ public void cacheStopped(String cacheName);
+
+ public void runEviction();
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/CommandsFactoryImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/CommandsFactoryImpl.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/CommandsFactoryImpl.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -93,7 +93,9 @@
public EvictCommand buildEvictCommand(Object key)
{
- return new EvictCommand(key);
+ EvictCommand command = new EvictCommand(key);
+ command.initialize(notifier);
+ return command;
}
public PrepareCommand buildPrepareCommand(GlobalTransaction gtx, List modifications, Address localAddress, boolean onePhaseCommit)
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/EvictCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/EvictCommand.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/EvictCommand.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -25,6 +25,7 @@
import org.jboss.starobrno.commands.read.AbstractDataCommand;
import org.jboss.starobrno.container.MVCCEntry;
import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.notifications.Notifier;
/**
* @author Mircea.Markus(a)jboss.com
@@ -33,11 +34,18 @@
{
public static final byte METHOD_ID = 120;
+ private Notifier notifier;
+
public EvictCommand(Object key)
{
this.key = key;
}
+ public void initialize(Notifier notifier)
+ {
+ this.notifier = notifier;
+ }
+
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
{
return visitor.visitEvictCommand(ctx, this);
@@ -45,14 +53,16 @@
public Object perform(InvocationContext ctx) throws Throwable
{
- // TODO: notification?!??
+
if (key == null) throw new NullPointerException("Key is null!!");
MVCCEntry e = ctx.lookupEntry(key);
if (e != null && !e.isNullEntry())
{
+ notifier.notifyCacheEntryEvicted(key, true, ctx);
e.setDeleted(true);
e.setValid(false);
+ notifier.notifyCacheEntryEvicted(key, false, ctx);
}
return null;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -31,9 +31,7 @@
import org.w3c.dom.Element;
import java.net.URL;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
+import java.util.*;
/**
* Encapsulates the configuration of a Cache.
@@ -50,6 +48,18 @@
private transient JGroupsStackParser jGroupsStackParser = new JGroupsStackParser();
private boolean invocationBatchingEnabled;
+ private Map<String, EvictionCacheConfig> evictionCacheConfigs = new HashMap<String, EvictionCacheConfig>(4);
+
+ public EvictionCacheConfig getEvictionCacheConfig(String cacheName)
+ {
+ return evictionCacheConfigs.values().iterator().next();
+ }
+
+ public void addEvictionCacheConfig(String cacheName, EvictionCacheConfig ecc)
+ {
+ evictionCacheConfigs.put(cacheName, ecc);
+ }
+
/**
* Behavior of the JVM shutdown hook registered by the cache
*/
@@ -970,4 +980,8 @@
return null;
}
+ public boolean isUsingEviction()
+ {
+ return getEvictionConfig() != null;
+ }
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionAlgorithmConfig.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionAlgorithmConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -59,4 +59,6 @@
* @return a clone of the EvictionAlgorithmConfig.
*/
EvictionAlgorithmConfig clone() throws CloneNotSupportedException;
+
+ public long getMinTimeToLive();
}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionCacheConfig.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionRegionConfig.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionCacheConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionCacheConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+import org.apache.commons.logging.LogFactory;
+
+public class EvictionCacheConfig extends ConfigurationComponent
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = -5482474634995601400L;
+
+ public static final String NAME = "name";
+ public static final String REGION = "region";
+
+ @Dynamic
+ private Integer eventQueueSize;
+ private EvictionAlgorithmConfig evictionAlgorithmConfig;
+ private String evictionActionClassName;
+
+ public EvictionCacheConfig(EvictionAlgorithmConfig evictionAlgorithmConfig)
+ {
+ eventQueueSize = EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
+ evictionActionClassName = EvictionConfig.EVICTION_ACTION_CLASS_DEFAULT;
+ this.evictionAlgorithmConfig = evictionAlgorithmConfig;
+ }
+
+ public EvictionCacheConfig(Integer eventQueueSize, EvictionAlgorithmConfig evictionAlgorithmConfig, String evictionActionClassName)
+ {
+ this.eventQueueSize = eventQueueSize;
+ this.evictionAlgorithmConfig = evictionAlgorithmConfig;
+ this.evictionActionClassName = evictionActionClassName;
+ }
+
+ public void setEventQueueSize(int queueSize)
+ {
+ testImmutability("eventQueueSize");
+ if (queueSize <= 0)
+ {
+ LogFactory.getLog(EvictionCacheConfig.class).warn("Ignoring invalid queue capacity " +
+ queueSize + " -- using " +
+ EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
+ queueSize = EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
+ }
+ this.eventQueueSize = queueSize;
+ }
+
+ /**
+ * Ensure this is a valid eviction region configuration.
+ */
+ public void validate()
+ {
+ if (eventQueueSize < 1)
+ throw new ConfigurationException("Eviction event queue size cannot be less than 1!");
+
+ if (evictionAlgorithmConfig == null)
+ throw new MissingPolicyException("Eviction algorithm configuration cannot be null!");
+
+ evictionAlgorithmConfig.validate();
+ }
+
+
+ public Integer getEventQueueSize()
+ {
+ return eventQueueSize;
+ }
+
+ public EvictionAlgorithmConfig getEvictionAlgorithmConfig()
+ {
+ return evictionAlgorithmConfig;
+ }
+
+ public String getEvictionActionClassName()
+ {
+ return evictionActionClassName;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ EvictionCacheConfig that = (EvictionCacheConfig) o;
+
+ if (eventQueueSize != null ? !eventQueueSize.equals(that.eventQueueSize) : that.eventQueueSize != null)
+ return false;
+ if (evictionActionClassName != null ? !evictionActionClassName.equals(that.evictionActionClassName) : that.evictionActionClassName != null)
+ return false;
+ if (evictionAlgorithmConfig != null ? !evictionAlgorithmConfig.equals(that.evictionAlgorithmConfig) : that.evictionAlgorithmConfig != null)
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result;
+ result = (eventQueueSize != null ? eventQueueSize.hashCode() : 0);
+ result = 31 * result + (evictionAlgorithmConfig != null ? evictionAlgorithmConfig.hashCode() : 0);
+ result = 31 * result + (evictionActionClassName != null ? evictionActionClassName.hashCode() : 0);
+ return result;
+ }
+
+}
\ No newline at end of file
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionConfig.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -22,8 +22,7 @@
package org.jboss.starobrno.config;
import org.jboss.cache.Fqn;
-import org.jboss.cache.RegionManagerImpl;
-import org.jboss.starobrno.eviction.DefaultEvictionActionPolicy;
+import org.jboss.starobrno.eviction.DefaultEvictionAction;
import java.util.LinkedList;
import java.util.List;
@@ -38,7 +37,7 @@
public static final int WAKEUP_DEFAULT = 5000;
public static final int EVENT_QUEUE_SIZE_DEFAULT = 200000;
- public static final String EVICTION_ACTION_POLICY_CLASS_DEFAULT = DefaultEvictionActionPolicy.class.getName();
+ public static final String EVICTION_ACTION_CLASS_DEFAULT = DefaultEvictionAction.class.getName();
/**
* value expressed in millis
@@ -50,56 +49,56 @@
// Dynamic to support runtime adds/removes of regions
@Dynamic
- private List<EvictionRegionConfig> evictionRegionConfigs;
- private EvictionRegionConfig defaultEvictionRegionConfig;
+ private List<EvictionCacheConfig> evictionCacheConfigs;
+ private EvictionCacheConfig defaultEvictionCacheConfig;
@Deprecated
private String defaultEvictionPolicyClass;
public EvictionConfig()
{
- evictionRegionConfigs = new LinkedList<EvictionRegionConfig>();
- defaultEvictionRegionConfig = new EvictionRegionConfig(Fqn.ROOT);
- defaultEvictionRegionConfig.setEventQueueSize(EVENT_QUEUE_SIZE_DEFAULT);
- defaultEvictionRegionConfig.setEvictionActionPolicyClassName(DefaultEvictionActionPolicy.class.getName());
+// evictionCacheConfigs = new LinkedList<EvictionCacheConfig>();
+// defaultEvictionCacheConfig = new EvictionCacheConfig(Fqn.ROOT);
+// defaultEvictionCacheConfig.setEventQueueSize(EVENT_QUEUE_SIZE_DEFAULT);
+// defaultEvictionCacheConfig.setEvictionActionClassName(DefaultEvictionAction.class.getName());
}
- public EvictionConfig(EvictionRegionConfig defaultEvictionRegionConfig)
+ public EvictionConfig(EvictionCacheConfig defaultEvictionCacheConfig)
{
- evictionRegionConfigs = new LinkedList<EvictionRegionConfig>();
- try
- {
- this.defaultEvictionRegionConfig = defaultEvictionRegionConfig.clone();
- }
- catch (CloneNotSupportedException e)
- {
- throw new ConfigurationException(e);
- }
- this.defaultEvictionRegionConfig.setEventQueueSize(EVENT_QUEUE_SIZE_DEFAULT);
- if (this.defaultEvictionRegionConfig.getEvictionActionPolicyClassName() == null)
- this.defaultEvictionRegionConfig.setEvictionActionPolicyClassName(DefaultEvictionActionPolicy.class.getName());
+ evictionCacheConfigs = new LinkedList<EvictionCacheConfig>();
+// try
+// {
+// this.defaultEvictionCacheConfig = defaultEvictionCacheConfig.clone();
+// }
+// catch (CloneNotSupportedException e)
+// {
+// throw new ConfigurationException(e);
+// }
+ this.defaultEvictionCacheConfig.setEventQueueSize(EVENT_QUEUE_SIZE_DEFAULT);
+// if (this.defaultEvictionCacheConfig.getEvictionActionClassName() == null)
+// this.defaultEvictionCacheConfig.setEvictionActionClassName(DefaultEvictionAction.class.getName());
}
- public EvictionConfig(EvictionRegionConfig defaultEvictionRegionConfig, int wakeupInterval)
+ public EvictionConfig(EvictionCacheConfig defaultEvictionCacheConfig, int wakeupInterval)
{
- this(defaultEvictionRegionConfig);
+ this(defaultEvictionCacheConfig);
this.wakeupInterval = wakeupInterval;
}
public boolean isValidConfig()
{
- return (defaultEvictionRegionConfig != null && defaultEvictionRegionConfig.getEvictionActionPolicyClassName() != null && defaultEvictionRegionConfig.getEvictionAlgorithmConfig() != null)
- || (evictionRegionConfigs != null && evictionRegionConfigs.size() > 0);
+ return (defaultEvictionCacheConfig != null && defaultEvictionCacheConfig.getEvictionActionClassName() != null && defaultEvictionCacheConfig.getEvictionAlgorithmConfig() != null)
+ || (evictionCacheConfigs != null && evictionCacheConfigs.size() > 0);
}
- public EvictionRegionConfig getDefaultEvictionRegionConfig()
+ public EvictionCacheConfig getDefaultEvictionRegionConfig()
{
- return defaultEvictionRegionConfig;
+ return defaultEvictionCacheConfig;
}
- public void setDefaultEvictionRegionConfig(EvictionRegionConfig defaultEvictionRegionConfig)
+ public void setDefaultEvictionRegionConfig(EvictionCacheConfig defaultEvictionCacheConfig)
{
- this.defaultEvictionRegionConfig = defaultEvictionRegionConfig;
- this.defaultEvictionRegionConfig.setEventQueueSizeIfUnset(EVENT_QUEUE_SIZE_DEFAULT);
+ this.defaultEvictionCacheConfig = defaultEvictionCacheConfig;
+// this.defaultEvictionCacheConfig.setEventQueueSizeIfUnset(EVENT_QUEUE_SIZE_DEFAULT);
}
/**
@@ -128,54 +127,54 @@
* @deprecated the default region is now created when this instance is constructed. Use {@link #getDefaultEvictionRegionConfig()} instead.
*/
@Deprecated
- public EvictionRegionConfig createDefaultEvictionRegionConfig()
+ public EvictionCacheConfig createDefaultEvictionRegionConfig()
{
return getDefaultEvictionRegionConfig();
}
- public List<EvictionRegionConfig> getEvictionRegionConfigs()
+ public List<EvictionCacheConfig> getEvictionCacheConfigs()
{
- return evictionRegionConfigs;
+ return evictionCacheConfigs;
}
- public void setEvictionRegionConfigs(List<EvictionRegionConfig> evictionRegionConfigs)
+ public void setEvictionRegionConfigs(List<EvictionCacheConfig> evictionCacheConfigs)
{
- testImmutability("evictionRegionConfigs");
- EvictionRegionConfig toRemove = null;
- for (EvictionRegionConfig erc : evictionRegionConfigs)
+ testImmutability("evictionCacheConfigs");
+ EvictionCacheConfig toRemove = null;
+ for (EvictionCacheConfig erc : evictionCacheConfigs)
{
- if (erc.getRegionFqn().isRoot() || erc.getRegionFqn().equals(RegionManagerImpl.DEFAULT_REGION))
- {
- mergeWithDefault(erc);
- toRemove = erc;
- break;
- }
+// if (erc.getCacheName().isRoot() || erc.getCacheName().equals(RegionManagerImpl.DEFAULT_REGION))
+// {
+// mergeWithDefault(erc);
+// toRemove = erc;
+// break;
+// }
}
- if (toRemove != null) evictionRegionConfigs.remove(toRemove);
+ if (toRemove != null) evictionCacheConfigs.remove(toRemove);
- this.evictionRegionConfigs = evictionRegionConfigs;
+ this.evictionCacheConfigs = evictionCacheConfigs;
}
- private void mergeWithDefault(EvictionRegionConfig erc)
+ private void mergeWithDefault(EvictionCacheConfig erc)
{
- erc.setEventQueueSizeIfUnset(defaultEvictionRegionConfig.getEventQueueSize());
- if (erc.getEvictionAlgorithmConfig() == null)
- erc.setEvictionAlgorithmConfig(defaultEvictionRegionConfig.getEvictionAlgorithmConfig());
- defaultEvictionRegionConfig = erc;
+// erc.setEventQueueSizeIfUnset(defaultEvictionCacheConfig.getEventQueueSize());
+// if (erc.getEvictionAlgorithmConfig() == null)
+// erc.setEvictionAlgorithmConfig(defaultEvictionCacheConfig.getEvictionAlgorithmConfig());
+// defaultEvictionCacheConfig = erc;
}
- public void addEvictionRegionConfig(EvictionRegionConfig evictionRegionConfig)
+ public void addEvictionRegionConfig(EvictionCacheConfig evictionCacheConfig)
{
- testImmutability("evictionRegionConfigs");
- if (evictionRegionConfig.getRegionFqn().isRoot() || evictionRegionConfig.getRegionFqn().equals(RegionManagerImpl.DEFAULT_REGION))
- {
- mergeWithDefault(evictionRegionConfig);
- }
- else
- {
- evictionRegionConfigs.add(evictionRegionConfig);
- }
+ testImmutability("evictionCacheConfigs");
+// if (evictionCacheConfig.getCacheName().isRoot() || evictionCacheConfig.getCacheName().equals(RegionManagerImpl.DEFAULT_REGION))
+// {
+// mergeWithDefault(evictionCacheConfig);
+// }
+// else
+// {
+// evictionCacheConfigs.add(evictionCacheConfig);
+// }
}
/**
@@ -236,9 +235,9 @@
if (defaultEventQueueSize != that.defaultEventQueueSize) return false;
if (wakeupInterval != that.wakeupInterval) return false;
- if (defaultEvictionRegionConfig != null ? !defaultEvictionRegionConfig.equals(that.defaultEvictionRegionConfig) : that.defaultEvictionRegionConfig != null)
+ if (defaultEvictionCacheConfig != null ? !defaultEvictionCacheConfig.equals(that.defaultEvictionCacheConfig) : that.defaultEvictionCacheConfig != null)
return false;
- if (evictionRegionConfigs != null ? !evictionRegionConfigs.equals(that.evictionRegionConfigs) : that.evictionRegionConfigs != null)
+ if (evictionCacheConfigs != null ? !evictionCacheConfigs.equals(that.evictionCacheConfigs) : that.evictionCacheConfigs != null)
return false;
return true;
@@ -249,7 +248,7 @@
int result;
result = 31 + (int) (wakeupInterval ^ (wakeupInterval >>> 32));
result = 31 * result + defaultEventQueueSize;
- result = 31 * result + (evictionRegionConfigs != null ? evictionRegionConfigs.hashCode() : 0);
+ result = 31 * result + (evictionCacheConfigs != null ? evictionCacheConfigs.hashCode() : 0);
return result;
}
@@ -257,12 +256,12 @@
public EvictionConfig clone() throws CloneNotSupportedException
{
EvictionConfig clone = (EvictionConfig) super.clone();
- if (evictionRegionConfigs != null)
+ if (evictionCacheConfigs != null)
{
// needs to be a deep copy
- clone.evictionRegionConfigs = new LinkedList<EvictionRegionConfig>();
- for (EvictionRegionConfig erc : evictionRegionConfigs)
- clone.addEvictionRegionConfig(erc.clone());
+ clone.evictionCacheConfigs = new LinkedList<EvictionCacheConfig>();
+// for (EvictionCacheConfig erc : evictionCacheConfigs)
+// clone.addEvictionRegionConfig(erc.clone());
}
return clone;
}
@@ -272,16 +271,16 @@
* Returns the <code>EvictionRegionConfig</code> coresponding to given region fqn, or <code>null</code> if no
* match is found.
*/
- public EvictionRegionConfig getEvictionRegionConfig(String region)
+ public EvictionCacheConfig getEvictionRegionConfig(String region)
{
Fqn fqn = Fqn.fromString(region);
- for (EvictionRegionConfig evConfig : getEvictionRegionConfigs())
+ for (EvictionCacheConfig evConfig : getEvictionCacheConfigs())
{
- if (evConfig.getRegionFqn().equals(fqn))
- {
- return evConfig;
- }
- }
+// if (evConfig.getCacheName().equals(fqn))
+// {
+// return evConfig;
+// }
+}
return null;
}
@@ -290,10 +289,10 @@
*
* @param config config to apply defaults to
*/
- public void applyDefaults(EvictionRegionConfig config)
+ public void applyDefaults(EvictionCacheConfig config)
{
- if (config == null) return; // no op
- config.setDefaults(defaultEvictionRegionConfig);
+// if (config == null) return; // no op
+// config.setDefaults(defaultEvictionCacheConfig);
}
/**
@@ -302,6 +301,6 @@
@Deprecated
public void setDefaultEventQueueSize(int queueSize)
{
- defaultEvictionRegionConfig.setEventQueueSize(queueSize);
+ defaultEvictionCacheConfig.setEventQueueSize(queueSize);
}
}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionRegionConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionRegionConfig.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionRegionConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,218 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.config;
-
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Fqn;
-import org.jboss.starobrno.util.Util;
-
-import java.lang.reflect.Method;
-
-public class EvictionRegionConfig extends ConfigurationComponent
-{
- /**
- * The serialVersionUID
- */
- private static final long serialVersionUID = -5482474634995601400L;
-
- public static final String NAME = "name";
- public static final String REGION = "region";
-
- private Fqn regionFqn;
- @Dynamic
- private Integer eventQueueSize;
- private EvictionAlgorithmConfig evictionAlgorithmConfig;
- private String evictionActionPolicyClassName;
-
- public EvictionRegionConfig()
- {
- }
-
- public EvictionRegionConfig(Fqn regionFqn, EvictionAlgorithmConfig evictionAlgorithmConfig)
- {
- this.regionFqn = regionFqn;
- this.evictionAlgorithmConfig = evictionAlgorithmConfig;
- }
-
- public EvictionRegionConfig(Fqn regionFqn, EvictionAlgorithmConfig evictionAlgorithmConfig, int queueSize)
- {
- this.regionFqn = regionFqn;
- this.evictionAlgorithmConfig = evictionAlgorithmConfig;
- this.eventQueueSize = queueSize;
- }
-
- public EvictionRegionConfig(Fqn fqn)
- {
- this.regionFqn = fqn;
- }
-
- public EvictionAlgorithmConfig getEvictionAlgorithmConfig()
- {
- return evictionAlgorithmConfig;
- }
-
- public void setEvictionAlgorithmConfig(EvictionAlgorithmConfig config)
- {
- testImmutability("evictionAlgorithmConfig");
- this.evictionAlgorithmConfig = config;
- }
-
- public Fqn getRegionFqn()
- {
- return regionFqn;
- }
-
- public void setRegionFqn(Fqn regionFqn)
- {
- testImmutability("regionFqn");
- this.regionFqn = regionFqn;
- }
-
- public String getRegionName()
- {
- return regionFqn == null ? null : regionFqn.toString();
- }
-
- public void setRegionName(String name)
- {
- setRegionFqn(name == null ? null : Fqn.fromString(name));
- }
-
- public int getEventQueueSize()
- {
- return eventQueueSize == null ? EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT : eventQueueSize;
- }
-
- public void setEventQueueSize(int queueSize)
- {
- testImmutability("eventQueueSize");
- if (queueSize <= 0)
- {
- LogFactory.getLog(EvictionRegionConfig.class).warn("Ignoring invalid queue capacity " +
- queueSize + " -- using " +
- EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
- queueSize = EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
- }
- this.eventQueueSize = queueSize;
- }
-
- public void setDefaults(EvictionRegionConfig defaults)
- {
- // go thru each element that is unset here and copy from "defaults"
- if (eventQueueSize == null) eventQueueSize = defaults.getEventQueueSize();
- if (evictionAlgorithmConfig == null) evictionAlgorithmConfig = defaults.getEvictionAlgorithmConfig();
- if (evictionActionPolicyClassName == null)
- evictionActionPolicyClassName = defaults.getEvictionActionPolicyClassName();
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- return true;
-
- if (obj instanceof EvictionRegionConfig)
- {
- EvictionRegionConfig other = (EvictionRegionConfig) obj;
- boolean equalRegions = Util.safeEquals(this.regionFqn, other.regionFqn);
- boolean equalConfigurations = Util.safeEquals(this.evictionAlgorithmConfig, other.evictionAlgorithmConfig);
- boolean equalEventQueuSizes = this.getEventQueueSize() == other.getEventQueueSize();
- return equalRegions && equalConfigurations && equalConfigurations && equalEventQueuSizes;
- }
- return false;
- }
-
- @Override
- public int hashCode()
- {
- int result = 17;
- result = 31 * result + (regionFqn == null ? 0 : regionFqn.hashCode());
-
- return result;
- }
-
- @Override
- public EvictionRegionConfig clone() throws CloneNotSupportedException
- {
- EvictionRegionConfig clone = (EvictionRegionConfig) super.clone();
- if (evictionAlgorithmConfig != null)
- {
- if (evictionAlgorithmConfig instanceof ConfigurationComponent)
- {
- clone.setEvictionAlgorithmConfig((EvictionAlgorithmConfig) ((ConfigurationComponent) evictionAlgorithmConfig).clone());
- }
- else
- {
- try
- {
- Method cloneMethod = this.evictionAlgorithmConfig.getClass().getDeclaredMethod("clone");
- EvictionAlgorithmConfig evictionAlgorithmConfig = (EvictionAlgorithmConfig) cloneMethod.invoke(this.evictionAlgorithmConfig);
- clone.setEvictionAlgorithmConfig(evictionAlgorithmConfig);
- }
- catch (Exception e)
- {
- CloneNotSupportedException cnse = new CloneNotSupportedException("Cannot invoke clone() on " + evictionAlgorithmConfig);
- cnse.initCause(e);
- throw cnse;
- }
- }
- }
-
- clone.evictionActionPolicyClassName = evictionActionPolicyClassName;
-
- return clone;
- }
-
- public boolean isDefaultRegion()
- {
- return regionFqn.isRoot();
- }
-
- public String getEvictionActionPolicyClassName()
- {
- return evictionActionPolicyClassName == null ? EvictionConfig.EVICTION_ACTION_POLICY_CLASS_DEFAULT : evictionActionPolicyClassName;
- }
-
- public void setEvictionActionPolicyClassName(String evictionActionPolicyClassName)
- {
- this.evictionActionPolicyClassName = evictionActionPolicyClassName;
- }
-
- public void setEventQueueSizeIfUnset(int eventQueueSize)
- {
- if (this.eventQueueSize == null) this.eventQueueSize = eventQueueSize;
- }
-
- /**
- * Ensure this is a valid eviction region configuration.
- */
- public void validate()
- {
- if (eventQueueSize < 1)
- throw new ConfigurationException("Eviction event queue size cannot be less than 1!");
-
- if (evictionAlgorithmConfig == null)
- throw new MissingPolicyException("Eviction algorithm configuration cannot be null!");
-
- evictionAlgorithmConfig.validate();
- }
-}
\ No newline at end of file
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/element/EvictionElementParser.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/element/EvictionElementParser.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/element/EvictionElementParser.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -22,11 +22,8 @@
package org.jboss.starobrno.config.parsing.element;
import org.jboss.starobrno.util.Util;
-import org.jboss.starobrno.config.ConfigurationException;
-import org.jboss.starobrno.config.EvictionAlgorithmConfig;
-import org.jboss.starobrno.config.EvictionConfig;
-import org.jboss.starobrno.config.EvictionRegionConfig;
-import org.jboss.starobrno.config.MissingPolicyException;
+import org.jboss.starobrno.config.EvictionCacheConfig;
+import org.jboss.starobrno.config.*;
import org.jboss.starobrno.config.parsing.ParsedAttributes;
import org.jboss.starobrno.config.parsing.XmlConfigHelper;
import org.jboss.starobrno.config.parsing.XmlParserBase;
@@ -62,124 +59,125 @@
throw new ConfigurationException("Missing mandatory attribute wakeUpInterval");
}
- List<EvictionRegionConfig> evictionRegionConfigs = new LinkedList<EvictionRegionConfig>();
+ List<EvictionCacheConfig> evictionCacheConfigs = new LinkedList<EvictionCacheConfig>();
Element defaultRegion = getSingleElementInCoreNS("default", evictionElement);
if (defaultRegion != null)
{
- EvictionRegionConfig defaultRegionConfig = getEvictionRegionConfig(defaultRegion, null, true);
- if (defaultRegionConfig.getEvictionAlgorithmConfig() == null)
+ EvictionCacheConfig defaultCacheConfig = getEvictionRegionConfig(defaultRegion, null, true);
+ if (defaultCacheConfig.getEvictionAlgorithmConfig() == null)
throw new MissingPolicyException("Default eviction region should have an evictionAlgorithmClass defined.");
- evictionConfig.setDefaultEvictionRegionConfig(defaultRegionConfig);
+ evictionConfig.setDefaultEvictionRegionConfig(defaultCacheConfig);
}
NodeList regions = evictionElement.getElementsByTagName("region");
for (int i = 0; i < regions.getLength(); i++)
{
Element regionConfig = (Element) regions.item(i);
- EvictionRegionConfig erc = getEvictionRegionConfig(regionConfig, evictionConfig.getDefaultEvictionRegionConfig(), false);
+ EvictionCacheConfig erc = getEvictionRegionConfig(regionConfig, evictionConfig.getDefaultEvictionRegionConfig(), false);
evictionConfig.applyDefaults(erc);
- evictionRegionConfigs.add(erc);
+ evictionCacheConfigs.add(erc);
}
- evictionConfig.setEvictionRegionConfigs(evictionRegionConfigs);
+ evictionConfig.setEvictionRegionConfigs(evictionCacheConfigs);
return evictionConfig;
}
@SuppressWarnings("unchecked")
- private EvictionRegionConfig getEvictionRegionConfig(Element element, EvictionRegionConfig defaultRegion, boolean isDefault)
+ private EvictionCacheConfig getEvictionRegionConfig(Element element, EvictionCacheConfig defaultCache, boolean isDefault)
{
- EvictionRegionConfig erc = new EvictionRegionConfig();
- erc.setRegionName(getAttributeValue(element, "name"));
- String queueSize = getAttributeValue(element, "eventQueueSize");
- if (existsAttribute(queueSize))
- {
- erc.setEventQueueSize(getInt(queueSize));
- }
- else if (defaultRegion == null)
- {
- erc.setEventQueueSize(EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
- }
-
- String algorithmClassName = getAttributeValue(element, "algorithmClass");
- EvictionAlgorithmConfig algorithmConfig = null; // every eviction region config needs an algorithm config.
-
- if (existsAttribute(algorithmClassName))
- {
- EvictionAlgorithm algorithm;
- Class<? extends EvictionAlgorithm> algorithmClass;
- // try using a 'getInstance()' factory.
-
- try
- {
- algorithmClass = Util.loadClass(algorithmClassName);
- }
- catch (Exception e)
- {
- throw new RuntimeException("Unable to load eviction algorithm class [" + algorithmClassName + "]", e);
- }
-
-
- try
- {
- algorithm = Util.getInstance(algorithmClass);
- }
- catch (Exception e)
- {
- throw new ConfigurationException("Unable to construct eviction algorithm class [" + algorithmClassName + "]", e);
- }
-
- try
- {
- algorithmConfig = Util.getInstance(algorithm.getConfigurationClass());
- }
- catch (Exception e)
- {
- throw new RuntimeException("Failed to instantiate eviction algorithm configuration class [" +
- algorithm.getConfigurationClass() + "]", e);
- }
- }
- else
- {
- if (!isDefault)
- {
- if (defaultRegion == null || defaultRegion.getEvictionAlgorithmConfig() == null)
- {
- throw new MissingPolicyException("There is no Eviction Algorithm Class specified on the region or for the entire cache!");
- }
- else
- {
- try
- {
- algorithmConfig = defaultRegion.getEvictionAlgorithmConfig().clone();
- }
- catch (CloneNotSupportedException e)
- {
- throw new ConfigurationException("Unable to clone eviction algorithm configuration from default", e);
- }
- }
- }
- }
-
- if (algorithmConfig != null)
- {
- parseEvictionPolicyConfig(element, algorithmConfig);
-
- erc.setEvictionAlgorithmConfig(algorithmConfig);
- }
-
- String actionPolicyClass = getAttributeValue(element, "actionPolicyClass");
- if (existsAttribute(actionPolicyClass))
- {
- erc.setEvictionActionPolicyClassName(actionPolicyClass);
- }
- else if (defaultRegion == null)
- {
- // this is the default region. Make sure we set the default EvictionActionPolicyClass.
- erc.setEvictionActionPolicyClassName(EvictionConfig.EVICTION_ACTION_POLICY_CLASS_DEFAULT);
- }
-
-
- return erc;
+// EvictionCacheConfig erc = new EvictionCacheConfig();
+// erc.setRegionName(getAttributeValue(element, "name"));
+// String queueSize = getAttributeValue(element, "eventQueueSize");
+// if (existsAttribute(queueSize))
+// {
+// erc.setEventQueueSize(getInt(queueSize));
+// }
+// else if (defaultCache == null)
+// {
+// erc.setEventQueueSize(EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
+// }
+//
+// String algorithmClassName = getAttributeValue(element, "algorithmClass");
+// EvictionAlgorithmConfig algorithmConfig = null; // every eviction region config needs an algorithm config.
+//
+// if (existsAttribute(algorithmClassName))
+// {
+// EvictionAlgorithm algorithm;
+// Class<? extends EvictionAlgorithm> algorithmClass;
+// // try using a 'getInstance()' factory.
+//
+// try
+// {
+// algorithmClass = Util.loadClass(algorithmClassName);
+// }
+// catch (Exception e)
+// {
+// throw new RuntimeException("Unable to load eviction algorithm class [" + algorithmClassName + "]", e);
+// }
+//
+//
+// try
+// {
+// algorithm = Util.getInstance(algorithmClass);
+// }
+// catch (Exception e)
+// {
+// throw new ConfigurationException("Unable to construct eviction algorithm class [" + algorithmClassName + "]", e);
+// }
+//
+// try
+// {
+// algorithmConfig = (EvictionAlgorithmConfig) Util.getInstance(algorithm.getConfigurationClass());
+// }
+// catch (Exception e)
+// {
+// throw new RuntimeException("Failed to instantiate eviction algorithm configuration class [" +
+// algorithm.getConfigurationClass() + "]", e);
+// }
+// }
+// else
+// {
+// if (!isDefault)
+// {
+// if (defaultCache == null || defaultCache.getEvictionAlgorithmConfig() == null)
+// {
+// throw new MissingPolicyException("There is no Eviction Algorithm Class specified on the region or for the entire cache!");
+// }
+// else
+// {
+// try
+// {
+// algorithmConfig = defaultCache.getEvictionAlgorithmConfig().clone();
+// }
+// catch (CloneNotSupportedException e)
+// {
+// throw new ConfigurationException("Unable to clone eviction algorithm configuration from default", e);
+// }
+// }
+// }
+// }
+//
+// if (algorithmConfig != null)
+// {
+// parseEvictionPolicyConfig(element, algorithmConfig);
+//
+// erc.setEvictionAlgorithmConfig(algorithmConfig);
+// }
+//
+// String actionPolicyClass = getAttributeValue(element, "actionPolicyClass");
+// if (existsAttribute(actionPolicyClass))
+// {
+// erc.setEvictionActionClassName(actionPolicyClass);
+// }
+// else if (defaultCache == null)
+// {
+// // this is the default region. Make sure we set the default EvictionActionPolicyClass.
+// erc.setEvictionActionClassName(EvictionConfig.EVICTION_ACTION_CLASS_DEFAULT);
+// }
+//
+//
+// return erc;
+ return null;
}
public static void parseEvictionPolicyConfig(Element element, EvictionAlgorithmConfig target)
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseEvictionAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseEvictionAlgorithm.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseEvictionAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,614 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheSPI_Legacy;
-import org.jboss.cache.Fqn;
-import org.jboss.starobrno.lock.TimeoutException;
-import org.jboss.starobrno.config.Configuration;
-import org.jboss.starobrno.config.EvictionAlgorithmConfig;
-import org.jboss.starobrno.eviction.EvictionEvent.Type;
-
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Abstract Event Processing Eviction Algorithm.
- * This class is used to implement basic event processing for Eviction Algorithms.
- * To extend this abstract class to make an Eviction Algorithm, implement the
- * abstract methods and a policy.
- *
- * @author Daniel Huang - dhuang(a)jboss.org 10/2005
- * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
- * @version $Revision: 6776 $
- */
-public abstract class BaseEvictionAlgorithm implements EvictionAlgorithm
-{
- private static final Log log = LogFactory.getLog(BaseEvictionAlgorithm.class);
- private static final boolean trace = log.isTraceEnabled();
- protected org.jboss.starobrno.eviction.EvictionActionPolicy evictionActionPolicy;
- protected EvictionAlgorithmConfig evictionAlgorithmConfig;
- /**
- * Contains Fqn instances.
- */
- protected BlockingQueue<Fqn> recycleQueue;
- /**
- * Contains NodeEntry instances.
- */
- protected org.jboss.starobrno.eviction.EvictionQueue evictionQueue;
- protected boolean allowTombstones = false;
- protected Configuration configuration;
- protected Fqn regionFqn;
- protected CacheSPI_Legacy<?, ?> cache;
-
- /**
- * This method will create an EvictionQueue implementation and prepare it for use.
- *
- * @return The created EvictionQueue to be used as the eviction queue for this algorithm.
- * @throws org.jboss.starobrno.eviction.EvictionException
- * if there are problems
- * @see org.jboss.starobrno.eviction.EvictionQueue
- */
- protected abstract org.jboss.starobrno.eviction.EvictionQueue setupEvictionQueue() throws org.jboss.starobrno.eviction.EvictionException;
-
- /**
- * This method will check whether the given node should be evicted or not.
- *
- * @param ne NodeEntry to test eviction for.
- * @return True if the given node should be evicted. False if the given node should not be evicted.
- */
- protected abstract boolean shouldEvictNode(org.jboss.starobrno.eviction.NodeEntry ne);
-
- protected BaseEvictionAlgorithm()
- {
- recycleQueue = new LinkedBlockingQueue<Fqn>(500000);
- }
-
- public synchronized void initialize()
- {
- if (evictionQueue == null)
- {
- evictionQueue = setupEvictionQueue();
- allowTombstones = false;
- }
- }
-
- public org.jboss.starobrno.eviction.EvictionActionPolicy getEvictionActionPolicy()
- {
- return evictionActionPolicy;
- }
-
- public void setEvictionActionPolicy(org.jboss.starobrno.eviction.EvictionActionPolicy evictionActionPolicy)
- {
- this.evictionActionPolicy = evictionActionPolicy;
- }
-
- public EvictionAlgorithmConfig getEvictionAlgorithmConfig()
- {
- return evictionAlgorithmConfig;
- }
-
- public void assignToRegion(Fqn fqn, CacheSPI_Legacy<?, ?> cache, EvictionAlgorithmConfig evictionAlgorithmConfig, Configuration configuration)
- {
- this.regionFqn = fqn;
- this.cache = cache;
- this.evictionAlgorithmConfig = evictionAlgorithmConfig;
- this.configuration = configuration;
- }
-
- public boolean canIgnoreEvent(Type eventType)
- {
- return false; // don't ignore anything!
- }
-
- /**
- * Process the given eviction event queue. Eviction Processing encompasses the following:
- * <p/>
- * - Add/Remove/Visit Nodes
- * - Prune according to Eviction Algorithm
- * - Empty/Retry the recycle queue of previously evicted but locked (during actual cache eviction) nodes.
- *
- * @param eventQueue queue containing eviction events
- * @throws org.jboss.starobrno.eviction.EvictionException
- *
- */
- public void process(BlockingQueue<org.jboss.starobrno.eviction.EvictionEvent> eventQueue) throws org.jboss.starobrno.eviction.EvictionException
- {
- if (trace) log.trace("process(): region: " + regionFqn);
- initialize();
- this.processQueues(eventQueue);
- this.emptyRecycleQueue();
- this.prune();
- }
-
- public void resetEvictionQueue()
- {
- // a no-op
- }
-
- /**
- * Get the underlying EvictionQueue implementation.
- *
- * @return the EvictionQueue used by this algorithm
- * @see org.jboss.starobrno.eviction.EvictionQueue
- */
- public org.jboss.starobrno.eviction.EvictionQueue getEvictionQueue()
- {
- return this.evictionQueue;
- }
-
- protected org.jboss.starobrno.eviction.EvictionEvent getNextInQueue(BlockingQueue<org.jboss.starobrno.eviction.EvictionEvent> queue)
- {
- try
- {
- return queue.poll(0, TimeUnit.SECONDS);
- }
- catch (InterruptedException e)
- {
- Thread.currentThread().interrupt();
- }
- return null;
- }
-
- /**
- * Event processing for Evict/Add/Visiting of nodes.
- * <p/>
- * - On AddEvents a new element is added into the eviction queue
- * - On RemoveEvents, the removed element is removed from the eviction queue.
- * - On VisitEvents, the visited node has its eviction statistics updated (idleTime, numberOfNodeVisists, etc..)
- *
- * @param queue queue to inspect
- * @throws org.jboss.starobrno.eviction.EvictionException
- * in the event of problems
- */
- protected void processQueues(BlockingQueue<org.jboss.starobrno.eviction.EvictionEvent> queue) throws org.jboss.starobrno.eviction.EvictionException
- {
- org.jboss.starobrno.eviction.EvictionEvent node;
- int count = 0;
- while ((node = getNextInQueue(queue)) != null)
- {
- count++;
- switch (node.getEventType())
- {
- case ADD_NODE_EVENT:
- this.processAddedNodes(node);
- break;
- case REMOVE_NODE_EVENT:
- this.processRemovedNodes(node);
- break;
- case VISIT_NODE_EVENT:
- this.processVisitedNodes(node);
- break;
- case ADD_ELEMENT_EVENT:
- this.processAddedElement(node);
- break;
- case REMOVE_ELEMENT_EVENT:
- this.processRemovedElement(node);
- break;
- case MARK_IN_USE_EVENT:
- this.processMarkInUseNodes(node.getFqn(), node.getInUseTimeout());
- break;
- case UNMARK_USE_EVENT:
- this.processUnmarkInUseNodes(node.getFqn());
- break;
- default:
- throw new RuntimeException("Illegal Eviction Event type " + node.getEventType());
- }
- }
-
- if (trace) log.trace("processed " + count + " node events");
- }
-
- protected void evict(org.jboss.starobrno.eviction.NodeEntry ne)
- {
-// NodeEntry ne = evictionQueue.getNodeEntry(fqn);
- if (ne != null)
- {
- evictionQueue.removeNodeEntry(ne);
- if (!this.evictCacheNode(ne.getFqn()))
- {
- try
- {
- boolean result = recycleQueue.offer(ne.getFqn(), 5, TimeUnit.SECONDS);
- if (!result)
- {
- log.warn("Unable to add Fqn[" + ne.getFqn() + "] to recycle " +
- "queue because it's full. This is often sign that " +
- "evictions are not occurring and nodes that should be " +
- "evicted are piling up waiting to be evicted.");
- }
- }
- catch (InterruptedException e)
- {
- log.debug("InterruptedException", e);
- }
- }
- }
- }
-
- /**
- * Evict a node from cache.
- *
- * @param fqn node corresponds to this fqn
- * @return True if successful
- */
- protected boolean evictCacheNode(Fqn fqn)
- {
- if (trace) log.trace("Attempting to evict cache node with fqn of " + fqn);
-
- try
- {
- evictionActionPolicy.evict(fqn);
- }
- catch (TimeoutException e)
- {
- log.warn("Eviction of " + fqn + " timed out, retrying later");
- log.debug(e, e);
- return false;
- }
- catch (Exception e)
- {
- log.error("Eviction of " + fqn + " failed", e);
- return false;
- }
-
- if (trace)
- {
- log.trace("Eviction of cache node with fqn of " + fqn + " successful");
- }
-
- return true;
- }
-
- protected void processMarkInUseNodes(Fqn fqn, long inUseTimeout) throws org.jboss.starobrno.eviction.EvictionException
- {
- if (trace)
- {
- log.trace("Marking node " + fqn + " as in use with a usage timeout of " + inUseTimeout);
- }
-
- org.jboss.starobrno.eviction.NodeEntry ne = evictionQueue.getNodeEntry(fqn);
- if (ne != null)
- {
- ne.setCurrentlyInUse(true, inUseTimeout);
- }
- }
-
- protected void processUnmarkInUseNodes(Fqn fqn) throws org.jboss.starobrno.eviction.EvictionException
- {
- if (trace)
- {
- log.trace("Unmarking node " + fqn + " as in use");
- }
-
- org.jboss.starobrno.eviction.NodeEntry ne = evictionQueue.getNodeEntry(fqn);
- if (ne != null)
- {
- ne.setCurrentlyInUse(false, 0);
- }
- }
-
- /**
- * Convenience method, which calls {@link #processAddedNodes(org.jboss.starobrno.eviction.EvictionEvent , int)} using values in the
- * evictedEventNode for number of added elements and the resetElementCount flag.
- *
- * @param evictedEventNode an evictedEventNode to process
- * @throws org.jboss.starobrno.eviction.EvictionException
- * on problems
- */
- protected void processAddedNodes(org.jboss.starobrno.eviction.EvictionEvent evictedEventNode) throws org.jboss.starobrno.eviction.EvictionException
- {
- processAddedNodes(evictedEventNode, evictedEventNode.getElementDifference());
- }
-
- protected void processAddedNodes(org.jboss.starobrno.eviction.EvictionEvent evictedEventNode, int numAddedElements) throws org.jboss.starobrno.eviction.EvictionException
- {
- Fqn fqn = evictedEventNode.getFqn();
-
- if (trace)
- {
- log.trace("Adding node " + fqn + " with " + numAddedElements + " elements to eviction queue");
- }
-
- org.jboss.starobrno.eviction.NodeEntry ne = evictionQueue.getNodeEntry(fqn);
- if (ne != null)
- {
- ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
- ne.setNumberOfNodeVisits(ne.getNumberOfNodeVisits() + 1);
- ne.setNumberOfElements(ne.getNumberOfElements() + numAddedElements);
- if (trace)
- {
- log.trace("Queue already contains " + ne.getFqn() + " processing it as visited");
- }
- processVisitedNodes(evictedEventNode);
- return;
- }
-
- ne = new org.jboss.starobrno.eviction.NodeEntry(fqn);
- ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
- ne.setNumberOfNodeVisits(1);
- ne.setNumberOfElements(numAddedElements);
-
- evictionQueue.addNodeEntry(ne);
-
- if (trace)
- {
- log.trace(ne.getFqn() + " added successfully to eviction queue");
- }
- }
-
- /**
- * Remove a node from cache.
- * <p/>
- * This method will remove the node from the eviction queue as well as
- * evict the node from cache.
- * <p/>
- * If a node cannot be removed from cache, this method will remove it from the eviction queue
- * and place the element into the recycleQueue. Each node in the recycle queue will get retried until
- * proper cache eviction has taken place.
- * <p/>
- * Because EvictionQueues are collections, when iterating them from an iterator, use iterator.remove()
- * to avoid ConcurrentModificationExceptions. Use the boolean parameter to indicate the calling context.
- *
- * @throws org.jboss.starobrno.eviction.EvictionException
- *
- */
- protected void processRemovedNodes(org.jboss.starobrno.eviction.EvictionEvent evictedEventNode) throws org.jboss.starobrno.eviction.EvictionException
- {
- Fqn fqn = evictedEventNode.getFqn();
-
- if (trace)
- {
- log.trace("Removing node " + fqn + " from eviction queue and attempting eviction");
- }
-
- org.jboss.starobrno.eviction.NodeEntry ne = evictionQueue.getNodeEntry(fqn);
- if (ne != null)
- {
- if (allowTombstones)
- {
- // don't remove from the queue - deleting a node results in a tombstone which means the nodes
- // still need to be considered for eviction!
- return;
- }
- else
- {
- // a removeNode operation will simply remove the node. Nothing to worry about.
- evictionQueue.removeNodeEntry(ne);
- }
- }
- else
- {
- if (trace)
- {
- log.trace("processRemoveNodes(): Can't find node associated with fqn: " + fqn
- + "Could have been evicted earlier. Will just continue.");
- }
- return;
- }
-
- if (trace)
- {
- log.trace(fqn + " removed from eviction queue");
- }
- }
-
- /**
- * Visit a node in cache.
- * <p/>
- * This method will update the numVisits and modifiedTimestamp properties of the Node.
- * These properties are used as statistics to determine eviction (LRU, LFU, MRU, etc..)
- * <p/>
- * *Note* that this method updates Node Entries by reference and does not put them back
- * into the queue. For some sorted collections, a remove, and a re-add is required to
- * maintain the sorted order of the elements.
- *
- * @throws org.jboss.starobrno.eviction.EvictionException
- *
- */
- protected void processVisitedNodes(org.jboss.starobrno.eviction.EvictionEvent evictedEventNode) throws org.jboss.starobrno.eviction.EvictionException
- {
- Fqn fqn = evictedEventNode.getFqn();
- org.jboss.starobrno.eviction.NodeEntry ne = evictionQueue.getNodeEntry(fqn);
- if (ne == null)
- {
- if (log.isDebugEnabled())
- {
- log.debug("Visiting node that was not added to eviction queues. Assuming that it has 1 element.");
- }
- this.processAddedNodes(evictedEventNode, 1);
- return;
- }
- // note this method will visit and modify the node statistics by reference!
- // if a collection is only guaranteed sort order by adding to the collection,
- // this implementation will not guarantee sort order.
- ne.setNumberOfNodeVisits(ne.getNumberOfNodeVisits() + 1);
- ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
- }
-
- protected void processRemovedElement(org.jboss.starobrno.eviction.EvictionEvent evictedEventNode) throws org.jboss.starobrno.eviction.EvictionException
- {
- Fqn fqn = evictedEventNode.getFqn();
- org.jboss.starobrno.eviction.NodeEntry ne = evictionQueue.getNodeEntry(fqn);
-
- if (ne == null)
- {
- if (log.isDebugEnabled())
- {
- log.debug("Removing element from " + fqn + " but eviction queue does not contain this node. " +
- "Ignoring removeElement event.");
- }
- return;
- }
-
- ne.setNumberOfElements(ne.getNumberOfElements() - 1);
- // also treat it as a node visit.
- ne.setNumberOfNodeVisits(ne.getNumberOfNodeVisits() + 1);
- ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
- }
-
- protected void processAddedElement(org.jboss.starobrno.eviction.EvictionEvent evictedEventNode) throws org.jboss.starobrno.eviction.EvictionException
- {
- Fqn fqn = evictedEventNode.getFqn();
- org.jboss.starobrno.eviction.NodeEntry ne = evictionQueue.getNodeEntry(fqn);
- if (ne == null)
- {
- if (trace)
- {
- log.trace("Adding element " + fqn + " for a node that doesn't exist yet. Process as an add.");
- }
- this.processAddedNodes(evictedEventNode, 1);
- return;
- }
-
- ne.setNumberOfElements(ne.getNumberOfElements() + 1);
-
- // also treat it as a node visit.
- ne.setNumberOfNodeVisits(ne.getNumberOfNodeVisits() + 1);
- ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
-// log.error ("*** Processing nodeAdded for fqn " + fqn + " NodeEntry's hashcode is " + ne.hashCode());
- }
-
-
- /**
- * Empty the Recycle Queue.
- * <p/>
- * This method will go through the recycle queue and retry to evict the nodes from cache.
- *
- * @throws org.jboss.starobrno.eviction.EvictionException
- *
- */
- protected void emptyRecycleQueue() throws org.jboss.starobrno.eviction.EvictionException
- {
- while (true)
- {
- Fqn fqn;
-
- try
- {
- //fqn = (Fqn) recycleQueue.take();
- fqn = recycleQueue.poll(0, TimeUnit.SECONDS);
- }
- catch (InterruptedException e)
- {
- log.debug(e, e);
- break;
- }
-
- if (fqn == null)
- {
- if (trace)
- {
- log.trace("Recycle queue is empty");
- }
- break;
- }
-
- if (trace)
- {
- log.trace("emptying recycle bin. Evict node " + fqn);
- }
-
- // Still doesn't work
- if (!evictCacheNode(fqn))
- {
- try
- {
- recycleQueue.put(fqn);
- }
- catch (InterruptedException e)
- {
- log.debug(e, e);
- }
- break;
- }
- }
- }
-
- protected boolean isNodeInUseAndNotTimedOut(org.jboss.starobrno.eviction.NodeEntry ne)
- {
- if (ne.isCurrentlyInUse())
- {
- if (ne.getInUseTimeoutTimestamp() == 0)
- {
- return true;
- }
-
- if (System.currentTimeMillis() < ne.getInUseTimeoutTimestamp())
- {
- return true;
- }
- }
- return false;
- }
-
- protected void prune() throws org.jboss.starobrno.eviction.EvictionException
- {
- org.jboss.starobrno.eviction.NodeEntry entry;
- while ((entry = evictionQueue.getFirstNodeEntry()) != null)
- {
- if (this.shouldEvictNode(entry))
- {
- this.evict(entry);
- }
- else
- {
- break;
- }
- }
- }
-
- /**
- * Returns debug information.
- */
- @Override
- public String toString()
- {
- return super.toString() +
- " recycle=" + recycleQueue.size() +
- " evict=" + evictionQueue.getNumberOfNodes();
- }
-
- /**
- * Tests whether a node entry is younger than the minimum time to live - if one is configured.
- *
- * @param entry the node entry being examined
- * @return true if the node is younger than - or exactly equal to - the minimum time to live, if one is configured for the given region. False otherwise.
- */
- protected boolean isYoungerThanMinimumTimeToLive(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- if (evictionAlgorithmConfig instanceof org.jboss.starobrno.eviction.EvictionAlgorithmConfigBase)
- {
- org.jboss.starobrno.eviction.EvictionAlgorithmConfigBase cfg = (org.jboss.starobrno.eviction.EvictionAlgorithmConfigBase) evictionAlgorithmConfig;
- long minTTL = cfg.getMinTimeToLive();
- return minTTL >= 1 && (entry.getModifiedTimeStamp() + minTTL > System.currentTimeMillis());
- }
- else
- {
- log.trace("Eviction policy implementation does not support minimum TTL!");
- return false;
- }
- }
-}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseSortedEvictionAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseSortedEvictionAlgorithm.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseSortedEvictionAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,126 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.concurrent.BlockingQueue;
-
-
-/**
- * An abstract SortedEvictionAlgorithm.
- * <p/>
- * This class supports early termination of the eviction queue processing. Because the eviction
- * queue is sorted by first to evict to last to evict, when iterating the eviction queue, the first time
- * a node is encountered that does not require eviction will terminate the loop early. This way we don't incur
- * the full breadth of the O(n) = n operation everytime we need to check for eviction (defined by eviction poll time
- * interval).
- *
- * @author Daniel Huang - dhuang(a)jboss.org - 10/2005
- */
-public abstract class BaseSortedEvictionAlgorithm extends BaseEvictionAlgorithm
-{
- private static final Log log = LogFactory.getLog(BaseSortedEvictionAlgorithm.class);
- private static final boolean trace = log.isTraceEnabled();
-
- @Override
- protected void processQueues(BlockingQueue<org.jboss.starobrno.eviction.EvictionEvent> queue) throws org.jboss.starobrno.eviction.EvictionException
- {
- boolean evictionNodesModified = false;
-
- org.jboss.starobrno.eviction.EvictionEvent node;
- int count = 0;
- while ((node = getNextInQueue(queue)) != null)
- {
- count++;
- switch (node.getEventType())
- {
- case ADD_NODE_EVENT:
- this.processAddedNodes(node);
- evictionNodesModified = true;
- break;
- case REMOVE_NODE_EVENT:
- this.processRemovedNodes(node);
- break;
- case VISIT_NODE_EVENT:
- this.processVisitedNodes(node);
- evictionNodesModified = true;
- break;
- case ADD_ELEMENT_EVENT:
- this.processAddedElement(node);
- evictionNodesModified = true;
- break;
- case REMOVE_ELEMENT_EVENT:
- this.processRemovedElement(node);
- evictionNodesModified = true;
- break;
- default:
- throw new RuntimeException("Illegal Eviction Event type " + node.getEventType());
- }
- }
-
- if (trace)
- {
- log.trace("Eviction nodes visited or added requires resort of queue " + evictionNodesModified);
- }
-
- this.resortEvictionQueue(evictionNodesModified);
-
-
- if (trace)
- {
- log.trace("processed " + count + " node events");
- }
-
- }
-
- /**
- * This method is called to resort the queue after add or visit events have occurred.
- * <p/>
- * If the parameter is true, the queue needs to be resorted. If it is false, the queue does not
- * need resorting.
- *
- * @param evictionQueueModified True if the queue was added to or visisted during event processing.
- */
- protected void resortEvictionQueue(boolean evictionQueueModified)
- {
- if (!evictionQueueModified)
- {
- if (log.isDebugEnabled())
- {
- log.debug("Eviction queue not modified. Resort unnecessary.");
- }
- return;
- }
- long begin = System.currentTimeMillis();
- ((org.jboss.starobrno.eviction.SortedEvictionQueue) evictionQueue).resortEvictionQueue();
- long end = System.currentTimeMillis();
-
- if (trace)
- {
- long diff = end - begin;
- log.trace("Took " + diff + "ms to sort queue with " + getEvictionQueue().getNumberOfNodes() + " elements");
- }
- }
-
-}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/DefaultEvictionAction.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/DefaultEvictionActionPolicy.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/DefaultEvictionAction.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/DefaultEvictionAction.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.starobrno.Cache;
+
+/**
+ * Default eviction action policy that calls {@link org.jboss.cache.Cache_Legacy#evict(org.jboss.cache.Fqn)} to evict a node.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class DefaultEvictionAction<K> implements EvictionAction<K>
+{
+ private static final Log log = LogFactory.getLog(DefaultEvictionAction.class);
+ private static boolean trace = log.isTraceEnabled();
+ private Cache<K, ?> cache;
+
+ public void setCache(Cache<K, ?> cache)
+ {
+ this.cache = cache;
+ }
+
+ public boolean evict(K key)
+ {
+ if (trace) log.trace("Attempting to evict cache node with key of " + key);
+
+ try
+ {
+ cache.evict(key);
+ log.trace("Eviction of cache node with key of " + key + " successful");
+ return true;
+ }
+ catch (Exception e)
+ {
+ if (log.isDebugEnabled()) log.debug("Unable to evict " + key, e);
+ return false;
+ }
+ }
+}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/DefaultEvictionActionPolicy.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/DefaultEvictionActionPolicy.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/DefaultEvictionActionPolicy.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,59 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Cache_Legacy;
-import org.jboss.cache.Fqn;
-
-/**
- * Default eviction action policy that calls {@link org.jboss.cache.Cache_Legacy#evict(org.jboss.cache.Fqn)} to evict a node.
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @since 3.0
- */
-public class DefaultEvictionActionPolicy implements EvictionActionPolicy
-{
- Cache_Legacy<?, ?> cache;
- private static final Log log = LogFactory.getLog(DefaultEvictionActionPolicy.class);
-
- public void setCache(Cache_Legacy<?, ?> cache)
- {
- this.cache = cache;
- }
-
- public boolean evict(Fqn fqn)
- {
- try
- {
- if (log.isTraceEnabled()) log.trace("Evicting Fqn " + fqn);
- cache.evict(fqn);
- return true;
- }
- catch (Exception e)
- {
- if (log.isDebugEnabled()) log.debug("Unable to evict " + fqn, e);
- return false;
- }
- }
-}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithm.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,62 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.jboss.starobrno.config.EvictionAlgorithmConfig;
-
-/**
- * @author Daniel Huang
- * @version $Revision: 6776 $
- */
-public class ElementSizeAlgorithm extends BaseSortedEvictionAlgorithm
-{
- @Override
- protected org.jboss.starobrno.eviction.EvictionQueue setupEvictionQueue() throws org.jboss.starobrno.eviction.EvictionException
- {
- return new org.jboss.starobrno.eviction.ElementSizeQueue();
- }
-
- @Override
- protected boolean shouldEvictNode(org.jboss.starobrno.eviction.NodeEntry ne)
- {
- // check the minimum time to live and see if we should not evict the node. This check will
- // ensure that, if configured, nodes are kept alive for at least a minimum period of time.
- if (isYoungerThanMinimumTimeToLive(ne)) return false;
- int size = this.getEvictionQueue().getNumberOfNodes();
- org.jboss.starobrno.eviction.ElementSizeAlgorithmConfig config = (org.jboss.starobrno.eviction.ElementSizeAlgorithmConfig) evictionAlgorithmConfig;
- return config.getMaxNodes() > -1 && size > config.getMaxNodes() || ne.getNumberOfElements() > config.getMaxElementsPerNode();
- }
-
- @Override
- protected void prune() throws org.jboss.starobrno.eviction.EvictionException
- {
- super.prune();
-
- // clean up the Queue's eviction removals
- ((org.jboss.starobrno.eviction.ElementSizeQueue) this.evictionQueue).prune();
- }
-
- public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
- {
- return ElementSizeAlgorithmConfig.class;
- }
-}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithmConfig.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithmConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -23,9 +23,10 @@
import org.jboss.starobrno.config.ConfigurationException;
import org.jboss.starobrno.config.Dynamic;
+import org.jboss.starobrno.eviction.algorithms.ElementSizeAlgorithm;
/**
- * Configuration for {@link org.jboss.starobrno.eviction.ElementSizeAlgorithm}.
+ * Configuration for {@link org.jboss.starobrno.eviction.algorithms.ElementSizeAlgorithm}.
* <p/>
* Requires a positive "maxElementsPerNode" value otherwise a ConfigurationException is thrown.
*
@@ -44,7 +45,7 @@
public ElementSizeAlgorithmConfig()
{
- evictionAlgorithmClassName = org.jboss.starobrno.eviction.ElementSizeAlgorithm.class.getName();
+ evictionAlgorithmClassName = ElementSizeAlgorithm.class.getName();
// Force configuration of maxElementsPerNode
setMaxElementsPerNode(-1);
}
@@ -116,7 +117,7 @@
{
super.reset();
setMaxElementsPerNode(-1);
- evictionAlgorithmClassName = org.jboss.starobrno.eviction.ElementSizeAlgorithm.class.getName();
+ evictionAlgorithmClassName = ElementSizeAlgorithm.class.getName();
}
@Override
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeQueue.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeQueue.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -21,38 +21,28 @@
*/
package org.jboss.starobrno.eviction;
-import org.jboss.cache.Fqn;
+import org.jboss.starobrno.eviction.algorithms.SortedEvictionQueue;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
+import java.util.*;
/**
* @author Daniel Huang
- * @version $Revision: 6776 $
*/
-public class ElementSizeQueue implements SortedEvictionQueue
+public class ElementSizeQueue<K> implements SortedEvictionQueue<K>
{
- private Map<Fqn, org.jboss.starobrno.eviction.NodeEntry> nodeMap;
- private LinkedList<org.jboss.starobrno.eviction.NodeEntry> evictionList;
- private Comparator<org.jboss.starobrno.eviction.NodeEntry> comparator;
+ private Map<K, KeyEntry<K>> nodeMap;
+ private LinkedList<KeyEntry<K>> evictionList;
+ private Comparator<KeyEntry> comparator;
- private Set<org.jboss.starobrno.eviction.NodeEntry> removalQueue;
+ private Set<KeyEntry> removalQueue;
private int numElements = 0;
- protected ElementSizeQueue()
+ public ElementSizeQueue()
{
- nodeMap = new HashMap<Fqn, org.jboss.starobrno.eviction.NodeEntry>();
- evictionList = new LinkedList<org.jboss.starobrno.eviction.NodeEntry>();
+ nodeMap = new HashMap<K, KeyEntry<K>>();
+ evictionList = new LinkedList<KeyEntry<K>>();
comparator = new MaxElementComparator();
- removalQueue = new HashSet<org.jboss.starobrno.eviction.NodeEntry>();
+ removalQueue = new HashSet<KeyEntry>();
}
public void resortEvictionQueue()
@@ -60,19 +50,18 @@
Collections.sort(evictionList, comparator);
}
- public org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry()
+ public KeyEntry<K> getFirstNodeEntry()
{
try
{
- org.jboss.starobrno.eviction.NodeEntry ne;
+ KeyEntry<K> ne;
while ((ne = evictionList.getFirst()) != null)
{
if (removalQueue.contains(ne))
{
evictionList.removeFirst();
removalQueue.remove(ne);
- }
- else
+ } else
{
break;
}
@@ -83,29 +72,23 @@
{
//
}
-
return null;
}
- public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn)
+ public KeyEntry<K> getNodeEntry(K key)
{
- return nodeMap.get(fqn);
+ return nodeMap.get(key);
}
- public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn)
+ public boolean containsNodeEntry(KeyEntry<K> entry)
{
- return this.getNodeEntry(Fqn.fromString(fqn));
+ K key = entry.getKey();
+ return this.getNodeEntry(key) != null;
}
- public boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ public void removeNodeEntry(KeyEntry<K> entry)
{
- Fqn fqn = entry.getFqn();
- return this.getNodeEntry(fqn) != null;
- }
-
- public void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- org.jboss.starobrno.eviction.NodeEntry ne = nodeMap.remove(entry.getFqn());
+ KeyEntry ne = nodeMap.remove(entry.getKey());
if (ne != null)
{
// don't remove directly from the LinkedList otherwise we will incur a O(n) = n
@@ -121,13 +104,12 @@
}
}
- public void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ public void addNodeEntry(KeyEntry<K> entry)
{
if (!this.containsNodeEntry(entry))
{
- Fqn fqn = entry.getFqn();
- entry.queue = this;
- nodeMap.put(fqn, entry);
+ K key = entry.getKey();
+ nodeMap.put(key, entry);
evictionList.add(entry);
this.numElements += entry.getNumberOfElements();
}
@@ -155,20 +137,20 @@
removalQueue.clear();
this.numElements = 0;
}
-
- protected final List<org.jboss.starobrno.eviction.NodeEntry> getEvictionList()
+
+ protected final List<KeyEntry<K>> getEvictionList()
{
return evictionList;
}
- protected final Set<org.jboss.starobrno.eviction.NodeEntry> getRemovalQueue()
+ protected final Set<KeyEntry> getRemovalQueue()
{
return removalQueue;
}
- protected final void prune()
+ public final void prune()
{
- Iterator<org.jboss.starobrno.eviction.NodeEntry> it = evictionList.iterator();
+ Iterator<KeyEntry<K>> it = evictionList.iterator();
while (it.hasNext() && removalQueue.size() > 0)
{
if (removalQueue.remove(it.next()))
@@ -178,7 +160,7 @@
}
}
- public Iterator<org.jboss.starobrno.eviction.NodeEntry> iterator()
+ public Iterator<KeyEntry<K>> iterator()
{
return evictionList.iterator();
}
@@ -194,37 +176,31 @@
* Note: this class has a natural ordering that is inconsistent with equals as defined by the java.lang.Comparator
* contract.
*/
- protected static class MaxElementComparator implements Comparator<org.jboss.starobrno.eviction.NodeEntry>
+ protected static class MaxElementComparator implements Comparator<KeyEntry>
{
- public int compare(org.jboss.starobrno.eviction.NodeEntry ne1, org.jboss.starobrno.eviction.NodeEntry ne2)
+ public int compare(KeyEntry ne1, KeyEntry ne2)
{
if (ne1.equals(ne2))
{
return 0;
}
-
int neNumElements = ne1.getNumberOfElements();
int neNumElements2 = ne2.getNumberOfElements();
if (neNumElements > neNumElements2)
{
return -1;
- }
- else if (neNumElements < neNumElements2)
+ } else if (neNumElements < neNumElements2)
{
return 1;
- }
- else if (neNumElements == neNumElements2)
+ } else if (neNumElements == neNumElements2)
{
return 0;
}
-
throw new RuntimeException("Should never reach this condition");
}
-
}
-
}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAction.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionActionPolicy.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAction.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAction.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.starobrno.Cache;
+
+/**
+ * Performs an eviction on a given Fqn.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public interface EvictionAction<K>
+{
+ /**
+ * Sets a reference to the cache.
+ *
+ * @param cache cache
+ */
+ void setCache(Cache<K, ?> cache);
+
+ /**
+ * Performs an eviction on a given node.
+ *
+ * @return true if the eviction was successful, false if not.
+ */
+ boolean evict(K key);
+}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionActionPolicy.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionActionPolicy.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionActionPolicy.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,49 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.jboss.cache.Cache_Legacy;
-import org.jboss.cache.Fqn;
-
-/**
- * Performs an eviction on a given Fqn.
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @since 3.0
- */
-public interface EvictionActionPolicy
-{
- /**
- * Sets a reference to the cache.
- *
- * @param cache cache
- */
- void setCache(Cache_Legacy<?, ?> cache);
-
- /**
- * Performs an eviction on a given node.
- *
- * @param fqn fqn to evict
- * @return true if the eviction was successful, false if not.
- */
- boolean evict(Fqn fqn);
-}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAlgorithm.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -21,8 +21,7 @@
*/
package org.jboss.starobrno.eviction;
-import org.jboss.cache.CacheSPI_Legacy;
-import org.jboss.cache.Fqn;
+import org.jboss.starobrno.CacheSPI;
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.EvictionAlgorithmConfig;
import org.jboss.starobrno.eviction.EvictionEvent.Type;
@@ -37,17 +36,14 @@
*
* @author Ben Wang 2-2004
* @author Daniel Huang - dhuang(a)jboss.org - 10/2005
- * @version $Revision: 6776 $
*/
-public interface EvictionAlgorithm
+public interface EvictionAlgorithm<K>
{
/**
* Entry point for eviction algorithm. Invoking this will cause the algorithm to process the queue of {@link EvictionEvent}
* passed in.
- *
- * @param queue to process
*/
- void process(BlockingQueue<EvictionEvent> queue) throws org.jboss.starobrno.eviction.EvictionException;
+ void process(BlockingQueue<EvictionEvent<K>> queue) throws EvictionException;
/**
* Reset the whole eviction queue. The queue may need to be reset due to corrupted state, for example.
@@ -56,27 +52,18 @@
/**
* Get the EvictionQueue implementation used by this algorithm.
- *
- * @return the EvictionQueue implementation.
*/
- org.jboss.starobrno.eviction.EvictionQueue getEvictionQueue();
+ EvictionQueue getEvictionQueue();
/**
* Sets the eviction action policy, so the algorithm knows what to do when a node is to be evicted.
- *
- * @param evictionActionPolicy to set
*/
- void setEvictionActionPolicy(org.jboss.starobrno.eviction.EvictionActionPolicy evictionActionPolicy);
+ void setEvictionAction(EvictionAction<K> evictionAction);
/**
- * Assigns the algorithm instance to a specific region.
- *
- * @param fqn of the region to be assigned to
- * @param cache cache reference
- * @param evictionAlgorithmConfig configuration for the current algorithm instance.
- * @param configuration for the entire cache.
+ * Assigns the algorithm instance to a given Cache.
*/
- void assignToRegion(Fqn fqn, CacheSPI_Legacy<?, ?> cache, EvictionAlgorithmConfig evictionAlgorithmConfig, Configuration configuration);
+ void assignToCache(CacheSPI<K, ?> cache, EvictionAlgorithmConfig evictionAlgorithmConfig);
/**
* Tests whether the algorithm would ignore certain event types on certain Fqns.
@@ -91,11 +78,5 @@
*/
void initialize();
- /**
- * This is a helper so that the XML parser will be able to select and use the correct {@link org.jboss.cache.config.EvictionAlgorithmConfig} implementation
- * class corresponding to this EvictionAlgorithm. E.g., the {@link FIFOAlgorithm} would return {@link FIFOAlgorithmConfig}.class.
- *
- * @return a class that is used to configure this EvictionAlgorithm.
- */
Class<? extends EvictionAlgorithmConfig> getConfigurationClass();
}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionCacheManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionCacheManager.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionCacheManager.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,63 @@
+package org.jboss.starobrno.eviction;
+
+import org.jboss.starobrno.config.EvictionCacheConfig;
+import org.jboss.cache.Fqn;
+
+/**
+ * There is one eviction manager per cache.
+ * @author Mircea.Markus(a)jboss.com
+ */
+public interface EvictionCacheManager<K>
+{
+ /**
+ * Processes the eviction queues (primary and recycle queues) associated with this cache.
+ */
+ void processEvictionQueues();
+
+ /**
+ * Clears the node event queue used for processing eviction.
+ */
+ void resetEvictionQueues();
+
+ /**
+ * Configures this EvictionCacheManager for eviction.
+ *
+ * @param evictionCacheConfig configuration to set
+ */
+ void configure(EvictionCacheConfig evictionCacheConfig);
+
+ /**
+ * Registers an eviction event on the cache's eviction event queue for later processing by
+ * {@link #processEvictionQueues()}.
+ */
+ EvictionEvent registerEvictionEvent(K key, EvictionEvent.Type eventType, int elementDifference);
+
+ /**
+ * An overloaded version of {@link #registerEvictionEvent(String, org.jboss.starobrno.eviction.EvictionEvent.Type, int)} which
+ * uses a default elementDifference value.
+ *
+ * @param eventType passed in to the constructor of {@link org.jboss.starobrno.eviction.EvictionEvent}
+ * @return an EvictedEventNode that has been created for this queue
+ */
+ EvictionEvent registerEvictionEvent(K key, EvictionEvent.Type eventType);
+
+ /**
+ * Marks a {@link org.jboss.cache.Node} as currently in use, by adding an event to the eviction queue.
+ * If there is an {@link org.jboss.cache.config.EvictionRegionConfig} associated with this cahe, and
+ * it respects this event (e.g., {@link org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm} does), then the {@link org.jboss.cache.Node} will not
+ * be evicted until {@link #unmarkNodeCurrentlyInUse(Fqn)} is invoked.
+ * <p/>
+ * This mechanism can be used to prevent eviction of data that the application
+ * is currently using, in the absence of any locks on the {@link org.jboss.cache.Node} where the
+ * data is stored.
+ */
+ void markNodeCurrentlyInUse(K key, long timeout);
+
+ /**
+ * Adds an event to the eviction queue indicating that a node is no longer in use.
+ *
+ * @param key Fqn of the node.
+ */
+ void unmarkNodeCurrentlyInUse(K key);
+}
+
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionCacheManagerImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionCacheManagerImpl.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionCacheManagerImpl.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,143 @@
+package org.jboss.starobrno.eviction;
+
+import org.jboss.starobrno.config.EvictionCacheConfig;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+import org.jboss.starobrno.util.Util;
+import org.jboss.starobrno.CacheSPI;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class EvictionCacheManagerImpl<K> implements EvictionCacheManager<K>
+{
+ private static Log log = LogFactory.getLog(EvictionCacheManagerImpl.class);
+ private static boolean trace = log.isTraceEnabled();
+
+ private BlockingQueue<EvictionEvent<K>> evictionEventQueue = null;
+ private int capacityWarnThreshold = 0;
+ private EvictionCacheConfig evictionCacheConfig;
+ private EvictionAlgorithm<K> evictionAlgorithm;
+ private CacheSPI<K,?> cache;
+
+ public EvictionCacheManagerImpl(CacheSPI<K, ?> cache)
+ {
+ this.cache = cache;
+ }
+
+ public void processEvictionQueues()
+ {
+ evictionAlgorithm.process(evictionEventQueue);
+ }
+
+ public void resetEvictionQueues()
+ {
+ evictionEventQueue.clear();
+ }
+
+ public EvictionEvent registerEvictionEvent(K key, EvictionEvent.Type eventType, int elementDifference)
+ {
+ if (evictionAlgorithm.canIgnoreEvent(eventType)) return null;
+ EvictionEvent<K> event = new EvictionEvent<K>(key, eventType, elementDifference);
+ registerEvictionEvent(event);
+ return event;
+ }
+
+ public EvictionEvent registerEvictionEvent(K key, EvictionEvent.Type eventType)
+ {
+ return registerEvictionEvent(key, eventType, 0);
+ }
+
+ public void markNodeCurrentlyInUse(K key, long timeout)
+ {
+ registerEvictionEvent(key, EvictionEvent.Type.MARK_IN_USE_EVENT, 0).setInUseTimeout(timeout);
+ }
+
+ public void unmarkNodeCurrentlyInUse(K key)
+ {
+ registerEvictionEvent(key, EvictionEvent.Type.UNMARK_USE_EVENT, 0);
+ }
+
+ public void configure(EvictionCacheConfig evictionCacheConfig)
+ {
+ this.evictionCacheConfig = evictionCacheConfig;
+ evictionAlgorithm = createEvictionAlgorithm(evictionCacheConfig.getEvictionAlgorithmConfig(), evictionCacheConfig.getEvictionActionClassName());
+ if (evictionEventQueue == null) createQueue();
+ evictionAlgorithm.initialize();
+ }
+
+ private void registerEvictionEvent(EvictionEvent<K> ee)
+ {
+ try
+ {
+ createQueue();// in case the queue does not exist yet.
+ if (evictionEventQueue.size() > capacityWarnThreshold)
+ {
+ if (log.isWarnEnabled())
+ log.warn("putNodeEvent(): eviction node event queue size is at 98% threshold value of capacity: " + evictionCacheConfig.getEventQueueSize() +
+ " Cache name: " + cache.getName() + " You will need to reduce the wakeUpIntervalSeconds parameter.");
+ }
+ evictionEventQueue.put(ee);
+ }
+ catch (InterruptedException e)
+ {
+ if (log.isDebugEnabled()) log.debug("Interrupted on adding event", e);
+ // reinstate interrupt flag
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ private void createQueue()
+ {
+ if (evictionEventQueue == null)
+ {
+ if (evictionCacheConfig == null)
+ {
+ throw new IllegalArgumentException("null eviction configuration");
+ }
+ int size = evictionCacheConfig.getEventQueueSize();
+ capacityWarnThreshold = (98 * size) / 100 - 100;
+ if (capacityWarnThreshold <= 0)
+ {
+ if (log.isWarnEnabled()) log.warn("Capacity warn threshold used in eviction is smaller than 1.");
+ }
+ evictionEventQueue = new LinkedBlockingQueue<EvictionEvent<K>>(size);
+ }
+ }
+
+ private EvictionAlgorithm<K> createEvictionAlgorithm(EvictionAlgorithmConfig algoConfig, String evictionActionClass)
+ {
+ if (algoConfig == null)
+ throw new IllegalArgumentException("Eviction algorithm class must not be null!");
+
+ if (evictionActionClass == null)
+ throw new IllegalArgumentException("Eviction action policy class must not be null!");
+
+ try
+ {
+ if (trace) log.trace("Instantiating " + evictionActionClass);
+ EvictionAction<K> evictionAction = (EvictionAction<K>) Util.getInstance(evictionActionClass);
+ evictionAction.setCache(cache);
+
+ if (trace) log.trace("Instantiating " + algoConfig.getEvictionAlgorithmClassName());
+ EvictionAlgorithm<K> algorithm = (EvictionAlgorithm) Util.getInstance(algoConfig.getEvictionAlgorithmClassName());
+ algorithm.setEvictionAction(evictionAction);
+ algorithm.assignToCache(cache, algoConfig);
+ return algorithm;
+ }
+ catch (Exception e)
+ {
+ log.fatal("Unable to instantiate eviction algorithm " + algoConfig.getEvictionAlgorithmClassName(), e);
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public String getCacheName()
+ {
+ return cache.getName();
+ }
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionEvent.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionEvent.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionEvent.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -30,9 +30,9 @@
*
* @see org.jboss.cache.Region
*/
-public class EvictionEvent
+public class EvictionEvent<K>
{
- private Fqn fqn;
+ private K key;
private Type type;
private int elementDifference;
@@ -54,9 +54,9 @@
UNMARK_USE_EVENT
}
- public EvictionEvent(Fqn fqn, Type type, int elementDifference)
+ public EvictionEvent(K key, Type type, int elementDifference)
{
- this.fqn = fqn;
+ this.key = key;
this.type = type;
this.elementDifference = elementDifference;
this.creationTimestamp = System.currentTimeMillis();
@@ -87,14 +87,14 @@
this.elementDifference = elementDifference;
}
- public Fqn getFqn()
+ public K getKey()
{
- return fqn;
+ return key;
}
- public void setFqn(Fqn fqn)
+ public void setKey(K key)
{
- this.fqn = fqn;
+ this.key = key;
}
public void setEventType(Type event)
@@ -110,18 +110,18 @@
@Override
public String toString()
{
- return "EvictedEventNode[fqn=" + fqn + " event=" + type + " diff=" + elementDifference + "]";
+ return "EvictedEventNode[key=" + key + " event=" + type + " diff=" + elementDifference + "]";
}
/**
* Copies this evicted event node to create a new one with the same values, except with a new Fqn root.
*
- * @param newRoot new Fqn root to use
+ * @param key new Fqn root to use
* @return a new EvictedEventNode instance
* @see org.jboss.cache.Region#copy(org.jboss.cache.Fqn)
*/
- public EvictionEvent copy(Fqn newRoot)
+ public EvictionEvent copy(K key)
{
- return new EvictionEvent(Fqn.fromRelativeFqn(newRoot, fqn), type, elementDifference);
+ return new EvictionEvent<K>(key, type, elementDifference);
}
}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionListEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionListEntry.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionListEntry.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,67 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-/**
- * // TODO: MANIK: Document this
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @since 3.0
- */
-class EvictionListEntry
-{
- EvictionListEntry next;
- EvictionListEntry previous;
-
- NodeEntry node;
-
- EvictionListEntry()
- {
- }
-
- EvictionListEntry(NodeEntry node)
- {
- this.node = node;
- }
-
- @Override
- public boolean equals(Object o)
- {
- if (!(o instanceof EvictionListEntry))
- return false;
- EvictionListEntry entry = (EvictionListEntry) o;
- return this.node.getFqn().equals(entry.node.getFqn());
- }
-
- @Override
- public int hashCode()
- {
- return this.node.getFqn().hashCode();
- }
-
- @Override
- public String toString()
- {
- return "EntryLE=" + node;
- }
-
-}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionManagerImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionManagerImpl.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionManagerImpl.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,79 @@
+package org.jboss.starobrno.eviction;
+
+import net.jcip.annotations.ThreadSafe;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.starobrno.EvictionManager;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+@ThreadSafe
+public class EvictionManagerImpl implements EvictionManager
+{
+ private static Log log = LogFactory.getLog(EvictionManagerImpl.class);
+ private boolean externalEvictionThread;
+ private EvictionTimerTask evictionTimerTask;
+ private final Map<String, EvictionCacheManager> evictionCacheManagers = new HashMap<String, EvictionCacheManager>(4);
+ private ThreadFactory threadFactory;
+ private long wakeUpInterval;
+
+ public synchronized void configureEvictionThread(long wakeUpInterval, ThreadFactory threadFactory)
+ {
+ if (wakeUpInterval <= 0)
+ {
+ log.info("wakeUpInterval is <= 0, not starting eviction thread");
+ externalEvictionThread = true;
+ return;
+ }
+ this.wakeUpInterval = wakeUpInterval;
+ this.threadFactory = threadFactory;
+ evictionTimerTask = new EvictionTimerTask(this);
+ }
+
+ public synchronized void cacheCreated(String cacheName, EvictionCacheManager cacheManager)
+ {
+ if (!externalEvictionThread && evictionCacheManagers.isEmpty())//this is the first cache to be added, also start ev thread here
+ {
+ evictionTimerTask.init(wakeUpInterval, threadFactory);
+ }
+ evictionCacheManagers.put(cacheName, cacheManager);
+ }
+
+ public synchronized void cacheStopped(String cacheName)
+ {
+ if (evictionCacheManagers.remove(cacheName) == null)
+ {
+ throw new IllegalStateException("Attempting to stop an unregistred cache: " + cacheName);
+ }
+ if (!externalEvictionThread && evictionCacheManagers.isEmpty())
+ {
+ evictionTimerTask.stop();
+ }
+ }
+
+ public void runEviction()
+ {
+ synchronized (evictionCacheManagers)
+ {
+ for (EvictionCacheManager evictionCacheManager : evictionCacheManagers.values())
+ {
+ try
+ {
+ evictionCacheManager.processEvictionQueues();
+ }
+ catch (EvictionException e)
+ {
+ //we cannot die in peace here, as this is not the main thread and the user won't get informed...
+ log.error("run(): error processing eviction with exception: " + e.toString()
+ + " will reset the eviction queue list.", e);
+ evictionCacheManager.resetEvictionQueues();
+ }
+ }
+ }
+ }
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueue.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueue.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -21,9 +21,6 @@
*/
package org.jboss.starobrno.eviction;
-import org.jboss.cache.Fqn;
-
-
/**
* Eviction Queue interface defines a contract for the Eviction Queue implementations used by EvictionPolicies.
* <p/>
@@ -33,7 +30,7 @@
* @author Daniel Huang (dhuang(a)jboss.org)
* @version $Revision: 6776 $
*/
-public interface EvictionQueue extends Iterable<org.jboss.starobrno.eviction.NodeEntry>
+public interface EvictionQueue<K> extends Iterable<KeyEntry<K>>
{
/**
* Get the first entry in the queue.
@@ -44,19 +41,17 @@
*
* @return first NodeEntry in queue.
*/
- org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry();
+ KeyEntry<K> getFirstNodeEntry();
/**
* Retrieve a node entry by Fqn.
* <p/>
* This will return null if the entry is not found.
*
- * @param fqn Fqn of the node entry to retrieve.
* @return Node Entry object associated with given Fqn param.
*/
- org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn);
+ KeyEntry<K> getNodeEntry(K key);
- org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn);
/**
* Check if queue contains the given NodeEntry.
@@ -64,7 +59,7 @@
* @param entry NodeEntry to check for existence in queue.
* @return true/false if NodeEntry exists in queue.
*/
- boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry);
+ boolean containsNodeEntry(KeyEntry<K> entry);
/**
* Remove a NodeEntry from queue.
@@ -73,14 +68,14 @@
*
* @param entry The NodeEntry to remove from queue.
*/
- void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry);
+ void removeNodeEntry(KeyEntry<K> entry);
/**
* Add a NodeEntry to the queue.
*
* @param entry The NodeEntry to add to queue.
*/
- void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry);
+ void addNodeEntry(KeyEntry<K> entry);
/**
* Get the number of nodes in the queue.
@@ -102,5 +97,4 @@
* Clear the queue.
*/
void clear();
-
}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueueList.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueueList.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueueList.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,349 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-import java.util.ListIterator;
-import java.util.NoSuchElementException;
-
-/**
- * @author Daniel Huang (dhuang(a)jboss.org)
- * @version $Revision: 6776 $
- */
-public class EvictionQueueList
-{
- EvictionListEntry head;
- EvictionListEntry tail;
- int modCount;
- private int size;
-
- EvictionQueueList()
- {
- head = null;
- tail = null;
- size = 0;
- modCount = 0;
- }
-
- void addToTop(EvictionListEntry entry)
- {
- EvictionListEntry formerHead = head;
- head = entry;
- // if there was no previous head then this list was empty.
- if (formerHead != null)
- {
- formerHead.previous = head;
- head.next = formerHead;
- head.previous = null;
- }
- else
- {
- tail = entry;
- }
- size++;
- modCount++;
- }
-
- void addToBottom(EvictionListEntry entry)
- {
- EvictionListEntry formerTail = tail;
- tail = entry;
- // if there was no previous head then this list was empty.
- if (formerTail != null)
- {
- tail.previous = formerTail;
- formerTail.next = tail;
- tail.next = null;
- }
- else
- {
- head = entry;
- }
- size++;
- modCount++;
- }
-
- void remove(EvictionListEntry entry)
- {
- if (this.isEmpty())
- {
- return;
- }
-
- if (isSingleNode(entry))
- {
- head = null;
- tail = null;
- }
- else if (isTail(entry))
- {
- tail = entry.previous;
- // unlink the last node.
- entry.previous.next = null;
- }
- else if (isHead(entry))
- {
- head = entry.next;
- head.previous = null;
- }
- else
- {
- // node is in between two other nodes.
- entry.next.previous = entry.previous;
- entry.previous.next = entry.next;
- }
- size--;
- modCount++;
- }
-
- int size()
- {
- return this.size;
- }
-
- void clear()
- {
- head = null;
- tail = null;
- size = 0;
- modCount++;
- }
-
- EvictionListEntry getFirst()
- {
- if (head == null)
- {
- throw new NoSuchElementException("List is empty");
- }
- return head;
- }
-
- EvictionListEntry getLast()
- {
- if (tail == null)
- {
- throw new NoSuchElementException("List is empty");
- }
- return tail;
- }
-
- Iterator<NodeEntry> iterator()
- {
- return new EvictionListIterator();
- }
-
- NodeEntry[] toNodeEntryArray()
- {
- if (isEmpty())
- {
- return null;
- }
- NodeEntry[] ret = new NodeEntry[size];
- int i = 0;
- EvictionListEntry temp = head;
-
- do
- {
- ret[i] = temp.node;
- temp = temp.next;
- i++;
- }
- while (temp != null);
-
- return ret;
- }
-
- EvictionListEntry[] toArray()
- {
- if (isEmpty())
- {
- return null;
- }
- EvictionListEntry[] ret = new EvictionListEntry[size];
- int i = 0;
- EvictionListEntry temp = head;
-
- do
- {
- ret[i] = temp;
- temp = temp.next;
- i++;
- }
- while (temp != null);
-
- return ret;
- }
-
- void fromArray(EvictionListEntry[] evictionListEntries)
- {
-
- for (EvictionListEntry evictionListEntry : evictionListEntries)
- {
- this.addToBottom(evictionListEntry);
- }
- }
-
- private boolean isEmpty()
- {
- return head == null && tail == null;
- }
-
- private boolean isSingleNode(EvictionListEntry entry)
- {
- return isTail(entry) && isHead(entry);
- }
-
- private boolean isTail(EvictionListEntry entry)
- {
- return entry.next == null;
- }
-
- private boolean isHead(EvictionListEntry entry)
- {
- return entry.previous == null;
- }
-
- @Override
- public String toString()
- {
- return Arrays.asList(toArray()).toString();
- }
-
- static class EvictionListComparator implements Comparator<EvictionListEntry>
- {
- Comparator<NodeEntry> nodeEntryComparator;
-
- EvictionListComparator(Comparator<NodeEntry> nodeEntryComparator)
- {
- this.nodeEntryComparator = nodeEntryComparator;
- }
-
- public int compare(EvictionListEntry e1, EvictionListEntry e2)
- {
- return nodeEntryComparator.compare(e1.node, e2.node);
- }
- }
-
- class EvictionListIterator implements ListIterator<NodeEntry>
- {
- EvictionListEntry next = head;
- EvictionListEntry previous;
- EvictionListEntry cursor;
-
- int initialModCount = EvictionQueueList.this.modCount;
-
- public boolean hasNext()
- {
- this.doConcurrentModCheck();
- return next != null;
- }
-
- public NodeEntry next()
- {
- this.doConcurrentModCheck();
- this.forwardCursor();
- return cursor.node;
- }
-
- public boolean hasPrevious()
- {
- this.doConcurrentModCheck();
- return previous != null;
- }
-
- public NodeEntry previous()
- {
- this.doConcurrentModCheck();
- this.rewindCursor();
- return cursor.node;
- }
-
- public int nextIndex()
- {
- throw new UnsupportedOperationException();
- }
-
- public int previousIndex()
- {
- throw new UnsupportedOperationException();
- }
-
- public void remove()
- {
- this.doConcurrentModCheck();
- if (cursor == null)
- {
- throw new IllegalStateException("Cannot remove from iterator when there is nothing at the current iteration point");
- }
- EvictionQueueList.this.remove(cursor);
- cursor = null;
- initialModCount++;
- }
-
- public void set(NodeEntry o)
- {
- this.doConcurrentModCheck();
- cursor.node = (NodeEntry) o;
- }
-
- public void add(NodeEntry o)
- {
- this.doConcurrentModCheck();
- initialModCount++;
- }
-
- private void doConcurrentModCheck()
- {
- if (EvictionQueueList.this.modCount != initialModCount)
- {
- throw new ConcurrentModificationException();
- }
- }
-
- private void forwardCursor()
- {
- if (next == null)
- {
- throw new NoSuchElementException("No more objects to iterate.");
- }
- previous = cursor;
- cursor = next;
- next = cursor.next;
- }
-
- private void rewindCursor()
- {
- if (previous == null)
- {
- throw new NoSuchElementException();
- }
- next = cursor;
- cursor = previous;
- previous = cursor.previous;
- }
- }
-
-}
-
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionTimerTask.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionTimerTask.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionTimerTask.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -23,10 +23,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Region;
-import org.jboss.cache.util.concurrent.ConcurrentHashSet;
+import org.jboss.starobrno.EvictionManager;
-import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
@@ -38,68 +36,36 @@
*
* @author Ben Wang 2-2004
* @author Daniel Huang (dhuang(a)jboss.org)
- * @version $Revision: 6840 $
*/
public class EvictionTimerTask
{
private Log log = LogFactory.getLog(EvictionTimerTask.class);
- private final Set<Region> processedRegions;
private static AtomicInteger tcount = new AtomicInteger();
private long wakeupInterval;
- ScheduledExecutorService scheduledExecutor;
+ private ScheduledExecutorService scheduledExecutor;
private Task task;
+ private EvictionManager evictionManager;
- public EvictionTimerTask()
+
+ public EvictionTimerTask(EvictionManager evManager)
{
- // synchronized set because we need to maintain thread safety
- // for dynamic configuration purposes.
- processedRegions = new ConcurrentHashSet<Region>();
+ this.evictionManager = evManager;
task = new Task();
}
public void init(long wakeupInterval, ThreadFactory evictionThreadFactory)
{
if (log.isTraceEnabled())
- log.trace("Creating a new eviction listener with wakeupInterval millis set at " + wakeupInterval);
+ log.trace("Creating a new eviction timer task with wakeupInterval millis set at " + wakeupInterval);
this.wakeupInterval = wakeupInterval;
start(evictionThreadFactory);
}
- /**
- * Add a MarshRegion to process by the Eviction Thread.
- *
- * @param region MarshRegion to process.
- */
- public void addRegionToProcess(Region region)
- {
- processedRegions.add(region);
- }
- /**
- * Remove a MarshRegion to process from the Eviction thread.
- *
- * @param region
- */
- public void removeRegionToProcess(Region region)
- {
- processedRegions.remove(region);
- }
-
- public boolean isRegionRegisteredForProcessing(Region region)
- {
- return processedRegions.contains(region);
- }
-
- public Set<Region> getProcessedRegions()
- {
- return processedRegions;
- }
-
public void stop()
{
if (log.isDebugEnabled()) log.debug("Stopping eviction timer");
-
if (scheduledExecutor != null)
{
scheduledExecutor.shutdownNow();
@@ -109,13 +75,6 @@
private void start(ThreadFactory tf)
{
- if (wakeupInterval < 1)
- {
- if (log.isInfoEnabled())
- log.info("Wakeup Interval set to " + wakeupInterval + ". Not starting an eviction thread!");
- return;
- }
-
if (tf == null) tf = new ThreadFactory()
{
public Thread newThread(Runnable r)
@@ -125,48 +84,15 @@
return t;
}
};
-
scheduledExecutor = Executors.newSingleThreadScheduledExecutor(tf);
scheduledExecutor.scheduleWithFixedDelay(task, wakeupInterval, wakeupInterval, TimeUnit.MILLISECONDS);
}
- private void processRegions()
- {
- synchronized (processedRegions)
- {
- for (Region region : processedRegions)
- {
- handleRegion(region);
- }
- }
- }
-
- private void handleRegion(Region region)
- {
- synchronized (region)
- {
- try
- {
- region.processEvictionQueues();
- }
- catch (EvictionException e)
- {
- log.error("run(): error processing eviction with exception: " + e.toString()
- + " will reset the eviction queue list.");
- region.resetEvictionQueues();
- log.debug("trace", e);
- }
- }
- }
-
public class Task implements Runnable
{
public void run()
{
- // Run the eviction thread.
- // This thread will synchronize the set of regions and iterate through every MarshRegion registered w/ the
- // Eviction thread. It also synchronizes on each individual region as it is being processed.
- processRegions();
+ evictionManager.runEviction();
}
}
}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithm.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,377 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.NodeSPI;
-import org.jboss.starobrno.config.EvictionAlgorithmConfig;
-import org.jboss.starobrno.eviction.EvictionEvent.Type;
-
-import java.util.Iterator;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import java.util.concurrent.BlockingQueue;
-
-/**
- * Eviction algorithm that uses a key in the Node data that indicates the time
- * the node should be evicted. The key must be a java.lang.Long object, with
- * the time to expire as milliseconds past midnight January 1st, 1970 UTC (the
- * same relative time as provided by {@link
- * java.lang.System#currentTimeMillis()}).
- * <p/>
- * This algorithm also obeys the configuration key {@link
- * org.jboss.starobrno.eviction.ExpirationAlgorithmConfig#getMaxNodes()}, and will evict the soonest to
- * expire entires first to reduce the region size. If there are not enough
- * nodes with expiration keys set, a warning is logged.
- * <p/>
- * If a node in the eviction region does not have an expiration value, then
- * {@link org.jboss.starobrno.eviction.ExpirationAlgorithmConfig#getTimeToLive()} (if set) will be used.
- * The expiration is updated when a node is added or updated.
- * <p/>
- * If there is no time-to-live set, and a node in the eviction region does not
- * have an expiration value, then that node will never be evicted. As
- * forgetting to indicate an expiration value is likely a mistake, a warning
- * message is logged by this class. This warning, however, can be disabled
- * through {@link org.jboss.starobrno.eviction.ExpirationAlgorithmConfig#setWarnNoExpirationKey(boolean)}.
- * <p/>
- * A node's expiration time can be changed by setting a new value in the node.
- * <p/>
- * Example usage:
- * <pre>
- * Cache cache;
- * Fqn fqn1 = Fqn.fromString("/node/1");
- * Long future = new Long(System.currentTimeMillis() + 2000);
- * cache.put(fqn1, ExpirationConfiguration.EXPIRATION_KEY, future);
- * cache.put(fqn1, "foo");
- * assertTrue(cache.get(fqn1) != null);
- * <p/>
- * Thread.sleep(5000); // 5 seconds
- * assertTrue(cache.get(fqn1) == null);
- * <p/>
- * </pre>
- */
-public class ExpirationAlgorithm extends BaseEvictionAlgorithm
-{
-
- private static final Log log = LogFactory.getLog(ExpirationAlgorithm.class);
- private static final boolean trace = log.isTraceEnabled();
-
- private org.jboss.starobrno.eviction.ExpirationAlgorithmConfig config;
-
- private SortedSet<ExpirationEntry> set;
-
- /**
- * Constructs a new algorithm with a policy.
- */
- public ExpirationAlgorithm()
- {
- this.set = new TreeSet<ExpirationEntry>();
- }
-
- private void addEvictionEntry(org.jboss.starobrno.eviction.EvictionEvent node)
- {
- Fqn fqn = node.getFqn();
- addEvictionEntry(fqn);
- }
-
- private void addEvictionEntry(Fqn fqn)
- {
- Long l = getExpiration(fqn);
- if (l == null)
- {
- if (config.isWarnNoExpirationKey() && log.isWarnEnabled())
- log.warn("No expiration key '" + config.getExpirationKeyName() + "' for Node: " + fqn);
- else if (log.isDebugEnabled())
- log.debug("No expiration key for Node: " + fqn);
- }
- else
- {
- setExpiration(fqn, l);
- }
- }
-
- private void setExpiration(Fqn fqn, Long l)
- {
- ExpirationEntry ee = new ExpirationEntry(fqn, l);
- if (trace)
- log.trace("adding eviction entry: " + ee);
- set.add(ee);
- }
-
- @SuppressWarnings("unchecked")
- private Long getExpiration(Fqn fqn)
- {
- NodeSPI n = cache.peek(fqn, false);
- if (n == null)
- return null;
- return (Long) n.getDirect(config.getExpirationKeyName());
- }
-
- @Override
- protected void processQueues(BlockingQueue<org.jboss.starobrno.eviction.EvictionEvent> queue) throws org.jboss.starobrno.eviction.EvictionException
- {
- org.jboss.starobrno.eviction.EvictionEvent node;
- int count = 0;
- while ((node = getNextInQueue(queue)) != null)
- {
- count++;
- switch (node.getEventType())
- {
- case ADD_NODE_EVENT:
- case ADD_ELEMENT_EVENT:
- addEvictionEntry(node);
- break;
- case REMOVE_ELEMENT_EVENT:
- case REMOVE_NODE_EVENT:
- case UNMARK_USE_EVENT:
- // Removals will be noticed when double-checking expiry time
- // removeEvictionEntry(node);
- break;
- case VISIT_NODE_EVENT:
- // unused
- break;
- case MARK_IN_USE_EVENT:
- markInUse(node);
- break;
- default:
- throw new RuntimeException("Illegal Eviction Event type " + node.getEventType());
- }
- }
-
- if (trace) log.trace("processed " + count + " node events in region: " + regionFqn);
- }
-
- private void markInUse(org.jboss.starobrno.eviction.EvictionEvent node)
- {
- long expiration = node.getInUseTimeout() + System.currentTimeMillis();
- setExpiration(node.getFqn(), expiration);
- }
-
- @Override
- protected void prune() throws org.jboss.starobrno.eviction.EvictionException
- {
- if (set.isEmpty())
- return;
- long now = System.currentTimeMillis();
- int max = config.getMaxNodes();
- for (Iterator<ExpirationEntry> i = set.iterator(); i.hasNext();)
- {
- ExpirationEntry ee = i.next();
- Long ce = getExpiration(ee.getFqn());
- if (ce == null || ce > ee.getExpiration())
- {
- // Expiration now older
- i.remove();
- continue;
- }
- if (ee.getExpiration() < now || (max != 0 && set.size() > max))
- {
- i.remove();
- evictCacheNode(ee.getFqn());
- }
- else
- {
- break;
- }
- }
- if (max != 0 && max > set.size())
- log.warn("Unable to remove nodes to reduce region size below " +
- config.getMaxNodes() + ". " +
- "Set expiration for nodes in this region");
- }
-
- @Override
- public void resetEvictionQueue()
- {
- for (ExpirationEntry ee : set)
- {
- addEvictionEntry(ee.getFqn());
- }
- }
-
- @Override
- protected org.jboss.starobrno.eviction.EvictionQueue setupEvictionQueue() throws org.jboss.starobrno.eviction.EvictionException
- {
- this.config = (org.jboss.starobrno.eviction.ExpirationAlgorithmConfig) evictionAlgorithmConfig;
- return new DummyEvictionQueue();
- }
-
- @Override
- protected boolean shouldEvictNode(org.jboss.starobrno.eviction.NodeEntry ne)
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean canIgnoreEvent(Type eventType)
- {
- return (eventType == org.jboss.starobrno.eviction.EvictionEvent.Type.VISIT_NODE_EVENT);
- }
-
- public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
- {
- return org.jboss.starobrno.eviction.ExpirationAlgorithmConfig.class;
- }
-
- /**
- * Ordered list of FQN, with the expiration taken from the Map at the time
- * of processing.
- */
- static class ExpirationEntry implements Comparable<ExpirationEntry>
- {
-
- private long expiration;
-
- private Fqn fqn;
-
- public ExpirationEntry(Fqn fqn)
- {
- this.fqn = fqn;
- }
-
- public ExpirationEntry(Fqn fqn, long expiration)
- {
- this.fqn = fqn;
- this.expiration = expiration;
- }
-
- /**
- * Compares expiration, then FQN order.
- */
- public int compareTo(ExpirationEntry ee)
- {
- long n = expiration - ee.expiration;
- if (n < 0)
- return -1;
- if (n > 0)
- return 1;
- return fqn.compareTo(ee.fqn);
- }
-
- /**
- * @return the expiration
- */
- public long getExpiration()
- {
- return expiration;
- }
-
- /**
- * @return the fqn
- */
- public Fqn getFqn()
- {
- return fqn;
- }
-
- @Override
- public boolean equals(Object o)
- {
- if (!(o instanceof ExpirationEntry))
- return false;
- ExpirationEntry ee = (ExpirationEntry) o;
- return expiration == ee.expiration && fqn.equals(ee.fqn);
- }
-
- @Override
- public int hashCode()
- {
- return (int) expiration ^ fqn.hashCode();
- }
-
- @Override
- public String toString()
- {
- long now = System.currentTimeMillis();
- long ttl = expiration - now;
- String sttl;
- if (ttl > 1000 * 60)
- sttl = (ttl / (1000 * 60)) + "min";
- else if (ttl > 1000)
- sttl = (ttl / 1000) + "s";
- else
- sttl = ttl + "ms";
- return "EE fqn=" + fqn + " ttl=" + sttl;
- }
- }
-
- class DummyEvictionQueue implements org.jboss.starobrno.eviction.EvictionQueue
- {
-
- public void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- throw new UnsupportedOperationException();
- }
-
- public void clear()
- {
- set.clear();
- }
-
- public boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- return false;
- }
-
- public org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry()
- {
- return null;
- }
-
- public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn)
- {
- return null;
- }
-
- public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn)
- {
- return null;
- }
-
- public int getNumberOfElements()
- {
- return set.size();
- }
-
- public int getNumberOfNodes()
- {
- return set.size();
- }
-
- public Iterator<org.jboss.starobrno.eviction.NodeEntry> iterator()
- {
- return null;
- }
-
- public void modifyElementCount(int difference)
- {
- }
-
- public void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- throw new UnsupportedOperationException();
- }
- }
-
-}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithmConfig.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithmConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -23,6 +23,7 @@
import org.jboss.cache.annotations.Compat;
import org.jboss.starobrno.config.Dynamic;
+import org.jboss.starobrno.eviction.algorithms.ExpirationAlgorithm;
import java.util.concurrent.TimeUnit;
@@ -53,7 +54,7 @@
public ExpirationAlgorithmConfig()
{
- evictionAlgorithmClassName = org.jboss.starobrno.eviction.ExpirationAlgorithm.class.getName();
+ evictionAlgorithmClassName = ExpirationAlgorithm.class.getName();
}
/**
@@ -154,7 +155,7 @@
public void reset()
{
super.reset();
- evictionAlgorithmClassName = org.jboss.starobrno.eviction.ExpirationAlgorithm.class.getName();
+ evictionAlgorithmClassName = ExpirationAlgorithm.class.getName();
warnNoExpirationKey = true;
timeToLive = 0;
}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithm.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,72 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.starobrno.config.EvictionAlgorithmConfig;
-
-/**
- * First-in-first-out algorithm used to evict nodes.
- *
- * @author Daniel Huang - dhuang(a)jboss.org
- * @author Morten Kvistgaard
- * @version $Revision: 6776 $
- */
-public class FIFOAlgorithm extends BaseEvictionAlgorithm
-{
- private static final Log log = LogFactory.getLog(FIFOAlgorithm.class);
- private static final boolean trace = log.isTraceEnabled();
-
-
- @Override
- protected org.jboss.starobrno.eviction.EvictionQueue setupEvictionQueue() throws org.jboss.starobrno.eviction.EvictionException
- {
- return new org.jboss.starobrno.eviction.FIFOQueue();
- }
-
- /**
- * For FIFO, a node should be evicted if the queue size is >= to the configured maxNodes size.
- */
- @Override
- protected boolean shouldEvictNode(org.jboss.starobrno.eviction.NodeEntry ne)
- {
- // check the minimum time to live and see if we should not evict the node. This check will
- // ensure that, if configured, nodes are kept alive for at least a minimum period of time.
- if (isYoungerThanMinimumTimeToLive(ne)) return false;
-
- org.jboss.starobrno.eviction.FIFOAlgorithmConfig config = (org.jboss.starobrno.eviction.FIFOAlgorithmConfig) evictionAlgorithmConfig;
- if (trace)
- {
- log.trace("Deciding whether node in queue " + ne.getFqn() + " requires eviction.");
- }
-
- int size = this.getEvictionQueue().getNumberOfNodes();
- return config.getMaxNodes() != 0 && size > config.getMaxNodes();
- }
-
- public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
- {
- return org.jboss.starobrno.eviction.FIFOAlgorithmConfig.class;
- }
-}
-
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithmConfig.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithmConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,97 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.jboss.starobrno.config.ConfigurationException;
-
-/**
- * Configuration for {@link org.jboss.starobrno.eviction.FIFOAlgorithm}.
- * <p/>
- * Requires a "maxNodes" attribute otherwise a ConfigurationException is thrown.
- *
- * @author Manik Surtani
- * @since 3.0
- */
-public class FIFOAlgorithmConfig extends EvictionAlgorithmConfigBase
-{
- /**
- * The serialVersionUID
- */
- private static final long serialVersionUID = -7229715009546277313L;
-
- public FIFOAlgorithmConfig()
- {
- evictionAlgorithmClassName = org.jboss.starobrno.eviction.FIFOAlgorithm.class.getName();
- // We require that maxNodes is set
- setMaxNodes(-1);
- }
-
- public FIFOAlgorithmConfig(int maxNodes)
- {
- evictionAlgorithmClassName = org.jboss.starobrno.eviction.FIFOAlgorithm.class.getName();
- // We require that maxNodes is set
- setMaxNodes(maxNodes);
- }
-
- /**
- * Requires a positive maxNodes value or ConfigurationException
- * is thrown.
- */
- @Override
- public void validate() throws ConfigurationException
- {
- super.validate();
- if (getMaxNodes() < 0)
- {
- throw new ConfigurationException("maxNodes must be must be " +
- "configured to a value greater than or equal to 0");
- }
- }
-
- @Override
- public String toString()
- {
- StringBuilder ret = new StringBuilder();
- ret.append("FIFOAlgorithmConfig: maxNodes = ").append(getMaxNodes());
- return ret.toString();
- }
-
- @Override
- public boolean equals(Object obj)
- {
- return (obj instanceof FIFOAlgorithmConfig && super.equals(obj));
- }
-
- @Override
- public void reset()
- {
- super.reset();
- setMaxNodes(-1);
- evictionAlgorithmClassName = org.jboss.starobrno.eviction.FIFOAlgorithm.class.getName();
- }
-
- @Override
- public FIFOAlgorithmConfig clone() throws CloneNotSupportedException
- {
- return (FIFOAlgorithmConfig) super.clone();
- }
-}
\ No newline at end of file
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOQueue.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOQueue.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,123 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.jboss.cache.Fqn;
-
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-/**
- * FIFO Eviction Queue implementation for FIFO Policy.
- *
- * @author Daniel Huang (dhuang(a)jboss.org)
- * @version $Revision: 6776 $
- */
-public class FIFOQueue implements EvictionQueue
-{
- private Map<Fqn, org.jboss.starobrno.eviction.NodeEntry> nodeMap;
- private int numElements = 0;
-
- protected FIFOQueue()
- {
- nodeMap = new LinkedHashMap<Fqn, org.jboss.starobrno.eviction.NodeEntry>();
- // We use a LinkedHashMap here because we want to maintain FIFO ordering and still get the benefits of
- // O(n) = 1 for add/remove/search.
- }
-
- public org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry()
- {
-/* Iterator it = nodeMap.keySet().iterator();
- if(it.hasNext()) {
- return (NodeEntry) nodeMap.get(it.next());
- }
-
- return null; */
-
- // this code path is *slightly* faster when profiling. 20ms faster iterating over 200000 entries in queue.
- if (nodeMap.size() > 0)
- {
- return nodeMap.values().iterator().next();
- }
-
- return null;
- }
-
- public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn)
- {
- return nodeMap.get(fqn);
- }
-
- public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn)
- {
- return this.getNodeEntry(Fqn.fromString(fqn));
- }
-
- public boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- Fqn fqn = entry.getFqn();
- return this.getNodeEntry(fqn) != null;
- }
-
- public void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- org.jboss.starobrno.eviction.NodeEntry e = nodeMap.remove(entry.getFqn());
- this.numElements -= e.getNumberOfElements();
- }
-
- public void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- if (!this.containsNodeEntry(entry))
- {
- entry.queue = this;
- nodeMap.put(entry.getFqn(), entry);
- this.numElements += entry.getNumberOfElements();
- }
- }
-
- public int getNumberOfNodes()
- {
- return nodeMap.size();
- }
-
- public int getNumberOfElements()
- {
- return this.numElements;
- }
-
- public void modifyElementCount(int difference)
- {
- this.numElements += difference;
- }
-
- public void clear()
- {
- nodeMap.clear();
- this.numElements = 0;
- }
-
- public Iterator<org.jboss.starobrno.eviction.NodeEntry> iterator()
- {
- return nodeMap.values().iterator();
- }
-}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/KeyEntry.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NodeEntry.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/KeyEntry.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/KeyEntry.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,230 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+/**
+ * Value object used in queue
+ *
+ * @author Ben Wang 2-2004
+ * @author Daniel Huang - dhuang(a)jboss.org
+ */
+public class KeyEntry<K>
+{
+ private long modifiedTimeStamp;
+ private long creationTimeStamp;
+ private int numberOfNodeVisits;
+ private int numberOfElements;
+ private K key;
+
+ private long inUseTimeoutTimestamp;
+ private boolean currentlyInUse = false;
+
+ private EvictionQueue queue;
+
+ /**
+ * Private constructor that automatically sets the creation time stamp of the node entry.
+ */
+ private KeyEntry()
+ {
+ this.creationTimeStamp = System.currentTimeMillis();
+ }
+
+ public KeyEntry(K key)
+ {
+ this();
+ setKey(key);
+ }
+
+ public KeyEntry(int numberOfNodeVisits, long modifiedTimeStamp, int numberOfElements, K key)
+ {
+ this(key);
+ this.numberOfNodeVisits = numberOfNodeVisits;
+ this.modifiedTimeStamp = modifiedTimeStamp;
+ this.numberOfElements = numberOfElements;
+ }
+
+ /**
+ * Is the node currently in use.
+ *
+ * @return True/false if the node is currently marked as in use.
+ */
+ public boolean isCurrentlyInUse()
+ {
+ return currentlyInUse;
+ }
+
+ public void setCurrentlyInUse(boolean currentlyInUse, long inUseTimeout)
+ {
+ this.currentlyInUse = currentlyInUse;
+ if (inUseTimeout > 0)
+ {
+ this.inUseTimeoutTimestamp = System.currentTimeMillis() + inUseTimeout;
+ }
+ }
+
+ public long getInUseTimeoutTimestamp()
+ {
+ return this.inUseTimeoutTimestamp;
+ }
+
+ /**
+ * Get modified time stamp. This stamp is created during the node is
+ * processed so it has some fuzy tolerance in there.
+ *
+ * @return The last modified time stamp
+ */
+ public long getModifiedTimeStamp()
+ {
+ return modifiedTimeStamp;
+ }
+
+ public void setModifiedTimeStamp(long modifiedTimeStamp)
+ {
+// log.error("Being modified to " + modifiedTimeStamp, new Throwable());
+ this.modifiedTimeStamp = modifiedTimeStamp;
+ }
+
+ /**
+ * Get the time stamp for when the node entry was created.
+ *
+ * @return The node entry creation time stamp
+ */
+ public long getCreationTimeStamp()
+ {
+ return creationTimeStamp;
+ }
+
+ public void setCreationTimeStamp(long creationTimeStamp)
+ {
+ this.creationTimeStamp = creationTimeStamp;
+ }
+
+ public int getNumberOfNodeVisits()
+ {
+ return numberOfNodeVisits;
+ }
+
+ public void setNumberOfNodeVisits(int numberOfNodeVisits)
+ {
+ this.numberOfNodeVisits = numberOfNodeVisits;
+ }
+
+ public void incerementNumberOfNodeVisits()
+ {
+ this.numberOfNodeVisits ++;
+ }
+
+ public int getNumberOfElements()
+ {
+ return numberOfElements;
+ }
+
+ public void setNumberOfElements(int numberOfElements)
+ {
+ if (queue != null)
+ {
+ int difference = numberOfElements - this.numberOfElements;
+ queue.modifyElementCount(difference);
+ }
+ this.numberOfElements = numberOfElements;
+ }
+
+ public K getKey()
+ {
+ return key;
+ }
+
+ void setKey(K key)
+ {
+ this.key = key;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return key.hashCode();
+ }
+
+ public boolean isNodeInUseAndNotTimedOut()
+ {
+ if (isCurrentlyInUse())
+ {
+ if (getInUseTimeoutTimestamp() == 0)
+ {
+ return true;
+ }
+
+ if (System.currentTimeMillis() < getInUseTimeoutTimestamp())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Tests whether a node entry is younger than the minimum time to live - if one is configured.
+ *
+ * @return true if the node is younger than - or exactly equal to - the minimum time to live, if one is configured for the given region. False otherwise.
+ */
+ public boolean isYoungerThanMinimumTimeToLive(long minTTL)
+ {
+ return minTTL >= 1 && (getModifiedTimeStamp() + minTTL > System.currentTimeMillis());
+ }
+
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (!(o instanceof KeyEntry))
+ return false;
+ KeyEntry ne = (KeyEntry) o;
+ return key.equals(ne.getKey());
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder output = new StringBuilder();
+ output.append("Fqn: ");
+ if (key != null)
+ {
+ output.append(key);
+ }
+ else
+ {
+ output.append(" null");
+ }
+
+ output.append(" CreateTime: ").append(this.getCreationTimeStamp());
+ output.append(" NodeVisits: ").append(this.getNumberOfNodeVisits());
+ output.append(" ModifiedTime: ").append(this.getModifiedTimeStamp());
+ output.append(" NumberOfElements: ").append(this.getNumberOfElements());
+ output.append(" CurrentlyInUse: ").append(this.isCurrentlyInUse());
+ return output.toString();
+ }
+
+ public void setQueue(EvictionQueue queue)
+ {
+ this.queue = queue;
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/KeyEntry.java
___________________________________________________________________
Name: svn:executable
+ *
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithm.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,107 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.starobrno.config.EvictionAlgorithmConfig;
-
-/**
- * Least Frequently Used algorithm for cache eviction.
- * Note that this algorithm is not thread-safe.
- * <p/>
- * This algorithm relies on maxNodes and minNodes to operate correctly.
- * Eviction takes place using Least Frequently Used algorithm. A node A
- * that is used less than a node B is evicted sooner.
- * <p/>
- * The minNodes property defines a threshold for eviction. If minNodes = 100,
- * the LFUAlgorithm will not evict the cache to anything less than 100 elements
- * still left in cache. The maxNodes property defines the maximum number of nodes
- * the cache will accept before eviction. maxNodes = 0 means that this region is
- * unbounded. minNodes = 0 means that the eviction queue will attempt to bring
- * the cache of this region to 0 elements (evict all elements) whenever it is run.
- * <p/>
- * This algorithm uses a sorted eviction queue. The eviction queue is sorted in
- * ascending order based on the number of times a node is visited. The more frequently
- * a node is visited, the less likely it will be evicted.
- *
- * @author Daniel Huang - dhuang(a)jboss.org 10/2005
- * @version $Revision: 6776 $
- */
-public class LFUAlgorithm extends BaseSortedEvictionAlgorithm
-{
- private static final Log log = LogFactory.getLog(LFUAlgorithm.class);
- private static final boolean trace = log.isTraceEnabled();
-
- @Override
- protected boolean shouldEvictNode(org.jboss.starobrno.eviction.NodeEntry ne)
- {
- if (trace)
- {
- log.trace("Deciding whether node in queue " + ne.getFqn() + " requires eviction.");
- }
-
- // check the minimum time to live and see if we should not evict the node. This check will
- // ensure that, if configured, nodes are kept alive for at least a minimum period of time.
- if (isYoungerThanMinimumTimeToLive(ne)) return false;
-
- org.jboss.starobrno.eviction.LFUAlgorithmConfig config = (org.jboss.starobrno.eviction.LFUAlgorithmConfig) evictionAlgorithmConfig;
- int size = this.getEvictionQueue().getNumberOfNodes();
- if (config.getMaxNodes() > -1 && size > config.getMaxNodes())
- {
- return true;
- }
- else if (size > config.getMinNodes())
- {
- return true;
- }
-
- return false;
- }
-
- /**
- * Will create a LFUQueue to be used as the underlying eviction queue.
- *
- * @return The created LFUQueue.
- * @throws org.jboss.starobrno.eviction.EvictionException
- *
- */
- @Override
- protected org.jboss.starobrno.eviction.EvictionQueue setupEvictionQueue() throws org.jboss.starobrno.eviction.EvictionException
- {
- return new org.jboss.starobrno.eviction.LFUQueue();
- }
-
- @Override
- protected void prune() throws org.jboss.starobrno.eviction.EvictionException
- {
- super.prune();
-
- // clean up the Queue's eviction removals
- ((org.jboss.starobrno.eviction.LFUQueue) this.evictionQueue).prune();
- }
-
- public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
- {
- return org.jboss.starobrno.eviction.LFUAlgorithmConfig.class;
- }
-}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithmConfig.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithmConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,104 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.jboss.starobrno.config.Dynamic;
-
-/**
- * Configuration implementation for {@link org.jboss.starobrno.eviction.LFUAlgorithm}.
- *
- * @author Manik Surtani
- * @since 3.0
- */
-public class LFUAlgorithmConfig extends EvictionAlgorithmConfigBase
-{
- /**
- * The serialVersionUID
- */
- private static final long serialVersionUID = 1865801530398969179L;
-
- @Dynamic
- private int minNodes;
-
- public LFUAlgorithmConfig()
- {
- evictionAlgorithmClassName = org.jboss.starobrno.eviction.LFUAlgorithm.class.getName();
- }
-
- public LFUAlgorithmConfig(int maxNodes, int minNodes)
- {
- this();
- setMaxNodes(maxNodes);
- setMinNodes(minNodes);
- }
-
- public int getMinNodes()
- {
- return minNodes;
- }
-
- public void setMinNodes(int minNodes)
- {
- testImmutability("minNodes");
- this.minNodes = minNodes;
- }
-
- @Override
- public String toString()
- {
- StringBuilder ret = new StringBuilder();
- ret.append("LFUAlgorithmConfig: maxNodes = ").append(getMaxNodes()).append(" minNodes = ").append(getMinNodes());
- return ret.toString();
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj instanceof LFUAlgorithmConfig && super.equals(obj))
- {
- return (this.minNodes == ((LFUAlgorithmConfig) obj).minNodes);
- }
- return false;
- }
-
- @Override
- public int hashCode()
- {
- int result = super.hashCode();
- result = 31 * result + minNodes;
- return result;
- }
-
- @Override
- public LFUAlgorithmConfig clone() throws CloneNotSupportedException
- {
- return (LFUAlgorithmConfig) super.clone();
- }
-
- @Override
- public void reset()
- {
- super.reset();
- minNodes = -1;
- evictionAlgorithmClassName = org.jboss.starobrno.eviction.LFUAlgorithm.class.getName();
- }
-}
\ No newline at end of file
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUQueue.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUQueue.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,237 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.jboss.cache.Fqn;
-
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-/**
- * LFUQueue EvictionQueue implementation for LFU Policy.
- * <p/>
- * The queue is sorted in least frequently used order.
- *
- * @author Daniel Huang (dhuang(a)jboss.org)
- * @version $Revision: 6776 $
- */
-public class LFUQueue implements SortedEvictionQueue
-{
- private Map<Fqn, org.jboss.starobrno.eviction.NodeEntry> nodeMap;
- private LinkedList<org.jboss.starobrno.eviction.NodeEntry> evictionList;
- private Comparator<org.jboss.starobrno.eviction.NodeEntry> comparator;
-
- private Set<org.jboss.starobrno.eviction.NodeEntry> removalQueue;
- private int numElements = 0;
-
- protected LFUQueue()
- {
- nodeMap = new HashMap<Fqn, org.jboss.starobrno.eviction.NodeEntry>();
- comparator = new LFUComparator();
- evictionList = new LinkedList<org.jboss.starobrno.eviction.NodeEntry>();
- removalQueue = new HashSet<org.jboss.starobrno.eviction.NodeEntry>();
- }
-
- /**
- * Return the first node to evict.
- * <p/>
- * This method will return the least frequently used entry in the queue.
- */
- public org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry()
- {
- try
- {
- org.jboss.starobrno.eviction.NodeEntry ne;
- while ((ne = evictionList.getFirst()) != null)
- {
- if (removalQueue.contains(ne))
- {
- evictionList.removeFirst();
- removalQueue.remove(ne);
- }
- else
- {
- break;
- }
- }
- return ne;
- }
- catch (NoSuchElementException e)
- {
- //
- }
-
- return null;
- }
-
- public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn)
- {
- return nodeMap.get(fqn);
- }
-
- public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn)
- {
- return this.getNodeEntry(Fqn.fromString(fqn));
- }
-
- public boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- Fqn fqn = entry.getFqn();
- return this.getNodeEntry(fqn) != null;
- }
-
- public void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- org.jboss.starobrno.eviction.NodeEntry ne = nodeMap.remove(entry.getFqn());
- if (ne != null)
- {
- // don't remove directly from the LinkedList otherwise we will incur a O(n) = n
- // performance penalty for every removal! In the prune method for LFU, we will iterate the LinkedList through ONCE
- // doing a single O(n) = n operation and removal. This is much preferred over running O(n) = n every single time
- // remove is called. There is also special logic in the getFirstNodeEntry that will know to check
- // the removalQueue before returning.
- this.removalQueue.add(ne);
-/* if(!evictionList.remove(ne)) {
- throw new RuntimeException("");
- } */
- this.numElements -= ne.getNumberOfElements();
- }
- }
-
- public void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- if (!this.containsNodeEntry(entry))
- {
- Fqn fqn = entry.getFqn();
- entry.queue = this;
- nodeMap.put(fqn, entry);
- evictionList.add(entry);
- this.numElements += entry.getNumberOfElements();
- }
- }
-
- public int getNumberOfNodes()
- {
- return nodeMap.size();
- }
-
- public int getNumberOfElements()
- {
- return this.numElements;
- }
-
- public void clear()
- {
- nodeMap.clear();
- evictionList.clear();
- removalQueue.clear();
- this.numElements = 0;
- }
-
- public void resortEvictionQueue()
- {
- Collections.sort(evictionList, comparator);
- }
-
- public void modifyElementCount(int difference)
- {
- this.numElements += difference;
- }
-
- protected void prune()
- {
- Iterator<org.jboss.starobrno.eviction.NodeEntry> it = this.iterator();
- while (it.hasNext() && removalQueue.size() > 0)
- {
- if (removalQueue.remove(it.next()))
- {
- it.remove();
- }
- }
- }
-
- protected final List<org.jboss.starobrno.eviction.NodeEntry> getEvictionList()
- {
- return this.evictionList;
- }
-
- protected final Set<org.jboss.starobrno.eviction.NodeEntry> getRemovalQueue()
- {
- return this.removalQueue;
- }
-
- public Iterator<org.jboss.starobrno.eviction.NodeEntry> iterator()
- {
- return evictionList.iterator();
- }
-
- /**
- * Comparator class for LFU.
- * <p/>
- * This class will sort the eviction queue in the correct eviction order.
- * The top of the list should evict before the bottom of the list.
- * <p/>
- * The sort is based on ascending order of nodeVisits.
- * <p/>
- * Note: this class has a natural ordering that is inconsistent with equals as defined by the java.lang.Comparator
- * contract.
- */
- protected static class LFUComparator implements Comparator<org.jboss.starobrno.eviction.NodeEntry>
- {
-
- public int compare(org.jboss.starobrno.eviction.NodeEntry ne1, org.jboss.starobrno.eviction.NodeEntry ne2)
- {
- if (ne1.equals(ne2))
- {
- return 0;
- }
-
- int neNodeHits = ne1.getNumberOfNodeVisits();
- int ne2NodeHits = ne2.getNumberOfNodeVisits();
-
- if (neNodeHits > ne2NodeHits)
- {
- return 1;
- }
- else if (neNodeHits < ne2NodeHits)
- {
- return -1;
- }
- else if (neNodeHits == ne2NodeHits)
- {
- return 0;
- }
-
- throw new RuntimeException("Should never reach this condition");
- }
- }
-
-}
-
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithm.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,198 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.starobrno.config.EvictionAlgorithmConfig;
-
-import java.util.Iterator;
-
-/**
- * Least recently Used algorithm to purge old data.
- * Note that this algorithm is not thread-safe.
- *
- * @author Ben Wang 02-2004
- * @author Daniel Huang - dhuang(a)jboss.org
- */
-public class LRUAlgorithm extends BaseEvictionAlgorithm
-{
- private static final Log log = LogFactory.getLog(LRUAlgorithm.class);
- private static final boolean trace = log.isTraceEnabled();
-
- @Override
- protected org.jboss.starobrno.eviction.EvictionQueue setupEvictionQueue() throws org.jboss.starobrno.eviction.EvictionException
- {
- return new org.jboss.starobrno.eviction.LRUQueue();
- }
-
- @Override
- protected boolean shouldEvictNode(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- // check the minimum time to live and see if we should not evict the node. This check will
- // ensure that, if configured, nodes are kept alive for at least a minimum period of time.
- if (isYoungerThanMinimumTimeToLive(entry)) return false;
-
- org.jboss.starobrno.eviction.LRUAlgorithmConfig config = (org.jboss.starobrno.eviction.LRUAlgorithmConfig) evictionAlgorithmConfig;
- // no idle or max time limit
- if (config.getTimeToLive() < 0 && config.getMaxAge() < 0) return false;
-
- long currentTime = System.currentTimeMillis();
- if (config.getTimeToLive() > -1)
- {
- long idleTime = currentTime - entry.getModifiedTimeStamp();
- if (trace)
- {
- log.trace("Node " + entry.getFqn() + " has been idle for " + idleTime + "ms");
- }
- if ((idleTime >= (config.getTimeToLive())))
- {
- if (trace)
- {
- log.trace("Node " + entry.getFqn() + " should be evicted because of idle time");
- log.trace("Time to live in millies is: " + (config.getTimeToLive()));
- log.trace("Config instance is: " + System.identityHashCode(config));
- }
- return true;
- }
- }
-
- if (config.getMaxAge() > -1)
- {
- long objectLifeTime = currentTime - entry.getCreationTimeStamp();
- if (trace)
- {
- log.trace("Node " + entry.getFqn() + " has been alive for " + objectLifeTime + "ms");
- }
- if ((objectLifeTime >= config.getMaxAge()))
- {
- if (trace)
- {
- log.trace("Node " + entry.getFqn() + " should be evicted because of max age");
- }
- return true;
- }
- }
-
- if (trace)
- {
- log.trace("Node " + entry.getFqn() + " should not be evicted");
- }
- return false;
- }
-
- @Override
- protected void evict(org.jboss.starobrno.eviction.NodeEntry ne)
- {
- if (ne != null)
- {
- if (!this.evictCacheNode(ne.getFqn()))
- {
- try
- {
- recycleQueue.put(ne.getFqn());
- }
- catch (InterruptedException e)
- {
- log.debug("InterruptedException", e);
- }
- }
- }
- }
-
- @Override
- protected void prune() throws org.jboss.starobrno.eviction.EvictionException
- {
- org.jboss.starobrno.eviction.LRUQueue lruQueue = (org.jboss.starobrno.eviction.LRUQueue) evictionQueue;
- org.jboss.starobrno.eviction.NodeEntry ne;
- Iterator it = lruQueue.iterateLRUQueue();
- while (it.hasNext())
- {
- ne = (org.jboss.starobrno.eviction.NodeEntry) it.next();
- if (isNodeInUseAndNotTimedOut(ne))
- {
- continue;
- }
-
- if (this.shouldEvictNode(ne))
- {
- it.remove();
- lruQueue.removeNodeEntryFromMaxAge(ne);
- this.evict(ne);
- }
- else
- {
- break;
- }
- }
-
- it = lruQueue.iterateMaxAgeQueue();
- while (it.hasNext())
- {
- ne = (org.jboss.starobrno.eviction.NodeEntry) it.next();
- if (isNodeInUseAndNotTimedOut(ne))
- {
- continue;
- }
-
- if (this.shouldEvictNode(ne))
- {
- it.remove();
- lruQueue.removeNodeEntryFromLRU(ne);
- this.evict(ne);
- }
- else
- {
- break;
- }
- }
-
- int maxNodes = ((org.jboss.starobrno.eviction.LRUAlgorithmConfig) evictionAlgorithmConfig).getMaxNodes();
- if (maxNodes <= 0)
- {
- return;
- }
-
- it = lruQueue.iterateLRUQueue();
- while (evictionQueue.getNumberOfNodes() > maxNodes)
- {
- ne = (org.jboss.starobrno.eviction.NodeEntry) it.next();
- if (trace)
- {
- log.trace("Node " + ne.getFqn() + " will be evicted because of exceeding the maxNode limit." +
- " maxNode: " + maxNodes + " but current queue size is: " + evictionQueue.getNumberOfNodes());
- }
-
- if (!this.isNodeInUseAndNotTimedOut(ne))
- {
- it.remove();
- lruQueue.removeNodeEntryFromMaxAge(ne);
- this.evict(ne);
- }
- }
- }
-
- public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
- {
- return org.jboss.starobrno.eviction.LRUAlgorithmConfig.class;
- }
-}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithmConfig.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithmConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,194 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.jboss.cache.annotations.Compat;
-import org.jboss.starobrno.config.ConfigurationException;
-import org.jboss.starobrno.config.Dynamic;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * Configuration implementation for {@link org.jboss.starobrno.eviction.LRUAlgorithm}.
- * <p/>
- *
- * @author Manik Surtani
- * @since 3.0
- */
-public class LRUAlgorithmConfig extends EvictionAlgorithmConfigBase
-{
- /**
- * The serialVersionUID
- */
- private static final long serialVersionUID = -3426716488271559729L;
-
- /**
- * value expressed in millis
- */
- @Dynamic
- private long timeToLive;
-
- /**
- * value expressed in millis
- */
- @Dynamic
- private long maxAge;
-
- public LRUAlgorithmConfig()
- {
- evictionAlgorithmClassName = org.jboss.starobrno.eviction.LRUAlgorithm.class.getName();
- // Force config of ttls
- setTimeToLive(-1);
- setMaxAge(-1);
- }
-
- public LRUAlgorithmConfig(long timeToLive, long maxAge)
- {
- this();
- this.timeToLive = timeToLive;
- this.maxAge = maxAge;
- }
-
- public LRUAlgorithmConfig(long timeToLive, int maxAge, int maxNodes)
- {
- this(timeToLive, maxAge);
- this.maxNodes = maxNodes;
- }
-
- /**
- * @return the time to live, in milliseconds
- */
- public long getTimeToLive()
- {
- return timeToLive;
- }
-
- /**
- * Sets the time to live
- *
- * @param timeToLive the time to live, in milliseconds
- */
- public void setTimeToLive(long timeToLive)
- {
- testImmutability("timeToLive");
- this.timeToLive = timeToLive;
- }
-
- public void setTimeToLive(long timeToLive, TimeUnit timeUnit)
- {
- testImmutability("timeToLive");
- this.timeToLive = timeUnit.toMillis(timeToLive);
- }
-
- @Deprecated
- @Compat
- public void setTimeToLiveSeconds(long time)
- {
- setTimeToLive(time, TimeUnit.SECONDS);
- }
-
- /**
- * @return the max age per element, in milliseconds
- */
- public long getMaxAge()
- {
- return maxAge;
- }
-
- /**
- * Sets the max age per element
- *
- * @param maxAge value in milliseconds
- */
- public void setMaxAge(long maxAge)
- {
- testImmutability("maxAge");
- this.maxAge = maxAge;
- }
-
- public void setMaxAge(long maxAge, TimeUnit timeUnit)
- {
- testImmutability("maxAge");
- this.maxAge = timeUnit.toMillis(maxAge);
- }
-
- /**
- * Requires a positive timeToLive value or ConfigurationException
- * is thrown.
- */
- @Override
- public void validate() throws ConfigurationException
- {
- super.validate();
- if (timeToLive < -1)
- {
- throw new ConfigurationException("timeToLive must be " +
- "configured to a value greater than or equal to 0 (or -1 for unlimited time to live) for " + getEvictionAlgorithmClassName());
- }
- }
-
- public String toString()
- {
- return "LRUAlgorithmConfig {" +
- "algorithmClassName=" + evictionAlgorithmClassName +
- ", timeToLive=" + timeToLive +
- ", maxAge=" + maxAge +
- '}';
- }
-
- public boolean equals(Object o)
- {
- if (this == o) return true;
- if (!(o instanceof LRUAlgorithmConfig)) return false;
- if (!super.equals(o)) return false;
-
- LRUAlgorithmConfig that = (LRUAlgorithmConfig) o;
-
- if (maxAge != that.maxAge) return false;
- if (timeToLive != that.timeToLive) return false;
-
- return true;
- }
-
- public int hashCode()
- {
- int result = super.hashCode();
- result = 31 * result + (int) (timeToLive ^ (timeToLive >>> 32));
- result = 31 * result + (int) (maxAge ^ (maxAge >>> 32));
- return result;
- }
-
- @Override
- public void reset()
- {
- super.reset();
- setTimeToLive(-1);
- setMaxAge(-1);
- evictionAlgorithmClassName = org.jboss.starobrno.eviction.LRUAlgorithm.class.getName();
- }
-
- @Override
- public LRUAlgorithmConfig clone() throws CloneNotSupportedException
- {
- return (LRUAlgorithmConfig) super.clone();
- }
-}
\ No newline at end of file
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUQueue.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUQueue.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,203 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.jboss.cache.Fqn;
-
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-/**
- * LRU Eviction Queue implementation.
- * <p/>
- * This eviction queue will iterate properly through two sorted lists.
- * One sorted by maxAge and the other sorted by idleTime.
- *
- * @author Daniel Huang (dhuang(a)jboss.org)
- * @version $Revision: 6776 $
- */
-public class LRUQueue implements EvictionQueue
-{
- private Map<Fqn, org.jboss.starobrno.eviction.NodeEntry> maxAgeQueue;
- private Map<Fqn, org.jboss.starobrno.eviction.NodeEntry> lruQueue;
- private long alternatingCount = 0;
- private int numElements = 0;
-
- protected LRUQueue()
- {
- maxAgeQueue = new LinkedHashMap<Fqn, org.jboss.starobrno.eviction.NodeEntry>();
- lruQueue = new LinkedHashMap<Fqn, org.jboss.starobrno.eviction.NodeEntry>(16, 0.75f, true);
- }
-
- protected void reorderByLRU(Fqn fqn)
- {
- // leave the max age queue alone - it is like a fifo.
-
- // the lru queue is access ordered. meaning the most recently read item is moved to the bottom of the queue.
- // simply calling get against it visits it and will cause LinkedHashMap to move it to the bottom of the queue.
- lruQueue.get(fqn);
- }
-
- public org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry()
- {
- // because the underlying queue is in two differently sorted queues, we alternate between them when calling
- // a generic getFirstNodeEntry.
- // we must alternate to keep things balanced when evicting nodes based on the maxNodes attribute. We don't
- // want to just prune from one queue but rather we want to be able to prune from both.
- org.jboss.starobrno.eviction.NodeEntry ne;
- if (alternatingCount % 2 == 0)
- {
- ne = this.getFirstLRUNodeEntry();
- if (ne == null)
- {
- ne = this.getFirstMaxAgeNodeEntry();
- }
- }
- else
- {
- ne = this.getFirstMaxAgeNodeEntry();
- if (ne == null)
- {
- ne = this.getFirstLRUNodeEntry();
- }
- }
- alternatingCount++;
- return ne;
- }
-
- public org.jboss.starobrno.eviction.NodeEntry getFirstLRUNodeEntry()
- {
- if (lruQueue.size() > 0)
- {
- return lruQueue.values().iterator().next();
- }
-
- return null;
- }
-
- public org.jboss.starobrno.eviction.NodeEntry getFirstMaxAgeNodeEntry()
- {
- if (maxAgeQueue.size() > 0)
- {
- return maxAgeQueue.values().iterator().next();
- }
-
- return null;
- }
-
- public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn)
- {
- return lruQueue.get(fqn);
- }
-
- public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn)
- {
- return this.getNodeEntry(Fqn.fromString(fqn));
- }
-
- public boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- return this.maxAgeQueue.containsKey(entry.getFqn());
- }
-
- protected void removeNodeEntryFromLRU(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- Fqn fqn = entry.getFqn();
- lruQueue.remove(fqn);
- }
-
- protected void removeNodeEntryFromMaxAge(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- Fqn fqn = entry.getFqn();
- maxAgeQueue.remove(fqn);
- }
-
- public void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- if (!this.containsNodeEntry(entry))
- {
- return;
- }
- Fqn fqn = entry.getFqn();
- org.jboss.starobrno.eviction.NodeEntry ne1 = lruQueue.remove(fqn);
- org.jboss.starobrno.eviction.NodeEntry ne2 = maxAgeQueue.remove(fqn);
-
- if (ne1 == null || ne2 == null)
- {
- throw new RuntimeException("The queues are out of sync.");
- }
-
- this.numElements -= ne1.getNumberOfElements();
-
- }
-
- public void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- if (!this.containsNodeEntry(entry))
- {
- Fqn fqn = entry.getFqn();
- entry.queue = this;
- maxAgeQueue.put(fqn, entry);
- lruQueue.put(fqn, entry);
- this.numElements += entry.getNumberOfElements();
- }
- }
-
- public int getNumberOfNodes()
- {
- return maxAgeQueue.size();
- }
-
- public int getNumberOfElements()
- {
- return this.numElements;
- }
-
- public void clear()
- {
- maxAgeQueue.clear();
- lruQueue.clear();
- this.numElements = 0;
- }
-
- public void modifyElementCount(int difference)
- {
- this.numElements += difference;
- }
-
- public Iterator<org.jboss.starobrno.eviction.NodeEntry> iterator()
- {
- return lruQueue.values().iterator();
- }
-
- protected final Iterator<org.jboss.starobrno.eviction.NodeEntry> iterateMaxAgeQueue()
- {
- return maxAgeQueue.values().iterator();
- }
-
- protected final Iterator<org.jboss.starobrno.eviction.NodeEntry> iterateLRUQueue()
- {
- return lruQueue.values().iterator();
- }
-
-}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithm.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,67 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.jboss.starobrno.config.EvictionAlgorithmConfig;
-
-/**
- * Most Recently Used Algorithm.
- * <p/>
- * This algorithm will evict the most recently used cache entries from cache.
- * <p/>
- * Note: None of the Eviction classes are thread safe. It is assumed that an individual instance of an EvictionPolicy/
- * EvictionAlgorithm/EvictionQueue/EvictionConfiguration are only operated on by one thread at any given time.
- *
- * @author Daniel Huang (dhuang(a)jboss.org)
- * @version $Revision: 6776 $
- */
-public class MRUAlgorithm extends BaseEvictionAlgorithm
-{
- @Override
- protected org.jboss.starobrno.eviction.EvictionQueue setupEvictionQueue() throws org.jboss.starobrno.eviction.EvictionException
- {
- return new org.jboss.starobrno.eviction.MRUQueue();
- }
-
- @Override
- protected boolean shouldEvictNode(org.jboss.starobrno.eviction.NodeEntry ne)
- {
- // check the minimum time to live and see if we should not evict the node. This check will
- // ensure that, if configured, nodes are kept alive for at least a minimum period of time.
- if (isYoungerThanMinimumTimeToLive(ne)) return false;
-
- org.jboss.starobrno.eviction.MRUAlgorithmConfig config = (org.jboss.starobrno.eviction.MRUAlgorithmConfig) evictionAlgorithmConfig;
- return evictionQueue.getNumberOfNodes() > config.getMaxNodes();
- }
-
- @Override
- protected void processVisitedNodes(org.jboss.starobrno.eviction.EvictionEvent evictedEventNode) throws org.jboss.starobrno.eviction.EvictionException
- {
- super.processVisitedNodes(evictedEventNode);
- ((org.jboss.starobrno.eviction.MRUQueue) evictionQueue).moveToTopOfStack(evictedEventNode.getFqn());
- }
-
- public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
- {
- return org.jboss.starobrno.eviction.MRUAlgorithmConfig.class;
- }
-}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithmConfig.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithmConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,95 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.jboss.starobrno.config.ConfigurationException;
-
-/**
- * Configuration for {@link org.jboss.starobrno.eviction.MRUAlgorithm}.
- * <p/>
- * Requires a "maxNodes" attribute otherwise a ConfigurationException is thrown.
- *
- * @author Manik Surtani
- * @since 3.0
- */
-public class MRUAlgorithmConfig extends EvictionAlgorithmConfigBase
-{
- /**
- * The serialVersionUID
- */
- private static final long serialVersionUID = -8734577898966155218L;
-
- public MRUAlgorithmConfig()
- {
- evictionAlgorithmClassName = org.jboss.starobrno.eviction.MRUAlgorithm.class.getName();
- // We require that maxNodes is set
- setMaxNodes(-1);
- }
-
- public MRUAlgorithmConfig(int maxNodes)
- {
- evictionAlgorithmClassName = org.jboss.starobrno.eviction.MRUAlgorithm.class.getName();
- setMaxNodes(maxNodes);
- }
-
- /**
- * Requires a positive maxNodes value or ConfigurationException
- * is thrown.
- */
- @Override
- public void validate() throws ConfigurationException
- {
- super.validate();
- if (getMaxNodes() < 0)
- throw new ConfigurationException("maxNodes not configured");
- }
-
- @Override
- public String toString()
- {
- StringBuilder str = new StringBuilder();
- str.append("MRUAlgorithmConfig: ").
- append(" maxNodes =").append(getMaxNodes());
- return str.toString();
- }
-
- @Override
- public boolean equals(Object obj)
- {
- return (obj instanceof MRUAlgorithmConfig && super.equals(obj));
- }
-
- @Override
- public void reset()
- {
- super.reset();
- setMaxNodes(-1);
- evictionAlgorithmClassName = org.jboss.starobrno.eviction.MRUAlgorithm.class.getName();
- }
-
- @Override
- public MRUAlgorithmConfig clone() throws CloneNotSupportedException
- {
- return (MRUAlgorithmConfig) super.clone();
- }
-
-}
\ No newline at end of file
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUQueue.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUQueue.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,169 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.jboss.cache.Fqn;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
-
-/**
- * MRU Eviction Queue implementation.
- * <p/>
- * This nodeMap is sorted by MRU. The first entry in the nodeMap
- * will also be the most recently used entry. The sort is implicit
- * based on a Stack that we can implicitly sort to the top by moving
- * a node that is used to the top of the eviction stack.
- *
- * @author Daniel Huang (dhuang(a)jboss.org)
- * @version $Revision: 6776 $
- */
-public class MRUQueue implements EvictionQueue
-{
- // we use our own Stack/Linked List implementation here because it guarantees O(n) = 1 for add, remove, get and
- // we can sort it in order of MRU implicitly while still getting O(n) = 1 access time
- // throughout.
- Map<Fqn, EvictionListEntry> nodeMap;
- org.jboss.starobrno.eviction.EvictionQueueList list;
- private int numElements = 0;
-
- protected MRUQueue()
- {
- nodeMap = new HashMap<Fqn, EvictionListEntry>();
- list = new org.jboss.starobrno.eviction.EvictionQueueList();
- }
-
- /**
- * This call moves a NodeEntry to the top of the stack.
- * <p/>
- * When a node is visited this method should be called to guarantee MRU ordering.
- *
- * @param fqn Fqn of the nodeEntry to move to the top of the stack.
- */
- protected void moveToTopOfStack(Fqn fqn)
- {
- EvictionListEntry le = nodeMap.remove(fqn);
- if (le != null)
- {
- list.remove(le);
- list.addToTop(le);
- nodeMap.put(le.node.getFqn(), le);
- }
- }
-
- /**
- * Will return the first entry in the nodeMap.
- * <p/>
- * The first entry in this nodeMap will also be the most recently used entry.
- *
- * @return The first node entry in nodeMap.
- */
- public org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry()
- {
- try
- {
- return list.getFirst().node;
- }
- catch (NoSuchElementException e)
- {
- //
- }
-
- return null;
- }
-
- public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn)
- {
- EvictionListEntry le = nodeMap.get(fqn);
- if (le != null)
- return le.node;
-
- return null;
- }
-
- public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn)
- {
- return this.getNodeEntry(Fqn.fromString(fqn));
- }
-
- public boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- return nodeMap.containsKey(entry.getFqn());
- }
-
- public void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- EvictionListEntry le = nodeMap.remove(entry.getFqn());
- if (le != null)
- {
- list.remove(le);
- this.numElements -= le.node.getNumberOfElements();
- }
- }
-
- public void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- if (!this.containsNodeEntry(entry))
- {
- entry.queue = this;
- EvictionListEntry le = new EvictionListEntry(entry);
- list.addToBottom(le);
- nodeMap.put(entry.getFqn(), le);
- this.numElements += entry.getNumberOfElements();
- }
- }
-
- public int getNumberOfNodes()
- {
- return list.size();
- }
-
- public int getNumberOfElements()
- {
- return this.numElements;
- }
-
- public void modifyElementCount(int difference)
- {
- this.numElements += difference;
- }
-
- public void clear()
- {
- nodeMap.clear();
- list.clear();
- this.numElements = 0;
- }
-
- public Iterator<org.jboss.starobrno.eviction.NodeEntry> iterator()
- {
- return list.iterator();
- }
-
- @Override
- public String toString()
- {
- return list.toString();
- }
-}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NodeEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NodeEntry.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NodeEntry.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,193 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.jboss.cache.Fqn;
-
-/**
- * Value object used in queue
- *
- * @author Ben Wang 2-2004
- * @author Daniel Huang - dhuang(a)jboss.org
- */
-public class NodeEntry
-{
- private long modifiedTimeStamp;
- private long creationTimeStamp;
- private int numberOfNodeVisits;
- private int numberOfElements;
- private Fqn fqn;
-
- private long inUseTimeoutTimestamp;
- private boolean currentlyInUse = false;
-
- EvictionQueue queue;
-
- /**
- * Private constructor that automatically sets the creation time stamp of the node entry.
- */
- private NodeEntry()
- {
- this.creationTimeStamp = System.currentTimeMillis();
- }
-
- public NodeEntry(Fqn fqn)
- {
- this();
- setFqn(fqn);
- }
-
- public NodeEntry(String fqn)
- {
- this();
- setFqn(Fqn.fromString(fqn));
- }
-
- /**
- * Is the node currently in use.
- *
- * @return True/false if the node is currently marked as in use.
- */
- public boolean isCurrentlyInUse()
- {
- return currentlyInUse;
- }
-
- public void setCurrentlyInUse(boolean currentlyInUse, long inUseTimeout)
- {
- this.currentlyInUse = currentlyInUse;
- if (inUseTimeout > 0)
- {
- this.inUseTimeoutTimestamp = System.currentTimeMillis() + inUseTimeout;
- }
- }
-
- public long getInUseTimeoutTimestamp()
- {
- return this.inUseTimeoutTimestamp;
- }
-
- /**
- * Get modified time stamp. This stamp is created during the node is
- * processed so it has some fuzy tolerance in there.
- *
- * @return The last modified time stamp
- */
- public long getModifiedTimeStamp()
- {
- return modifiedTimeStamp;
- }
-
- public void setModifiedTimeStamp(long modifiedTimeStamp)
- {
-// log.error("Being modified to " + modifiedTimeStamp, new Throwable());
- this.modifiedTimeStamp = modifiedTimeStamp;
- }
-
- /**
- * Get the time stamp for when the node entry was created.
- *
- * @return The node entry creation time stamp
- */
- public long getCreationTimeStamp()
- {
- return creationTimeStamp;
- }
-
- public void setCreationTimeStamp(long creationTimeStamp)
- {
- this.creationTimeStamp = creationTimeStamp;
- }
-
- public int getNumberOfNodeVisits()
- {
- return numberOfNodeVisits;
- }
-
- public void setNumberOfNodeVisits(int numberOfNodeVisits)
- {
- this.numberOfNodeVisits = numberOfNodeVisits;
- }
-
- public int getNumberOfElements()
- {
- return numberOfElements;
- }
-
- public void setNumberOfElements(int numberOfElements)
- {
- if (queue != null)
- {
- int difference = numberOfElements - this.numberOfElements;
- queue.modifyElementCount(difference);
- }
- this.numberOfElements = numberOfElements;
- }
-
- public Fqn getFqn()
- {
- return fqn;
- }
-
- void setFqn(Fqn fqn)
- {
- this.fqn = fqn;
- }
-
- @Override
- public int hashCode()
- {
- return fqn.hashCode();
- }
-
- @Override
- public boolean equals(Object o)
- {
- if (!(o instanceof NodeEntry))
- return false;
- NodeEntry ne = (NodeEntry) o;
- return fqn.equals(ne.getFqn());
- }
-
- @Override
- public String toString()
- {
- StringBuilder output = new StringBuilder();
- output.append("Fqn: ");
- if (fqn != null)
- {
- output.append(fqn);
- }
- else
- {
- output.append(" null");
- }
-
- output.append(" CreateTime: ").append(this.getCreationTimeStamp());
- output.append(" NodeVisits: ").append(this.getNumberOfNodeVisits());
- output.append(" ModifiedTime: ").append(this.getModifiedTimeStamp());
- output.append(" NumberOfElements: ").append(this.getNumberOfElements());
- output.append(" CurrentlyInUse: ").append(this.isCurrentlyInUse());
- return output.toString();
- }
-
-}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithm.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,98 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.jboss.cache.CacheSPI_Legacy;
-import org.jboss.cache.Fqn;
-import org.jboss.starobrno.config.Configuration;
-import org.jboss.starobrno.config.EvictionAlgorithmConfig;
-import org.jboss.starobrno.eviction.EvictionEvent.Type;
-
-import java.util.concurrent.BlockingQueue;
-
-/**
- * An eviction algorithm that does nothing - a no-op for everything.
- *
- * @author Brian Stansberry
- */
-public class NullEvictionAlgorithm implements EvictionAlgorithm
-{
- /**
- * Singleton instance of this class.
- */
- private static final NullEvictionAlgorithm INSTANCE = new NullEvictionAlgorithm();
-
- /**
- * Constructs a new NullEvictionAlgorithm.
- */
- private NullEvictionAlgorithm()
- {
- }
-
- public static NullEvictionAlgorithm getInstance()
- {
- return INSTANCE;
- }
-
- /**
- * Returns {@link org.jboss.starobrno.eviction.NullEvictionQueue#INSTANCE}.
- */
- public org.jboss.starobrno.eviction.EvictionQueue getEvictionQueue()
- {
- return org.jboss.starobrno.eviction.NullEvictionQueue.INSTANCE;
- }
-
- public void setEvictionActionPolicy(org.jboss.starobrno.eviction.EvictionActionPolicy evictionActionPolicy)
- {
- // no-op
- }
-
- public void assignToRegion(Fqn fqn, CacheSPI_Legacy<?, ?> cache, EvictionAlgorithmConfig evictionAlgorithmConfig, Configuration configuration)
- {
- // no-op
- }
-
- public void process(BlockingQueue<org.jboss.starobrno.eviction.EvictionEvent> queue) throws org.jboss.starobrno.eviction.EvictionException
- {
- // no-op
- }
-
- public void resetEvictionQueue()
- {
- // no-op
- }
-
- public boolean canIgnoreEvent(Type eventType)
- {
- return true; // always ignore everything!
- }
-
- public void initialize()
- {
- // no-op
- }
-
- public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
- {
- return org.jboss.starobrno.eviction.NullEvictionAlgorithmConfig.class;
- }
-}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithmConfig.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithmConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,63 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.jboss.starobrno.config.ConfigurationComponent;
-import org.jboss.starobrno.config.ConfigurationException;
-import org.jboss.starobrno.config.EvictionAlgorithmConfig;
-
-/**
- * Configuration class for {@link NullEvictionAlgorithm}.
- *
- * @author Manik Surtani
- * @since 3.0
- */
-public class NullEvictionAlgorithmConfig extends ConfigurationComponent implements EvictionAlgorithmConfig
-{
- private static final long serialVersionUID = -6591180473728241737L;
-
- /**
- * No-op
- */
- public void reset()
- {
- // no-op
- }
-
- public String getEvictionAlgorithmClassName()
- {
- return NullEvictionAlgorithm.class.getName();
- }
-
- /**
- * No-op
- */
- public void validate() throws ConfigurationException
- {
- // no-op
- }
-
- public NullEvictionAlgorithmConfig clone() throws CloneNotSupportedException
- {
- return (NullEvictionAlgorithmConfig) super.clone();
- }
-}
\ No newline at end of file
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionQueue.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionQueue.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,161 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-import org.jboss.cache.Fqn;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * A queue that does nothing.
- *
- * @author Brian Stansberry
- */
-public class NullEvictionQueue implements EvictionQueue
-{
- /**
- * Singleton instance of this class.
- */
- public static final NullEvictionQueue INSTANCE = new NullEvictionQueue();
-
- /**
- * Constructs a new NullEvictionQueue.
- */
- private NullEvictionQueue()
- {
- }
-
- /**
- * No-op
- */
- public void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- // no-op
- }
-
- /**
- * No-op
- */
- public void clear()
- {
- // no-op
- }
-
- /**
- * Returns <code>false</code>
- */
- public boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- return false;
- }
-
- /**
- * Returns <code>null</code>
- */
- public org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry()
- {
- return null;
- }
-
- /**
- * Returns <code>null</code>
- */
- public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn)
- {
- return null;
- }
-
- /**
- * Returns <code>null</code>
- */
- public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn)
- {
- return null;
- }
-
- /**
- * Returns <code>0</code>
- */
- public int getNumberOfElements()
- {
- return 0;
- }
-
- /**
- * Returns <code>0</code>
- */
- public int getNumberOfNodes()
- {
- return 0;
- }
-
- /**
- * Returns an <code>Iterator</code> whose
- * <code>hasNext()</code> returns <code>false</code>.
- */
- public Iterator<org.jboss.starobrno.eviction.NodeEntry> iterator()
- {
- return NullQueueIterator.INSTANCE;
- }
-
- /**
- * No-op
- */
- public void modifyElementCount(int difference)
- {
- // no-op
- }
-
- /**
- * No-op
- */
- public void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
- {
- // no-op
- }
-
- static class NullQueueIterator implements Iterator<org.jboss.starobrno.eviction.NodeEntry>
- {
- private static final NullQueueIterator INSTANCE = new NullQueueIterator();
-
- private NullQueueIterator()
- {
- }
-
- public boolean hasNext()
- {
- return false;
- }
-
- public org.jboss.starobrno.eviction.NodeEntry next()
- {
- throw new NoSuchElementException("No more elements");
- }
-
- public void remove()
- {
- throw new IllegalStateException("Must call next() before remove()");
- }
- }
-
-}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/RemoveOnEvictActionPolicy.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/RemoveOnEvictActionPolicy.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/RemoveOnEvictActionPolicy.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -25,6 +25,7 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Cache_Legacy;
import org.jboss.cache.Fqn;
+import org.jboss.starobrno.Cache;
/**
* An eviction action policy that calls {@link org.jboss.cache.Cache_Legacy#removeNode(org.jboss.cache.Fqn)} to evict a node.
@@ -32,25 +33,26 @@
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 3.0
*/
-public class RemoveOnEvictActionPolicy implements EvictionActionPolicy
+public class RemoveOnEvictActionPolicy<K> implements EvictionAction<K>
{
- Cache_Legacy<?, ?> cache;
- private static final Log log = LogFactory.getLog(org.jboss.starobrno.eviction.DefaultEvictionActionPolicy.class);
+ private Cache<K, ?> cache;
+ private static final Log log = LogFactory.getLog(DefaultEvictionAction.class);
- public void setCache(Cache_Legacy<?, ?> cache)
+ public void setCache(Cache<K, ?> cache)
{
this.cache = cache;
}
- public boolean evict(Fqn fqn)
+ public boolean evict(K key)
{
try
{
- return cache.removeNode(fqn);
+ cache.remove(key);
+ return true;
}
catch (Exception e)
{
- if (log.isDebugEnabled()) log.debug("Unable to evict " + fqn, e);
+ if (log.isDebugEnabled()) log.debug("Unable to evict " + key, e);
return false;
}
}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/SortedEvictionQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/SortedEvictionQueue.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/SortedEvictionQueue.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -1,36 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.eviction;
-
-/**
- * Sorted Eviction Queue implementation.
- *
- * @author Daniel Huang (dhuang(a)jboss.org)
- * @version $Revision: 6776 $
- */
-public interface SortedEvictionQueue extends EvictionQueue
-{
- /**
- * Provide contract to resort a sorted queue.
- */
- void resortEvictionQueue();
-}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/BaseEvictionAlgorithm.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseEvictionAlgorithm.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/BaseEvictionAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/BaseEvictionAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,467 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.starobrno.CacheSPI;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+import org.jboss.starobrno.eviction.*;
+import org.jboss.starobrno.eviction.EvictionEvent.Type;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Abstract Event Processing Eviction Algorithm.
+ * This class is used to implement basic event processing for Eviction Algorithms.
+ * To extend this abstract class to make an Eviction Algorithm, implement the
+ * abstract methods and a policy.
+ *
+ * @author Daniel Huang - dhuang(a)jboss.org 10/2005
+ * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
+ */
+public abstract class BaseEvictionAlgorithm<K> implements EvictionAlgorithm<K>
+{
+ private static final Log log = LogFactory.getLog(BaseEvictionAlgorithm.class);
+ private static final boolean trace = log.isTraceEnabled();
+ protected EvictionAction<K> evictionAction;
+ protected EvictionAlgorithmConfig evictionAlgorithmConfig;
+ protected BlockingQueue<K> recycleQueue;
+ protected EvictionQueue<K> evictionQueue;
+ protected CacheSPI<K, ?> cache;
+
+ /**
+ * This method will create an EvictionQueue implementation and prepare it for use.
+ *
+ * @return The created EvictionQueue to be used as the eviction queue for this algorithm.
+ * @see org.jboss.starobrno.eviction.EvictionQueue
+ */
+ protected abstract EvictionQueue<K> setupEvictionQueue() throws EvictionException;
+
+ /**
+ * This method will check whether the given node should be evicted or not.
+ *
+ * @param ne NodeEntry to test eviction for.
+ * @return True if the given node should be evicted. False if the given node should not be evicted.
+ */
+ protected abstract boolean shouldEvictNode(KeyEntry<K> ne);
+
+ protected BaseEvictionAlgorithm()
+ {
+ recycleQueue = new LinkedBlockingQueue<K>(500000);
+ }
+
+ public synchronized void initialize()
+ {
+ if (evictionQueue == null)
+ {
+ evictionQueue = setupEvictionQueue();
+ }
+ }
+
+ public EvictionAction getEvictionActionPolicy()
+ {
+ return evictionAction;
+ }
+
+ public void setEvictionAction(EvictionAction<K> evictionAction)
+ {
+ this.evictionAction = evictionAction;
+ }
+
+ public EvictionAlgorithmConfig getEvictionAlgorithmConfig()
+ {
+ return evictionAlgorithmConfig;
+ }
+
+ public void assignToCache(CacheSPI<K, ?> cache, EvictionAlgorithmConfig evictionAlgorithmConfig)
+ {
+ this.cache = cache;
+ this.evictionAlgorithmConfig = evictionAlgorithmConfig;
+ }
+
+ public boolean canIgnoreEvent(Type eventType)
+ {
+ return false; // don't ignore anything!
+ }
+
+ /**
+ * Process the given eviction event queue. Eviction Processing encompasses the following:
+ * <p/>
+ * - Add/Remove/Visit Nodes
+ * - Prune according to Eviction Algorithm
+ * - Empty/Retry the recycle queue of previously evicted but locked (during actual cache eviction) nodes.
+ *
+ * @param eventQueue queue containing eviction events
+ * @throws org.jboss.starobrno.eviction.EvictionException
+ *
+ */
+ public void process(BlockingQueue<EvictionEvent<K>> eventQueue) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ if (trace) log.trace("process(): cache: " + cache);
+ initialize();
+ this.processQueues(eventQueue);
+ this.emptyRecycleQueue();
+ this.prune();
+ }
+
+ public void resetEvictionQueue()
+ {
+ // a no-op
+ }
+
+ /**
+ * Get the underlying EvictionQueue implementation.
+ *
+ * @return the EvictionQueue used by this algorithm
+ * @see org.jboss.starobrno.eviction.EvictionQueue
+ */
+ public EvictionQueue getEvictionQueue()
+ {
+ return this.evictionQueue;
+ }
+
+ protected EvictionEvent<K> getNextInQueue(BlockingQueue<EvictionEvent<K>> queue)
+ {
+ try
+ {
+ return queue.poll(0, TimeUnit.SECONDS);
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ return null;
+ }
+
+ /**
+ * Event processing for Evict/Add/Visiting of nodes.
+ * <p/>
+ * - On AddEvents a new element is added into the eviction queue
+ * - On RemoveEvents, the removed element is removed from the eviction queue.
+ * - On VisitEvents, the visited node has its eviction statistics updated (idleTime, numberOfNodeVisists, etc..)
+ *
+ * @param queue queue to inspect
+ * @throws org.jboss.starobrno.eviction.EvictionException
+ * in the event of problems
+ */
+ protected void processQueues(BlockingQueue<EvictionEvent<K>> queue) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ EvictionEvent<K> node;
+ int count = 0;
+ while ((node = getNextInQueue(queue)) != null)
+ {
+ count++;
+ switch (node.getEventType())
+ {
+ case ADD_NODE_EVENT:
+ this.processAddedNodes(node);
+ break;
+ case REMOVE_NODE_EVENT:
+ this.processRemovedNodes(node);
+ break;
+ case VISIT_NODE_EVENT:
+ this.processVisitedNodes(node);
+ break;
+ case ADD_ELEMENT_EVENT:
+ this.processAddedElement(node);
+ break;
+ case REMOVE_ELEMENT_EVENT:
+ this.processRemovedElement(node);
+ break;
+ case MARK_IN_USE_EVENT:
+ this.processMarkInUseNodes(node.getKey(), node.getInUseTimeout());
+ break;
+ case UNMARK_USE_EVENT:
+ this.processUnmarkInUseNodes(node.getKey());
+ break;
+ default:
+ throw new RuntimeException("Illegal Eviction Event type " + node.getEventType());
+ }
+ }
+ if (trace) log.trace("processed " + count + " node events");
+ }
+
+ protected void evict(KeyEntry<K> ne)
+ {
+ if (ne != null)
+ {
+ evictionQueue.removeNodeEntry(ne);
+ if (!evictionAction.evict(ne.getKey()))
+ {
+ try
+ {
+ boolean result = recycleQueue.offer(ne.getKey(), 5, TimeUnit.SECONDS);
+ if (!result)
+ {
+ log.warn("Unable to add Fqn[" + ne.getKey() + "] to recycle " +
+ "queue because it's full. This is often sign that " +
+ "evictions are not occurring and nodes that should be " +
+ "evicted are piling up waiting to be evicted.");
+ }
+ }
+ catch (InterruptedException e)
+ {
+ log.debug("InterruptedException", e);
+ }
+ }
+ }
+ }
+
+ protected void processMarkInUseNodes(K key, long inUseTimeout) throws EvictionException
+ {
+ if (trace)
+ {
+ log.trace("Marking " + key + " as in use with a usage timeout of " + inUseTimeout);
+ }
+
+ KeyEntry ne = evictionQueue.getNodeEntry(key);
+ if (ne != null)
+ {
+ ne.setCurrentlyInUse(true, inUseTimeout);
+ }
+ }
+
+ protected void processUnmarkInUseNodes(K key) throws EvictionException
+ {
+ if (trace)
+ {
+ log.trace("Unmarking node " + key + " as in use");
+ }
+
+ KeyEntry ne = evictionQueue.getNodeEntry(key);
+ if (ne != null)
+ {
+ ne.setCurrentlyInUse(false, 0);
+ }
+ }
+
+ /**
+ * Convenience method, which calls {@link #processAddedNodes(EvictionEvent , int)} using values in the
+ * evictedEventNode for number of added elements and the resetElementCount flag.
+ *
+ * @param evictedEventNode an evictedEventNode to process
+ * @throws EvictionException on problems
+ */
+ protected void processAddedNodes(EvictionEvent<K> evictedEventNode) throws EvictionException
+ {
+ processAddedNodes(evictedEventNode, evictedEventNode.getElementDifference());
+ }
+
+ protected void processAddedNodes(EvictionEvent<K> evictedEventNode, int numAddedElements) throws EvictionException
+ {
+ K key = evictedEventNode.getKey();
+ if (trace) log.trace("Adding node " + key + " with " + numAddedElements + " elements to eviction queue");
+ KeyEntry<K> ne = evictionQueue.getNodeEntry(key);
+ if (ne != null)
+ {
+ ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
+ ne.incerementNumberOfNodeVisits();
+ ne.setNumberOfElements(ne.getNumberOfElements() + numAddedElements);
+ if (trace) log.trace("Queue already contains " + ne.getKey() + " processing it as visited");
+ processVisitedNodes(evictedEventNode);
+ return;
+ }
+ ne = new KeyEntry<K>(1, evictedEventNode.getCreationTimestamp(), numAddedElements, key);
+ evictionQueue.addNodeEntry(ne);
+ ne.setQueue(evictionQueue);
+ if (trace) log.trace(ne.getKey() + " added successfully to eviction queue");
+ }
+
+ /**
+ * Remove a node from cache.
+ * <p/>
+ * This method will remove the node from the eviction queue as well as
+ * evict the node from cache.
+ * <p/>
+ * If a node cannot be removed from cache, this method will remove it from the eviction queue
+ * and place the element into the recycleQueue. Each node in the recycle queue will get retried until
+ * proper cache eviction has taken place.
+ * <p/>
+ * Because EvictionQueues are collections, when iterating them from an iterator, use iterator.remove()
+ * to avoid ConcurrentModificationExceptions. Use the boolean parameter to indicate the calling context.
+ *
+ * @throws EvictionException
+ */
+ protected void processRemovedNodes(EvictionEvent<K> evictedEventNode) throws EvictionException
+ {
+ K key = evictedEventNode.getKey();
+
+ if (trace)
+ {
+ log.trace("Removing key " + key + " from eviction queue and attempting eviction");
+ }
+
+ KeyEntry<K> ne = evictionQueue.getNodeEntry(key);
+ if (ne != null)
+ {
+ evictionQueue.removeNodeEntry(ne);
+ } else
+ {
+ if (trace)
+ log.trace("processRemoveNodes(): Can't find node associated with key: " + key
+ + "Could have been evicted earlier. Will just continue.");
+ return;
+ }
+
+ if (trace)
+ {
+ log.trace(key + " removed from eviction queue");
+ }
+ }
+
+ /**
+ * Visit a node in cache.
+ * <p/>
+ * This method will update the numVisits and modifiedTimestamp properties of the Node.
+ * These properties are used as statistics to determine eviction (LRU, LFU, MRU, etc..)
+ * <p/>
+ * *Note* that this method updates Node Entries by reference and does not put them back
+ * into the queue. For some sorted collections, a remove, and a re-add is required to
+ * maintain the sorted order of the elements.
+ *
+ * @throws EvictionException
+ */
+ protected void processVisitedNodes(EvictionEvent<K> evictedEventNode) throws EvictionException
+ {
+ K key = evictedEventNode.getKey();
+ KeyEntry<K> ne = evictionQueue.getNodeEntry(key);
+ if (ne == null)
+ {
+ if (trace) log.trace("Visiting node that was not added to eviction queues. Assuming that it has 1 element.");
+ this.processAddedNodes(evictedEventNode, 1);
+ return;
+ }
+ // note this method will visit and modify the node statistics by reference!
+ // if a collection is only guaranteed sort order by adding to the collection,
+ // this implementation will not guarantee sort order.
+ ne.incerementNumberOfNodeVisits();
+ ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
+ }
+
+ protected void processRemovedElement(EvictionEvent<K> evictedEventNode) throws EvictionException
+ {
+ K key = evictedEventNode.getKey();
+ KeyEntry<K> ne = evictionQueue.getNodeEntry(key);
+
+ if (ne == null)
+ {
+ if (trace)
+ log.trace("Removing element from " + key + " but eviction queue does not contain this node. " +
+ "Ignoring removeElement event.");
+ return;
+ }
+
+ ne.setNumberOfElements(ne.getNumberOfElements() - 1);
+ // also treat it as a node visit.
+ ne.incerementNumberOfNodeVisits();
+ ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
+ }
+
+ protected void processAddedElement(EvictionEvent<K> evictedEventNode) throws EvictionException
+ {
+ K key = evictedEventNode.getKey();
+ KeyEntry<K> ne = evictionQueue.getNodeEntry(key);
+ if (ne == null)
+ {
+ if (trace) log.trace("Adding element " + key + " for a node that doesn't exist yet. Process as an add.");
+ this.processAddedNodes(evictedEventNode, 1);
+ return;
+ }
+ ne.setNumberOfElements(ne.getNumberOfElements() + 1);
+ ne.incerementNumberOfNodeVisits();// also treat it as a node visit.
+ ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
+ }
+
+
+ /**
+ * Empty the Recycle Queue.
+ * <p/>
+ * This method will go through the recycle queue and retry to evict the nodes from cache.
+ *
+ * @throws EvictionException
+ */
+ protected void emptyRecycleQueue() throws EvictionException
+ {
+ while (true)
+ {
+ K key;
+ try
+ {
+ key = recycleQueue.poll(0, TimeUnit.SECONDS);
+ }
+ catch (InterruptedException e)
+ {
+ log.debug(e, e);
+ break;
+ }
+
+ if (key == null)
+ {
+ if (trace) log.trace("Recycle queue is empty");
+ break;
+ }
+
+ if (trace) log.trace("emptying recycle bin. Evict key " + key);
+
+ // Still doesn't work
+ if (!evictionAction.evict(key))
+ {
+ try
+ {
+ recycleQueue.put(key);
+ }
+ catch (InterruptedException e)
+ {
+ if (trace) log.trace(e, e);
+ }
+ break;
+ }
+ }
+ }
+
+ protected void prune() throws EvictionException
+ {
+ KeyEntry<K> entry;
+ while ((entry = evictionQueue.getFirstNodeEntry()) != null)
+ {
+ if (this.shouldEvictNode(entry))
+ {
+ this.evict(entry);
+ } else
+ {
+ break;
+ }
+ }
+ }
+
+ /**
+ * Returns debug information.
+ */
+ @Override
+ public String toString()
+ {
+ return super.toString() + " recycle=" + recycleQueue.size() + " evict=" + evictionQueue.getNumberOfNodes();
+ }
+}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/BaseSortedEvictionAlgorithm.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseSortedEvictionAlgorithm.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/BaseSortedEvictionAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/BaseSortedEvictionAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.starobrno.eviction.EvictionEvent;
+import org.jboss.starobrno.eviction.EvictionException;
+import org.jboss.starobrno.eviction.algorithms.SortedEvictionQueue;
+
+import java.util.concurrent.BlockingQueue;
+
+
+/**
+ * An abstract SortedEvictionAlgorithm.
+ * <p/>
+ * This class supports early termination of the eviction queue processing. Because the eviction
+ * queue is sorted by first to evict to last to evict, when iterating the eviction queue, the first time
+ * a node is encountered that does not require eviction will terminate the loop early. This way we don't incur
+ * the full breadth of the O(n) = n operation everytime we need to check for eviction (defined by eviction poll time
+ * interval).
+ *
+ * @author Daniel Huang - dhuang(a)jboss.org - 10/2005
+ */
+public abstract class BaseSortedEvictionAlgorithm<K> extends BaseEvictionAlgorithm<K>
+{
+ private static final Log log = LogFactory.getLog(BaseSortedEvictionAlgorithm.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ @Override
+ protected void processQueues(BlockingQueue<EvictionEvent<K>> queue) throws EvictionException
+ {
+ boolean evictionNodesModified = false;
+
+ EvictionEvent<K> node;
+ int count = 0;
+ while ((node = getNextInQueue(queue)) != null)
+ {
+ count++;
+ switch (node.getEventType())
+ {
+ case ADD_NODE_EVENT:
+ this.processAddedNodes(node);
+ evictionNodesModified = true;
+ break;
+ case REMOVE_NODE_EVENT:
+ this.processRemovedNodes(node);
+ break;
+ case VISIT_NODE_EVENT:
+ this.processVisitedNodes(node);
+ evictionNodesModified = true;
+ break;
+ case ADD_ELEMENT_EVENT:
+ this.processAddedElement(node);
+ evictionNodesModified = true;
+ break;
+ case REMOVE_ELEMENT_EVENT:
+ this.processRemovedElement(node);
+ evictionNodesModified = true;
+ break;
+ default:
+ throw new RuntimeException("Illegal Eviction Event type " + node.getEventType());
+ }
+ }
+
+ if (trace) log.trace("Eviction nodes visited or added requires resort of queue " + evictionNodesModified);
+ this.resortEvictionQueue(evictionNodesModified);
+ if (trace) log.trace("processed " + count + " node events");
+ }
+
+ /**
+ * This method is called to resort the queue after add or visit events have occurred.
+ * <p/>
+ * If the parameter is true, the queue needs to be resorted. If it is false, the queue does not
+ * need resorting.
+ *
+ * @param evictionQueueModified True if the queue was added to or visisted during event processing.
+ */
+ protected void resortEvictionQueue(boolean evictionQueueModified)
+ {
+ if (!evictionQueueModified)
+ {
+ if (trace) log.debug("Eviction queue not modified. Resort unnecessary.");
+ return;
+ }
+ long begin = System.currentTimeMillis();
+ ((SortedEvictionQueue) evictionQueue).resortEvictionQueue();
+
+ if (trace)
+ {
+ long end = System.currentTimeMillis();
+ long diff = end - begin;
+ log.trace("Took " + diff + "ms to sort queue with " + getEvictionQueue().getNumberOfNodes() + " elements");
+ }
+ }
+
+}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/ElementSizeAlgorithm.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithm.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/ElementSizeAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/ElementSizeAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms;
+
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+import org.jboss.starobrno.eviction.*;
+
+/**
+ * @author Daniel Huang
+ * @version $Revision: 6776 $
+ */
+public class ElementSizeAlgorithm<K> extends BaseSortedEvictionAlgorithm<K>
+{
+ @Override
+ protected EvictionQueue<K> setupEvictionQueue() throws EvictionException
+ {
+ return new ElementSizeQueue<K>();
+ }
+
+ @Override
+ protected boolean shouldEvictNode(KeyEntry<K> ne)
+ {
+ // check the minimum time to live and see if we should not evict the node. This check will
+ // ensure that, if configured, nodes are kept alive for at least a minimum period of time.
+ if (ne.isYoungerThanMinimumTimeToLive(evictionAlgorithmConfig.getMinTimeToLive())) return false;
+ int size = this.getEvictionQueue().getNumberOfNodes();
+ ElementSizeAlgorithmConfig config = (ElementSizeAlgorithmConfig) evictionAlgorithmConfig;
+ return config.getMaxNodes() > -1 && size > config.getMaxNodes() || ne.getNumberOfElements() > config.getMaxElementsPerNode();
+ }
+
+ @Override
+ protected void prune() throws EvictionException
+ {
+ super.prune();
+
+ // clean up the Queue's eviction removals
+ ((ElementSizeQueue) this.evictionQueue).prune();
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return ElementSizeAlgorithmConfig.class;
+ }
+}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/ExpirationAlgorithm.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithm.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/ExpirationAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/ExpirationAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,364 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+import org.jboss.starobrno.eviction.*;
+import org.jboss.starobrno.eviction.EvictionEvent.Type;
+
+import java.util.Iterator;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.BlockingQueue;
+
+/**
+ * Eviction algorithm that uses a key in the Node data that indicates the time
+ * the node should be evicted. The key must be a java.lang.Long object, with
+ * the time to expire as milliseconds past midnight January 1st, 1970 UTC (the
+ * same relative time as provided by {@link
+ * java.lang.System#currentTimeMillis()}).
+ * <p/>
+ * This algorithm also obeys the configuration key {@link
+ * org.jboss.starobrno.eviction.ExpirationAlgorithmConfig#getMaxNodes()}, and will evict the soonest to
+ * expire entires first to reduce the region size. If there are not enough
+ * nodes with expiration keys set, a warning is logged.
+ * <p/>
+ * If a node in the eviction region does not have an expiration value, then
+ * {@link org.jboss.starobrno.eviction.ExpirationAlgorithmConfig#getTimeToLive()} (if set) will be used.
+ * The expiration is updated when a node is added or updated.
+ * <p/>
+ * If there is no time-to-live set, and a node in the eviction region does not
+ * have an expiration value, then that node will never be evicted. As
+ * forgetting to indicate an expiration value is likely a mistake, a warning
+ * message is logged by this class. This warning, however, can be disabled
+ * through {@link org.jboss.starobrno.eviction.ExpirationAlgorithmConfig#setWarnNoExpirationKey(boolean)}.
+ * <p/>
+ * A node's expiration time can be changed by setting a new value in the node.
+ * <p/>
+ * Example usage:
+ * <pre>
+ * Cache cache;
+ * Fqn fqn1 = Fqn.fromString("/node/1");
+ * Long future = new Long(System.currentTimeMillis() + 2000);
+ * cache.put(fqn1, ExpirationConfiguration.EXPIRATION_KEY, future);
+ * cache.put(fqn1, "foo");
+ * assertTrue(cache.get(fqn1) != null);
+ * <p/>
+ * Thread.sleep(5000); // 5 seconds
+ * assertTrue(cache.get(fqn1) == null);
+ * <p/>
+ * </pre>
+ */
+public class ExpirationAlgorithm<K> extends BaseEvictionAlgorithm<K>
+{
+
+ private static final Log log = LogFactory.getLog(ExpirationAlgorithm.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ private ExpirationAlgorithmConfig config;
+
+ private SortedSet<ExpirationEntry<K>> set;
+
+ /**
+ * Constructs a new algorithm with a policy.
+ */
+ public ExpirationAlgorithm()
+ {
+ this.set = new TreeSet<ExpirationEntry<K>>();
+ }
+
+ private void addEvictionEntry(EvictionEvent<K> node)
+ {
+ K key = node.getKey();
+ addEvictionEntry(key);
+ }
+
+ private void addEvictionEntry(K key)
+ {
+ Long l = getExpiration();
+ if (l == null)
+ {
+ if (config.isWarnNoExpirationKey() && log.isWarnEnabled())
+ log.warn("No expiration key '" + config.getExpirationKeyName() + "' for Node: " + key);
+ else if (log.isDebugEnabled())
+ log.debug("No expiration key for Node: " + key);
+ } else
+ {
+ setExpiration(key, l);
+ }
+ }
+
+ private void setExpiration(K key, Long l)
+ {
+ ExpirationEntry<K> ee = new ExpirationEntry<K>(key, l);
+ if (trace) log.trace("adding eviction entry: " + ee);
+ set.add(ee);
+ }
+
+ private Long getExpiration()
+ {
+ return (Long) cache.getDirect(config.getExpirationKeyName());
+ }
+
+ @Override
+ protected void processQueues(BlockingQueue<EvictionEvent<K>> queue) throws EvictionException
+ {
+ EvictionEvent<K> node;
+ int count = 0;
+ while ((node = getNextInQueue(queue)) != null)
+ {
+ count++;
+ switch (node.getEventType())
+ {
+ case ADD_NODE_EVENT:
+ case ADD_ELEMENT_EVENT:
+ addEvictionEntry(node);
+ break;
+ case REMOVE_ELEMENT_EVENT:
+ case REMOVE_NODE_EVENT:
+ case UNMARK_USE_EVENT:
+ // Removals will be noticed when double-checking expiry time
+ // removeEvictionEntry(node);
+ break;
+ case VISIT_NODE_EVENT:
+ // unused
+ break;
+ case MARK_IN_USE_EVENT:
+ markInUse(node);
+ break;
+ default:
+ throw new RuntimeException("Illegal Eviction Event type " + node.getEventType());
+ }
+ }
+
+ if (trace) log.trace("processed " + count + " node events in cache: " + cache.getName());
+ }
+
+ private void markInUse(EvictionEvent<K> node)
+ {
+ long expiration = node.getInUseTimeout() + System.currentTimeMillis();
+ setExpiration(node.getKey(), expiration);
+ }
+
+ @Override
+ protected void prune() throws EvictionException
+ {
+ if (set.isEmpty())
+ return;
+ long now = System.currentTimeMillis();
+ int max = config.getMaxNodes();
+ for (Iterator<ExpirationEntry<K>> i = set.iterator(); i.hasNext();)
+ {
+ ExpirationEntry<K> ee = i.next();
+ Long ce = getExpiration();
+ if (ce == null || ce > ee.getExpiration())
+ {
+ // Expiration now older
+ i.remove();
+ continue;
+ }
+ if (ee.getExpiration() < now || (max != 0 && set.size() > max))
+ {
+ i.remove();
+ evictionAction.evict(ee.getKey());
+ } else
+ {
+ break;
+ }
+ }
+ if (max != 0 && max > set.size())
+ log.warn("Unable to remove nodes to reduce region size below " +
+ config.getMaxNodes() + ". " +
+ "Set expiration for nodes in this region");
+ }
+
+ @Override
+ public void resetEvictionQueue()
+ {
+ for (ExpirationEntry<K> ee : set)
+ {
+ addEvictionEntry(ee.getKey());
+ }
+ }
+
+ @Override
+ @SuppressWarnings(value = "unchecked")
+ protected EvictionQueue<K> setupEvictionQueue() throws EvictionException
+ {
+ this.config = (ExpirationAlgorithmConfig) evictionAlgorithmConfig;
+ return new DummyEvictionQueue<K>();
+ }
+
+ @Override
+ protected boolean shouldEvictNode(KeyEntry<K> ne)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean canIgnoreEvent(Type eventType)
+ {
+ return (eventType == EvictionEvent.Type.VISIT_NODE_EVENT);
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return ExpirationAlgorithmConfig.class;
+ }
+
+ /**
+ * Ordered list of FQN, with the expiration taken from the Map at the time
+ * of processing.
+ */
+ static class ExpirationEntry<K> implements Comparable<ExpirationEntry>
+ {
+ private long expiration;
+
+ private K key;
+
+ public ExpirationEntry(K key)
+ {
+ this.key = key;
+ }
+
+ public ExpirationEntry(K key, long expiration)
+ {
+ this.key = key;
+ this.expiration = expiration;
+ }
+
+ /**
+ * Compares expiration, then FQN order.
+ */
+ public int compareTo(ExpirationEntry ee)
+ {
+ long n = expiration - ee.expiration;
+ if (n < 0)
+ return -1;
+ if (n > 0)
+ return 1;
+ return 0;
+ }
+
+ /**
+ * @return the expiration
+ */
+ public long getExpiration()
+ {
+ return expiration;
+ }
+
+ /**
+ * @return the fqn
+ */
+ public K getKey()
+ {
+ return key;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (!(o instanceof ExpirationEntry))
+ return false;
+ ExpirationEntry ee = (ExpirationEntry) o;
+ return expiration == ee.expiration && key.equals(ee.key);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return (int) expiration ^ key.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ long now = System.currentTimeMillis();
+ long ttl = expiration - now;
+ String sttl;
+ if (ttl > 1000 * 60)
+ sttl = (ttl / (1000 * 60)) + "min";
+ else if (ttl > 1000)
+ sttl = (ttl / 1000) + "s";
+ else
+ sttl = ttl + "ms";
+ return "EE key=" + key + " ttl=" + sttl;
+ }
+ }
+
+ class DummyEvictionQueue<K> implements EvictionQueue<K>
+ {
+
+ public void addNodeEntry(KeyEntry entry)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear()
+ {
+ set.clear();
+ }
+
+ public boolean containsNodeEntry(KeyEntry entry)
+ {
+ return false;
+ }
+
+ public KeyEntry<K> getFirstNodeEntry()
+ {
+ return null;
+ }
+
+ public KeyEntry<K> getNodeEntry(K k)
+ {
+ return null;
+ }
+
+ public int getNumberOfElements()
+ {
+ return set.size();
+ }
+
+ public int getNumberOfNodes()
+ {
+ return set.size();
+ }
+
+ public Iterator<KeyEntry<K>> iterator()
+ {
+ return null;
+ }
+
+ public void modifyElementCount(int difference)
+ {
+ }
+
+ public void removeNodeEntry(KeyEntry entry)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/ExpirationAlgorithm.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/NULL/NullEvictionAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/NULL/NullEvictionAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/NULL/NullEvictionAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.NULL;
+
+import org.jboss.starobrno.CacheSPI;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+import org.jboss.starobrno.eviction.EvictionAction;
+import org.jboss.starobrno.eviction.EvictionAlgorithm;
+import org.jboss.starobrno.eviction.EvictionEvent.Type;
+import org.jboss.starobrno.eviction.EvictionException;
+import org.jboss.starobrno.eviction.EvictionQueue;
+
+import java.util.concurrent.BlockingQueue;
+
+/**
+ * An eviction algorithm that does nothing - a no-op for everything.
+ *
+ * @author Brian Stansberry
+ */
+public class NullEvictionAlgorithm implements EvictionAlgorithm
+{
+ /**
+ * Singleton instance of this class.
+ */
+ private static final NullEvictionAlgorithm INSTANCE = new NullEvictionAlgorithm();
+
+ /**
+ * Constructs a new NullEvictionAlgorithm.
+ */
+ private NullEvictionAlgorithm()
+ {
+ }
+
+ public static NullEvictionAlgorithm getInstance()
+ {
+ return INSTANCE;
+ }
+
+ /**
+ * Returns {@link NullEvictionQueue#INSTANCE}.
+ */
+ public EvictionQueue getEvictionQueue()
+ {
+ return NullEvictionQueue.INSTANCE;
+ }
+
+ public void setEvictionAction(EvictionAction evictionAction)
+ {
+ // no-op
+ }
+
+ public void assignToCache(CacheSPI cache, EvictionAlgorithmConfig evictionAlgorithmConfig)
+ {
+ // no-op
+ }
+
+ public void process(BlockingQueue queue) throws EvictionException
+ {
+ // no-op
+ }
+
+ public void resetEvictionQueue()
+ {
+ // no-op
+ }
+
+ public boolean canIgnoreEvent(Type eventType)
+ {
+ return true; // always ignore everything!
+ }
+
+ public void initialize()
+ {
+ // no-op
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return NullEvictionAlgorithmConfig.class;
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/NULL/NullEvictionAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/NULL/NullEvictionAlgorithmConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/NULL/NullEvictionAlgorithmConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.NULL;
+
+import org.jboss.starobrno.config.ConfigurationComponent;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+
+/**
+ * Configuration class for {@link NullEvictionAlgorithm}.
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class NullEvictionAlgorithmConfig extends ConfigurationComponent implements EvictionAlgorithmConfig
+{
+ private static final long serialVersionUID = -6591180473728241737L;
+
+ /**
+ * No-op
+ */
+ public void reset()
+ {
+ // no-op
+ }
+
+ public String getEvictionAlgorithmClassName()
+ {
+ return NullEvictionAlgorithm.class.getName();
+ }
+
+ /**
+ * No-op
+ */
+ public void validate() throws ConfigurationException
+ {
+ // no-op
+ }
+
+ public NullEvictionAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (NullEvictionAlgorithmConfig) super.clone();
+ }
+
+ public long getMinTimeToLive()
+ {
+ throw new UnsupportedOperationException("Not implemented");//todo please implement!
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/NULL/NullEvictionQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/NULL/NullEvictionQueue.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/NULL/NullEvictionQueue.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,163 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.NULL;
+
+import org.jboss.starobrno.eviction.EvictionQueue;
+import org.jboss.starobrno.eviction.KeyEntry;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * A queue that does nothing.
+ *
+ * @author Brian Stansberry
+ */
+public class NullEvictionQueue implements EvictionQueue
+{
+ /**
+ * Singleton instance of this class.
+ */
+ public static final NullEvictionQueue INSTANCE = new NullEvictionQueue();
+
+ /**
+ * Constructs a new NullEvictionQueue.
+ */
+ private NullEvictionQueue()
+ {
+ }
+
+ /**
+ * No-op
+ */
+ public void addNodeEntry(KeyEntry entry)
+ {
+ // no-op
+ }
+
+ /**
+ * No-op
+ */
+ public void clear()
+ {
+ // no-op
+ }
+
+ /**
+ * Returns <code>false</code>
+ */
+ public boolean containsNodeEntry(KeyEntry entry)
+ {
+ return false;
+ }
+
+ /**
+ * Returns <code>null</code>
+ */
+ public KeyEntry getFirstNodeEntry()
+ {
+ return null;
+ }
+
+ /**
+ * Returns <code>null</code>
+ */
+ public KeyEntry getNodeEntry(Object fqn)
+ {
+ return null;
+ }
+
+ /**
+ * Returns <code>null</code>
+ */
+ public KeyEntry getNodeEntry(String fqn)
+ {
+ return null;
+ }
+
+ /**
+ * Returns <code>0</code>
+ */
+ public int getNumberOfElements()
+ {
+ return 0;
+ }
+
+ /**
+ * Returns <code>0</code>
+ */
+ public int getNumberOfNodes()
+ {
+ return 0;
+ }
+
+ /**
+ * Returns an <code>Iterator</code> whose
+ * <code>hasNext()</code> returns <code>false</code>.
+ */
+ public Iterator iterator()
+ {
+ return NullQueueIterator.INSTANCE;
+ }
+
+
+ /**
+ * No-op
+ */
+ public void modifyElementCount(int difference)
+ {
+ // no-op
+ }
+
+ /**
+ * No-op
+ */
+ public void removeNodeEntry(KeyEntry entry)
+ {
+ // no-op
+ }
+
+ static class NullQueueIterator implements Iterator<KeyEntry>
+ {
+ private static final NullQueueIterator INSTANCE = new NullQueueIterator();
+
+ private NullQueueIterator()
+ {
+ }
+
+ public boolean hasNext()
+ {
+ return false;
+ }
+
+ public KeyEntry next()
+ {
+ throw new NoSuchElementException("No more elements");
+ }
+
+ public void remove()
+ {
+ throw new IllegalStateException("Must call next() before remove()");
+ }
+ }
+
+}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/SortedEvictionQueue.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/SortedEvictionQueue.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/SortedEvictionQueue.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/SortedEvictionQueue.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms;
+
+import org.jboss.starobrno.eviction.EvictionQueue;
+
+/**
+ * Sorted Eviction Queue implementation.
+ *
+ * @author Daniel Huang (dhuang(a)jboss.org)
+ * @version $Revision: 6776 $
+ */
+public interface SortedEvictionQueue<K> extends EvictionQueue<K>
+{
+ /**
+ * Provide contract to resort a sorted queue.
+ */
+ void resortEvictionQueue();
+}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/fifo/FIFOAlgorithm.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithm.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/fifo/FIFOAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/fifo/FIFOAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.fifo;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+import org.jboss.starobrno.eviction.algorithms.BaseEvictionAlgorithm;
+import org.jboss.starobrno.eviction.EvictionQueue;
+import org.jboss.starobrno.eviction.EvictionException;
+import org.jboss.starobrno.eviction.KeyEntry;
+
+/**
+ * First-in-first-out algorithm used to evict nodes.
+ *
+ * @author Daniel Huang - dhuang(a)jboss.org
+ * @author Morten Kvistgaard
+ * @version $Revision: 6776 $
+ */
+public class FIFOAlgorithm<K> extends BaseEvictionAlgorithm<K>
+{
+ private static final Log log = LogFactory.getLog(FIFOAlgorithm.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ @Override
+ protected EvictionQueue<K> setupEvictionQueue() throws EvictionException
+ {
+ return new FIFOQueue<K>();
+ }
+
+ /**
+ * For FIFO, a node should be evicted if the queue size is >= to the configured maxNodes size.
+ */
+ @Override
+ protected boolean shouldEvictNode(KeyEntry ne)
+ {
+ // check the minimum time to live and see if we should not evict the node. This check will
+ // ensure that, if configured, nodes are kept alive for at least a minimum period of time.
+ if (ne.isYoungerThanMinimumTimeToLive(evictionAlgorithmConfig.getMinTimeToLive())) return false;
+
+ FIFOAlgorithmConfig config = (FIFOAlgorithmConfig) evictionAlgorithmConfig;
+ if (trace) log.trace("Deciding whether node in queue " + ne.getKey() + " requires eviction.");
+
+ int size = this.getEvictionQueue().getNumberOfNodes();
+ return config.getMaxNodes() != 0 && size > config.getMaxNodes();
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return FIFOAlgorithmConfig.class;
+ }
+}
+
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/fifo/FIFOAlgorithm.java
___________________________________________________________________
Name: svn:executable
+ *
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/fifo/FIFOAlgorithmConfig.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithmConfig.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/fifo/FIFOAlgorithmConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/fifo/FIFOAlgorithmConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.fifo;
+
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.eviction.EvictionAlgorithmConfigBase;
+
+/**
+ * Configuration for {@link FIFOAlgorithm}.
+ * <p/>
+ * Requires a "maxNodes" attribute otherwise a ConfigurationException is thrown.
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class FIFOAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = -7229715009546277313L;
+
+ public FIFOAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = FIFOAlgorithm.class.getName();
+ // We require that maxNodes is set
+ setMaxNodes(-1);
+ }
+
+ public FIFOAlgorithmConfig(int maxNodes)
+ {
+ evictionAlgorithmClassName = FIFOAlgorithm.class.getName();
+ // We require that maxNodes is set
+ setMaxNodes(maxNodes);
+ }
+
+ /**
+ * Requires a positive maxNodes value or ConfigurationException
+ * is thrown.
+ */
+ @Override
+ public void validate() throws ConfigurationException
+ {
+ super.validate();
+ if (getMaxNodes() < 0)
+ {
+ throw new ConfigurationException("maxNodes must be must be " +
+ "configured to a value greater than or equal to 0");
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder ret = new StringBuilder();
+ ret.append("FIFOAlgorithmConfig: maxNodes = ").append(getMaxNodes());
+ return ret.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return (obj instanceof FIFOAlgorithmConfig && super.equals(obj));
+ }
+
+ @Override
+ public void reset()
+ {
+ super.reset();
+ setMaxNodes(-1);
+ evictionAlgorithmClassName = FIFOAlgorithm.class.getName();
+ }
+
+ @Override
+ public FIFOAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (FIFOAlgorithmConfig) super.clone();
+ }
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/fifo/FIFOQueue.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOQueue.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/fifo/FIFOQueue.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/fifo/FIFOQueue.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.fifo;
+
+import org.jboss.starobrno.eviction.EvictionQueue;
+import org.jboss.starobrno.eviction.KeyEntry;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * FIFO Eviction Queue implementation for FIFO Policy.
+ *
+ * @author Daniel Huang (dhuang(a)jboss.org)
+ * @version $Revision: 6776 $
+ */
+public class FIFOQueue<K> implements EvictionQueue<K>
+{
+ private Map<K, KeyEntry<K>> keyMap;
+ private int numElements = 0;
+
+ protected FIFOQueue()
+ {
+ keyMap = new LinkedHashMap<K, KeyEntry<K>>();
+ // We use a LinkedHashMap here because we want to maintain FIFO ordering and still get the benefits of
+ // O(n) = 1 for add/remove/search.
+ }
+
+ public KeyEntry<K> getFirstNodeEntry()
+ {
+ if (keyMap.size() > 0)
+ {
+ return keyMap.values().iterator().next();
+ }
+ return null;
+ }
+
+ public KeyEntry<K> getNodeEntry(K key)
+ {
+ return keyMap.get(key);
+ }
+
+ public boolean containsNodeEntry(KeyEntry<K> entry)
+ {
+ K key = entry.getKey();
+ return this.getNodeEntry(key) != null;
+ }
+
+ public void removeNodeEntry(KeyEntry<K> entry)
+ {
+ KeyEntry<K> e = keyMap.remove(entry.getKey());
+ this.numElements -= e.getNumberOfElements();
+ }
+
+ public void addNodeEntry(KeyEntry<K> entry)
+ {
+ if (!this.containsNodeEntry(entry))
+ {
+ keyMap.put(entry.getKey(), entry);
+ this.numElements += entry.getNumberOfElements();
+ }
+ }
+
+ public int getNumberOfNodes()
+ {
+ return keyMap.size();
+ }
+
+ public int getNumberOfElements()
+ {
+ return this.numElements;
+ }
+
+ public void modifyElementCount(int difference)
+ {
+ this.numElements += difference;
+ }
+
+ public void clear()
+ {
+ keyMap.clear();
+ this.numElements = 0;
+ }
+
+ public Iterator<KeyEntry<K>> iterator()
+ {
+ return keyMap.values().iterator();
+ }
+}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lfu/LFUAlgorithm.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithm.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lfu/LFUAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lfu/LFUAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.lfu;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+import org.jboss.starobrno.eviction.algorithms.BaseSortedEvictionAlgorithm;
+import org.jboss.starobrno.eviction.EvictionQueue;
+import org.jboss.starobrno.eviction.KeyEntry;
+import org.jboss.starobrno.eviction.EvictionException;
+
+/**
+ * Least Frequently Used algorithm for cache eviction.
+ * Note that this algorithm is not thread-safe.
+ * <p/>
+ * This algorithm relies on maxNodes and minNodes to operate correctly.
+ * Eviction takes place using Least Frequently Used algorithm. A node A
+ * that is used less than a node B is evicted sooner.
+ * <p/>
+ * The minNodes property defines a threshold for eviction. If minNodes = 100,
+ * the LFUAlgorithm will not evict the cache to anything less than 100 elements
+ * still left in cache. The maxNodes property defines the maximum number of nodes
+ * the cache will accept before eviction. maxNodes = 0 means that this region is
+ * unbounded. minNodes = 0 means that the eviction queue will attempt to bring
+ * the cache of this region to 0 elements (evict all elements) whenever it is run.
+ * <p/>
+ * This algorithm uses a sorted eviction queue. The eviction queue is sorted in
+ * ascending order based on the number of times a node is visited. The more frequently
+ * a node is visited, the less likely it will be evicted.
+ *
+ * @author Daniel Huang - dhuang(a)jboss.org 10/2005
+ * @version $Revision: 6776 $
+ */
+public class LFUAlgorithm extends BaseSortedEvictionAlgorithm
+{
+ private static final Log log = LogFactory.getLog(LFUAlgorithm.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ @Override
+ protected boolean shouldEvictNode( KeyEntry ne)
+ {
+ if (trace)
+ {
+ log.trace("Deciding whether node in queue " + ne.getKey() + " requires eviction.");
+ }
+
+ // check the minimum time to live and see if we should not evict the node. This check will
+ // ensure that, if configured, nodes are kept alive for at least a minimum period of time.
+ if (ne.isYoungerThanMinimumTimeToLive(evictionAlgorithmConfig.getMinTimeToLive())) return false;
+
+ LFUAlgorithmConfig config = (LFUAlgorithmConfig) evictionAlgorithmConfig;
+ int size = this.getEvictionQueue().getNumberOfNodes();
+ if (config.getMaxNodes() > -1 && size > config.getMaxNodes())
+ {
+ return true;
+ }
+ else if (size > config.getMinNodes())
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Will create a LFUQueue to be used as the underlying eviction queue.
+ *
+ * @return The created LFUQueue.
+ * @throws org.jboss.starobrno.eviction.EvictionException
+ *
+ */
+ @Override
+ protected EvictionQueue setupEvictionQueue() throws EvictionException
+ {
+ return new LFUQueue();
+ }
+
+ @Override
+ protected void prune() throws EvictionException
+ {
+ super.prune();
+
+ // clean up the Queue's eviction removals
+ ((LFUQueue) this.evictionQueue).prune();
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return LFUAlgorithmConfig.class;
+ }
+}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lfu/LFUAlgorithmConfig.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithmConfig.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lfu/LFUAlgorithmConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lfu/LFUAlgorithmConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.lfu;
+
+import org.jboss.starobrno.config.Dynamic;
+import org.jboss.starobrno.eviction.EvictionAlgorithmConfigBase;
+
+/**
+ * Configuration implementation for {@link LFUAlgorithm}.
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class LFUAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = 1865801530398969179L;
+
+ @Dynamic
+ private int minNodes;
+
+ public LFUAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = LFUAlgorithm.class.getName();
+ }
+
+ public LFUAlgorithmConfig(int maxNodes, int minNodes)
+ {
+ this();
+ setMaxNodes(maxNodes);
+ setMinNodes(minNodes);
+ }
+
+ public int getMinNodes()
+ {
+ return minNodes;
+ }
+
+ public void setMinNodes(int minNodes)
+ {
+ testImmutability("minNodes");
+ this.minNodes = minNodes;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder ret = new StringBuilder();
+ ret.append("LFUAlgorithmConfig: maxNodes = ").append(getMaxNodes()).append(" minNodes = ").append(getMinNodes());
+ return ret.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof LFUAlgorithmConfig && super.equals(obj))
+ {
+ return (this.minNodes == ((LFUAlgorithmConfig) obj).minNodes);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = super.hashCode();
+ result = 31 * result + minNodes;
+ return result;
+ }
+
+ @Override
+ public LFUAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (LFUAlgorithmConfig) super.clone();
+ }
+
+ @Override
+ public void reset()
+ {
+ super.reset();
+ minNodes = -1;
+ evictionAlgorithmClassName = LFUAlgorithm.class.getName();
+ }
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lfu/LFUQueue.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUQueue.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lfu/LFUQueue.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lfu/LFUQueue.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,215 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.lfu;
+
+import org.jboss.starobrno.eviction.KeyEntry;
+import org.jboss.starobrno.eviction.algorithms.SortedEvictionQueue;
+
+import java.util.*;
+
+/**
+ * LFUQueue EvictionQueue implementation for LFU Policy.
+ * <p/>
+ * The queue is sorted in least frequently used order.
+ *
+ * @author Daniel Huang (dhuang(a)jboss.org)
+ * @version $Revision: 6776 $
+ */
+public class LFUQueue<K> implements SortedEvictionQueue<K>
+{
+ private Map<K, KeyEntry<K>> keyMap;
+ private LinkedList<KeyEntry<K>> evictionList;
+ private Set<KeyEntry<K>> removalQueue;
+ private Comparator<KeyEntry<K>> comparator;
+
+ private int numElements = 0;
+
+ protected LFUQueue()
+ {
+ keyMap = new HashMap<K, KeyEntry<K>>();
+ comparator = new LFUComparator<K>();
+ evictionList = new LinkedList<KeyEntry<K>>();
+ removalQueue = new HashSet<KeyEntry<K>>();
+ }
+
+ /**
+ * Return the first node to evict.
+ * <p/>
+ * This method will return the least frequently used entry in the queue.
+ */
+ public KeyEntry<K> getFirstNodeEntry()
+ {
+ try
+ {
+ KeyEntry<K> ne;
+ while ((ne = evictionList.getFirst()) != null)
+ {
+ if (removalQueue.contains(ne))
+ {
+ evictionList.removeFirst();
+ removalQueue.remove(ne);
+ } else
+ {
+ break;
+ }
+ }
+ return ne;
+ }
+ catch (NoSuchElementException e)
+ {
+ //
+ }
+ return null;
+ }
+
+ public KeyEntry<K> getNodeEntry(K key)
+ {
+ return keyMap.get(key);
+ }
+
+ public boolean containsNodeEntry(KeyEntry<K> entry)
+ {
+ K key = entry.getKey();
+ return this.getNodeEntry(key) != null;
+ }
+
+ public void removeNodeEntry(KeyEntry<K> entry)
+ {
+ KeyEntry<K> ne = keyMap.remove(entry.getKey());
+ if (ne != null)
+ {
+ // don't remove directly from the LinkedList otherwise we will incur a O(n) = n
+ // performance penalty for every removal! In the prune method for LFU, we will iterate the LinkedList through ONCE
+ // doing a single O(n) = n operation and removal. This is much preferred over running O(n) = n every single time
+ // remove is called. There is also special logic in the getFirstNodeEntry that will know to check
+ // the removalQueue before returning.
+ this.removalQueue.add(ne);
+ this.numElements -= ne.getNumberOfElements();
+ }
+ }
+
+ public void addNodeEntry(KeyEntry<K> entry)
+ {
+ if (!this.containsNodeEntry(entry))
+ {
+ K key = entry.getKey();
+ keyMap.put(key, entry);
+ evictionList.add(entry);
+ this.numElements += entry.getNumberOfElements();
+ }
+ }
+
+ public int getNumberOfNodes()
+ {
+ return keyMap.size();
+ }
+
+ public int getNumberOfElements()
+ {
+ return this.numElements;
+ }
+
+ public void clear()
+ {
+ keyMap.clear();
+ evictionList.clear();
+ removalQueue.clear();
+ this.numElements = 0;
+ }
+
+ public void resortEvictionQueue()
+ {
+ Collections.sort(evictionList, comparator);
+ }
+
+ public void modifyElementCount(int difference)
+ {
+ this.numElements += difference;
+ }
+
+ protected void prune()
+ {
+ Iterator<KeyEntry<K>> it = this.iterator();
+ while (it.hasNext() && removalQueue.size() > 0)
+ {
+ if (removalQueue.remove(it.next()))
+ {
+ it.remove();
+ }
+ }
+ }
+
+ protected final List<KeyEntry<K>> getEvictionList()
+ {
+ return this.evictionList;
+ }
+
+ protected final Set<KeyEntry<K>> getRemovalQueue()
+ {
+ return this.removalQueue;
+ }
+
+ public Iterator<KeyEntry<K>> iterator()
+ {
+ return evictionList.iterator();
+ }
+
+ /**
+ * Comparator class for LFU.
+ * <p/>
+ * This class will sort the eviction queue in the correct eviction order.
+ * The top of the list should evict before the bottom of the list.
+ * <p/>
+ * The sort is based on ascending order of nodeVisits.
+ * <p/>
+ * Note: this class has a natural ordering that is inconsistent with equals as defined by the java.lang.Comparator
+ * contract.
+ */
+ protected static class LFUComparator<K> implements Comparator<KeyEntry<K>>
+ {
+
+ public int compare(KeyEntry<K> ne1, KeyEntry<K> ne2)
+ {
+ if (ne1.equals(ne2))
+ {
+ return 0;
+ }
+
+ int neNodeHits = ne1.getNumberOfNodeVisits();
+ int ne2NodeHits = ne2.getNumberOfNodeVisits();
+
+ if (neNodeHits > ne2NodeHits)
+ {
+ return 1;
+ } else if (neNodeHits < ne2NodeHits)
+ {
+ return -1;
+ } else if (neNodeHits == ne2NodeHits)
+ {
+ return 0;
+ }
+ throw new RuntimeException("Should never reach this condition");
+ }
+ }
+
+}
+
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lru/LRUAlgorithm.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithm.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lru/LRUAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lru/LRUAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,192 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.lru;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+import org.jboss.starobrno.eviction.algorithms.BaseEvictionAlgorithm;
+import org.jboss.starobrno.eviction.KeyEntry;
+import org.jboss.starobrno.eviction.EvictionQueue;
+import org.jboss.starobrno.eviction.EvictionException;
+
+import java.util.Iterator;
+
+/**
+ * Least recently Used algorithm to purge old data.
+ * Note that this algorithm is not thread-safe.
+ *
+ * @author Ben Wang 02-2004
+ * @author Daniel Huang - dhuang(a)jboss.org
+ */
+public class LRUAlgorithm<K> extends BaseEvictionAlgorithm<K>
+{
+ private static final Log log = LogFactory.getLog(LRUAlgorithm.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ @Override
+ protected EvictionQueue<K> setupEvictionQueue() throws EvictionException
+ {
+ return new LRUQueue<K>();
+ }
+
+ @Override
+ protected boolean shouldEvictNode(KeyEntry<K> entry)
+ {
+ // check the minimum time to live and see if we should not evict the node. This check will
+ // ensure that, if configured, nodes are kept alive for at least a minimum period of time.
+ if (entry.isYoungerThanMinimumTimeToLive(evictionAlgorithmConfig.getMinTimeToLive())) return false;
+
+ LRUAlgorithmConfig config = (LRUAlgorithmConfig) evictionAlgorithmConfig;
+ // no idle or max time limit
+ if (config.getTimeToLive() < 0 && config.getMaxAge() < 0) return false;
+
+ long currentTime = System.currentTimeMillis();
+ if (config.getTimeToLive() > -1)
+ {
+ long idleTime = currentTime - entry.getModifiedTimeStamp();
+ if (trace)
+ {
+ log.trace("Node " + entry.getKey() + " has been idle for " + idleTime + "ms");
+ }
+ if ((idleTime >= (config.getTimeToLive())))
+ {
+ if (trace)
+ {
+ log.trace("Node " + entry.getKey() + " should be evicted because of idle time");
+ log.trace("Time to live in millies is: " + (config.getTimeToLive()));
+ log.trace("Config instance is: " + System.identityHashCode(config));
+ }
+ return true;
+ }
+ }
+
+ if (config.getMaxAge() > -1)
+ {
+ long objectLifeTime = currentTime - entry.getCreationTimeStamp();
+ if (trace)
+ {
+ log.trace("Node " + entry.getKey() + " has been alive for " + objectLifeTime + "ms");
+ }
+ if ((objectLifeTime >= config.getMaxAge()))
+ {
+ if (trace)
+ {
+ log.trace("Node " + entry.getKey() + " should be evicted because of max age");
+ }
+ return true;
+ }
+ }
+
+ if (trace)
+ {
+ log.trace("Node " + entry.getKey() + " should not be evicted");
+ }
+ return false;
+ }
+
+ @Override
+ protected void evict(KeyEntry<K> ne)
+ {
+ if (ne != null)
+ {
+ if (!evictionAction.evict(ne.getKey()))
+ {
+ try
+ {
+ recycleQueue.put(ne.getKey());
+ }
+ catch (InterruptedException e)
+ {
+ log.debug("InterruptedException", e);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void prune() throws EvictionException
+ {
+ LRUQueue<K> lruQueue = (LRUQueue<K>) evictionQueue;
+ KeyEntry<K> ne;
+ Iterator<KeyEntry<K>> it = lruQueue.iterateLRUQueue();
+ while (it.hasNext())
+ {
+ ne = it.next();
+ if (ne.isNodeInUseAndNotTimedOut()) continue;
+ if (this.shouldEvictNode(ne))
+ {
+ it.remove();
+ lruQueue.removeNodeEntryFromMaxAge(ne);
+ this.evict(ne);
+ } else
+ {
+ break;
+ }
+ }
+
+ it = lruQueue.iterateMaxAgeQueue();
+ while (it.hasNext())
+ {
+ ne = it.next();
+ if (ne.isNodeInUseAndNotTimedOut()) continue;
+ if (this.shouldEvictNode(ne))
+ {
+ it.remove();
+ lruQueue.removeNodeEntryFromLRU(ne);
+ this.evict(ne);
+ } else
+ {
+ break;
+ }
+ }
+
+ int maxNodes = ((LRUAlgorithmConfig) evictionAlgorithmConfig).getMaxNodes();
+ if (maxNodes <= 0)
+ {
+ return;
+ }
+
+ it = lruQueue.iterateLRUQueue();
+ while (evictionQueue.getNumberOfNodes() > maxNodes)
+ {
+ ne = it.next();
+ if (trace)
+ {
+ log.trace("Node " + ne.getKey() + " will be evicted because of exceeding the maxNode limit." +
+ " maxNode: " + maxNodes + " but current queue size is: " + evictionQueue.getNumberOfNodes());
+ }
+
+ if (!ne.isNodeInUseAndNotTimedOut())
+ {
+ it.remove();
+ lruQueue.removeNodeEntryFromMaxAge(ne);
+ this.evict(ne);
+ }
+ }
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return LRUAlgorithmConfig.class;
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lru/LRUAlgorithm.java
___________________________________________________________________
Name: svn:executable
+ *
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lru/LRUAlgorithmConfig.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithmConfig.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lru/LRUAlgorithmConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lru/LRUAlgorithmConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,195 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.lru;
+
+import org.jboss.cache.annotations.Compat;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.Dynamic;
+import org.jboss.starobrno.eviction.EvictionAlgorithmConfigBase;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Configuration implementation for {@link LRUAlgorithm}.
+ * <p/>
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class LRUAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = -3426716488271559729L;
+
+ /**
+ * value expressed in millis
+ */
+ @Dynamic
+ private long timeToLive;
+
+ /**
+ * value expressed in millis
+ */
+ @Dynamic
+ private long maxAge;
+
+ public LRUAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = LRUAlgorithm.class.getName();
+ // Force config of ttls
+ setTimeToLive(-1);
+ setMaxAge(-1);
+ }
+
+ public LRUAlgorithmConfig(long timeToLive, long maxAge)
+ {
+ this();
+ this.timeToLive = timeToLive;
+ this.maxAge = maxAge;
+ }
+
+ public LRUAlgorithmConfig(long timeToLive, int maxAge, int maxNodes)
+ {
+ this(timeToLive, maxAge);
+ this.maxNodes = maxNodes;
+ }
+
+ /**
+ * @return the time to live, in milliseconds
+ */
+ public long getTimeToLive()
+ {
+ return timeToLive;
+ }
+
+ /**
+ * Sets the time to live
+ *
+ * @param timeToLive the time to live, in milliseconds
+ */
+ public void setTimeToLive(long timeToLive)
+ {
+ testImmutability("timeToLive");
+ this.timeToLive = timeToLive;
+ }
+
+ public void setTimeToLive(long timeToLive, TimeUnit timeUnit)
+ {
+ testImmutability("timeToLive");
+ this.timeToLive = timeUnit.toMillis(timeToLive);
+ }
+
+ @Deprecated
+ @Compat
+ public void setTimeToLiveSeconds(long time)
+ {
+ setTimeToLive(time, TimeUnit.SECONDS);
+ }
+
+ /**
+ * @return the max age per element, in milliseconds
+ */
+ public long getMaxAge()
+ {
+ return maxAge;
+ }
+
+ /**
+ * Sets the max age per element
+ *
+ * @param maxAge value in milliseconds
+ */
+ public void setMaxAge(long maxAge)
+ {
+ testImmutability("maxAge");
+ this.maxAge = maxAge;
+ }
+
+ public void setMaxAge(long maxAge, TimeUnit timeUnit)
+ {
+ testImmutability("maxAge");
+ this.maxAge = timeUnit.toMillis(maxAge);
+ }
+
+ /**
+ * Requires a positive timeToLive value or ConfigurationException
+ * is thrown.
+ */
+ @Override
+ public void validate() throws ConfigurationException
+ {
+ super.validate();
+ if (timeToLive < -1)
+ {
+ throw new ConfigurationException("timeToLive must be " +
+ "configured to a value greater than or equal to 0 (or -1 for unlimited time to live) for " + getEvictionAlgorithmClassName());
+ }
+ }
+
+ public String toString()
+ {
+ return "LRUAlgorithmConfig {" +
+ "algorithmClassName=" + evictionAlgorithmClassName +
+ ", timeToLive=" + timeToLive +
+ ", maxAge=" + maxAge +
+ '}';
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (!(o instanceof LRUAlgorithmConfig)) return false;
+ if (!super.equals(o)) return false;
+
+ LRUAlgorithmConfig that = (LRUAlgorithmConfig) o;
+
+ if (maxAge != that.maxAge) return false;
+ if (timeToLive != that.timeToLive) return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result = super.hashCode();
+ result = 31 * result + (int) (timeToLive ^ (timeToLive >>> 32));
+ result = 31 * result + (int) (maxAge ^ (maxAge >>> 32));
+ return result;
+ }
+
+ @Override
+ public void reset()
+ {
+ super.reset();
+ setTimeToLive(-1);
+ setMaxAge(-1);
+ evictionAlgorithmClassName = LRUAlgorithm.class.getName();
+ }
+
+ @Override
+ public LRUAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (LRUAlgorithmConfig) super.clone();
+ }
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lru/LRUQueue.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUQueue.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lru/LRUQueue.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/lru/LRUQueue.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,185 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.lru;
+
+import org.jboss.starobrno.eviction.EvictionQueue;
+import org.jboss.starobrno.eviction.KeyEntry;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * LRU Eviction Queue implementation.
+ * <p/>
+ * This eviction queue will iterate properly through two sorted lists.
+ * One sorted by maxAge and the other sorted by idleTime.
+ *
+ * @author Daniel Huang (dhuang(a)jboss.org)
+ * @version $Revision: 6776 $
+ */
+public class LRUQueue<K> implements EvictionQueue<K>
+{
+ private Map<K, KeyEntry<K>> maxAgeQueue;
+ private Map<K, KeyEntry<K>> lruQueue;
+ private long alternatingCount = 0;
+ private int numElements = 0;
+
+ protected LRUQueue()
+ {
+ maxAgeQueue = new LinkedHashMap<K, KeyEntry<K>>();
+ lruQueue = new LinkedHashMap<K, KeyEntry<K>>(16, 0.75f, true);
+ }
+
+ /**
+ * because the underlying queue is in two differently sorted queues, we alternate between them when calling
+ * a generic getFirstNodeEntry.
+ * we must alternate to keep things balanced when evicting nodes based on the maxNodes attribute. We don't
+ * want to just prune from one queue but rather we want to be able to prune from both.
+ */
+ public KeyEntry<K> getFirstNodeEntry()
+ {
+ KeyEntry<K> ne;
+ if (alternatingCount % 2 == 0)
+ {
+ ne = this.getFirstLRUNodeEntry();
+ if (ne == null)
+ {
+ ne = this.getFirstMaxAgeNodeEntry();
+ }
+ } else
+ {
+ ne = this.getFirstMaxAgeNodeEntry();
+ if (ne == null)
+ {
+ ne = this.getFirstLRUNodeEntry();
+ }
+ }
+ alternatingCount++;
+ return ne;
+ }
+
+ public KeyEntry<K> getFirstLRUNodeEntry()
+ {
+ if (lruQueue.size() > 0)
+ {
+ return lruQueue.values().iterator().next();
+ }
+ return null;
+ }
+
+ public KeyEntry<K> getFirstMaxAgeNodeEntry()
+ {
+ if (maxAgeQueue.size() > 0)
+ {
+ return maxAgeQueue.values().iterator().next();
+ }
+ return null;
+ }
+
+ public KeyEntry<K> getNodeEntry(K key)
+ {
+ return lruQueue.get(key);
+ }
+
+ public boolean containsNodeEntry(KeyEntry<K> entry)
+ {
+ return this.maxAgeQueue.containsKey(entry.getKey());
+ }
+
+ protected void removeNodeEntryFromLRU(KeyEntry<K> entry)
+ {
+ K key = entry.getKey();
+ lruQueue.remove(key);
+ }
+
+ protected void removeNodeEntryFromMaxAge(KeyEntry<K> entry)
+ {
+ K key = entry.getKey();
+ maxAgeQueue.remove(key);
+ }
+
+ public void removeNodeEntry(KeyEntry<K> entry)
+ {
+ if (!this.containsNodeEntry(entry))
+ {
+ return;
+ }
+ K key = entry.getKey();
+ KeyEntry ne1 = lruQueue.remove(key);
+ KeyEntry ne2 = maxAgeQueue.remove(key);
+ if (ne1 == null || ne2 == null)
+ {
+ throw new RuntimeException("The queues are out of sync.");
+ }
+ this.numElements -= ne1.getNumberOfElements();
+ }
+
+ public void addNodeEntry(KeyEntry<K> entry)
+ {
+ if (!this.containsNodeEntry(entry))
+ {
+ K key = entry.getKey();
+ maxAgeQueue.put(key, entry);
+ lruQueue.put(key, entry);
+ this.numElements += entry.getNumberOfElements();
+ }
+ }
+
+ public int getNumberOfNodes()
+ {
+ return maxAgeQueue.size();
+ }
+
+ public int getNumberOfElements()
+ {
+ return this.numElements;
+ }
+
+ public void clear()
+ {
+ maxAgeQueue.clear();
+ lruQueue.clear();
+ this.numElements = 0;
+ }
+
+ public void modifyElementCount(int difference)
+ {
+ this.numElements += difference;
+ }
+
+ public Iterator<KeyEntry<K>> iterator()
+ {
+ return lruQueue.values().iterator();
+ }
+
+ protected final Iterator<KeyEntry<K>> iterateMaxAgeQueue()
+ {
+ return maxAgeQueue.values().iterator();
+ }
+
+ protected final Iterator<KeyEntry<K>> iterateLRUQueue()
+ {
+ return lruQueue.values().iterator();
+ }
+
+}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/EvictionListEntry.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionListEntry.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/EvictionListEntry.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/EvictionListEntry.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.mru;
+
+import org.jboss.starobrno.eviction.KeyEntry;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class EvictionListEntry<K>
+{
+ EvictionListEntry<K> next;
+ KeyEntry<K> keyEntry;
+ EvictionListEntry<K> previous;
+
+ EvictionListEntry()
+ {
+ }
+
+ EvictionListEntry(KeyEntry<K> keyEntry)
+ {
+ this.keyEntry = keyEntry;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (!(o instanceof EvictionListEntry))
+ return false;
+ EvictionListEntry entry = (EvictionListEntry) o;
+ return this.keyEntry.getKey().equals(entry.keyEntry.getKey());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return this.keyEntry.getKey().hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return "EvictionListEntry=" + keyEntry;
+ }
+
+}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/EvictionQueueList.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueueList.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/EvictionQueueList.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/EvictionQueueList.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,348 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.mru;
+
+import org.jboss.starobrno.eviction.KeyEntry;
+
+import java.util.*;
+
+/**
+ * @author Daniel Huang (dhuang(a)jboss.org)
+ * @version $Revision: 6776 $
+ */
+public class EvictionQueueList<K>
+{
+ private EvictionListEntry<K> head;
+ private EvictionListEntry<K> tail;
+ private int modCount;
+ private int size;
+
+ EvictionQueueList()
+ {
+ head = null;
+ tail = null;
+ size = 0;
+ modCount = 0;
+ }
+
+ void addToTop(EvictionListEntry<K> entry)
+ {
+ EvictionListEntry<K> formerHead = head;
+ head = entry;
+ // if there was no previous head then this list was empty.
+ if (formerHead != null)
+ {
+ formerHead.previous = head;
+ head.next = formerHead;
+ head.previous = null;
+ }
+ else
+ {
+ tail = entry;
+ }
+ size++;
+ modCount++;
+ }
+
+ void addToBottom(EvictionListEntry<K> entry)
+ {
+ EvictionListEntry<K> formerTail = tail;
+ tail = entry;
+ // if there was no previous head then this list was empty.
+ if (formerTail != null)
+ {
+ tail.previous = formerTail;
+ formerTail.next = tail;
+ tail.next = null;
+ }
+ else
+ {
+ head = entry;
+ }
+ size++;
+ modCount++;
+ }
+
+ void remove(EvictionListEntry<K> entry)
+ {
+ if (this.isEmpty())
+ {
+ return;
+ }
+
+ if (isSingleNode(entry))
+ {
+ head = null;
+ tail = null;
+ }
+ else if (isTail(entry))
+ {
+ tail = entry.previous;
+ // unlink the last node.
+ entry.previous.next = null;
+ }
+ else if (isHead(entry))
+ {
+ head = entry.next;
+ head.previous = null;
+ }
+ else
+ {
+ // node is in between two other nodes.
+ entry.next.previous = entry.previous;
+ entry.previous.next = entry.next;
+ }
+ size--;
+ modCount++;
+ }
+
+ int size()
+ {
+ return this.size;
+ }
+
+ void clear()
+ {
+ head = null;
+ tail = null;
+ size = 0;
+ modCount++;
+ }
+
+ EvictionListEntry<K> getFirst()
+ {
+ if (head == null)
+ {
+ throw new NoSuchElementException("List is empty");
+ }
+ return head;
+ }
+
+ EvictionListEntry getLast()
+ {
+ if (tail == null)
+ {
+ throw new NoSuchElementException("List is empty");
+ }
+ return tail;
+ }
+
+ @SuppressWarnings(value = "unchecked")
+ Iterator<KeyEntry<K>> iterator()
+ {
+ return new EvictionListIterator();
+ }
+
+ KeyEntry[] toNodeEntryArray()
+ {
+ if (isEmpty())
+ {
+ return null;
+ }
+ KeyEntry[] ret = new KeyEntry[size];
+ int i = 0;
+ EvictionListEntry temp = head;
+
+ do
+ {
+ ret[i] = temp.keyEntry;
+ temp = temp.next;
+ i++;
+ }
+ while (temp != null);
+
+ return ret;
+ }
+
+ EvictionListEntry[] toArray()
+ {
+ if (isEmpty())
+ {
+ return null;
+ }
+ EvictionListEntry[] ret = new EvictionListEntry[size];
+ int i = 0;
+ EvictionListEntry temp = head;
+
+ do
+ {
+ ret[i] = temp;
+ temp = temp.next;
+ i++;
+ }
+ while (temp != null);
+
+ return ret;
+ }
+
+ void fromArray(EvictionListEntry<K>[] evictionListEntries)
+ {
+
+ for (EvictionListEntry<K> evictionListEntry : evictionListEntries)
+ {
+ this.addToBottom(evictionListEntry);
+ }
+ }
+
+ private boolean isEmpty()
+ {
+ return head == null && tail == null;
+ }
+
+ private boolean isSingleNode(EvictionListEntry entry)
+ {
+ return isTail(entry) && isHead(entry);
+ }
+
+ private boolean isTail(EvictionListEntry entry)
+ {
+ return entry.next == null;
+ }
+
+ private boolean isHead(EvictionListEntry entry)
+ {
+ return entry.previous == null;
+ }
+
+ @Override
+ public String toString()
+ {
+ return Arrays.asList(toArray()).toString();
+ }
+
+ static class EvictionListComparator implements Comparator<EvictionListEntry>
+ {
+ Comparator<KeyEntry> nodeEntryComparator;
+
+ EvictionListComparator(Comparator<KeyEntry> nodeEntryComparator)
+ {
+ this.nodeEntryComparator = nodeEntryComparator;
+ }
+
+ public int compare(EvictionListEntry e1, EvictionListEntry e2)
+ {
+ return nodeEntryComparator.compare(e1.keyEntry, e2.keyEntry);
+ }
+ }
+
+ class EvictionListIterator implements ListIterator
+ {
+ EvictionListEntry<K> next = head;
+ EvictionListEntry<K> previous;
+ EvictionListEntry<K> cursor;
+
+ int initialModCount = EvictionQueueList.this.modCount;
+
+ public boolean hasNext()
+ {
+ this.doConcurrentModCheck();
+ return next != null;
+ }
+
+ public KeyEntry<K> next()
+ {
+ this.doConcurrentModCheck();
+ this.forwardCursor();
+ return cursor.keyEntry;
+ }
+
+ public boolean hasPrevious()
+ {
+ this.doConcurrentModCheck();
+ return previous != null;
+ }
+
+ public KeyEntry<K> previous()
+ {
+ this.doConcurrentModCheck();
+ this.rewindCursor();
+ return cursor.keyEntry;
+ }
+
+ public int nextIndex()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public int previousIndex()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void remove()
+ {
+ this.doConcurrentModCheck();
+ if (cursor == null)
+ {
+ throw new IllegalStateException("Cannot remove from iterator when there is nothing at the current iteration point");
+ }
+ EvictionQueueList.this.remove(cursor);
+ cursor = null;
+ initialModCount++;
+ }
+
+ @SuppressWarnings(value = "unchecked")
+ public void set(Object o)
+ {
+ this.doConcurrentModCheck();
+ cursor.keyEntry = (KeyEntry<K>) o;
+ }
+
+ public void add(Object o)
+ {
+ this.doConcurrentModCheck();
+ initialModCount++;
+ }
+
+ private void doConcurrentModCheck()
+ {
+ if (EvictionQueueList.this.modCount != initialModCount)
+ {
+ throw new ConcurrentModificationException();
+ }
+ }
+
+ private void forwardCursor()
+ {
+ if (next == null)
+ {
+ throw new NoSuchElementException("No more objects to iterate.");
+ }
+ previous = cursor;
+ cursor = next;
+ next = cursor.next;
+ }
+
+ private void rewindCursor()
+ {
+ if (previous == null)
+ {
+ throw new NoSuchElementException();
+ }
+ next = cursor;
+ cursor = previous;
+ previous = cursor.previous;
+ }
+ }
+
+}
+
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/MRUAlgorithm.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithm.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/MRUAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/MRUAlgorithm.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.mru;
+
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+import org.jboss.starobrno.eviction.algorithms.BaseEvictionAlgorithm;
+import org.jboss.starobrno.eviction.KeyEntry;
+import org.jboss.starobrno.eviction.EvictionException;
+import org.jboss.starobrno.eviction.EvictionEvent;
+import org.jboss.starobrno.eviction.EvictionQueue;
+
+/**
+ * Most Recently Used Algorithm.
+ * <p/>
+ * This algorithm will evict the most recently used cache entries from cache.
+ * <p/>
+ * Note: None of the Eviction classes are thread safe. It is assumed that an individual instance of an EvictionPolicy/
+ * EvictionAlgorithm/EvictionQueue/EvictionConfiguration are only operated on by one thread at any given time.
+ *
+ * @author Daniel Huang (dhuang(a)jboss.org)
+ * @version $Revision: 6776 $
+ */
+public class MRUAlgorithm<K> extends BaseEvictionAlgorithm<K>
+{
+ @Override
+ protected EvictionQueue<K> setupEvictionQueue() throws EvictionException
+ {
+ return new MRUQueue<K>();
+ }
+
+ @Override
+ protected boolean shouldEvictNode(KeyEntry ne)
+ {
+ // check the minimum time to live and see if we should not evict the node. This check will
+ // ensure that, if configured, nodes are kept alive for at least a minimum period of time.
+ if (ne.isYoungerThanMinimumTimeToLive(evictionAlgorithmConfig.getMinTimeToLive())) return false;
+
+ MRUAlgorithmConfig config = (MRUAlgorithmConfig) evictionAlgorithmConfig;
+ return evictionQueue.getNumberOfNodes() > config.getMaxNodes();
+ }
+
+ @Override
+ protected void processVisitedNodes(EvictionEvent<K> evictedEventNode) throws EvictionException
+ {
+ super.processVisitedNodes(evictedEventNode);
+ ((MRUQueue<K>) evictionQueue).moveToTopOfStack(evictedEventNode.getKey());
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return MRUAlgorithmConfig.class;
+ }
+}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/MRUAlgorithmConfig.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithmConfig.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/MRUAlgorithmConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/MRUAlgorithmConfig.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.mru;
+
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.eviction.EvictionAlgorithmConfigBase;
+
+/**
+ * Configuration for {@link MRUAlgorithm}.
+ * <p/>
+ * Requires a "maxNodes" attribute otherwise a ConfigurationException is thrown.
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class MRUAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = -8734577898966155218L;
+
+ public MRUAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = MRUAlgorithm.class.getName();
+ // We require that maxNodes is set
+ setMaxNodes(-1);
+ }
+
+ public MRUAlgorithmConfig(int maxNodes)
+ {
+ evictionAlgorithmClassName = MRUAlgorithm.class.getName();
+ setMaxNodes(maxNodes);
+ }
+
+ /**
+ * Requires a positive maxNodes value or ConfigurationException
+ * is thrown.
+ */
+ @Override
+ public void validate() throws ConfigurationException
+ {
+ super.validate();
+ if (getMaxNodes() < 0)
+ throw new ConfigurationException("maxNodes not configured");
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder str = new StringBuilder();
+ str.append("MRUAlgorithmConfig: ").
+ append(" maxNodes =").append(getMaxNodes());
+ return str.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return (obj instanceof MRUAlgorithmConfig && super.equals(obj));
+ }
+
+ @Override
+ public void reset()
+ {
+ super.reset();
+ setMaxNodes(-1);
+ evictionAlgorithmClassName = MRUAlgorithm.class.getName();
+ }
+
+ @Override
+ public MRUAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (MRUAlgorithmConfig) super.clone();
+ }
+
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/MRUQueue.java (from rev 7011, core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUQueue.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/MRUQueue.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/algorithms/mru/MRUQueue.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,162 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction.algorithms.mru;
+
+import org.jboss.starobrno.eviction.EvictionQueue;
+import org.jboss.starobrno.eviction.KeyEntry;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+/**
+ * MRU Eviction Queue implementation.
+ * <p/>
+ * This nodeMap is sorted by MRU. The first entry in the nodeMap
+ * will also be the most recently used entry. The sort is implicit
+ * based on a Stack that we can implicitly sort to the top by moving
+ * a node that is used to the top of the eviction stack.
+ *
+ * @author Daniel Huang (dhuang(a)jboss.org)
+ * @version $Revision: 6776 $
+ */
+public class MRUQueue<K> implements EvictionQueue<K>
+{
+ // we use our own Stack/Linked List implementation here because it guarantees O(n) = 1 for add, remove, get and
+ // we can sort it in order of MRU implicitly while still getting O(n) = 1 access time
+ // throughout.
+ Map<K, EvictionListEntry<K>> keyMap;
+ private EvictionQueueList<K> list;
+ private int numElements = 0;
+
+ protected MRUQueue()
+ {
+ keyMap = new HashMap<K, EvictionListEntry<K>>();
+ list = new EvictionQueueList<K>();
+ }
+
+ /**
+ * This call moves a NodeEntry to the top of the stack.
+ * <p/>
+ * When a node is visited this method should be called to guarantee MRU ordering.
+ *
+ * @param key Fqn of the nodeEntry to move to the top of the stack.
+ */
+ protected void moveToTopOfStack(K key)
+ {
+ EvictionListEntry<K> le = keyMap.remove(key);
+ if (le != null)
+ {
+ list.remove(le);
+ list.addToTop(le);
+ keyMap.put(le.keyEntry.getKey(), le);
+ }
+ }
+
+ /**
+ * Will return the first entry in the nodeMap.
+ * <p/>
+ * The first entry in this nodeMap will also be the most recently used entry.
+ *
+ * @return The first node entry in nodeMap.
+ */
+ public KeyEntry<K> getFirstNodeEntry()
+ {
+ try
+ {
+ return list.getFirst().keyEntry;
+ }
+ catch (NoSuchElementException e)
+ {
+ //
+ }
+ return null;
+ }
+
+ public KeyEntry<K> getNodeEntry(K key)
+ {
+ EvictionListEntry<K> le = keyMap.get(key);
+ if (le != null)
+ return le.keyEntry;
+ return null;
+ }
+
+ public boolean containsNodeEntry(KeyEntry<K> entry)
+ {
+ return keyMap.containsKey(entry.getKey());
+ }
+
+ public void removeNodeEntry(KeyEntry<K> entry)
+ {
+ EvictionListEntry<K> le = keyMap.remove(entry.getKey());
+ if (le != null)
+ {
+ list.remove(le);
+ this.numElements -= le.keyEntry.getNumberOfElements();
+ }
+ }
+
+ public void addNodeEntry(KeyEntry<K> entry)
+ {
+ if (!this.containsNodeEntry(entry))
+ {
+ EvictionListEntry<K> le = new EvictionListEntry<K>(entry);
+ list.addToBottom(le);
+ keyMap.put(entry.getKey(), le);
+ this.numElements += entry.getNumberOfElements();
+ }
+ }
+
+ public int getNumberOfNodes()
+ {
+ return list.size();
+ }
+
+ public int getNumberOfElements()
+ {
+ return this.numElements;
+ }
+
+ public void modifyElementCount(int difference)
+ {
+ this.numElements += difference;
+ }
+
+ public void clear()
+ {
+ keyMap.clear();
+ list.clear();
+ this.numElements = 0;
+ }
+
+ public Iterator<KeyEntry<K>> iterator()
+ {
+ return list.iterator();
+ }
+
+ @Override
+ public String toString()
+ {
+ return list.toString();
+ }
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -199,6 +199,7 @@
s.add(NullComponentFactory.class);
s.add(LockManagerFactory.class);
s.add(DataContainerFactory.class);
+ s.add(EvictionManagerFactory.class);
return s;
}
@@ -244,7 +245,7 @@
if (trace) log.trace("Registering component " + c + " under name " + name);
componentLookup.put(name, c);
}
- c.nonVolatile = component.getClass().isAnnotationPresent(NonVolatile.class);
+ c.nonVolatile = component.getClass().isAnnotationPresent(NonVolatile.class) || type.isAnnotationPresent(NonVolatile.class);
addComponentDependencies(c);
// inject dependencies for this component
c.injectDependencies();
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/EvictionManagerFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/EvictionManagerFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/EvictionManagerFactory.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,24 @@
+package org.jboss.starobrno.factories;
+
+import org.jboss.starobrno.factories.annotations.DefaultFactoryFor;
+import org.jboss.starobrno.EvictionManager;
+import org.jboss.starobrno.eviction.EvictionManagerImpl;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+@DefaultFactoryFor (classes = {EvictionManager.class})
+public class EvictionManagerFactory extends ComponentFactory
+{
+ protected <T> T construct(Class<T> componentType)
+ {
+ if ( componentType != EvictionManager.class)
+ {
+ throw new IllegalStateException();
+ }
+ EvictionManagerImpl evManager = new EvictionManagerImpl();
+ long wakeupInterval = configuration.getEvictionConfig().getWakeupInterval();
+ evManager.configureEvictionThread(wakeupInterval, configuration.getRuntimeConfig().getEvictionTimerThreadFactory());
+ return (T) evManager;
+ }
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/factories/InterceptorChainFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/InterceptorChainFactory.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/InterceptorChainFactory.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -25,9 +25,14 @@
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.config.ConfigurationException;
import org.jboss.starobrno.config.CustomInterceptorConfig;
+import org.jboss.starobrno.config.EvictionCacheConfig;
import org.jboss.starobrno.factories.annotations.DefaultFactoryFor;
import org.jboss.starobrno.interceptors.*;
import org.jboss.starobrno.interceptors.base.CommandInterceptor;
+import org.jboss.starobrno.eviction.EvictionCacheManager;
+import org.jboss.starobrno.eviction.EvictionCacheManagerImpl;
+import org.jboss.starobrno.EvictionManager;
+import org.jboss.starobrno.CacheSPI;
import java.util.List;
@@ -156,10 +161,17 @@
//
// }
- // TODO: Uncomment once the EvictionInterceptor has been moved to Starobrno
- // eviction interceptor to come before the optimistic node interceptor
-// if (configuration.getEvictionConfig() != null && configuration.getEvictionConfig().isValidConfig())
-// interceptorChain.appendIntereceptor(createInterceptor(configuration.isUsingBuddyReplication() ? BuddyRegionAwareEvictionInterceptor.class : EvictionInterceptor.class));
+ if (configuration.isUsingEviction())
+ {
+ EvictionInterceptor evictionInterceptor = (EvictionInterceptor) createInterceptor(EvictionInterceptor.class);
+ interceptorChain.appendIntereceptor(evictionInterceptor);
+ EvictionCacheConfig ecc = configuration.getEvictionCacheConfig("bla");
+ EvictionCacheManager evCacheManager = new EvictionCacheManagerImpl(componentRegistry.getComponent(CacheSPI.class));
+ evCacheManager.configure(ecc);
+ evictionInterceptor.setEvictionCacheManager(evCacheManager);
+ EvictionManager evManager = componentRegistry.getComponent(EvictionManager.class);
+ evManager.cacheCreated("bla", evCacheManager);
+ }
CommandInterceptor callInterceptor = createInterceptor(CallInterceptor.class);
interceptorChain.appendIntereceptor(callInterceptor);
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/NonVolatile.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/NonVolatile.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/NonVolatile.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -28,7 +28,7 @@
/**
* This annotation is used for components that will be registered in the {@link org.jboss.cache.factories.ComponentRegistry},
- * that are resilient to changes in configuration. Examples are the {@link org.jboss.cache.CacheSPI_Legacy} implementation used, which does
+ * that are resilient to changes in configuration. Examples are the {@link org.jboss.cache.CacheSPI} implementation used, which does
* not change regardless of the configuration. Components such as the {@link org.jboss.cache.lock.LockManager}, though, should
* <b>never</b> be marked as <tt>@NonVolatile</tt> since based on the configuration, different lock manager implementations
* may be selected. LockManager is, hence, <b>not</b> resilient to changes in the configuration.
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/EvictionInterceptor.java (from rev 7016, core/branches/flat/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/EvictionInterceptor.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/EvictionInterceptor.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -0,0 +1,138 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.interceptors;
+
+import org.jboss.starobrno.commands.read.GetKeyValueCommand;
+import org.jboss.starobrno.commands.write.*;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.eviction.EvictionCacheManager;
+import org.jboss.starobrno.eviction.EvictionEvent;
+import static org.jboss.starobrno.eviction.EvictionEvent.Type.*;
+import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.interceptors.base.CommandInterceptor;
+
+/**
+ * Eviction Interceptor.
+ * <p/>
+ * This interceptor is used to handle eviction events.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class EvictionInterceptor extends CommandInterceptor
+{
+ protected EvictionCacheManager evictionCacheManager;
+
+ /**
+ * this method is for ease of unit testing. thus package access.
+ * <p/>
+ * Not to be attempted to be used anywhere else.
+ */
+ public void setEvictionCacheManager(EvictionCacheManager evictionCacheManager)
+ {
+ this.evictionCacheManager = evictionCacheManager;
+ }
+
+
+ @Override
+ public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
+ {
+ Object retVal = invokeNextInterceptor(ctx, command);
+ if (command.getKey() != null)
+ {
+ registerEvictionEvent(command.getKey(), ADD_ELEMENT_EVENT, 1);
+ }
+ return retVal;
+ }
+
+ @Override
+ public Object visitPutMapCommand(InvocationContext ctx, PutMapCommand command) throws Throwable
+ {
+ Object retVal = invokeNextInterceptor(ctx, command);
+ if (command.getMap() == null)
+ {
+ if (trace) log.trace("Putting null data.");
+ } else
+ {
+ int size;
+ synchronized (command.getMap())
+ {
+ size = command.getMap().size();
+ }
+ registerEvictionEvent(null, ADD_NODE_EVENT, size);
+ }
+ return retVal;
+ }
+
+ @Override
+ public Object visitRemoveCommand(InvocationContext ctx, RemoveCommand command) throws Throwable
+ {
+ Object retVal = invokeNextInterceptor(ctx, command);
+ if (retVal == null)
+ {
+ if (trace) log.trace("No event added. Element does not exist");
+ } else
+ {
+ if (command.getKey() != null)
+ {
+ registerEvictionEvent(command.getKey(), REMOVE_ELEMENT_EVENT, 1);
+ }
+ }
+ return retVal;
+ }
+
+ @Override
+ public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
+ {
+ Object retVal = invokeNextInterceptor(ctx, command);
+ if (retVal == null)
+ {
+ if (trace) log.trace("No event added. Element does not exist");
+ } else if (command.getKey() != null)
+ {
+ registerEvictionEvent(command.getKey(), VISIT_NODE_EVENT, 0);
+ }
+ return retVal;
+ }
+
+ public Object visitReplaceCommand(InvocationContext ctx, ReplaceCommand command) throws Throwable
+ {
+ Boolean replaced = (Boolean) invokeNextInterceptor(ctx, command);
+ if (replaced) registerEvictionEvent(command.getKey(), ADD_NODE_EVENT, 1);
+ else registerEvictionEvent(command.getKey(), VISIT_NODE_EVENT, 0);
+ return replaced;
+ }
+
+ @Override
+ public Object visitClearCommand(InvocationContext ctx, ClearCommand command) throws Throwable
+ {
+ Object retVal = invokeNextInterceptor(ctx, command);
+ registerEvictionEvent(null, REMOVE_NODE_EVENT, 0);
+ return retVal;
+ }
+
+ @SuppressWarnings(value = "unchecked")
+ private void registerEvictionEvent(Object key, EvictionEvent.Type type, int elementDifference)
+ {
+ evictionCacheManager.registerEvictionEvent(key, type, elementDifference);
+ if (trace) log.trace("Registering event " + type + " on node " + key);
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/EvictionInterceptor.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/remoting/ChannelMessageListener.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/remoting/ChannelMessageListener.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/remoting/ChannelMessageListener.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -329,7 +329,7 @@
{
log.debug("Setting received partial state for subroot " + state_id);
Fqn subroot = Fqn.fromString(targetRoot);
-// Region region = regionManager.getRegion(subroot, false);
+// Region region = evictionCacheManager.getRegion(subroot, false);
// ClassLoader cl = null;
// if (region != null)
// {
@@ -378,7 +378,7 @@
log.debug("Setting received partial state for subroot " + stateId);
in = new MarshalledValueInputStream(istream);
Fqn subroot = Fqn.fromString(targetRoot);
-// Region region = regionManager.getRegion(subroot, false);
+// Region region = evictionCacheManager.getRegion(subroot, false);
// ClassLoader cl = null;
// if (region != null)
// {
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/remoting/RPCManagerImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/remoting/RPCManagerImpl.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/remoting/RPCManagerImpl.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -306,10 +306,10 @@
// {
// boolean localTx = deadOwner.getAddress().equals(getLocalAddress());
// TODO: Fix me!!!
-// boolean broken = LockUtil.breakTransactionLock(node.getFqn(), lockManager, deadOwner, localTx, txTable, txManager);
+// boolean broken = LockUtil.breakTransactionLock(node.getKey(), lockManager, deadOwner, localTx, txTable, txManager);
// boolean broken = true;
//
-// if (broken && trace) log.trace("Broke lock for node " + node.getFqn() + " held by " + deadOwner);
+// if (broken && trace) log.trace("Broke lock for node " + node.getKey() + " held by " + deadOwner);
// }
//
// Recursively unlock children
@@ -328,7 +328,7 @@
private void removeLocksForDeadMembers(InternalNode<?, ?> node, List deadMembers)
{
Set<GlobalTransaction> deadOwners = new HashSet<GlobalTransaction>();
- Object owner = lockManager.getWriteOwner(node.getFqn());
+ Object owner = lockManager.getWriteOwner(node.getKey());
if (isLockOwnerDead(owner, deadMembers)) deadOwners.add((GlobalTransaction) owner);
@@ -337,10 +337,10 @@
for (GlobalTransaction deadOwner : deadOwners)
{
boolean localTx = deadOwner.getAddress().equals(getLocalAddress());
-// boolean broken = LockUtil.breakTransactionLock(node.getFqn(), lockManager, deadOwner, localTx, txTable, txManager);
+// boolean broken = LockUtil.breakTransactionLock(node.getKey(), lockManager, deadOwner, localTx, txTable, txManager);
boolean broken = true; // TODO fix me!!
- if (broken && trace) log.trace("Broke lock for node " + node.getFqn() + " held by " + deadOwner);
+ if (broken && trace) log.trace("Broke lock for node " + node.getKey() + " held by " + deadOwner);
}
// Recursively unlock children
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/statetransfer/DefaultStateTransferManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/statetransfer/DefaultStateTransferManager.java 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/statetransfer/DefaultStateTransferManager.java 2008-10-29 19:06:26 UTC (rev 7029)
@@ -91,7 +91,7 @@
/*
// can't give state for regions currently being activated/inactivated
- boolean canProvideState = (!regionManager.isInactive(fqn) && cache.peek(fqn, false) != null);
+ boolean canProvideState = (!evictionCacheManager.isInactive(fqn) && cache.peek(fqn, false) != null);
if (trace) log.trace("Can provide state? " + canProvideState);
if (canProvideState && (fetchPersistentState || fetchTransientState))
{
@@ -116,7 +116,7 @@
{
String exceptionMessage = "Cache instance at " + cache.getLocalAddress() + " cannot provide state for fqn " + fqn + ".";
- if (regionManager.isInactive(fqn))
+ if (evictionCacheManager.isInactive(fqn))
{
exceptionMessage += " Region for fqn " + fqn + " is inactive.";
e = new InactiveRegionException(exceptionMessage);
Modified: core/branches/flat/src/main/resources/config-samples/cacheloader-enabled.xml
===================================================================
--- core/branches/flat/src/main/resources/config-samples/cacheloader-enabled.xml 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/resources/config-samples/cacheloader-enabled.xml 2008-10-29 19:06:26 UTC (rev 7029)
@@ -21,7 +21,7 @@
<!-- Specific eviction policy configurations -->
<eviction wakeUpInterval="5000">
<!-- Cache wide default -->
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm" eventQueueSize="200000">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm" eventQueueSize="200000">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">3000</attribute>
</default>
Modified: core/branches/flat/src/main/resources/config-samples/eviction-enabled.xml
===================================================================
--- core/branches/flat/src/main/resources/config-samples/eviction-enabled.xml 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/main/resources/config-samples/eviction-enabled.xml 2008-10-29 19:06:26 UTC (rev 7029)
@@ -25,7 +25,7 @@
-->
<eviction wakeUpInterval="5000">
<!-- Cache wide default -->
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm" eventQueueSize="200000">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm" eventQueueSize="200000">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000000</attribute>
</default>
Modified: core/branches/flat/src/test/resources/configs/clonable-config.xml
===================================================================
--- core/branches/flat/src/test/resources/configs/clonable-config.xml 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/test/resources/configs/clonable-config.xml 2008-10-29 19:06:26 UTC (rev 7029)
@@ -45,18 +45,18 @@
</buddy>
</replication>
<eviction wakeUpInterval="45000">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm" eventQueueSize="4">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm" eventQueueSize="4">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000000</attribute>
<attribute name="maxAge">15000</attribute>
</default>
- <region name="/fifo" algorithmClass="org.jboss.starobrno.eviction.FIFOAlgorithm">
+ <region name="/fifo" algorithmClass="org.jboss.starobrno.eviction.algorithms.fifo.FIFOAlgorithm">
<attribute name="maxNodes">5000</attribute>
</region>
- <region name="/mru" algorithmClass="org.jboss.starobrno.eviction.MRUAlgorithm">
+ <region name="/mru" algorithmClass="org.jboss.starobrno.eviction.algorithms.mru.MRUAlgorithm">
<attribute name="maxNodes">10000</attribute>
</region>
- <region name="/lfu" algorithmClass="org.jboss.starobrno.eviction.LFUAlgorithm">
+ <region name="/lfu" algorithmClass="org.jboss.starobrno.eviction.algorithms.lfu.LFUAlgorithm">
<attribute name="maxNodes">5000</attribute>
<attribute name="minNodes">4000</attribute>
</region>
Modified: core/branches/flat/src/test/resources/configs/local-lru-eviction.xml
===================================================================
--- core/branches/flat/src/test/resources/configs/local-lru-eviction.xml 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/test/resources/configs/local-lru-eviction.xml 2008-10-29 19:06:26 UTC (rev 7029)
@@ -7,7 +7,7 @@
<stateRetrieval timeout="20000"/>
<transport clusterName="JBossCache-Cluster"/>
<eviction wakeUpInterval="5000">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm" eventQueueSize="200000">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm" eventQueueSize="200000">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000000</attribute>
</default>
Modified: core/branches/flat/src/test/resources/configs/local-passivation.xml
===================================================================
--- core/branches/flat/src/test/resources/configs/local-passivation.xml 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/test/resources/configs/local-passivation.xml 2008-10-29 19:06:26 UTC (rev 7029)
@@ -7,7 +7,7 @@
<stateRetrieval timeout="20000"/>
<transport clusterName="JBossCache-Cluster"/>
<eviction wakeUpInterval="1000">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm" eventQueueSize="200000">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm" eventQueueSize="200000">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000</attribute>
</default>
Modified: core/branches/flat/src/test/resources/configs/local-tx.xml
===================================================================
--- core/branches/flat/src/test/resources/configs/local-tx.xml 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/test/resources/configs/local-tx.xml 2008-10-29 19:06:26 UTC (rev 7029)
@@ -8,7 +8,7 @@
<stateRetrieval timeout="20000"/>
<transport clusterName="JBossCache-Cluster"/>
<eviction wakeUpInterval="5000">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm" eventQueueSize="200000">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm" eventQueueSize="200000">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000000</attribute>
</default>
Modified: core/branches/flat/src/test/resources/configs/mixedPolicy-eviction.xml
===================================================================
--- core/branches/flat/src/test/resources/configs/mixedPolicy-eviction.xml 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/test/resources/configs/mixedPolicy-eviction.xml 2008-10-29 19:06:26 UTC (rev 7029)
@@ -35,14 +35,14 @@
</jgroupsConfig>
</transport>
<eviction wakeUpInterval="5000">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm" eventQueueSize="200000">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm" eventQueueSize="200000">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000000</attribute>
</default>
- <region name="/org/jboss/data" algorithmClass="org.jboss.starobrno.eviction.FIFOAlgorithm">
+ <region name="/org/jboss/data" algorithmClass="org.jboss.starobrno.eviction.algorithms.fifo.FIFOAlgorithm">
<attribute name="maxNodes">5000</attribute>
</region>
- <region name="/test/" algorithmClass="org.jboss.starobrno.eviction.MRUAlgorithm">
+ <region name="/test/" algorithmClass="org.jboss.starobrno.eviction.algorithms.mru.MRUAlgorithm">
<attribute name="maxNodes">10000</attribute>
</region>
<region name="/maxAgeTest/">
Modified: core/branches/flat/src/test/resources/configs/parser-test-async.xml
===================================================================
--- core/branches/flat/src/test/resources/configs/parser-test-async.xml 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/test/resources/configs/parser-test-async.xml 2008-10-29 19:06:26 UTC (rev 7029)
@@ -59,14 +59,14 @@
<jmxStatistics enabled="false"/>
<eviction wakeUpInterval="5">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm" eventQueueSize="200000">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm" eventQueueSize="200000">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000</attribute>
</default>
<region name="/org/jboss/data">
<attribute name="timeToLive">1002</attribute>
</region>
- <region name="/org/jboss/xyz" algorithmClass="org.jboss.starobrno.eviction.MRUAlgorithm" eventQueueSize="21">
+ <region name="/org/jboss/xyz" algorithmClass="org.jboss.starobrno.eviction.algorithms.mru.MRUAlgorithm" eventQueueSize="21">
<attribute name="maxNodes">2103</attribute>
<attribute name="minTimeToLive">22</attribute>
</region>
Modified: core/branches/flat/src/test/resources/configs/parser-test.xml
===================================================================
--- core/branches/flat/src/test/resources/configs/parser-test.xml 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/test/resources/configs/parser-test.xml 2008-10-29 19:06:26 UTC (rev 7029)
@@ -59,14 +59,14 @@
<jmxStatistics enabled="false"/>
<eviction wakeUpInterval="5">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm" eventQueueSize="200000">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm" eventQueueSize="200000">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000</attribute>
</default>
<region name="/org/jboss/data">
<attribute name="timeToLive">1002</attribute>
</region>
- <region name="/org/jboss/xyz" algorithmClass="org.jboss.starobrno.eviction.MRUAlgorithm" eventQueueSize="21">
+ <region name="/org/jboss/xyz" algorithmClass="org.jboss.starobrno.eviction.algorithms.mru.MRUAlgorithm" eventQueueSize="21">
<attribute name="maxNodes">2103</attribute>
<attribute name="minTimeToLive">22</attribute>
</region>
Modified: core/branches/flat/src/test/resources/configs/policyPerRegion-eviction.xml
===================================================================
--- core/branches/flat/src/test/resources/configs/policyPerRegion-eviction.xml 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/test/resources/configs/policyPerRegion-eviction.xml 2008-10-29 19:06:26 UTC (rev 7029)
@@ -35,21 +35,21 @@
</transport>
<eviction wakeUpInterval="5000">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000000</attribute>
</default>
- <region name="/org/jboss/data" algorithmClass="org.jboss.starobrno.eviction.LFUAlgorithm">
+ <region name="/org/jboss/data" algorithmClass="org.jboss.starobrno.eviction.algorithms.lfu.LFUAlgorithm">
<attribute name="maxNodes">5000</attribute>
<attribute name="minNodes">1000</attribute>
</region>
- <region name="/org/jboss/test/data" algorithmClass="org.jboss.starobrno.eviction.FIFOAlgorithm">
+ <region name="/org/jboss/test/data" algorithmClass="org.jboss.starobrno.eviction.algorithms.fifo.FIFOAlgorithm">
<attribute name="maxNodes">5</attribute>
</region>
- <region name="/test/" algorithmClass="org.jboss.starobrno.eviction.MRUAlgorithm">
+ <region name="/test/" algorithmClass="org.jboss.starobrno.eviction.algorithms.mru.MRUAlgorithm">
<attribute name="maxNodes">10000</attribute>
</region>
- <region name="/maxAgeTest/" algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm">
+ <region name="/maxAgeTest/" algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm">
<attribute name="maxNodes">10000</attribute>
<attribute name="timeToLive">8000</attribute>
<attribute name="maxAge">10000</attribute>
Modified: core/branches/flat/src/test/resources/configs/string-property-replaced.xml
===================================================================
--- core/branches/flat/src/test/resources/configs/string-property-replaced.xml 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/test/resources/configs/string-property-replaced.xml 2008-10-29 19:06:26 UTC (rev 7029)
@@ -25,7 +25,7 @@
</replication>
<eviction wakeUpInterval="5000">
<default
- algorithmClass="${test.property.EvictionPolicyConfig.policyClass:org.jboss.starobrno.eviction.LRUAlgorithm}">
+ algorithmClass="${test.property.EvictionPolicyConfig.policyClass:org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm}">
<attribute name="maxNodes">${test.property.EvictionPolicyConfig.maxNodes:5000}</attribute>
<attribute name="timeToLive">1000000</attribute>
</default>
Modified: core/branches/flat/src/test/resources/jbc2-registry-configs.xml
===================================================================
(Binary files differ)
Modified: core/branches/flat/src/test/resources/jbc3-registry-configs.xml
===================================================================
--- core/branches/flat/src/test/resources/jbc3-registry-configs.xml 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/test/resources/jbc3-registry-configs.xml 2008-10-29 19:06:26 UTC (rev 7029)
@@ -24,7 +24,7 @@
<sync replTimeout="20000"/>
</invalidation>
<eviction wakeUpInterval="5000">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000</attribute>
</default>
@@ -47,7 +47,7 @@
<sync replTimeout="20000"/>
</invalidation>
<eviction wakeUpInterval="5000">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000</attribute>
</default>
@@ -65,7 +65,7 @@
<locking lockAcquisitionTimeout="15000" nodeLockingScheme="optimistic"/>
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<eviction wakeUpInterval="5000">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000</attribute>
</default>
@@ -90,7 +90,7 @@
<async/>
</replication>
<eviction wakeUpInterval="5000">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000</attribute>
</default>
@@ -115,7 +115,7 @@
<async/>
</replication>
<eviction wakeUpInterval="5000">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000</attribute>
</default>
@@ -143,7 +143,7 @@
<sync replTimeout="20000"/>
</replication>
<eviction wakeUpInterval="5000">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000</attribute>
</default>
@@ -172,7 +172,7 @@
<sync replTimeout="20000"/>
</replication>
<eviction wakeUpInterval="5000">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000</attribute>
</default>
Modified: core/branches/flat/src/test/resources/unit-test-cache-service.xml
===================================================================
--- core/branches/flat/src/test/resources/unit-test-cache-service.xml 2008-10-29 14:11:57 UTC (rev 7028)
+++ core/branches/flat/src/test/resources/unit-test-cache-service.xml 2008-10-29 19:06:26 UTC (rev 7029)
@@ -10,7 +10,7 @@
<sync replTimeout="15000"/>
</replication>
<eviction wakeUpInterval="2000">
- <default algorithmClass="org.jboss.starobrno.eviction.LRUAlgorithm">
+ <default algorithmClass="org.jboss.starobrno.eviction.algorithms.lru.LRUAlgorithm">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000</attribute>
</default>
16 years, 2 months
JBoss Cache SVN: r7028 - core/trunk/src/main/java/org/jboss/cache/interceptors.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-29 10:11:57 -0400 (Wed, 29 Oct 2008)
New Revision: 7028
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
Log:
JBCACHE-1431 - missing null chk
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-10-29 13:36:30 UTC (rev 7027)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-10-29 14:11:57 UTC (rev 7028)
@@ -291,7 +291,7 @@
n = helper.wrapNodeForWriting(ctx, fqn, true, true, true, false, false);
n.setDataLoaded(false);
}
- if (!bypassLoadingData)
+ if (!bypassLoadingData && n != null)
{
n = loadNode(ctx, fqn, n);
}
16 years, 2 months
JBoss Cache SVN: r7027 - core/trunk/src/main/docbook/userguide/en/modules.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-29 09:36:30 -0400 (Wed, 29 Oct 2008)
New Revision: 7027
Modified:
core/trunk/src/main/docbook/userguide/en/modules/deployment.xml
Log:
Corrected code sample to remove deprecated classes
Modified: core/trunk/src/main/docbook/userguide/en/modules/deployment.xml
===================================================================
--- core/trunk/src/main/docbook/userguide/en/modules/deployment.xml 2008-10-29 13:21:40 UTC (rev 7026)
+++ core/trunk/src/main/docbook/userguide/en/modules/deployment.xml 2008-10-29 13:36:30 UTC (rev 7027)
@@ -219,33 +219,28 @@
<title>With a Cache instance</title>
<para>
Simplest way to do this is to create your <literal>Cache</literal> and pass it to the
- <literal>CacheJmxWrapper</literal> constructor.
+ <literal>JmxRegistrationManager</literal> constructor.
</para>
<programlisting role="JAVA"><![CDATA[
CacheFactory factory = new DefaultCacheFactory();
// Build but don't start the cache
// (although it would work OK if we started it)
- Cache cache = factory.createCache("cache-configuration.xml", false);
+ Cache cache = factory.createCache("cache-configuration.xml");
- CacheJmxWrapperMBean wrapper = new CacheJmxWrapper(cache);
MBeanServer server = getMBeanServer(); // however you do it
ObjectName on = new ObjectName("jboss.cache:service=Cache");
- server.registerMBean(wrapper, on);
+
+ JmxRegistrationManager jmxManager = new JmxRegistrationManager(server, cache, on);
+ jmxManager.registerAllMBeans();
- // Invoking lifecycle methods on the wrapper results
- // in a call through to the cache
- wrapper.create();
- wrapper.start();
-
... use the cache
... on application shutdown
- // Invoking lifecycle methods on the wrapper results
- // in a call through to the cache
- wrapper.stop();
- wrapper.destroy();
+ jmxManager.unregisterAllMBeans();
+ cache.stop();
+
]]></programlisting>
</section>
16 years, 2 months
JBoss Cache SVN: r7026 - in core/trunk/src: test/java/org/jboss/cache/passivation and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-29 09:21:40 -0400 (Wed, 29 Oct 2008)
New Revision: 7026
Modified:
core/trunk/src/main/java/org/jboss/cache/commands/read/GravitateDataCommand.java
core/trunk/src/test/java/org/jboss/cache/passivation/ReplAndStateTransferWithPassivationTest.java
Log:
Added state tfr with BR tests
Modified: core/trunk/src/main/java/org/jboss/cache/commands/read/GravitateDataCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/read/GravitateDataCommand.java 2008-10-29 05:00:16 UTC (rev 7025)
+++ core/trunk/src/main/java/org/jboss/cache/commands/read/GravitateDataCommand.java 2008-10-29 13:21:40 UTC (rev 7026)
@@ -172,6 +172,8 @@
{
// make sure we LOAD data for this node!!
actualNode.getData();
+ // and children!
+ actualNode.getChildrenNames();
}
if (backupNodeFqn == null && searchSubtrees)
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/ReplAndStateTransferWithPassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/ReplAndStateTransferWithPassivationTest.java 2008-10-29 05:00:16 UTC (rev 7025)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/ReplAndStateTransferWithPassivationTest.java 2008-10-29 13:21:40 UTC (rev 7026)
@@ -27,6 +27,8 @@
import org.jboss.cache.Node;
import org.jboss.cache.Region;
import org.jboss.cache.UnitTestCacheFactory;
+import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
+import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.CacheMode;
@@ -44,12 +46,12 @@
{
public void testStateTransferOfPassivatedState() throws Exception
{
- doTest(NodeLockingScheme.MVCC);
+ doTest(NodeLockingScheme.MVCC, false);
}
public void testStateTransferOfPassivatedStatePessimistic() throws Exception
{
- doTest(NodeLockingScheme.PESSIMISTIC);
+ doTest(NodeLockingScheme.PESSIMISTIC, false);
}
public void testStateTransferOfPassivatedPartialState() throws Exception
@@ -62,7 +64,16 @@
doPartialStateTransferTest(NodeLockingScheme.PESSIMISTIC);
}
+ public void testStateTransferOfPassivatedPartialStateBR() throws Exception
+ {
+ doTest(NodeLockingScheme.MVCC, true);
+ }
+ public void testStateTransferOfPassivatedPartialStateBRPessimistic() throws Exception
+ {
+ doTest(NodeLockingScheme.PESSIMISTIC, true);
+ }
+
private void doPartialStateTransferTest(NodeLockingScheme nls) throws Exception
{
CacheSPI cache1=null, cache2=null;
@@ -74,8 +85,8 @@
nameSet.add("b");
nameSet.add("c");
- cache1 = (CacheSPI) new UnitTestCacheFactory().createCache(buildConf(nls, "cache1", true));
- cache2 = (CacheSPI) new UnitTestCacheFactory().createCache(buildConf(nls, "cache2", true));
+ cache1 = (CacheSPI) new UnitTestCacheFactory().createCache(buildConf(nls, "cache1", true, false));
+ cache2 = (CacheSPI) new UnitTestCacheFactory().createCache(buildConf(nls, "cache2", true, false));
Region r1 = cache1.getRegionManager().getRegion(subtree, true);
Region r2 = cache2.getRegionManager().getRegion(subtree, true);
@@ -103,27 +114,40 @@
}
}
- private void doTest(NodeLockingScheme nls) throws Exception
+ private void doTest(NodeLockingScheme nls, boolean useBR) throws Exception
{
Cache cache1=null, cache2=null;
+ Fqn fqn = useBR ? Fqn.fromString("/someFqn") : Fqn.ROOT;
+ Fqn A = Fqn.fromRelativeElements(fqn, "a"), B = Fqn.fromRelativeElements(fqn, "b"), C = Fqn.fromRelativeElements(fqn, "c");
try
{
Set<Object> nameSet = new HashSet<Object>();
- nameSet.add("a");
- nameSet.add("b");
- nameSet.add("c");
+ nameSet.add(A.getLastElement());
+ nameSet.add(B.getLastElement());
+ nameSet.add(C.getLastElement());
+
+ cache1 = new UnitTestCacheFactory().createCache(buildConf(nls, "cache1", false, useBR));
- cache1 = new UnitTestCacheFactory().createCache(buildConf(nls, "cache1", false));
+ cache1.put(A, "k", "v");
+ cache1.put(B, "k", "v");
+ cache1.put(C, "k", "v");
+ assert cache1.getNode(fqn).getChildrenNames().equals(nameSet);
- cache1.put("/a", "k", "v");
- cache1.put("/b", "k", "v");
- cache1.put("/c", "k", "v");
- assert cache1.getRoot().getChildrenNames().equals(nameSet);
+ cache1.evict(A);
- cache1.evict(Fqn.fromString("/a"));
-
- cache2 = new UnitTestCacheFactory().createCache(buildConf(nls, "cache2", false));
- assert cache2.getRoot().getChildrenNames().equals(nameSet) : "Expecting " + nameSet + " but got " + cache2.getRoot().getChildrenNames();
+ cache2 = new UnitTestCacheFactory().createCache(buildConf(nls, "cache2", false, useBR));
+ if (useBR)
+ {
+ Set backupNameSet = new HashSet(nameSet);
+ backupNameSet.remove(BuddyFqnTransformer.BUDDY_BACKUP_SUBTREE);
+ cache2.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
+ Node backupNode = cache2.getNode(fqn);
+ assert backupNode.getChildrenNames().equals(backupNameSet) : "Expecting " + backupNameSet + " but got " + backupNode.getChildrenNames();
+ }
+ else
+ {
+ assert cache2.getRoot().getChildrenNames().equals(nameSet) : "Expecting " + nameSet + " but got " + cache2.getRoot().getChildrenNames();
+ }
}
finally
{
@@ -131,7 +155,7 @@
}
}
- private Configuration buildConf(NodeLockingScheme nls, String n, boolean regionbased) throws Exception
+ private Configuration buildConf(NodeLockingScheme nls, String n, boolean regionbased, boolean useBR) throws Exception
{
Configuration c = new Configuration();
if (regionbased)
@@ -144,6 +168,15 @@
CacheLoaderConfig clc = getSingleCacheLoaderConfig("", DummySharedInMemoryCacheLoader.class.getName(), "bin="+n, false, true, false);
clc.setPassivation(true);
c.setCacheLoaderConfig(clc);
+ if (useBR)
+ {
+ BuddyReplicationConfig brc = new BuddyReplicationConfig();
+ brc.setEnabled(true);
+ brc.setAutoDataGravitation(false);
+ brc.setDataGravitationSearchBackupTrees(true);
+ brc.setDataGravitationRemoveOnFind(true);
+ c.setBuddyReplicationConfig(brc);
+ }
return c;
}
16 years, 2 months
JBoss Cache SVN: r7025 - enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES.
by jbosscache-commits@lists.jboss.org
Author: mospina
Date: 2008-10-29 01:00:16 -0400 (Wed, 29 Oct 2008)
New Revision: 7025
Modified:
enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Basic_api.po
enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Eviction_policies.po
Log:
translation in progress
Modified: enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Basic_api.po
===================================================================
--- enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Basic_api.po 2008-10-28 23:30:07 UTC (rev 7024)
+++ enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Basic_api.po 2008-10-29 05:00:16 UTC (rev 7025)
@@ -8,7 +8,7 @@
"Project-Id-Version: Basic_api\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2008-09-21 04:43+0000\n"
-"PO-Revision-Date: 2008-10-17 12:17+1000\n"
+"PO-Revision-Date: 2008-10-29 14:57+1000\n"
"Last-Translator: Angela Garcia\n"
"Language-Team: <en(a)li.org>\n"
"MIME-Version: 1.0\n"
@@ -20,13 +20,13 @@
#: Basic_api.xml:5
#, no-c-format
msgid "Basic API"
-msgstr ""
+msgstr "API básica"
#. Tag: para
#: Basic_api.xml:6
#, no-c-format
msgid "Here's some sample code before we dive into the API itself:"
-msgstr ""
+msgstr "Aquí tiene un poco de código como ejemplo antes de profundizar en la API:"
#. Tag: programlisting
#: Basic_api.xml:9
@@ -69,7 +69,7 @@
"configuration options. However, the <literal>TreeCache</literal> can be "
"configured entirely from an XML file (shown later) and we don't recommend "
"manual configuration as shown in the sample."
-msgstr ""
+msgstr "El código de ejemplo primero crea una instancia <literal>TreeCache</literal> y luego la configura. Hay otro constructor, el cual acepta un número de opciones de configuración. Sin embargo, el <literal>TreeCache</literal> se puede configurar por completo desde un archivo XML (lo veremos más adelante) y no recomendamos la configuración manual como lo puede ver en el ejemplo."
#. Tag: para
#: Basic_api.xml:13
@@ -80,7 +80,7 @@
"options is shown later). Then we start the <literal>TreeCache</literal>. If "
"replication is enabled, this will make the <literal>TreeCache</literal> join "
"the cluster, and acquire initial state from an existing node."
-msgstr ""
+msgstr "Prrmero se configura el nombre del clúster, las propiedades de la pila JGroups subyacente y el modo del caché (replicación sincrónica) - más adelante podrá ver una lista de opciones de configuración. Luego iniciamos el <literal>TreeCache</literal>. Si la replicación se encuentra habilitada entonces esto hará que el <literal>TreeCache</literal> se una al clúster y adquiere el estado inicial de un nodo existente. "
#. Tag: para
#: Basic_api.xml:16
@@ -91,6 +91,9 @@
"literal> by default creates intermediary nodes that don't exist). The key "
"\"name\" is then inserted into the \"/a/b/c\" node, with a value of \"Ben\"."
msgstr ""
+"Luego añadimos dos cosas al caché: el primer elemento crea un nodo \"a\" "
+"con un nodo hijo \"b\" que tiene un nodo hijo \"c\", (<literal>TreeCache</"
+"literal> por defecto crea nodos intermediarios que no existen). Luego el \"nombre\" clave es insertado en el nodo \"/a/b/c\" con un valor de \"Ben\"."
#. Tag: para
#: Basic_api.xml:19
@@ -99,18 +102,20 @@
"The other element will create just the subnode \"d\" of \"c\" because \"/a/b/"
"c\" already exists. It binds the integer 322649 under key \"uid\"."
msgstr ""
+"El otro elemento sólo creará el sub-nodo \"d\" de \"c\" ya que \"/a/b/"
+"c\" ya existe. Enlaza el número entero 322649 bajo la clave \"uid\"."
#. Tag: para
#: Basic_api.xml:22
#, no-c-format
msgid "The resulting tree looks like this:"
-msgstr ""
+msgstr "El árbol que resulta se ve así:"
#. Tag: title
#: Basic_api.xml:26
#, no-c-format
msgid "Sample Tree Nodes"
-msgstr ""
+msgstr "Árbol de nodos de ejemplo"
#. Tag: para
#: Basic_api.xml:33
@@ -120,6 +125,8 @@
"Nodes \"/a/b/c\" has values \"name\" associated with \"Ben\" in its map, and "
"node \"/a/b/c/d\" has values \"uid\" and 322649."
msgstr ""
+"El <literal>TreeCache</literal> tiene 4 nodos \"a\", \"b\", \"c\" y \"d\". "
+"Los nodos \"/a/b/c\" tiene valores \"name\" asociado con \"Ben\" en su mapa y el nodo \"/a/b/c/d\" tiene valores \"uid\" y 322649."
#. Tag: para
#: Basic_api.xml:36
@@ -128,7 +135,7 @@
"Each node can be retrieved by its absolute name (e.g. \"/a/b/c\") or by "
"navigating from parent to children (e.g. navigate from \"a\" to \"b\", then "
"from \"b\" to \"c\")."
-msgstr ""
+msgstr "Cada nodo se puede recuperar por su nombre absoluto (por ejemplo, \"/a/b/c\") o navegando de padre a hijo (por ejemplo, navegar de \"a\" to \"b\" y luego de \"b\" a \"c\")."
#. Tag: para
#: Basic_api.xml:39
@@ -136,7 +143,7 @@
msgid ""
"The next method in the example gets the value associated with key=\"uid\" in "
"node \"/a/b/c/d\", which is the integer 322649."
-msgstr ""
+msgstr "El siguiente método en el ejemplo obtiene el valor asociado con key=\"uid\" en el nodo \"/a/b/c/d\", el cual es el número entero 322649."
#. Tag: para
#: Basic_api.xml:42
@@ -145,7 +152,7 @@
"The remove() method then removes node \"/a/b\" and all subnodes recursively "
"from the cache. In this case, nodes \"/a/b/c/d\", \"/a/b/c\" and \"/a/b\" "
"will be removed, leaving only \"/a\"."
-msgstr ""
+msgstr "El método remove() luego remueve el nodo \"/a/b\" y todos los sub-nodos recursivamente del caché. En este caso, los nodos \"/a/b/c/d\", \"/a/b/c\" y \"/a/b\" serán removidos dejando sólo a \"/a\"."
#. Tag: para
#: Basic_api.xml:45
@@ -157,7 +164,7 @@
"stopped, all contents will be deleted. And when it is restarted, if it joins "
"a cache group, the state will be replicated initially. So potentially you "
"can recreate the contents."
-msgstr ""
+msgstr "Finalmente, se detiene el <literal>TreeCache</literal>. Esto hará que deje el clúster y todo nodo en el clúster será notificado. Observe que <literal>TreeCache</literal> se pueder detener e iniciar de nuevo. Cuando se detiene, todo el contenido se borrará. Cuando se reinicie, si se une a un grupo caché, el estado será replicado inicialmente. Así que potencialmente puede recrear el contenido."
#. Tag: para
#: Basic_api.xml:48
@@ -167,6 +174,8 @@
"remove() methods to replicated their changes to all nodes in the cluster. "
"The get() method was executed on the local cache only."
msgstr ""
+"En el ejemplo, la replicación fue habilitada, lo cual causó que los métodos 2 put() y 1 "
+"remove() replicaran sus cambios a todos los nodos en el clúster. El método get() fue ejecutado en el caché local sólamente. "
#. Tag: para
#: Basic_api.xml:51
@@ -178,6 +187,8 @@
"(). All strings are actually transformed into Fqns internally. Fqns are more "
"efficient than strings, for example:"
msgstr ""
+"Las claves en el caché pueden ser cadenas separadas por barras oblicuas ('/'), por ejemplo \"/a/b/c\" o pueden ser nombres completamente calificados (Fqns). Un nombre completamente calificado es básicamente una lista de objetos que necesitan implementar hashCode() e iguales"
+"(). De hecho todas las cadenas son transformadas internamente en nombre completamente calificados. Fqns son más eficientes que cadenas, por ejemplo:"
#. Tag: programlisting
#: Basic_api.xml:54
@@ -200,7 +211,7 @@
"collisions, leading to actual string comparisons. Also, clients of the cache "
"may already have identifiers for their objects in Object form, and don't "
"want to transform between Object and Strings, preventing unnecessary copying."
-msgstr ""
+msgstr "En este ejemplo, queremos acceder un nodo que tiene información para el empleado con id=322649 en el departmento con id=300. La versión de la cadena necesita dos búsquedas en cadenas, mientras que la versión Fqn necesita dos búsquedas en números enteros. En un hashtable grande, el método hashCode() para una cadena puede tener choques lo cual llevaría a comparaciones de cadenas. También puede que los clientes del caché ya tengan identificadores para sus objetos en forma de objetos y no quieran transformar entre objetos y cadenas previniendo un copiado innecesario. "
#. Tag: para
#: Basic_api.xml:58
@@ -208,7 +219,7 @@
msgid ""
"Note that the modification methods are put() and remove(). The only get "
"method is get()."
-msgstr ""
+msgstr "Observe que los métodos de modificación son put() y remove(). El único método get es get()."
#. Tag: para
#: Basic_api.xml:61
@@ -223,6 +234,9 @@
"the node's map, overwriting existing keys and values. Content that is not in "
"the new map remains in the node's map."
msgstr ""
+"Hay dos métodos put()<footnote><para> Ademas de sus métodos de ayuda equivalentes que toman una cadena como nombre del nodo. </para> </footnote> : <literal>put(Fqn "
+"node, Object key, Object key)</literal> y <literal>put(Fqn node, Map "
+"values)</literal>. El primero toma el nombre del nodo, lo crea si aún no existe y pone la clave y el valor en el mapa del nodo, retornando el valor anterior. El último toma un mapa de claves y valores y los añade al mapa del nodo, sobreescribiendo las claves y valores existentes. El contenido que no se encuentra en el mapa nuevo entonces permanece en el mapa del nodo."
#. Tag: para
#: Basic_api.xml:67
@@ -234,6 +248,9 @@
"removes the entire node and all subnodes, and the third removes all elements "
"from the given node's map."
msgstr ""
+"Hay tres métodos remove(): <literal>remove(Fqn node, Object key)</"
+"literal>, <literal>remove(Fqn node)</literal> y <literal>removeData(Fqn "
+"node)</literal>. El primero remueve la clave dada del nodo. El segundo remueve el nodo completo y todos los sub-nodos y el tercero remueve todos los elementos del mapa de nodos dado."
#. Tag: para
#: Basic_api.xml:70
@@ -245,6 +262,9 @@
"Node in a future release. </para> </footnote> object, allowing for direct "
"navigation, the latter returns the value for the given key for a node."
msgstr ""
+"Los métodos get son: <literal>get(Fqn node)</literal> y <literal>get(Fqn "
+"node, Object key)</literal>. El primero retorna un nodo<footnote><para> Este se utiliza principalmente internamente y puede que en un lanzamiento futuro decidamos remover acceso público al nodo. </para> </footnote> objeto, permitiendo una "
+"navigación directa, el último retorna el valor para la clave dada para un nodo."
#. Tag: para
#: Basic_api.xml:76
@@ -253,5 +273,5 @@
"Also, the <literal>TreeCache</literal> has a number of getters and setters. "
"Since the API may change at any time, we recommend the Javadoc for up-to-"
"date information."
-msgstr ""
+msgstr "También el <literal>TreeCache</literal> tiene un número de getters y setters. Ya que la API puede cambiar en cualquier momento, le recomendamos consultar los Javadoc para obtener información actualizada."
Modified: enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Eviction_policies.po
===================================================================
--- enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Eviction_policies.po 2008-10-28 23:30:07 UTC (rev 7024)
+++ enterprise-docs/tags/JBoss_EAP_4_3/Cache_Tree_Cache_Guide/es-ES/Eviction_policies.po 2008-10-29 05:00:16 UTC (rev 7025)
@@ -8,7 +8,7 @@
"Project-Id-Version: Eviction_policies\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2008-09-21 04:44+0000\n"
-"PO-Revision-Date: 2008-10-17 12:12+1000\n"
+"PO-Revision-Date: 2008-10-29 11:53+1000\n"
"Last-Translator: Angela Garcia\n"
"Language-Team: <en(a)li.org>\n"
"MIME-Version: 1.0\n"
@@ -30,13 +30,13 @@
"e.g., life time and maximum numbers allowed. Memory constraints on servers "
"mean caches cannot grow indefinitely, so policies need to be in place to "
"restrict the size of the cache in memory."
-msgstr ""
+msgstr "Las políticas de eliminación especifican el comportamiento de un nodo que reside dentro del caché, por ejemplo, el tiempo de vida y los números máximos que se permiten. Las restricciones de memoria en los servidores significa que los cachés no pueden crecer indefinidamente así que es necesario que las políticas se encuentren establecidas para restringir el tamaño del caché en la memoria. "
#. Tag: title
#: Eviction_policies.xml:10
#, no-c-format
msgid "Eviction Policy Plugin"
-msgstr ""
+msgstr "Plugin de la política de eliminación"
#. Tag: para
#: Eviction_policies.xml:11
@@ -53,7 +53,7 @@
"implementation that will know how to correlate cache add, remove, and visit "
"events back to a defined eviction behavior. It's the policy provider's "
"responsibility to decide when to call back the cache \"evict\" operation."
-msgstr ""
+msgstr "El diseño del marco de trabajo de la política de eliminación de JBoss Cache se basa en el patrón observable (aunque todavía sincrónico) en donde el administrador de la región de eliminación registrará un <literal>TreeCacheListener</literal> para manejar los eventos cachés y transmitirlos a las políticas de eliminación. Cuando se añade, se elimina, se remueve o se visita un nodo en caché, el <literal>TreeCacheListener</literal> registrado de eliminación mantendrá las estadísticas del estado y se le transmitirá la información a cada región individual de eliminación. Cada región puede definir una implementación del <literal>EvictionPolicy</literal> diferente que sabrá como correlacionar el añadir, remover y visitar eventos en un comportamiento de eliminación definido. Es la responsabilidad del proveedor el decidir cuando volver a llamar la operación de \"eliminación\" del caché."
#. Tag: para
#: Eviction_policies.xml:14
@@ -65,7 +65,7 @@
"removes and visits (gets) to the cache during the configured interval. The "
"eviction thread is responsible for kicking off the eviction policy "
"processing (a single pass) for each configured eviction cache region."
-msgstr ""
+msgstr "Hay un sólo hilo de eliminación (temporizador) que ejecutará en un intervalo configurado. Este hilo realizará llamadas a cada uno de los proveedores de políticas y le informará si alguno de los <literal>TreeCacheListener</literal> agregó adiciones, eliminaciones y visitas (gets) al caché durante el intervalo configurado. El hilo de eliminación es el responsable de iniciar el procesamiento de la política de eliminación (un sólo pase) para cada región caché de eliminación configurada. "
#. Tag: para
#: Eviction_policies.xml:17
@@ -78,12 +78,15 @@
"of these interface implementations define all the underlying mechanics "
"necessary for a complete eviction policy implementation."
msgstr ""
+"Con el fin de implementar una política de eliminación se deben implementar las siguientes interfaces: org.jboss.cache.eviction.EvictionPolicy, org.jboss.cache."
+"eviction.EvictionAlgorithm, org.jboss.cache.eviction.EvictionQueue y org."
+"jboss.cache.eviction.EvictionConfiguration. Cuando se ponen juntas, cada una de estas implementaciones de interfaz definen toda la mecánica subyacente necesaria para una implementación completa de la política de eliminación. "
#. Tag: title
#: Eviction_policies.xml:21
#, no-c-format
msgid "TreeCache eviction UML Diagram"
-msgstr ""
+msgstr "Diagrama UML de eliminación TreeCache"
#. Tag: programlisting
#: Eviction_policies.xml:28
@@ -477,7 +480,7 @@
"The EvictionConfiguration class 'parseXMLConfig(Element)' method expects "
"only the DOM element pertaining to the region the policy is being configured "
"for."
-msgstr ""
+msgstr "La clase EvictionConfiguration del método 'parseXMLConfig(Element)' sólo espera el elemento DOM que se refiere a la región para la cual se está configurando la política. "
#. Tag: para
#: Eviction_policies.xml:44
@@ -488,6 +491,8 @@
"cache region. (e.g. for LRUConfiguration there is a int getMaxNodes() and a "
"setMaxNodes(int))"
msgstr ""
+"La implementación EvictionConfiguration debe mantener los métodos getter y setter para las propiedades configuradas relacionadas con la política utilizada en una región caché dada, (por ejemplo, para LRUConfiguration hay un int getMaxNodes() y un "
+"setMaxNodes(int))"
#. Tag: para
#: Eviction_policies.xml:49
@@ -500,6 +505,8 @@
"implementing SortedEvictionQueue takes care of most of the common "
"functionality available in a set of eviction policy provider classes"
msgstr ""
+"No obstante la implementación de un nuevo proveedor de políticas de eliminación se puede simplificar aún más extendiendo BaseEvictionPolicy y "
+"BaseEvictionAlgorithm. También para EvictionAlgorithms ordenados apropiadamente (en orden de eliminación - vea LFUAlgorithm) extendiendo BaseSortedEvictionAlgorithm e implementando SortedEvictionQueue se encarga de la mayoría de las funcionalidades comunes disponibles en un grupo de clases del proveedor de políticas de eliminación. "
#. Tag: programlisting
#: Eviction_policies.xml:52
@@ -1410,7 +1417,7 @@
"because of held locks. That list is pruned. Finally, the EvictionQueue "
"itself is pruned for entries that should be evicted based upon the "
"configured eviction rules for the region."
-msgstr ""
+msgstr "La clase BaseEvictionAlgorithm mantiene una estructura de procesamiento. Procesará eventos ADD, REMOVE y VISIT en la cola primero por región (los eventos se originan del EvictionTreeCacheListener). Tmabién mantiene una colección de cosas que no fueron eliminados apropiadamente durante la última ronda debido a bloqueos. Esta lista se reducirá. Finalmente el EvictionQueue mismo se reduce para entradas que se deben eliminar con base en las reglas de eliminación configuradas para la región."
#. Tag: programlisting
#: Eviction_policies.xml:64
@@ -1603,7 +1610,7 @@
"visited. This allows the Algorithm to determine whether to resort the "
"eviction queue items (in first to evict order) or to skip the potentially "
"expensive sorting if there have been no changes to the cache in this region."
-msgstr ""
+msgstr "La clase BaseSortedEvictionAlgorithm mantendrá un valor boolean durante el procesamiento del algoritmo que determinará si algún nuevo nodo fue añadido o visitado. Esto le permite al algoritmo determinar si debe recurrir a las cosas que se encuentran en la cola de eliminación (en orden de eliminación primero) o si saltarse el orden potencialmente caro si no se han presentado cambios al caché en esta región. "
#. Tag: programlisting
#: Eviction_policies.xml:75
@@ -1635,13 +1642,13 @@
"evict order. The first entry in the list should evict before the last entry "
"in the queue. The last entry in the queue should be the last entry that will "
"require eviction."
-msgstr ""
+msgstr "La interfaz SortedEvictionQueue define el contrato utilizado por la clase abstracta BaseSortedEvictionAlgorithm que se utiliza para recurrir a la cola subyacente. De nuevo, el orden de la cola debe ser primero en orden de eliminación. La primera entrada en la lista se debe eliminar antes de la última entrada en la cola. La última entrada en la cola debe ser la última entrada que necesitará eliminarse. "
#. Tag: title
#: Eviction_policies.xml:89
#, no-c-format
msgid "TreeCache Eviction Policy Configuration"
-msgstr ""
+msgstr "Configuración de la política de eliminación de TreeCache "
#. Tag: para
#: Eviction_policies.xml:90
@@ -1652,7 +1659,7 @@
"can define its own eviction policy provider or it can use the eviction "
"policy provider class defined at the cache level (1.2.x backwards "
"compatibility)"
-msgstr ""
+msgstr "TreeCache 1.2.X permite configurar una sola clase de proveedor de políticas de eliminación para uso con todas las regiones. Desde TreeCache 1.3.x cada región de caché puede definir su propio proveedor de política de eliminación o puede utilizar la clase de proveedor de política de eliminación definida a nivel de caché (1.2.x compatibilidad retroactiva). "
#. Tag: para
#: Eviction_policies.xml:93
@@ -1660,7 +1667,7 @@
msgid ""
"Here is an example of a legacy 1.2.x EvictionPolicyConfig element to "
"configure TreeCache for use with a single eviction policy provider"
-msgstr ""
+msgstr "Este es un ejemplo de un elemento 1.2.x EvictionPolicyConfig heredado para configurar el TreeCache para uso con un sólo proveedor de política de eliminación. "
#. Tag: programlisting
#: Eviction_policies.xml:96
@@ -1756,7 +1763,7 @@
#: Eviction_policies.xml:97
#, no-c-format
msgid "Here is an example of configuring a different eviction provider per region"
-msgstr ""
+msgstr "Este es un ejemplo de la configuración de diferentes proveedores de eliminación por región"
#. Tag: programlisting
#: Eviction_policies.xml:100
@@ -1837,7 +1844,7 @@
"Lastly, an example of mixed mode. In this scenario the regions that have a "
"specific policy defined will use that policy. Those that do not will default "
"to the policy defined on the entire cache instance."
-msgstr ""
+msgstr "Por último, un ejemplo con modos mezclados. En este escenario las regiones que tienen una política especifica definida utilizarán esa política. Aquellos que no tengan una utilizarán por defecto la política definida en toda la instancia del caché. "
#. Tag: programlisting
#: Eviction_policies.xml:104
@@ -1912,6 +1919,8 @@
"how to set an LRU region to have maxNodes to 12345 timeToLiveSeconds to 500 "
"and maxAgeSeconds to 1000 programatically."
msgstr ""
+"Ahora TreeCache permite la reconfiguración de los proveedores de políticas de eliminación programáticamente en tiempo de ejecución. Un ejemplo de cómo reconfigurar en tiempo de ejecución y de cómo establecer una región LRU para que tenga un maxNodes de hasta 12345, timeToLiveSeconds de hasta 500 "
+"y un maxAgeSeconds de hasta 1000 programáticamente."
#. Tag: programlisting
#: Eviction_policies.xml:108
@@ -1949,7 +1958,7 @@
#: Eviction_policies.xml:112
#, no-c-format
msgid "TreeCache LRU eviction policy implementation"
-msgstr ""
+msgstr "Implementación de la política de eliminación LRU TreeCache "
#. Tag: para
#: Eviction_policies.xml:113
@@ -1960,6 +1969,8 @@
"This policy guarantees O(n) = 1 for adds, removals and lookups (visits). It "
"has the following configuration parameters:"
msgstr ""
+"TreeCache ha implementado una política de eliminación LRU, <literal>org.jboss.cache."
+"eviction.LRUPolicy</literal> que controla el tiempo de vida y la edad del nodo. Esta política garantiza O(n) = 1 para adds, removals y lookups (visitas). Tiene los siguientes parámetros de configuración:"
#. Tag: para
#: Eviction_policies.xml:118 Eviction_policies.xml:156
@@ -1970,6 +1981,8 @@
"to process the node events and also to perform sweeping for the size limit "
"and age-out nodes."
msgstr ""
+"<literal>wakeUpIntervalSeconds</literal>. Este es el intervalo (en segundos) "
+"para procesar los eventos de nodos y también para barrer los nodos de acuerdo con el límite de tamaño y de edad de los nodos."
#. Tag: para
#: Eviction_policies.xml:123 Eviction_policies.xml:161
@@ -1988,6 +2001,11 @@
"user. In addition, the region configuration is not programmable, i.e., all "
"the policies have to be specified via XML configuration."
msgstr ""
+"<literal>Region</literal>. La región es un grupo de nodos que poseen la misma política de eliminación, por ejemplo, el mismo tiempo de expiración. En TreeCache, la región está denotada por un fqn, por ejemplo, <literal>/company/personnel</literal>, y es recursivo. El orden es importante al especificar la región. Por ejemplo, si se especifica <literal>/org/"
+"jboss/test</literal> antes que <literal>/org/jboss/test/data</"
+"literal> entonces cualquier nodo bajo <literal>/org/jboss/test/data</literal> "
+"pertenece a la primera región en vez de la segunda. Observe también que cuando se activa la política de eliminación siempre debe haber una región <literal>/_default_</"
+"literal>, la cual cubre todas las políticas de eliminación no especificadas por el usuario. Además la configuración de la región no es programable, por ejemplo, todas las políticas tienen que ser especificadas a través de la configuración XML."
#. Tag: para
#: Eviction_policies.xml:126
@@ -1995,7 +2013,7 @@
msgid ""
"<literal>maxNodes</literal>. This is the maximum number of nodes allowed in "
"this region. 0 denotes no limit."
-msgstr ""
+msgstr "<literal>maxNodes</literal>. Este es el número máximo de nodos permitidos en esta región. 0 denota que no hay límite."
#. Tag: para
#: Eviction_policies.xml:131
@@ -2003,7 +2021,7 @@
msgid ""
"<literal>timeToLiveSeconds</literal>. Time to idle (in seconds) before the "
"node is swept away. 0 denotes no limit."
-msgstr ""
+msgstr "<literal>timeToLiveSeconds</literal>. Tiempo de inactividad (en segundos) antes de que el nodo sea barrido. 0 denota que no hay límite."
#. Tag: para
#: Eviction_policies.xml:136
@@ -2013,18 +2031,21 @@
"(in seconds) regardless of idle time before the node is swept away. 0 "
"denotes no limit."
msgstr ""
+"<literal>maxAgeSeconds</literal>. El tiempo que un objeto debe existir en TreeCache "
+"(en segundos) sin importar el tiempo de inactividad antes de que el nodo sea barrido. 0 "
+"denota que no hay límite."
#. Tag: para
#: Eviction_policies.xml:144
#, no-c-format
msgid "Please see the above section for an example."
-msgstr ""
+msgstr "Consulte la sección anterior si desea ver un ejemplo."
#. Tag: title
#: Eviction_policies.xml:150
#, no-c-format
msgid "TreeCache FIFO eviction policy implementation"
-msgstr ""
+msgstr "Implementación de la política de eliminación FIFO TreeCache"
#. Tag: para
#: Eviction_policies.xml:151
@@ -2035,6 +2056,9 @@
"first in first out order. This policy guarantees O(n) = 1 for adds, removals "
"and lookups (visits). It has the following configuration parameters:"
msgstr ""
+"TreeCache ha implementado política de eliminación FIFO, <literal>org.jboss.cache."
+"eviction.FIFOPolicy</literal>, que controlará la eliminación en un orden del que primero entrar, primero sale. Esta política garantiza O(n) = 1 para adds, removals "
+"y lookups (visitas). Cuenta con los siguientes parámetros de configuración:"
#. Tag: para
#: Eviction_policies.xml:164 Eviction_policies.xml:192
@@ -2044,19 +2068,21 @@
"this region. Any integer less than or equal to 0 will throw an exception "
"when the policy provider is being configured for use."
msgstr ""
+"<literal>maxNodes</literal>. Este es el número máximo de nodos que se permiten en "
+"esta región. Cualquier número entero menor o igual a 0 presentará una excepción cuando el proveedor de la política está siendo configurado para su uso."
#. Tag: para
#: Eviction_policies.xml:172 Eviction_policies.xml:200
#: Eviction_policies.xml:233
#, no-c-format
msgid "Please read the above section for an example."
-msgstr ""
+msgstr "Si desea ver un ejemplo por favor lea la sección anterior. "
#. Tag: title
#: Eviction_policies.xml:178
#, no-c-format
msgid "TreeCache MRU eviction policy implementation"
-msgstr ""
+msgstr "Implementación de la política de eliminación MRU TreeCache "
#. Tag: para
#: Eviction_policies.xml:179
@@ -2068,12 +2094,15 @@
"to evict with this policy. This policy guarantees O(n) = 1 for adds, "
"removals and lookups (visits). It has the following configuration parameters:"
msgstr ""
+"TreeCache ha implementado una política de eliminación MRU, <literal>org.jboss.cache."
+"eviction.MRUPolicy</literal> que controlará la eliminación con base en el algoritmo utilizado más recientemente. Los nodos utilizados más recientemente serán los primeros en salir con esta política. Esta política garantiza O(n) = 1 para adds, "
+"removals y lookups (visitas). Cuenta con los siguientes parámetros de configuración:"
#. Tag: title
#: Eviction_policies.xml:206
#, no-c-format
msgid "TreeCache LFU eviction policy implementation"
-msgstr ""
+msgstr "Implementación de la política de eliminación LFU TreeCache"
#. Tag: para
#: Eviction_policies.xml:207
@@ -2094,6 +2123,9 @@
"single O(n) = n pruning operation is necessary to clean up the "
"EvictionQueue. LFU has the following configuration parameters:"
msgstr ""
+"TreeCache ha implementado una política de eliminación LFU, <literal>org.jboss.cache."
+"eviction.LFUPolicy</literal> que controlará la eliminación con base en el algoritmo menos utilizado. Los nodos usados con menos frecuencia serán los primeros en ser eliminados con esta política. El uso de nodos empieza en 1 cuando se añade por primera vez un nodo. Cada vez que es visitado, el contador del uso de nodos incrementa en 1. Este número se utiliza para determinar los nodos que se utilizan con menos frecuencia. LFU también es un algoritmo de eliminación ordenada. La implementación EvictionQueue subyacente y el algoritmo se organizan en orden ascendiente del contador de visitas del nodo. Esta clase garantiza O(n) = 1 para adds, removal y búsquedas. Sin embargo, cuando cualquier número de nodos se añaden/visitan a la cola para un pase de procesamiento dado entonces se utiliza una sola operación O(n) = n*log(n) para recurrir a la cola en el orde LFU apropiado. De manera similar si cualquier nodos es eliminado o removido entonces es necesario una sóla op!
eración de reducción O(n) = n para limpiar la "
+"EvictionQueue. LFU cuenta con los siguientes parámetros de configuración:"
#. Tag: para
#: Eviction_policies.xml:220
@@ -2102,7 +2134,7 @@
"<literal>maxNodes</literal>. This is the maximum number of nodes allowed in "
"this region. A value of 0 for maxNodes means that there is no upper bound "
"for the configured cache region."
-msgstr ""
+msgstr "<literal>maxNodes</literal>. Es el número máximo de nodos permitidos en esta región. Un valor de 0 para maxNodes significa que no hay un límite superior para la región caché configurada."
#. Tag: para
#: Eviction_policies.xml:225
@@ -2114,4 +2146,6 @@
"cache is pruned down to the 10 most frequently used nodes when the eviction "
"timer makes a pass through the eviction algorithm."
msgstr ""
+"<literal>minNodes</literal>. Este es el número mínimo de nodos permitidos en esta región. Este valor determina hasta donde se debe reducir la cola de eliminación por pase, por ejemplo, si minNodes es 10 y el caché crece hasta 100 nodos entonces el "
+"caché se reduce hasta los 10 nodos más utilizados cuando el temporizador de eliminación realiza un pase por el algoritmo de eliminación."
16 years, 2 months
JBoss Cache SVN: r7024 - in pojo/tags: 2.2.1.GA and 4 other directories.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-10-28 19:30:07 -0400 (Tue, 28 Oct 2008)
New Revision: 7024
Added:
pojo/tags/2.2.1.GA/
pojo/tags/2.2.1.GA/pom.xml
pojo/tags/2.2.1.GA/src/main/docbook/faq/en/master.xml
pojo/tags/2.2.1.GA/src/main/docbook/tutorial/en/master.xml
pojo/tags/2.2.1.GA/src/main/docbook/userguide/en/master.xml
pojo/tags/2.2.1.GA/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java
Removed:
pojo/tags/2.2.1.GA/pom.xml
pojo/tags/2.2.1.GA/src/main/docbook/faq/en/master.xml
pojo/tags/2.2.1.GA/src/main/docbook/tutorial/en/master.xml
pojo/tags/2.2.1.GA/src/main/docbook/userguide/en/master.xml
pojo/tags/2.2.1.GA/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java
Log:
Merge link fix
Copied: pojo/tags/2.2.1.GA (from rev 6997, pojo/branches/2.2)
Deleted: pojo/tags/2.2.1.GA/pom.xml
===================================================================
--- pojo/branches/2.2/pom.xml 2008-10-21 22:39:19 UTC (rev 6997)
+++ pojo/tags/2.2.1.GA/pom.xml 2008-10-28 23:30:07 UTC (rev 7024)
@@ -1,299 +0,0 @@
-<?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>
- <properties>
- <jbosscache-pojo-version>2.2.0.GA</jbosscache-pojo-version>
- <jbosscache-core-version>2.2.0.GA</jbosscache-core-version>
- <jboss.aop.version>2.0.0.GA</jboss.aop.version>
- </properties>
- <parent>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-common-parent</artifactId>
- <version>1.1</version>
- </parent>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-pojo</artifactId>
- <version>${jbosscache-pojo-version}</version>
- <name>JBoss Cache - POJO Edition</name>
- <description>JBoss Cache - POJO Edition</description>
- <packaging>jar</packaging>
- <dependencies>
- <dependency>
- <groupId>org.jboss.aop</groupId>
- <artifactId>jboss-aop</artifactId>
- <version>${jboss.aop.version}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-core</artifactId>
- <version>${jbosscache-core-version}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-core</artifactId>
- <version>${jbosscache-core-version}</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.0.4</version>
- </dependency>
- <dependency>
- <groupId>net.jcip</groupId>
- <artifactId>jcip-annotations</artifactId>
- <version>1.0</version>
- <optional>true</optional>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>javadoc</goal>
- </goals>
- <configuration>
- <aggregate>${jbosscache.reports.aggregate}</aggregate>
- <links>
- <link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
- <link>http://java.sun.com/javaee/5/docs/api/</link>
- <link>http://labs.jboss.org/file-access/default/members/jbosscache/freezone/doc...</link>
- </links>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>2.2-beta-1</version>
- <executions>
- <execution>
- <id>assemble</id>
- <phase>install</phase>
- <goals>
- <goal>attached</goal>
- </goals>
- <configuration>
- <descriptors>
- <descriptor>assembly/bin.xml</descriptor>
- <descriptor>assembly/doc.xml</descriptor>
- <descriptor>assembly/all.xml</descriptor>
- </descriptors>
- <finalName>${artifactId}-${jbosscache-pojo-version}</finalName>
- <outputDirectory>target/distribution</outputDirectory>
- <workDirectory>target/assembly/work</workDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.3</version>
- <configuration>
- <systemProperties>
- <property>
- <name>bind.address</name>
- <value>127.0.0.1</value>
- </property>
- <property>
- <name>java.net.preferIPv4Stack</name>
- <value>true</value>
- </property>
- <property>
- <name>jgroups.stack</name>
- <value>udp</value>
- </property>
- </systemProperties>
- <groups>functional</groups>
- <forkMode>always</forkMode>
- <argLine>-Djboss.aop.path=${basedir}/src/main/resources/META-INF/pojocache-aop.xml -javaagent:${settings.localRepository}/org/jboss/aop/jboss-aop/${jboss.aop.version}/jboss-aop-${jboss.aop.version}.jar</argLine>
- <!-- Warning, this does not work right on 2.4-SNAPSHOT, (see SUREFIRE-349) -->
- <!-- This seems to fail in some cases on 2.3 as well, disable for now -->
- <useSystemClassLoader>true</useSystemClassLoader>
- <redirectTestOutputToFile>false</redirectTestOutputToFile>
- </configuration>
- </plugin>
- <!-- the docbook generation plugin for the user guide -->
- <plugin>
- <groupId>org.jboss.maven.plugins</groupId>
- <artifactId>maven-jdocbook-plugin</artifactId>
- <version>2.0.0</version>
- <extensions>true</extensions>
- <dependencies>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jbossorg-docbook-xslt</artifactId>
- <version>1.0.0</version>
- </dependency>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jbossorg-jdocbook-style</artifactId>
- <version>1.0.0</version>
- <type>jdocbook-style</type>
- </dependency>
- <dependency>
- <groupId>com.uwyn</groupId>
- <artifactId>jhighlight</artifactId>
- <version>1.0</version>
- </dependency>
- <dependency>
- <groupId>de.java2html</groupId>
- <artifactId>java2html</artifactId>
- <version>5.0</version>
- </dependency>
- <dependency>
- <groupId>org.richfaces.docs</groupId>
- <artifactId>highlight</artifactId>
- <version>3.1.4.GA</version>
- </dependency>
- </dependencies>
- <executions>
-
- <!-- The User Guide-->
- <execution>
- <id>userguide_en</id>
- <phase>package</phase>
- <goals>
- <goal>resources</goal>
- <goal>generate</goal>
- </goals>
- <configuration>
- <sourceDocumentName>master.xml</sourceDocumentName>
- <sourceDirectory>${basedir}/src/main/docbook/userguide/en</sourceDirectory>
- <imageResource>
- <directory>${basedir}/src/main/docbook/images</directory>
- </imageResource>
- <cssResource>
- <directory>${basedir}/src/main/docbook/css</directory>
- </cssResource>
- <targetDirectory>${basedir}/target/docbook/userguide_en</targetDirectory>
- <formats>
- <format>
- <formatName>pdf</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/main-pdf.xsl</stylesheetResource>
- <finalName>userguide_en.pdf</finalName>
- </format>
- <format>
- <formatName>html</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/main-html.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- <format>
- <formatName>html_single</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/nochunk-html.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- </formats>
- <options>
- <xincludeSupported>false</xincludeSupported>
- </options>
- </configuration>
- </execution>
-
- <!-- The Tutorial -->
- <execution>
- <id>tutorial_en</id>
- <phase>package</phase>
- <goals>
- <goal>resources</goal>
- <goal>generate</goal>
- </goals>
- <configuration>
- <sourceDocumentName>master.xml</sourceDocumentName>
- <sourceDirectory>${basedir}/src/main/docbook/tutorial/en</sourceDirectory>
- <imageResource>
- <directory>${basedir}/src/main/docbook/images</directory>
- </imageResource>
- <cssResource>
- <directory>${basedir}/src/main/docbook/css</directory>
- </cssResource>
- <targetDirectory>${basedir}/target/docbook/tutorial_en</targetDirectory>
- <formats>
- <format>
- <formatName>pdf</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/main-pdf.xsl</stylesheetResource>
- <finalName>tutorial_en.pdf</finalName>
- </format>
- <format>
- <formatName>html</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/main-html.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- <format>
- <formatName>html_single</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/nochunk-html.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- </formats>
- <options>
- <xincludeSupported>false</xincludeSupported>
- </options>
- </configuration>
- </execution>
-
- <!-- the FAQs -->
- <execution>
- <id>faq_en</id>
- <phase>package</phase>
- <goals>
- <goal>resources</goal>
- <goal>generate</goal>
- </goals>
- <configuration>
- <sourceDocumentName>master.xml</sourceDocumentName>
- <sourceDirectory>${basedir}/src/main/docbook/faq/en</sourceDirectory>
- <imageResource>
- <directory>${basedir}/src/main/docbook/images</directory>
- </imageResource>
- <cssResource>
- <directory>${basedir}/src/main/docbook/css</directory>
- </cssResource>
- <targetDirectory>${basedir}/target/docbook/faq_en</targetDirectory>
- <formats>
- <format>
- <formatName>pdf</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/main-pdf.xsl</stylesheetResource>
- <finalName>faq_en.pdf</finalName>
- </format>
- <format>
- <formatName>html</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/main-html.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- <format>
- <formatName>html_single</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/nochunk-html.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- </formats>
- <options>
- <xincludeSupported>false</xincludeSupported>
- </options>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <!-- basic JBoss repository so that the common parent POM in jbosscache-support can be found -->
- <repositories>
- <repository>
- <id>snapshots.jboss.org</id>
- <url>http://snapshots.jboss.org/maven2</url>
- </repository>
- <repository>
- <id>repository.jboss.org</id>
- <url>http://repository.jboss.org/maven2</url>
- </repository>
- </repositories>
-</project>
Copied: pojo/tags/2.2.1.GA/pom.xml (from rev 6999, pojo/branches/2.2/pom.xml)
===================================================================
--- pojo/tags/2.2.1.GA/pom.xml (rev 0)
+++ pojo/tags/2.2.1.GA/pom.xml 2008-10-28 23:30:07 UTC (rev 7024)
@@ -0,0 +1,299 @@
+<?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>
+ <properties>
+ <jbosscache-pojo-version>2.2.1.GA</jbosscache-pojo-version>
+ <jbosscache-core-version>2.2.1.GA</jbosscache-core-version>
+ <jboss.aop.version>2.0.0.GA</jboss.aop.version>
+ </properties>
+ <parent>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-common-parent</artifactId>
+ <version>1.1</version>
+ </parent>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-pojo</artifactId>
+ <version>${jbosscache-pojo-version}</version>
+ <name>JBoss Cache - POJO Edition</name>
+ <description>JBoss Cache - POJO Edition</description>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.aop</groupId>
+ <artifactId>jboss-aop</artifactId>
+ <version>${jboss.aop.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-core</artifactId>
+ <version>${jbosscache-core-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-core</artifactId>
+ <version>${jbosscache-core-version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>net.jcip</groupId>
+ <artifactId>jcip-annotations</artifactId>
+ <version>1.0</version>
+ <optional>true</optional>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>javadoc</goal>
+ </goals>
+ <configuration>
+ <aggregate>${jbosscache.reports.aggregate}</aggregate>
+ <links>
+ <link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
+ <link>http://java.sun.com/javaee/5/docs/api/</link>
+ <link>http://labs.jboss.org/file-access/default/members/jbosscache/freezone/doc...</link>
+ </links>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2-beta-1</version>
+ <executions>
+ <execution>
+ <id>assemble</id>
+ <phase>install</phase>
+ <goals>
+ <goal>attached</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+ <descriptor>assembly/bin.xml</descriptor>
+ <descriptor>assembly/doc.xml</descriptor>
+ <descriptor>assembly/all.xml</descriptor>
+ </descriptors>
+ <finalName>${artifactId}-${jbosscache-pojo-version}</finalName>
+ <outputDirectory>target/distribution</outputDirectory>
+ <workDirectory>target/assembly/work</workDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <systemProperties>
+ <property>
+ <name>bind.address</name>
+ <value>127.0.0.1</value>
+ </property>
+ <property>
+ <name>java.net.preferIPv4Stack</name>
+ <value>true</value>
+ </property>
+ <property>
+ <name>jgroups.stack</name>
+ <value>udp</value>
+ </property>
+ </systemProperties>
+ <groups>functional</groups>
+ <forkMode>always</forkMode>
+ <argLine>-Djboss.aop.path=${basedir}/src/main/resources/META-INF/pojocache-aop.xml -javaagent:${settings.localRepository}/org/jboss/aop/jboss-aop/${jboss.aop.version}/jboss-aop-${jboss.aop.version}.jar</argLine>
+ <!-- Warning, this does not work right on 2.4-SNAPSHOT, (see SUREFIRE-349) -->
+ <!-- This seems to fail in some cases on 2.3 as well, disable for now -->
+ <useSystemClassLoader>true</useSystemClassLoader>
+ <redirectTestOutputToFile>false</redirectTestOutputToFile>
+ </configuration>
+ </plugin>
+ <!-- the docbook generation plugin for the user guide -->
+ <plugin>
+ <groupId>org.jboss.maven.plugins</groupId>
+ <artifactId>maven-jdocbook-plugin</artifactId>
+ <version>2.0.0</version>
+ <extensions>true</extensions>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jbossorg-docbook-xslt</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jbossorg-jdocbook-style</artifactId>
+ <version>1.0.0</version>
+ <type>jdocbook-style</type>
+ </dependency>
+ <dependency>
+ <groupId>com.uwyn</groupId>
+ <artifactId>jhighlight</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>de.java2html</groupId>
+ <artifactId>java2html</artifactId>
+ <version>5.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.docs</groupId>
+ <artifactId>highlight</artifactId>
+ <version>3.1.4.GA</version>
+ </dependency>
+ </dependencies>
+ <executions>
+
+ <!-- The User Guide-->
+ <execution>
+ <id>userguide_en</id>
+ <phase>package</phase>
+ <goals>
+ <goal>resources</goal>
+ <goal>generate</goal>
+ </goals>
+ <configuration>
+ <sourceDocumentName>master.xml</sourceDocumentName>
+ <sourceDirectory>${basedir}/src/main/docbook/userguide/en</sourceDirectory>
+ <imageResource>
+ <directory>${basedir}/src/main/docbook/images</directory>
+ </imageResource>
+ <cssResource>
+ <directory>${basedir}/src/main/docbook/css</directory>
+ </cssResource>
+ <targetDirectory>${basedir}/target/docbook/userguide_en</targetDirectory>
+ <formats>
+ <format>
+ <formatName>pdf</formatName>
+ <stylesheetResource>classpath:/xslt/org/jboss/main-pdf.xsl</stylesheetResource>
+ <finalName>userguide_en.pdf</finalName>
+ </format>
+ <format>
+ <formatName>html</formatName>
+ <stylesheetResource>classpath:/xslt/org/jboss/main-html.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ <format>
+ <formatName>html_single</formatName>
+ <stylesheetResource>classpath:/xslt/org/jboss/nochunk-html.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ </formats>
+ <options>
+ <xincludeSupported>false</xincludeSupported>
+ </options>
+ </configuration>
+ </execution>
+
+ <!-- The Tutorial -->
+ <execution>
+ <id>tutorial_en</id>
+ <phase>package</phase>
+ <goals>
+ <goal>resources</goal>
+ <goal>generate</goal>
+ </goals>
+ <configuration>
+ <sourceDocumentName>master.xml</sourceDocumentName>
+ <sourceDirectory>${basedir}/src/main/docbook/tutorial/en</sourceDirectory>
+ <imageResource>
+ <directory>${basedir}/src/main/docbook/images</directory>
+ </imageResource>
+ <cssResource>
+ <directory>${basedir}/src/main/docbook/css</directory>
+ </cssResource>
+ <targetDirectory>${basedir}/target/docbook/tutorial_en</targetDirectory>
+ <formats>
+ <format>
+ <formatName>pdf</formatName>
+ <stylesheetResource>classpath:/xslt/org/jboss/main-pdf.xsl</stylesheetResource>
+ <finalName>tutorial_en.pdf</finalName>
+ </format>
+ <format>
+ <formatName>html</formatName>
+ <stylesheetResource>classpath:/xslt/org/jboss/main-html.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ <format>
+ <formatName>html_single</formatName>
+ <stylesheetResource>classpath:/xslt/org/jboss/nochunk-html.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ </formats>
+ <options>
+ <xincludeSupported>false</xincludeSupported>
+ </options>
+ </configuration>
+ </execution>
+
+ <!-- the FAQs -->
+ <execution>
+ <id>faq_en</id>
+ <phase>package</phase>
+ <goals>
+ <goal>resources</goal>
+ <goal>generate</goal>
+ </goals>
+ <configuration>
+ <sourceDocumentName>master.xml</sourceDocumentName>
+ <sourceDirectory>${basedir}/src/main/docbook/faq/en</sourceDirectory>
+ <imageResource>
+ <directory>${basedir}/src/main/docbook/images</directory>
+ </imageResource>
+ <cssResource>
+ <directory>${basedir}/src/main/docbook/css</directory>
+ </cssResource>
+ <targetDirectory>${basedir}/target/docbook/faq_en</targetDirectory>
+ <formats>
+ <format>
+ <formatName>pdf</formatName>
+ <stylesheetResource>classpath:/xslt/org/jboss/main-pdf.xsl</stylesheetResource>
+ <finalName>faq_en.pdf</finalName>
+ </format>
+ <format>
+ <formatName>html</formatName>
+ <stylesheetResource>classpath:/xslt/org/jboss/main-html.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ <format>
+ <formatName>html_single</formatName>
+ <stylesheetResource>classpath:/xslt/org/jboss/nochunk-html.xsl</stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ </formats>
+ <options>
+ <xincludeSupported>false</xincludeSupported>
+ </options>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <!-- basic JBoss repository so that the common parent POM in jbosscache-support can be found -->
+ <repositories>
+ <repository>
+ <id>snapshots.jboss.org</id>
+ <url>http://snapshots.jboss.org/maven2</url>
+ </repository>
+ <repository>
+ <id>repository.jboss.org</id>
+ <url>http://repository.jboss.org/maven2</url>
+ </repository>
+ </repositories>
+</project>
Deleted: pojo/tags/2.2.1.GA/src/main/docbook/faq/en/master.xml
===================================================================
--- pojo/branches/2.2/src/main/docbook/faq/en/master.xml 2008-10-21 22:39:19 UTC (rev 6997)
+++ pojo/tags/2.2.1.GA/src/main/docbook/faq/en/master.xml 2008-10-28 23:30:07 UTC (rev 7024)
@@ -1,665 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
- "../../../../docbook-support/support/docbook-dtd/docbookx.dtd"
- >
-<article class="faq" lang="en">
- <articleinfo>
- <title>Frequently Asked Questions about POJO Cache</title>
- <releaseinfo>Release 2.2.0.GA</releaseinfo>
- <pubdate>October 2008</pubdate>
-
- <author>
- <firstname>Ben</firstname>
- <surname>Wang</surname>
- <email>ben.wang(a)jboss.com</email>
- </author>
- <author>
- <firstname>Scott</firstname>
- <surname>Marlow</surname>
- <email>smarlow(a)novell.com</email>
- </author>
- <author>
- <firstname>Jason</firstname>
- <surname>Greene</surname>
- <email>jason.greene(a)jboss.com</email>
- </author>
- </articleinfo>
-
- <para>These are frequently asked questions regarding POJO Cache.</para>
-
- <qandaset defaultlabel="qanda">
- <title>General Information</title>
-
- <qandaentry>
- <question id="a49">
- <para>What is POJO Cache?</para>
- </question>
-
- <answer>
- <para>POJO Cache is a fine-grained field-level replicated and
- transactional POJO (plain old Java object) cache. By POJO, we mean
- that the cache: 1) automatically manages object mapping and
- relationship for a client under both local and replicated cache
- mode, 2) provides support for inheritance relationship between
- "aspectized" POJOs. By leveraging the dynamic AOP in JBossAop, it is
- able to map a complex object into the cache store, preserve and
- manage the object relationship behind the scene. During replication
- mode, it performs fine-granularity (i.e., on a per-field basis)
- update, and thus has the potential to boost cache performance and
- minimize network traffic.
- </para>
-
- <para>From a user perspective, once your POJO is managed by the
- cache, all cache operations are transparent. Therefore, all the
- usual in-VM POJO method semantics are still preserved, providing
- ease of use. For example, if a POJO has been put in POJO Cache (by
- calling
- <literal>attach</literal>
- , for example), then any POJO get/set
- method will be
- intercepted by POJO Cache to provide the data from the
- cache.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a1">
- <para>What is the relationship between Core Cache and POJO Cache?</para>
- </question>
-
- <answer>
- <para>Cores Cache is a traditional generic distributed cache system.
- POJO Cache uses Core Cache as the underlying distributed state system to achieve object caching.
- As a result, all the replication aspects are configured with the Cache configuration XML.
- Additionally, POJO Cache also has API to expose the Cache interface (via
- <literal>getCache()</literal>
- API).
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a52">
- <para>What is the difference between Core Cache and
- POJO Cache?
- </para>
- </question>
-
- <answer>
- <para>Think of POJO Cache as a Cache on steroids. :-)
- Seriously, both are cache stores-- one is a generic cache and the other other one POJO Cache.
- However, while Cache only
- provides pure object reference storage (e.g.,
- <literal>put(FQN fqn,
- Object key, Object value)
- </literal>
- ), POJO Cache goes beyond that
- and performs fine-grained field level replication object mapping and
- relationship management for a user behind the scenes. As a result,
- if you have complex object systems that you would like to cache, you
- can have POJO Cache manage it for you. You simply treat your
- object systems as they are residing in-memory, e.g., use your
- regular POJO methods without worrying about cache management.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a521">
- <para>How does POJO Cache work then?</para>
- </question>
-
- <answer>
- <para>POJO Cache uses the JBoss AOP project to perform field level
- interception. This allows POJO Cache to monitor changes to your object model, and react
- accordingly.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a522">
- <para>What's changed between 1.x and 2.x release then?</para>
- </question>
-
- <answer>
- <para>Starting in 2.0 release, we have a separate library for POJO Cache,
- <literal>pojocache.jar</literal>
- that
- is extra to the core
- <literal>jboss-cache.jar</literal>
- . Since we uses Cache as a delegate, user
- will need to have a regular xml to configure the core Cache functionality (e.g., replication and locking
- aspect). In addition, there is also the
- <literal>pojocache-aop.xml</literal>
- that specifies the POJO Cache
- interceptor stack (that can be left as default).
- </para>
- <para>Additionally, here are the changed features:
- <itemizedlist>
- <listitem>
- <para>New APIs. It replaces
- <literal>putObject, removeObject, and get</literal>
- with
- <literal>attach, detach, and find</literal>
- .
- </para>
- </listitem>
- <listitem>
- <para>New POJO based events that a user can subscribe to.</para>
- </listitem>
- <listitem>
- <para>New configuration pojocache-aop.xml specifically for POJO Cache, in addition to
- the regular cache-service.xml for the delegating Cache.
- </para>
- </listitem>
- <listitem>
- <para>New package namespace (
- <literal>org.jboss.cache.pojo)</literal>
- for POJO Cache.
- The previous
- <literal>org.jboss.cache.aop</literal>
- space has been deprecated.
- </para>
- </listitem>
- </itemizedlist>
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a53">
- <para>How do you use POJO Cache?</para>
- </question>
-
- <answer>
- <para>In order to use POJO Cache, you will need to:</para>
-
- <itemizedlist>
- <listitem>
- <para>Annotate your POJOt with @Replicable.
- </para>
- </listitem>
- <listitem>
- <para>Instrument your POJO. This can be done at load-time using special JVM arguments (prefered), or at compile time using the
- AOP precompiler tool (aopc). See the user guide for more specific details on instrumentation.
- </para>
- </listitem>
- </itemizedlist>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a541">
- <para>What is the JDK version required to run POJO Cache 2.x?</para>
- </question>
-
- <answer>
- <para>POJO Cache 2.x requires Java 5 or newer.</para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a542">
- <para>Can I run POJO Cache as a standalone mode?</para>
- </question>
-
- <answer>
- <para>Yes, same as the Core Cache library, you can run POJO Cache either as a standalone or
- inside an application server.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a543">
- <para>What is the JBoss AS recommended version to run POJO Cache 2.x?</para>
- </question>
-
- <answer>
- <para>POJO Cache can be run either in AS4.0.5 (and up) and 5.0. But either way, it will require
- JDK5.0 though.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a56">
- <para>Can I pre-compile objects used in POJO Cache, so that I don't have to provide an AOP descriptor?
- </para>
- </question>
-
- <answer>
- <para>Yes. The AOP library included with POJO Cache has a pre-compiler called
- <literal>aopc</literal> that can be used to instrument objects in advance. However,
- this is not the recommended approach, since your classes become tied to a specific AOP version.
- See the instrumentation chapter in the user guide for more information.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a561">
- <para>In POJO Cache 2.x release, do I still need
- <literal>annoc</literal>
- ?
- </para>
- </question>
-
- <answer>
- <para>No. POJO Cache 2.x requires JDK 5, and recommends load-time instrumentation. Alternatively the offline aopc tool may be used.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a57">
- <para>How do I use aopc on multiple module directories?</para>
- </question>
-
- <answer>
- <para>In aopc, you specify the src path for a specific directory. To
- pre-compile multiple ones, you will need to invoke aopc multiple
- times.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a57a">
- <para>Does POJO Cache provide a listener/event model for catching changes?</para>
- </question>
-
- <answer>
- <para>Yes. See the javadoc for PojoCache.addListener() and @PojoCacheListener.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a58">
- <para>What's in the
- <literal>pojocaches-aop.xml</literal>
- configuration?
- </para>
- </question>
-
- <answer>
- <para>
- These descriptors are necessary for instrumentation. However, you typically do not need to touch them since they include a rule
- which matches the classes with an @Replicable annotation. Therefore, all you need to do, is just
- annotate your class with @Replicable. Advanced users may decide to customize them with special AOP prepare statements that match
- classes which do not have @Replicable.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a58a">
- <para>What's the difference between
- <literal>jboss-aop.xml</literal>
- <literal>pojocache-aop.xml</literal>
- ?
- </para>
- </question>
-
- <answer>
- <para>
- <literal>pojocache-aop.xml</literal>
- is essentially a
- <literal>jboss-aop.xml</literal>
- ,
- except it is used specifically for POJO Cache. The analogy is similar to JBoss' own
- MBean service file
- <literal>jboss-service.xml</literal>
- , for example. So in our documentation,
- we will use these two terms interchangeably.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a59">
- <para>Can I use annotations instead of editing the AOP XML descriptors?</para>
- </question>
-
- <answer>
- <para>Yes, in release 2.0, we recommend you use the @Replicable annotation, and don't bother with editing the AOP files.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a60">
- <para>Is there a problem with using a custom AOP descriptor over the provided annotations?</para>
- </question>
-
- <answer>
- <para>The only real benefit to a custom AOP descriptor is if you can't easily add the annotation to the class source (it's not under your control).
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a61">
- <para>What are the
- <literal>@org.jboss.cache.pojo.annotation.Transient</literal>
- and
- <literal>@org.jboss.cache.pojo.annotation.Serializable</literal>
- field level annotations?
- </para>
- </question>
-
- <answer>
- <para>In 2.0, we also offer two additional field-level annotations. The first one,
- <literal>@org.jboss.cache.pojo.Transient</literal>
- ,
- when applied has the same effect as declaring a field
- <literal>transient</literal>
- . POJO Cache
- won't put this field under management.
- </para>
- <para>The second one,
- <literal>@org.jboss.cache.pojo.Serializable</literal>
- when applied,
- will cause POJO Cache to
- treat the field as a Serializable object even when it is
- <literal>@org.jboss.cache.pojo.Replicable</literal>
- .
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a62">
- <para>Why do you recommend load-time over compile-time instrumentation?</para>
- </question>
-
- <answer>
- <para> The major problem with compile-time instrumentation is that it adds a binary dependency on your class files to whatever
- version of JBoss AOP that was used to run aopc. Once this has been done, the class may not work with a future version of
- JBoss AOP (although the AOP team tries to ensure binary compatibility across minor revisions). Load-time doesn't have
- this problem since the class is instrumented only in memory, and only when it is loaded.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a63">
- <para>Is it possible to store the same object multiple times but
- with different Fqn paths? Like /foo/byName and /foo/byId ?
- </para>
- </question>
-
- <answer>
- <para>Yes, you can use POJO Cache to do that. It supports the
- notion of multiple object references. POJO Cache manages the unique object
- through association of the dynamic cache interceptor.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a64">
- <para>Do I have to instrument my objects?
- </para>
- </question>
-
- <answer>
- <para> You can also attach objects that implement
- <literal>Serializable</literal>. However, you lose field-level replication and object identity preservation.
- This is really only supported as a compatibility measure. It is definately worth useing instrumentation.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a65">
- <para>Will POJO Cache intercept changes made from Java Reflection?</para>
- </question>
-
- <answer>
- <para>Yes and No. Since POJO Cache intercepts field changes, any method
- of an object that has been annotated with @Replicable will be handled properly when called with reflection.
- However, modifying fields using reflection is not currently supported.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a66">
- <para>When I declare my POJO to be "aspectized", what happens to the
- fields with transient, static, and final modifiers?
- </para>
- </question>
-
- <answer>
- <para>POJO Cache currently will ignore the fields with these
- modifiers. That is, it won't put these fields into the cache (and
- thus no replication either).
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a67">
- <para>What are those keys such as
- <literal>JBoss:internal:class</literal>
- and
- <literal>PojoInstance</literal>
- ?
- </para>
- </question>
-
- <answer>
- <para>They are for internal use only. Users should ignore these keys
- and values in the node hashmap.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a68">
- <para>What about Collection classes? Do I need to declare them
- "prepared"?
- </para>
- </question>
-
- <answer>
- <para>No. Since the Collection classes such as
- <literal>ArrayList</literal>
- are java util classes, aop by default
- won't instrument these classes. Instead, POJO Cache will generate
- a dynamic class proxy for the Collection classes (upon the
- <literal>attach</literal>
- call is invoked). The proxy will
- delegate the operations to a cache interceptor that implements the
- actual Collection classes APIs. That is, the system classes won't be
- invoked when used in POJO Cache.
- </para>
-
- <para>Internally, the cache interceptor implements the APIs by
- direct interaction with respect to the underlying cache store. Note
- that this can have implications in performance for certain APIs. For
- example, both
- <literal>ArrayList</literal>
- and
- <literal>LinkedList</literal>
- will have the same implementation.
- Plan is currently underway to optimize these APIs.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a69">
- <para>How do I use
- <literal>List</literal>
- ,
- <literal>Set</literal>
- ,
- and
- <literal>Map</literal> with POJO Cache?
- </para>
- </question>
-
- <answer>
- <para>POJO Cache supports all classes that implement
- <literal>List</literal>
- ,
- <literal>Set</literal>
- , and
- <literal>Map</literal>
- without instrumentation. This is done using a dynamic proxy. Here is an example using
- <literal>ArrayList</literal>:
- </para>
-
- <programlisting role="JAVA"><![CDATA[
- ArrayList list = new ArrayList();
- list.add("first");
-
- cache.attach("/list/test", list); // Put the list under the cache
- list.add("second"); // Won't work since AOP intercepts the dynamic proxy not the original POJO.
-
- ArrayList myList = (List)cache.find("/list/test"); // we are getting a dynamic proxy instead
- myList.add("second"); // it works now
- myList.add("third");
- myList.remove("third");
- ]]></programlisting>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a70">
- <para>What is the proper way of assigning two different keys with
- Collection class object?
- </para>
- </question>
-
- <answer>
- <para>Let's say you want to assign a
- <literal>List</literal>
- object
- under two different names, you will need to use the class proxy to
- insert the second time to ensure both are managed by the cache. Here
- is the code snippet.
- </para>
-
- <programlisting role="JAVA"><![CDATA[
- ArrayList list = new ArrayList();
- list.add("first");
-
- cache.attach("/list", list); // Put the list under the aop cache
-
- ArrayList myList = (List)cache.find("/list"); // we are getting a dynamic proxy instead
- myList.add("second"); // it works now
-
- cache.attach("/list_alias", myList); // Note you will need to use the proxy here!!
- myList.remove("second");
- ]]></programlisting>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a71">
- <para>OK, so I know I am supposed to use proxy when manipulating the
- Collection classes once they are managed by the cache. But what
- happens to POJOs that share the Collection objects, e.g., a
- <literal>List</literal>
- instance that is shared by two objects??
- </para>
- </question>
-
- <answer>
- <para>POJOss that share Collection instance references will be
- handled by the cache automatically. That is, when you ask the Cache
- to manage it, the Cache will dynamically swap out the regular
- Collection references with the dynamic proxy ones. As a result, it
- is transparent to you.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a72">
- <para>What happens when my instrumented object contains collections?
- </para>
- </question>
-
- <answer>
- <para>When an object is passed to
- <literal>attach</literal>
- , it will recursively map the field
- members into the cache store as well. If the field member is of a
- Collection class (e.g., List, Set, or Map), POJO Cache will first
- map the collection into cache. Then, it will swap out
- the field reference with an corresponding proxy reference.
- </para>
-
- <para>This is necessary so that an internal update on the field
- member will be intercepted by the cache.
- </para>
- </answer>
- </qandaentry>
-
-
- <qandaentry>
- <question id="a73">
- <para>What are the limitations of using Java Collections in POJO Cache?</para>
- </question>
- <answer>
- <para>
- List, Set, and Map are supported; however, these APIs do not stipulate
- of constraints like whether a null key or value is allowed. Therefore the behavior of an attached collection may differ
- slightly from the originals Java implementation. The behavior implemented by POJO Cache follows
- java.util.HashSet for any Set type, java.util.ArrayList for any List type, and java.util.HashMap for any Map type.s
- </para>
- </answer>
- </qandaentry>
- </qandaset>
-
-
- <qandaset defaultlabel="qanda">
- <title>Passiviation and eviction</title>
- <qandaentry>
- <question id="a80">
- <para>Can I use eviction to evict a POJO from the memory?</para>
- </question>
- <answer>
- <para>In 2.0 release, we removed the POJO-based eviction policy since it has always been
- problematic in earlier release. You can, however, use the standard Core Cache eviction system to
- evict the data that backs the POJO.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question id="a81">
- <para>Is passivation supported?</para>
- </question>
- <answer>
- <para>Yes, in order to reduce memory consumption, you can use the passivation feature that comes with
- Core Cache. Passivation uses the combination of eviction and a cache loader such that when the
- items are old, it will be evicted from memory and store in a cache store (can be DB or file). Next time,
- when the item needs to be accessed again, we will retrieve it from the cache store.
- </para>
- </answer>
- </qandaentry>
- </qandaset>
-
- <qandaset defaultlabel="qanda">
- <title>Troubleshooting</title>
- <qandaentry>
- <question id="a90">
- <para>I am having problems getting POJO Cache to work, where can I get information on troubleshooting?</para>
- </question>
- <answer>
- <para>Troubleshooting section can be found in the following
- <ulink url="http://wiki.jboss.org/wiki/Wiki.jsp?page=PojoCacheTroubleshooting">wiki link</ulink>
- .
- </para>
- </answer>
- </qandaentry>
- </qandaset>
-</article>
Copied: pojo/tags/2.2.1.GA/src/main/docbook/faq/en/master.xml (from rev 6999, pojo/branches/2.2/src/main/docbook/faq/en/master.xml)
===================================================================
--- pojo/tags/2.2.1.GA/src/main/docbook/faq/en/master.xml (rev 0)
+++ pojo/tags/2.2.1.GA/src/main/docbook/faq/en/master.xml 2008-10-28 23:30:07 UTC (rev 7024)
@@ -0,0 +1,665 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+ "../../../../docbook-support/support/docbook-dtd/docbookx.dtd"
+ >
+<article class="faq" lang="en">
+ <articleinfo>
+ <title>Frequently Asked Questions about POJO Cache</title>
+ <releaseinfo>Release 2.2.1.GA</releaseinfo>
+ <pubdate>October 2008</pubdate>
+
+ <author>
+ <firstname>Ben</firstname>
+ <surname>Wang</surname>
+ <email>ben.wang(a)jboss.com</email>
+ </author>
+ <author>
+ <firstname>Scott</firstname>
+ <surname>Marlow</surname>
+ <email>smarlow(a)novell.com</email>
+ </author>
+ <author>
+ <firstname>Jason</firstname>
+ <surname>Greene</surname>
+ <email>jason.greene(a)jboss.com</email>
+ </author>
+ </articleinfo>
+
+ <para>These are frequently asked questions regarding POJO Cache.</para>
+
+ <qandaset defaultlabel="qanda">
+ <title>General Information</title>
+
+ <qandaentry>
+ <question id="a49">
+ <para>What is POJO Cache?</para>
+ </question>
+
+ <answer>
+ <para>POJO Cache is a fine-grained field-level replicated and
+ transactional POJO (plain old Java object) cache. By POJO, we mean
+ that the cache: 1) automatically manages object mapping and
+ relationship for a client under both local and replicated cache
+ mode, 2) provides support for inheritance relationship between
+ "aspectized" POJOs. By leveraging the dynamic AOP in JBossAop, it is
+ able to map a complex object into the cache store, preserve and
+ manage the object relationship behind the scene. During replication
+ mode, it performs fine-granularity (i.e., on a per-field basis)
+ update, and thus has the potential to boost cache performance and
+ minimize network traffic.
+ </para>
+
+ <para>From a user perspective, once your POJO is managed by the
+ cache, all cache operations are transparent. Therefore, all the
+ usual in-VM POJO method semantics are still preserved, providing
+ ease of use. For example, if a POJO has been put in POJO Cache (by
+ calling
+ <literal>attach</literal>
+ , for example), then any POJO get/set
+ method will be
+ intercepted by POJO Cache to provide the data from the
+ cache.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a1">
+ <para>What is the relationship between Core Cache and POJO Cache?</para>
+ </question>
+
+ <answer>
+ <para>Cores Cache is a traditional generic distributed cache system.
+ POJO Cache uses Core Cache as the underlying distributed state system to achieve object caching.
+ As a result, all the replication aspects are configured with the Cache configuration XML.
+ Additionally, POJO Cache also has API to expose the Cache interface (via
+ <literal>getCache()</literal>
+ API).
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a52">
+ <para>What is the difference between Core Cache and
+ POJO Cache?
+ </para>
+ </question>
+
+ <answer>
+ <para>Think of POJO Cache as a Cache on steroids. :-)
+ Seriously, both are cache stores-- one is a generic cache and the other other one POJO Cache.
+ However, while Cache only
+ provides pure object reference storage (e.g.,
+ <literal>put(FQN fqn,
+ Object key, Object value)
+ </literal>
+ ), POJO Cache goes beyond that
+ and performs fine-grained field level replication object mapping and
+ relationship management for a user behind the scenes. As a result,
+ if you have complex object systems that you would like to cache, you
+ can have POJO Cache manage it for you. You simply treat your
+ object systems as they are residing in-memory, e.g., use your
+ regular POJO methods without worrying about cache management.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a521">
+ <para>How does POJO Cache work then?</para>
+ </question>
+
+ <answer>
+ <para>POJO Cache uses the JBoss AOP project to perform field level
+ interception. This allows POJO Cache to monitor changes to your object model, and react
+ accordingly.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a522">
+ <para>What's changed between 1.x and 2.x release then?</para>
+ </question>
+
+ <answer>
+ <para>Starting in 2.0 release, we have a separate library for POJO Cache,
+ <literal>pojocache.jar</literal>
+ that
+ is extra to the core
+ <literal>jboss-cache.jar</literal>
+ . Since we uses Cache as a delegate, user
+ will need to have a regular xml to configure the core Cache functionality (e.g., replication and locking
+ aspect). In addition, there is also the
+ <literal>pojocache-aop.xml</literal>
+ that specifies the POJO Cache
+ interceptor stack (that can be left as default).
+ </para>
+ <para>Additionally, here are the changed features:
+ <itemizedlist>
+ <listitem>
+ <para>New APIs. It replaces
+ <literal>putObject, removeObject, and get</literal>
+ with
+ <literal>attach, detach, and find</literal>
+ .
+ </para>
+ </listitem>
+ <listitem>
+ <para>New POJO based events that a user can subscribe to.</para>
+ </listitem>
+ <listitem>
+ <para>New configuration pojocache-aop.xml specifically for POJO Cache, in addition to
+ the regular cache-service.xml for the delegating Cache.
+ </para>
+ </listitem>
+ <listitem>
+ <para>New package namespace (
+ <literal>org.jboss.cache.pojo)</literal>
+ for POJO Cache.
+ The previous
+ <literal>org.jboss.cache.aop</literal>
+ space has been deprecated.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a53">
+ <para>How do you use POJO Cache?</para>
+ </question>
+
+ <answer>
+ <para>In order to use POJO Cache, you will need to:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>Annotate your POJOt with @Replicable.
+ </para>
+ </listitem>
+ <listitem>
+ <para>Instrument your POJO. This can be done at load-time using special JVM arguments (prefered), or at compile time using the
+ AOP precompiler tool (aopc). See the user guide for more specific details on instrumentation.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a541">
+ <para>What is the JDK version required to run POJO Cache 2.x?</para>
+ </question>
+
+ <answer>
+ <para>POJO Cache 2.x requires Java 5 or newer.</para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a542">
+ <para>Can I run POJO Cache as a standalone mode?</para>
+ </question>
+
+ <answer>
+ <para>Yes, same as the Core Cache library, you can run POJO Cache either as a standalone or
+ inside an application server.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a543">
+ <para>What is the JBoss AS recommended version to run POJO Cache 2.x?</para>
+ </question>
+
+ <answer>
+ <para>POJO Cache can be run either in AS4.0.5 (and up) and 5.0. But either way, it will require
+ JDK5.0 though.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a56">
+ <para>Can I pre-compile objects used in POJO Cache, so that I don't have to provide an AOP descriptor?
+ </para>
+ </question>
+
+ <answer>
+ <para>Yes. The AOP library included with POJO Cache has a pre-compiler called
+ <literal>aopc</literal> that can be used to instrument objects in advance. However,
+ this is not the recommended approach, since your classes become tied to a specific AOP version.
+ See the instrumentation chapter in the user guide for more information.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a561">
+ <para>In POJO Cache 2.x release, do I still need
+ <literal>annoc</literal>
+ ?
+ </para>
+ </question>
+
+ <answer>
+ <para>No. POJO Cache 2.x requires JDK 5, and recommends load-time instrumentation. Alternatively the offline aopc tool may be used.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a57">
+ <para>How do I use aopc on multiple module directories?</para>
+ </question>
+
+ <answer>
+ <para>In aopc, you specify the src path for a specific directory. To
+ pre-compile multiple ones, you will need to invoke aopc multiple
+ times.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a57a">
+ <para>Does POJO Cache provide a listener/event model for catching changes?</para>
+ </question>
+
+ <answer>
+ <para>Yes. See the javadoc for PojoCache.addListener() and @PojoCacheListener.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a58">
+ <para>What's in the
+ <literal>pojocaches-aop.xml</literal>
+ configuration?
+ </para>
+ </question>
+
+ <answer>
+ <para>
+ These descriptors are necessary for instrumentation. However, you typically do not need to touch them since they include a rule
+ which matches the classes with an @Replicable annotation. Therefore, all you need to do, is just
+ annotate your class with @Replicable. Advanced users may decide to customize them with special AOP prepare statements that match
+ classes which do not have @Replicable.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a58a">
+ <para>What's the difference between
+ <literal>jboss-aop.xml</literal>
+ <literal>pojocache-aop.xml</literal>
+ ?
+ </para>
+ </question>
+
+ <answer>
+ <para>
+ <literal>pojocache-aop.xml</literal>
+ is essentially a
+ <literal>jboss-aop.xml</literal>
+ ,
+ except it is used specifically for POJO Cache. The analogy is similar to JBoss' own
+ MBean service file
+ <literal>jboss-service.xml</literal>
+ , for example. So in our documentation,
+ we will use these two terms interchangeably.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a59">
+ <para>Can I use annotations instead of editing the AOP XML descriptors?</para>
+ </question>
+
+ <answer>
+ <para>Yes, in release 2.0, we recommend you use the @Replicable annotation, and don't bother with editing the AOP files.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a60">
+ <para>Is there a problem with using a custom AOP descriptor over the provided annotations?</para>
+ </question>
+
+ <answer>
+ <para>The only real benefit to a custom AOP descriptor is if you can't easily add the annotation to the class source (it's not under your control).
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a61">
+ <para>What are the
+ <literal>@org.jboss.cache.pojo.annotation.Transient</literal>
+ and
+ <literal>@org.jboss.cache.pojo.annotation.Serializable</literal>
+ field level annotations?
+ </para>
+ </question>
+
+ <answer>
+ <para>In 2.0, we also offer two additional field-level annotations. The first one,
+ <literal>@org.jboss.cache.pojo.Transient</literal>
+ ,
+ when applied has the same effect as declaring a field
+ <literal>transient</literal>
+ . POJO Cache
+ won't put this field under management.
+ </para>
+ <para>The second one,
+ <literal>@org.jboss.cache.pojo.Serializable</literal>
+ when applied,
+ will cause POJO Cache to
+ treat the field as a Serializable object even when it is
+ <literal>@org.jboss.cache.pojo.Replicable</literal>
+ .
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a62">
+ <para>Why do you recommend load-time over compile-time instrumentation?</para>
+ </question>
+
+ <answer>
+ <para> The major problem with compile-time instrumentation is that it adds a binary dependency on your class files to whatever
+ version of JBoss AOP that was used to run aopc. Once this has been done, the class may not work with a future version of
+ JBoss AOP (although the AOP team tries to ensure binary compatibility across minor revisions). Load-time doesn't have
+ this problem since the class is instrumented only in memory, and only when it is loaded.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a63">
+ <para>Is it possible to store the same object multiple times but
+ with different Fqn paths? Like /foo/byName and /foo/byId ?
+ </para>
+ </question>
+
+ <answer>
+ <para>Yes, you can use POJO Cache to do that. It supports the
+ notion of multiple object references. POJO Cache manages the unique object
+ through association of the dynamic cache interceptor.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a64">
+ <para>Do I have to instrument my objects?
+ </para>
+ </question>
+
+ <answer>
+ <para> You can also attach objects that implement
+ <literal>Serializable</literal>. However, you lose field-level replication and object identity preservation.
+ This is really only supported as a compatibility measure. It is definately worth useing instrumentation.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a65">
+ <para>Will POJO Cache intercept changes made from Java Reflection?</para>
+ </question>
+
+ <answer>
+ <para>Yes and No. Since POJO Cache intercepts field changes, any method
+ of an object that has been annotated with @Replicable will be handled properly when called with reflection.
+ However, modifying fields using reflection is not currently supported.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a66">
+ <para>When I declare my POJO to be "aspectized", what happens to the
+ fields with transient, static, and final modifiers?
+ </para>
+ </question>
+
+ <answer>
+ <para>POJO Cache currently will ignore the fields with these
+ modifiers. That is, it won't put these fields into the cache (and
+ thus no replication either).
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a67">
+ <para>What are those keys such as
+ <literal>JBoss:internal:class</literal>
+ and
+ <literal>PojoInstance</literal>
+ ?
+ </para>
+ </question>
+
+ <answer>
+ <para>They are for internal use only. Users should ignore these keys
+ and values in the node hashmap.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a68">
+ <para>What about Collection classes? Do I need to declare them
+ "prepared"?
+ </para>
+ </question>
+
+ <answer>
+ <para>No. Since the Collection classes such as
+ <literal>ArrayList</literal>
+ are java util classes, aop by default
+ won't instrument these classes. Instead, POJO Cache will generate
+ a dynamic class proxy for the Collection classes (upon the
+ <literal>attach</literal>
+ call is invoked). The proxy will
+ delegate the operations to a cache interceptor that implements the
+ actual Collection classes APIs. That is, the system classes won't be
+ invoked when used in POJO Cache.
+ </para>
+
+ <para>Internally, the cache interceptor implements the APIs by
+ direct interaction with respect to the underlying cache store. Note
+ that this can have implications in performance for certain APIs. For
+ example, both
+ <literal>ArrayList</literal>
+ and
+ <literal>LinkedList</literal>
+ will have the same implementation.
+ Plan is currently underway to optimize these APIs.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a69">
+ <para>How do I use
+ <literal>List</literal>
+ ,
+ <literal>Set</literal>
+ ,
+ and
+ <literal>Map</literal> with POJO Cache?
+ </para>
+ </question>
+
+ <answer>
+ <para>POJO Cache supports all classes that implement
+ <literal>List</literal>
+ ,
+ <literal>Set</literal>
+ , and
+ <literal>Map</literal>
+ without instrumentation. This is done using a dynamic proxy. Here is an example using
+ <literal>ArrayList</literal>:
+ </para>
+
+ <programlisting role="JAVA"><![CDATA[
+ ArrayList list = new ArrayList();
+ list.add("first");
+
+ cache.attach("/list/test", list); // Put the list under the cache
+ list.add("second"); // Won't work since AOP intercepts the dynamic proxy not the original POJO.
+
+ ArrayList myList = (List)cache.find("/list/test"); // we are getting a dynamic proxy instead
+ myList.add("second"); // it works now
+ myList.add("third");
+ myList.remove("third");
+ ]]></programlisting>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a70">
+ <para>What is the proper way of assigning two different keys with
+ Collection class object?
+ </para>
+ </question>
+
+ <answer>
+ <para>Let's say you want to assign a
+ <literal>List</literal>
+ object
+ under two different names, you will need to use the class proxy to
+ insert the second time to ensure both are managed by the cache. Here
+ is the code snippet.
+ </para>
+
+ <programlisting role="JAVA"><![CDATA[
+ ArrayList list = new ArrayList();
+ list.add("first");
+
+ cache.attach("/list", list); // Put the list under the aop cache
+
+ ArrayList myList = (List)cache.find("/list"); // we are getting a dynamic proxy instead
+ myList.add("second"); // it works now
+
+ cache.attach("/list_alias", myList); // Note you will need to use the proxy here!!
+ myList.remove("second");
+ ]]></programlisting>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a71">
+ <para>OK, so I know I am supposed to use proxy when manipulating the
+ Collection classes once they are managed by the cache. But what
+ happens to POJOs that share the Collection objects, e.g., a
+ <literal>List</literal>
+ instance that is shared by two objects??
+ </para>
+ </question>
+
+ <answer>
+ <para>POJOss that share Collection instance references will be
+ handled by the cache automatically. That is, when you ask the Cache
+ to manage it, the Cache will dynamically swap out the regular
+ Collection references with the dynamic proxy ones. As a result, it
+ is transparent to you.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a72">
+ <para>What happens when my instrumented object contains collections?
+ </para>
+ </question>
+
+ <answer>
+ <para>When an object is passed to
+ <literal>attach</literal>
+ , it will recursively map the field
+ members into the cache store as well. If the field member is of a
+ Collection class (e.g., List, Set, or Map), POJO Cache will first
+ map the collection into cache. Then, it will swap out
+ the field reference with an corresponding proxy reference.
+ </para>
+
+ <para>This is necessary so that an internal update on the field
+ member will be intercepted by the cache.
+ </para>
+ </answer>
+ </qandaentry>
+
+
+ <qandaentry>
+ <question id="a73">
+ <para>What are the limitations of using Java Collections in POJO Cache?</para>
+ </question>
+ <answer>
+ <para>
+ List, Set, and Map are supported; however, these APIs do not stipulate
+ of constraints like whether a null key or value is allowed. Therefore the behavior of an attached collection may differ
+ slightly from the originals Java implementation. The behavior implemented by POJO Cache follows
+ java.util.HashSet for any Set type, java.util.ArrayList for any List type, and java.util.HashMap for any Map type.s
+ </para>
+ </answer>
+ </qandaentry>
+ </qandaset>
+
+
+ <qandaset defaultlabel="qanda">
+ <title>Passiviation and eviction</title>
+ <qandaentry>
+ <question id="a80">
+ <para>Can I use eviction to evict a POJO from the memory?</para>
+ </question>
+ <answer>
+ <para>In 2.0 release, we removed the POJO-based eviction policy since it has always been
+ problematic in earlier release. You can, however, use the standard Core Cache eviction system to
+ evict the data that backs the POJO.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question id="a81">
+ <para>Is passivation supported?</para>
+ </question>
+ <answer>
+ <para>Yes, in order to reduce memory consumption, you can use the passivation feature that comes with
+ Core Cache. Passivation uses the combination of eviction and a cache loader such that when the
+ items are old, it will be evicted from memory and store in a cache store (can be DB or file). Next time,
+ when the item needs to be accessed again, we will retrieve it from the cache store.
+ </para>
+ </answer>
+ </qandaentry>
+ </qandaset>
+
+ <qandaset defaultlabel="qanda">
+ <title>Troubleshooting</title>
+ <qandaentry>
+ <question id="a90">
+ <para>I am having problems getting POJO Cache to work, where can I get information on troubleshooting?</para>
+ </question>
+ <answer>
+ <para>Troubleshooting section can be found in the following
+ <ulink url="http://wiki.jboss.org/wiki/Wiki.jsp?page=PojoCacheTroubleshooting">wiki link</ulink>
+ .
+ </para>
+ </answer>
+ </qandaentry>
+ </qandaset>
+</article>
Deleted: pojo/tags/2.2.1.GA/src/main/docbook/tutorial/en/master.xml
===================================================================
--- pojo/branches/2.2/src/main/docbook/tutorial/en/master.xml 2008-10-21 22:39:19 UTC (rev 6997)
+++ pojo/tags/2.2.1.GA/src/main/docbook/tutorial/en/master.xml 2008-10-28 23:30:07 UTC (rev 7024)
@@ -1,401 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<article lang="en">
- <articleinfo>
- <title>POJO Cache Tutorial</title>
- <releaseinfo>Release 2.2.0</releaseinfo>
- <pubdate>October 2008</pubdate>
- <author>
- <firstname>Ben</firstname>
- <surname>Wang</surname>
- <email>ben.wang(a)jboss.com</email>
- </author>
- <author>
- <firstname>Galder</firstname>
- <surname>Zamarreño</surname>
- <email>galder.zamarreno(a)jboss.com</email>
- </author>
- </articleinfo>
-
- <section>
- <title>Introduction</title>
-
- <para>POJO Cache is an in-memory, transactional, and replicated POJO (plain old Java object) cache system that
- allows users to operate on a POJO transparently without active user management of either replication or
- persistency aspects. This tutorial focuses on the usage of the POJO Cache API.
- </para>
- <para>For details of configuration, usage and APIs, please refer to the
- <ulink url="http://labs.jboss.org/portal/jbosscache/docs/index.html">users manual</ulink>.
- </para>
- </section>
-
- <section>
- <title>What You Will Learn</title>
-
- <itemizedlist>
- <listitem>
- <para>POJO Cache creation and modification</para>
- </listitem>
-
- <listitem>
- <para>Replication of POJO fields</para>
- </listitem>
-
- <listitem>
- <para>Using Collections in POJO Cache</para>
- </listitem>
-
- <listitem>
- <para>Transactions</para>
- </listitem>
-
- </itemizedlist>
- </section>
-
- <section>
- <title>Configuration</title>
-
- <para>First download the JBoss Cache 2.x distribution from
- <ulink url="http://labs.jboss.org/portal/jbosscache/download/index.html">the download page</ulink>
- . You probably want the
- <literal>jbosscache-pojo-2.X.Y.zip</literal>
- distribution. Unzip it, and you will get a directory containing the distribution, such as
- <literal>jbosscache-pojo-2.X.Y</literal>
- .
- For the sake of this tutorial, I will refer to this as
- <literal>POJO Cache</literal>
- .
- </para>
-
- <para>The configuration files are located under the
- <literal>jbosscache-pojo/etc</literal>
- directory. You can modify the behavior of the underlying cache through editing the various configuration files.
- </para>
-
- <itemizedlist>
- <listitem>
- <para>
- <literal>log4j.xml</literal>
- . Logging output. You can enable logging, specify log levels or change the name and path to the log file.
- </para>
- </listitem>
-
- <listitem>
- <para>
- <literal>META-INF/replSync-service.xml</literal>
- . Cache configuration file used for this tutorial.
- </para>
- </listitem>
-
- <listitem>
- <para>
- <literal>pojocache-aop.xml</literal>
- . POJO Cache configuration file that contains, amongst other things, the annotation to use on POJOs so
- that they're aspectised. For more information, please the POJO Cache
- <ulink url="http://labs.jboss.org/portal/jbosscache/docs/index.html">users manual</ulink>
- .
- </para>
- </listitem>
- </itemizedlist>
- </section>
-
- <section>
- <title>Script</title>
-
- <para>The only script needed for this tutorial is the
- <literal>jbosscache-pojo/build.xml</literal>
- ant script.
- </para>
- </section>
-
- <section>
- <title>Example POJOs</title>
-
- <para>The example POJO classes used for POJO Cache demo are:
- <literal>org.jboss.cache.pojo.test.Person</literal>
- and
- <literal>org.jboss.cache.pojo.test.Address</literal>
- . They are located
- under
- <literal>tests/functional</literal>
- directory.The demo will demonstrate that once a POJO has been attached to the cache, plain get/set POJO methods
- will be intercepted by the cache.
- </para>
-
- <para>Here is the snippet of the class definition for
- <literal>Person</literal>
- and
- <literal>Address</literal>
- with the
- <literal>Replicable</literal>
- annotation.
- </para>
-
- <programlisting role="JAVA"><![CDATA[
-(a)org.jboss.cache.pojo.annotation.Replicable
-public class Person
-{
- ...
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name=name;
- }
-
- // ...
-
- public List<String> getLanguages()
- {
- return languages;
- }
-
- public void setLanguages(List<String> languages)
- {
- this.languages = languages;
- }
-
- // ...
-
- public Address getAddress()
- {
- return address;
- }
-
- public void setAddress(Address address)
- {
- this.address = address;
- }
-
- // ...
-}
- ]]></programlisting>
-
- <programlisting role="JAVA"><![CDATA[
-(a)org.jboss.cache.pojo.annotation.Replicable
-public class Address
-{
- // ...
- public String getStreet()
- {
- return street;
- }
- public void setStreet(String street)
- {
- this.street=street;
- }
- // ...
-}
- ]]></programlisting>
- </section>
-
- <section>
- <title>Running The Demo GUI</title>
-
- <para>
- The demo is run by calling the ant script (via the driver) with the
- <literal>run.demo</literal>
- target. E.g.,
- </para>
-
- <para>
- <literal>ant run.demo</literal>
- </para>
- <para>
- This will cause a GUI window to appear, giving you a tree view of the cache in the top pane and a BeanShell
- view of the JVM in the lower pane.
- </para>
- <para>
- The BeanShell view is preset with the following variables:
- <itemizedlist>
- <listitem>
- <literal>cache</literal>
- - a reference to the POJO Cache interface, used by the GUI instance.
- </listitem>
- <listitem>
- <literal>transactionManager</literal>
- - a reference to the registered transaction manager.
- </listitem>
- </itemizedlist>
- The references made available to the BeanShell window point to the same cache instance used by the tree view in
- the GUI above.
- </para>
-
- <para>
- To run the demo as a replicated demo, it is useful to start another command line window and run the ant script
- again as you did above. Now you will have two cache instances running in two separate GUIs, replicating state
- to each other.
- </para>
-
- </section>
-
- <section>
- <title>Tutorials</title>
- It is recommended that you shut down and restart the demo GUI for each of the following tutorials, to ensure
- clean caches every time. To inspect POJO attribute changes via GUI, please refer to the POJO Cache
- <ulink
- url="http://labs.jboss.org/portal/jbosscache/docs/index.html">user manual
- </ulink>
- to understand how the POJOs are mapped internally in the cache.
-
- <section>
- <title>POJO Cache API, POJO manipulation, and Replication</title>
- <para>
- For this tutorial, start two instance of the demo GUI. In this tutorial, we will:
-
- <itemizedlist>
- <listitem>Attach POJOs to the cache and see them being replicated.</listitem>
- <listitem>After attaching, manipulate the POJOs and see the individual changes replicated.</listitem>
- <listitem>Retrieve POJOs from the cache, manipulate them and see the changes replicated.</listitem>
- <listitem>Create POJOs that share a common POJO and the consequences of changes to this.</listitem>
- <listitem>Detach POJOs from the cache.</listitem>
- <listitem>After detaching, manipulates the POJOs and see how the values in the cache are unchanged.</listitem>
- </itemizedlist>
-
- </para>
-
- <orderedlist>
- <listitem>In the 1st GUI instance, create a POJO, i.e. a Person with an Address:
- <programlisting role="JAVA"><![CDATA[
- joe = new Person();
- joe.setName("Joe Black");
- joe.setAge(31);
-
- addr = new Address();
- addr.setCity("Sunnyvale");
- addr.setStreet("123 Albert Ave");
- addr.setZip(94086);
-
- joe.setAddress(addr);
- ]]></programlisting>
- </listitem>
-
- <listitem>Attach the POJO to the cache:
- <programlisting role="JAVA"><![CDATA[
- cache.attach("pojo/joe", joe);
- ]]></programlisting>
- </listitem>
-
- <listitem>Change attributes of the POJO and see the individual changes being propagated to the 2nd
- cache GUI:
- <programlisting role="JAVA"><![CDATA[
- joe.setAge(41);
- ]]></programlisting>
- </listitem>
-
- <listitem>In the 2nd GUI instance, get a reference to the Person in the cache and create a second Person
- with the existing Person's Address:
- <programlisting role="JAVA"><![CDATA[
- joe = cache.find("pojo/joe");
-
- mary = new Person();
- mary.setName("Mary White");
- mary.setAge(30);
-
- mary.setAddress(joe.getAddress());
- ]]></programlisting>
- </listitem>
-
- <listitem>Attach the new POJO to the cache:
- <programlisting role="JAVA"><![CDATA[
- cache.attach("pojo/mary", mary);
- ]]></programlisting>
- </listitem>
-
- <listitem>Now, change either Person's Address and see how the change applies to both POJOs and has been
- propagated to the other cache, visible in the 1st GUI instance:
- <programlisting role="JAVA"><![CDATA[
- mary.getAddress().setZip(95000);
- ]]></programlisting>
- </listitem>
-
-
- <listitem>Still in the 2nd GUI instance, detach the POJOs from the cache and see how the POJOs are no longer
- visible:
- <programlisting role="JAVA"><![CDATA[
- cache.detach("pojo/joe");
- cache.detach("pojo/mary");
- ]]></programlisting>
- </listitem>
-
- <listitem>Finally, in any of GUI instances, change some attributes of the POJO and see these changes have
- no effect in the cache:
- <programlisting role="JAVA"><![CDATA[
- joe.setName("Joe White");
- ]]></programlisting>
- </listitem>
-
- </orderedlist>
-
- </section>
-
- <section>
- <title>Collections</title>
- <para>
- For this tutorial, start two instances of the demo GUI. In this tutorial, we will:
-
- <itemizedlist>
- <listitem>Attach a POJO to the cache and see it being replicated.</listitem>
- <listitem>Set a Collection attribute in this POJO</listitem>
- <listitem>Manipulate this Collection attribute and see the changes visible in the GUI and being replicated</listitem>
- <listitem>Detach a POJO from the cache.</listitem>
- </itemizedlist>
-
- </para>
-
- <orderedlist>
- <listitem>In the 1st GUI instance, create a POJO with a Collection attribute:
- <programlisting role="JAVA"><![CDATA[
- joe = new Person();
- joe.setName("Joe Black");
-
- lang = new ArrayList();
- lang.add("Spanish");
-
- joe.setLanguages(lang);
- ]]></programlisting>
- </listitem>
-
- <listitem>Attach the POJO to the cache:
- <programlisting role="JAVA"><![CDATA[
- cache.attach("pojo/joe", joe);
- ]]></programlisting>
- </listitem>
-
- <listitem>Get a proxy reference to the Collection and add a new element to it:
- <programlisting role="JAVA"><![CDATA[
- proxyLang = joe.getLanguages();
- proxyLang.add("English");
- ]]></programlisting>
- </listitem>
-
- <listitem>Detach the pojo from the cache:
- <programlisting role="JAVA"><![CDATA[
- cache.detach("pojo/joe");
- ]]></programlisting>
- </listitem>
-
- <listitem>Use the proxy reference to the Collection to add another element and see how this does not get
- added to the cache:
- <programlisting role="JAVA"><![CDATA[
- proxyLang.add("French");
- ]]></programlisting>
- </listitem>
-
- </orderedlist>
- </section>
- </section>
-
- <section>
- <title>Transactions</title>
- <para>
- For this tutorial, start two instances instance of the demo GUI. Repeat the exercises in the previous
- tutorial, only starting transactions before attaching/detaching nodes or modiying the POJOs. This will depict
- how replication only occurs on transaction boundaries. Try rolling back a few transactions as well, to see how
- nothing gets replicated in these cases.
- </para>
- </section>
-
-</article>
Copied: pojo/tags/2.2.1.GA/src/main/docbook/tutorial/en/master.xml (from rev 6999, pojo/branches/2.2/src/main/docbook/tutorial/en/master.xml)
===================================================================
--- pojo/tags/2.2.1.GA/src/main/docbook/tutorial/en/master.xml (rev 0)
+++ pojo/tags/2.2.1.GA/src/main/docbook/tutorial/en/master.xml 2008-10-28 23:30:07 UTC (rev 7024)
@@ -0,0 +1,401 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<article lang="en">
+ <articleinfo>
+ <title>POJO Cache Tutorial</title>
+ <releaseinfo>Release 2.2.1</releaseinfo>
+ <pubdate>October 2008</pubdate>
+ <author>
+ <firstname>Ben</firstname>
+ <surname>Wang</surname>
+ <email>ben.wang(a)jboss.com</email>
+ </author>
+ <author>
+ <firstname>Galder</firstname>
+ <surname>Zamarreño</surname>
+ <email>galder.zamarreno(a)jboss.com</email>
+ </author>
+ </articleinfo>
+
+ <section>
+ <title>Introduction</title>
+
+ <para>POJO Cache is an in-memory, transactional, and replicated POJO (plain old Java object) cache system that
+ allows users to operate on a POJO transparently without active user management of either replication or
+ persistency aspects. This tutorial focuses on the usage of the POJO Cache API.
+ </para>
+ <para>For details of configuration, usage and APIs, please refer to the
+ <ulink url="http://labs.jboss.org/portal/jbosscache/docs/index.html">users manual</ulink>.
+ </para>
+ </section>
+
+ <section>
+ <title>What You Will Learn</title>
+
+ <itemizedlist>
+ <listitem>
+ <para>POJO Cache creation and modification</para>
+ </listitem>
+
+ <listitem>
+ <para>Replication of POJO fields</para>
+ </listitem>
+
+ <listitem>
+ <para>Using Collections in POJO Cache</para>
+ </listitem>
+
+ <listitem>
+ <para>Transactions</para>
+ </listitem>
+
+ </itemizedlist>
+ </section>
+
+ <section>
+ <title>Configuration</title>
+
+ <para>First download the JBoss Cache 2.x distribution from
+ <ulink url="http://labs.jboss.org/portal/jbosscache/download/index.html">the download page</ulink>
+ . You probably want the
+ <literal>jbosscache-pojo-2.X.Y.zip</literal>
+ distribution. Unzip it, and you will get a directory containing the distribution, such as
+ <literal>jbosscache-pojo-2.X.Y</literal>
+ .
+ For the sake of this tutorial, I will refer to this as
+ <literal>POJO Cache</literal>
+ .
+ </para>
+
+ <para>The configuration files are located under the
+ <literal>jbosscache-pojo/etc</literal>
+ directory. You can modify the behavior of the underlying cache through editing the various configuration files.
+ </para>
+
+ <itemizedlist>
+ <listitem>
+ <para>
+ <literal>log4j.xml</literal>
+ . Logging output. You can enable logging, specify log levels or change the name and path to the log file.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ <literal>META-INF/replSync-service.xml</literal>
+ . Cache configuration file used for this tutorial.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ <literal>pojocache-aop.xml</literal>
+ . POJO Cache configuration file that contains, amongst other things, the annotation to use on POJOs so
+ that they're aspectised. For more information, please the POJO Cache
+ <ulink url="http://labs.jboss.org/portal/jbosscache/docs/index.html">users manual</ulink>
+ .
+ </para>
+ </listitem>
+ </itemizedlist>
+ </section>
+
+ <section>
+ <title>Script</title>
+
+ <para>The only script needed for this tutorial is the
+ <literal>jbosscache-pojo/build.xml</literal>
+ ant script.
+ </para>
+ </section>
+
+ <section>
+ <title>Example POJOs</title>
+
+ <para>The example POJO classes used for POJO Cache demo are:
+ <literal>org.jboss.cache.pojo.test.Person</literal>
+ and
+ <literal>org.jboss.cache.pojo.test.Address</literal>
+ . They are located
+ under
+ <literal>tests/functional</literal>
+ directory.The demo will demonstrate that once a POJO has been attached to the cache, plain get/set POJO methods
+ will be intercepted by the cache.
+ </para>
+
+ <para>Here is the snippet of the class definition for
+ <literal>Person</literal>
+ and
+ <literal>Address</literal>
+ with the
+ <literal>Replicable</literal>
+ annotation.
+ </para>
+
+ <programlisting role="JAVA"><![CDATA[
+(a)org.jboss.cache.pojo.annotation.Replicable
+public class Person
+{
+ ...
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name=name;
+ }
+
+ // ...
+
+ public List<String> getLanguages()
+ {
+ return languages;
+ }
+
+ public void setLanguages(List<String> languages)
+ {
+ this.languages = languages;
+ }
+
+ // ...
+
+ public Address getAddress()
+ {
+ return address;
+ }
+
+ public void setAddress(Address address)
+ {
+ this.address = address;
+ }
+
+ // ...
+}
+ ]]></programlisting>
+
+ <programlisting role="JAVA"><![CDATA[
+(a)org.jboss.cache.pojo.annotation.Replicable
+public class Address
+{
+ // ...
+ public String getStreet()
+ {
+ return street;
+ }
+ public void setStreet(String street)
+ {
+ this.street=street;
+ }
+ // ...
+}
+ ]]></programlisting>
+ </section>
+
+ <section>
+ <title>Running The Demo GUI</title>
+
+ <para>
+ The demo is run by calling the ant script (via the driver) with the
+ <literal>run.demo</literal>
+ target. E.g.,
+ </para>
+
+ <para>
+ <literal>ant run.demo</literal>
+ </para>
+ <para>
+ This will cause a GUI window to appear, giving you a tree view of the cache in the top pane and a BeanShell
+ view of the JVM in the lower pane.
+ </para>
+ <para>
+ The BeanShell view is preset with the following variables:
+ <itemizedlist>
+ <listitem>
+ <literal>cache</literal>
+ - a reference to the POJO Cache interface, used by the GUI instance.
+ </listitem>
+ <listitem>
+ <literal>transactionManager</literal>
+ - a reference to the registered transaction manager.
+ </listitem>
+ </itemizedlist>
+ The references made available to the BeanShell window point to the same cache instance used by the tree view in
+ the GUI above.
+ </para>
+
+ <para>
+ To run the demo as a replicated demo, it is useful to start another command line window and run the ant script
+ again as you did above. Now you will have two cache instances running in two separate GUIs, replicating state
+ to each other.
+ </para>
+
+ </section>
+
+ <section>
+ <title>Tutorials</title>
+ It is recommended that you shut down and restart the demo GUI for each of the following tutorials, to ensure
+ clean caches every time. To inspect POJO attribute changes via GUI, please refer to the POJO Cache
+ <ulink
+ url="http://labs.jboss.org/portal/jbosscache/docs/index.html">user manual
+ </ulink>
+ to understand how the POJOs are mapped internally in the cache.
+
+ <section>
+ <title>POJO Cache API, POJO manipulation, and Replication</title>
+ <para>
+ For this tutorial, start two instance of the demo GUI. In this tutorial, we will:
+
+ <itemizedlist>
+ <listitem>Attach POJOs to the cache and see them being replicated.</listitem>
+ <listitem>After attaching, manipulate the POJOs and see the individual changes replicated.</listitem>
+ <listitem>Retrieve POJOs from the cache, manipulate them and see the changes replicated.</listitem>
+ <listitem>Create POJOs that share a common POJO and the consequences of changes to this.</listitem>
+ <listitem>Detach POJOs from the cache.</listitem>
+ <listitem>After detaching, manipulates the POJOs and see how the values in the cache are unchanged.</listitem>
+ </itemizedlist>
+
+ </para>
+
+ <orderedlist>
+ <listitem>In the 1st GUI instance, create a POJO, i.e. a Person with an Address:
+ <programlisting role="JAVA"><![CDATA[
+ joe = new Person();
+ joe.setName("Joe Black");
+ joe.setAge(31);
+
+ addr = new Address();
+ addr.setCity("Sunnyvale");
+ addr.setStreet("123 Albert Ave");
+ addr.setZip(94086);
+
+ joe.setAddress(addr);
+ ]]></programlisting>
+ </listitem>
+
+ <listitem>Attach the POJO to the cache:
+ <programlisting role="JAVA"><![CDATA[
+ cache.attach("pojo/joe", joe);
+ ]]></programlisting>
+ </listitem>
+
+ <listitem>Change attributes of the POJO and see the individual changes being propagated to the 2nd
+ cache GUI:
+ <programlisting role="JAVA"><![CDATA[
+ joe.setAge(41);
+ ]]></programlisting>
+ </listitem>
+
+ <listitem>In the 2nd GUI instance, get a reference to the Person in the cache and create a second Person
+ with the existing Person's Address:
+ <programlisting role="JAVA"><![CDATA[
+ joe = cache.find("pojo/joe");
+
+ mary = new Person();
+ mary.setName("Mary White");
+ mary.setAge(30);
+
+ mary.setAddress(joe.getAddress());
+ ]]></programlisting>
+ </listitem>
+
+ <listitem>Attach the new POJO to the cache:
+ <programlisting role="JAVA"><![CDATA[
+ cache.attach("pojo/mary", mary);
+ ]]></programlisting>
+ </listitem>
+
+ <listitem>Now, change either Person's Address and see how the change applies to both POJOs and has been
+ propagated to the other cache, visible in the 1st GUI instance:
+ <programlisting role="JAVA"><![CDATA[
+ mary.getAddress().setZip(95000);
+ ]]></programlisting>
+ </listitem>
+
+
+ <listitem>Still in the 2nd GUI instance, detach the POJOs from the cache and see how the POJOs are no longer
+ visible:
+ <programlisting role="JAVA"><![CDATA[
+ cache.detach("pojo/joe");
+ cache.detach("pojo/mary");
+ ]]></programlisting>
+ </listitem>
+
+ <listitem>Finally, in any of GUI instances, change some attributes of the POJO and see these changes have
+ no effect in the cache:
+ <programlisting role="JAVA"><![CDATA[
+ joe.setName("Joe White");
+ ]]></programlisting>
+ </listitem>
+
+ </orderedlist>
+
+ </section>
+
+ <section>
+ <title>Collections</title>
+ <para>
+ For this tutorial, start two instances of the demo GUI. In this tutorial, we will:
+
+ <itemizedlist>
+ <listitem>Attach a POJO to the cache and see it being replicated.</listitem>
+ <listitem>Set a Collection attribute in this POJO</listitem>
+ <listitem>Manipulate this Collection attribute and see the changes visible in the GUI and being replicated</listitem>
+ <listitem>Detach a POJO from the cache.</listitem>
+ </itemizedlist>
+
+ </para>
+
+ <orderedlist>
+ <listitem>In the 1st GUI instance, create a POJO with a Collection attribute:
+ <programlisting role="JAVA"><![CDATA[
+ joe = new Person();
+ joe.setName("Joe Black");
+
+ lang = new ArrayList();
+ lang.add("Spanish");
+
+ joe.setLanguages(lang);
+ ]]></programlisting>
+ </listitem>
+
+ <listitem>Attach the POJO to the cache:
+ <programlisting role="JAVA"><![CDATA[
+ cache.attach("pojo/joe", joe);
+ ]]></programlisting>
+ </listitem>
+
+ <listitem>Get a proxy reference to the Collection and add a new element to it:
+ <programlisting role="JAVA"><![CDATA[
+ proxyLang = joe.getLanguages();
+ proxyLang.add("English");
+ ]]></programlisting>
+ </listitem>
+
+ <listitem>Detach the pojo from the cache:
+ <programlisting role="JAVA"><![CDATA[
+ cache.detach("pojo/joe");
+ ]]></programlisting>
+ </listitem>
+
+ <listitem>Use the proxy reference to the Collection to add another element and see how this does not get
+ added to the cache:
+ <programlisting role="JAVA"><![CDATA[
+ proxyLang.add("French");
+ ]]></programlisting>
+ </listitem>
+
+ </orderedlist>
+ </section>
+ </section>
+
+ <section>
+ <title>Transactions</title>
+ <para>
+ For this tutorial, start two instances instance of the demo GUI. Repeat the exercises in the previous
+ tutorial, only starting transactions before attaching/detaching nodes or modiying the POJOs. This will depict
+ how replication only occurs on transaction boundaries. Try rolling back a few transactions as well, to see how
+ nothing gets replicated in these cases.
+ </para>
+ </section>
+
+</article>
Deleted: pojo/tags/2.2.1.GA/src/main/docbook/userguide/en/master.xml
===================================================================
--- pojo/branches/2.2/src/main/docbook/userguide/en/master.xml 2008-10-21 22:39:19 UTC (rev 6997)
+++ pojo/tags/2.2.1.GA/src/main/docbook/userguide/en/master.xml 2008-10-28 23:30:07 UTC (rev 7024)
@@ -1,102 +0,0 @@
-<?xml version='1.0' encoding="iso-8859-1"?>
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3CR3//EN"
- "../../../../docbook-support/support/docbook-dtd/docbookx.dtd"
- [
- <!ENTITY term SYSTEM "modules/term.xml">
- <!ENTITY intro SYSTEM "modules/introduction.xml">
- <!ENTITY arch SYSTEM "modules/architecture.xml">
- <!ENTITY api SYSTEM "modules/api.xml">
- <!ENTITY config SYSTEM "modules/configuration.xml">
- <!ENTITY instrumentation SYSTEM "modules/instrumentation.xml">
- <!ENTITY example SYSTEM "modules/example.xml">
- <!ENTITY trouble SYSTEM "modules/troubleshooting.xml">
- <!ENTITY appendix SYSTEM "modules/appendix.xml">
- ]>
-
-<book lang="en">
-
- <bookinfo>
- <title>POJO Cache</title>
- <subtitle>User Documentation</subtitle>
- <releaseinfo>Release 2.2.0.GA</releaseinfo>
- <pubdate>October 2008</pubdate>
-
- <author>
- <firstname>Ben</firstname>
- <surname>Wang</surname>
- <email>ben.wang(a)jboss.com</email>
- </author>
- <author>
- <firstname>Jason</firstname>
- <surname>Greene</surname>
- <email>jason.greene(a)jboss.com</email>
- </author>
- </bookinfo>
-
- <toc/>
-
- <preface id="preface" revision="1">
- <title>Preface</title>
-
- <para>
- POJO Cache is an in-memory, transactional, and clustered cache system that
- allows users to operate on a POJO (Plain Old Java Object) transparently and without
- active user management of either replication or persistence aspects.
-
- JBoss Cache, which includes POJO Cache, is a 100% Java based library that can be
- run either as a standalone program or inside an application server.
- </para>
-
- <para>
- This document is meant to be a user and reference guide to explain the architecture, api, configuration, and
- examples for POJO Cache. We assume the readers are familiar with both JGroups and the core JBoss Cache usages.
- </para>
-
- <para>
- If you have questions, use the user
- <ulink url="http://www.jboss.com/index.html?module=bb&op=viewforum&f=157">forum</ulink>
- linked on the JBoss Cache website. We also
- provide tracking links for tracking bug reports and feature requests on
- <ulink url="http://jira.jboss.com">JBoss Jira web site</ulink>
- . If you
- are interested in the development of POJO Cache, post a message on the forum. If
- you are interested in translating this documentation into your language, contact us
- on the developer mailing list.
- </para>
-
- <para>
- JBoss Cache is an open source product, using the business and OEM-friendly OSI-approved LGPL license.
- Commercial development support, production support and training for JBoss Cache is available through
- <ulink url="http://www.jboss.com">JBoss, a division of Red Hat Inc.</ulink>
- </para>
-
- <para>
- In some of the example listings, what is meant to be displayed on one line does not fit
- inside the available page width. These lines have been broken up. A '\' at the end of a
- line means that a break has been introduced to fit in the page, with the following lines
- indented. So:
- </para>
- <programlisting>
- Let's pretend to have an extremely \
- long line that \
- does not fit
- This one is short
- </programlisting>
- <para>Is really:</para>
- <programlisting>
- Let's pretend to have an extremely long line that does not fit
- This one is short
- </programlisting>
- </preface>
-
-
- &term;
- &intro;
- &arch;
- &api;
- &config;
- &instrumentation;
- &trouble;
- &appendix;
-</book>
-
Copied: pojo/tags/2.2.1.GA/src/main/docbook/userguide/en/master.xml (from rev 6999, pojo/branches/2.2/src/main/docbook/userguide/en/master.xml)
===================================================================
--- pojo/tags/2.2.1.GA/src/main/docbook/userguide/en/master.xml (rev 0)
+++ pojo/tags/2.2.1.GA/src/main/docbook/userguide/en/master.xml 2008-10-28 23:30:07 UTC (rev 7024)
@@ -0,0 +1,102 @@
+<?xml version='1.0' encoding="iso-8859-1"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3CR3//EN"
+ "../../../../docbook-support/support/docbook-dtd/docbookx.dtd"
+ [
+ <!ENTITY term SYSTEM "modules/term.xml">
+ <!ENTITY intro SYSTEM "modules/introduction.xml">
+ <!ENTITY arch SYSTEM "modules/architecture.xml">
+ <!ENTITY api SYSTEM "modules/api.xml">
+ <!ENTITY config SYSTEM "modules/configuration.xml">
+ <!ENTITY instrumentation SYSTEM "modules/instrumentation.xml">
+ <!ENTITY example SYSTEM "modules/example.xml">
+ <!ENTITY trouble SYSTEM "modules/troubleshooting.xml">
+ <!ENTITY appendix SYSTEM "modules/appendix.xml">
+ ]>
+
+<book lang="en">
+
+ <bookinfo>
+ <title>POJO Cache</title>
+ <subtitle>User Documentation</subtitle>
+ <releaseinfo>Release 2.2.1.GA</releaseinfo>
+ <pubdate>October 2008</pubdate>
+
+ <author>
+ <firstname>Ben</firstname>
+ <surname>Wang</surname>
+ <email>ben.wang(a)jboss.com</email>
+ </author>
+ <author>
+ <firstname>Jason</firstname>
+ <surname>Greene</surname>
+ <email>jason.greene(a)jboss.com</email>
+ </author>
+ </bookinfo>
+
+ <toc/>
+
+ <preface id="preface" revision="1">
+ <title>Preface</title>
+
+ <para>
+ POJO Cache is an in-memory, transactional, and clustered cache system that
+ allows users to operate on a POJO (Plain Old Java Object) transparently and without
+ active user management of either replication or persistence aspects.
+
+ JBoss Cache, which includes POJO Cache, is a 100% Java based library that can be
+ run either as a standalone program or inside an application server.
+ </para>
+
+ <para>
+ This document is meant to be a user and reference guide to explain the architecture, api, configuration, and
+ examples for POJO Cache. We assume the readers are familiar with both JGroups and the core JBoss Cache usages.
+ </para>
+
+ <para>
+ If you have questions, use the user
+ <ulink url="http://www.jboss.com/index.html?module=bb&op=viewforum&f=157">forum</ulink>
+ linked on the JBoss Cache website. We also
+ provide tracking links for tracking bug reports and feature requests on
+ <ulink url="http://jira.jboss.com">JBoss Jira web site</ulink>
+ . If you
+ are interested in the development of POJO Cache, post a message on the forum. If
+ you are interested in translating this documentation into your language, contact us
+ on the developer mailing list.
+ </para>
+
+ <para>
+ JBoss Cache is an open source product, using the business and OEM-friendly OSI-approved LGPL license.
+ Commercial development support, production support and training for JBoss Cache is available through
+ <ulink url="http://www.jboss.com">JBoss, a division of Red Hat Inc.</ulink>
+ </para>
+
+ <para>
+ In some of the example listings, what is meant to be displayed on one line does not fit
+ inside the available page width. These lines have been broken up. A '\' at the end of a
+ line means that a break has been introduced to fit in the page, with the following lines
+ indented. So:
+ </para>
+ <programlisting>
+ Let's pretend to have an extremely \
+ long line that \
+ does not fit
+ This one is short
+ </programlisting>
+ <para>Is really:</para>
+ <programlisting>
+ Let's pretend to have an extremely long line that does not fit
+ This one is short
+ </programlisting>
+ </preface>
+
+
+ &term;
+ &intro;
+ &arch;
+ &api;
+ &config;
+ &instrumentation;
+ &trouble;
+ &appendix;
+</book>
+
Deleted: pojo/tags/2.2.1.GA/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java
===================================================================
--- pojo/branches/2.2/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java 2008-10-21 22:39:19 UTC (rev 6997)
+++ pojo/tags/2.2.1.GA/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java 2008-10-28 23:30:07 UTC (rev 7024)
@@ -1,168 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.cache.pojo;
-
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.buddyreplication.NextMemberBuddyLocatorConfig;
-import org.jboss.cache.config.BuddyReplicationConfig;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.pojo.test.Person;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- * A BuddyReplicatedTest.
- *
- * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
- * @version $Revision$
- */
-@Test(groups = {"functional"})
-public class BuddyReplicationTest
-{
- Log log = LogFactory.getLog(ReplicatedTest.class);
- PojoCache cache, cache1;
-
- @BeforeMethod(alwaysRun = true)
- protected void setUp() throws Exception
- {
- log.info("setUp() ....");
- boolean toStart = false;
- Configuration cfg1 = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
- addBuddyReplication(cfg1);
- cache = PojoCacheFactory.createCache(cfg1, toStart);
- cache.start();
- Configuration cfg2 = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
- addBuddyReplication(cfg2);
- cache1 = PojoCacheFactory.createCache(cfg2, toStart);
- cache1.start();
-
- // Enable gravitation
- cache.getThreadContext().setGravitationEnabled(true);
- cache1.getThreadContext().setGravitationEnabled(true);
- }
-
- @AfterMethod(alwaysRun = true)
- protected void tearDown() throws Exception
- {
- cache.stop();
- cache1.stop();
- }
-
- private void addBuddyReplication(Configuration cfg)
- {
- BuddyReplicationConfig brc = new BuddyReplicationConfig();
- brc.setAutoDataGravitation(false);
- brc.setBuddyPoolName("test");
- brc.setEnabled(true);
- NextMemberBuddyLocatorConfig blc = new NextMemberBuddyLocatorConfig();
- brc.setBuddyLocatorConfig(blc);
-
- cfg.setBuddyReplicationConfig(brc);
- }
-
- private Person createPerson(String id, String name, int age)
- {
- Person p = new Person();
- p.setName(name);
- p.setAge(age);
- cache.attach(id, p);
- return p;
- }
-
- private Person getReplicatedPerson(String id) throws PojoCacheException
- {
- Person repl = (Person) cache1.find(id);
- assertNotNull("Person found at " + id, repl);
- return repl;
- }
-
- public void testSimple() throws Exception
- {
- log.info("testSimple() ....");
- Person ben = createPerson("/person/test1", "Ben Wang", 40);
- assertEquals("Ben Wang", ben.getName());
- Person repl = getReplicatedPerson("/person/test1");
- assertEquals("Ben Wang", repl.getName());
- cache.detach("/person/test1");
- }
-
-
- public void testDynamicRefSwapping() throws Exception
- {
- Person person = createPerson("/person/test3", "Joe", 32);
- try
- {
- person.setAge(30);
- List<String> med = person.getMedication();
- assertNull("Medication should be null ", med);
- person.setAge(61);
- med = person.getMedication();
- assertEquals("Medication ", (Object) "Lipitor", (Object) med.get(0));
- assertEquals("Medication on cache1 ", "Lipitor",
- person.getMedication().get(0));
-
- person.setAge(71);
- assertEquals("Medication ", "Vioxx", med.get(1));
- Person repl = getReplicatedPerson("/person/test3");
- assertEquals("Medication on cache1 ", "Vioxx",
- repl.getMedication().get(1));
- cache.detach("/person/test3");
-
- } catch (Exception e)
- {
- // should be thrown
- }
- }
-
- public void testTransient() throws Exception
- {
- log.info("testTransient() ....");
- Person ben = createPerson("/person/test1", "Ben Wang", 40);
- ben.setCurrentStatus("Idle");
- assertEquals("Cache 1 ", "Idle", ben.getCurrentStatus());
- Person repl = getReplicatedPerson("/person/test1");
- assertEquals("Cache 2 ", "Active",
- repl.getCurrentStatus());
- cache.detach("/person/test1");
- }
-
- public void testModification() throws Exception
- {
- Person ben = createPerson("/person/test2", "Ben Wang", 40);
- ben.setName("Harald Gliebe");
- assertEquals(ben.getName(), "Harald Gliebe");
- Person repl = getReplicatedPerson("/person/test2");
- assertEquals("Harald Gliebe", repl.getName());
- cache.detach("/person/test2");
- }
-}
Copied: pojo/tags/2.2.1.GA/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java (from rev 6999, pojo/branches/2.2/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java)
===================================================================
--- pojo/tags/2.2.1.GA/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java (rev 0)
+++ pojo/tags/2.2.1.GA/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java 2008-10-28 23:30:07 UTC (rev 7024)
@@ -0,0 +1,169 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cache.pojo;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertNull;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.buddyreplication.NextMemberBuddyLocatorConfig;
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.pojo.test.Person;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * A BuddyReplicatedTest.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision$
+ */
+@Test(groups = {"functional"})
+public class BuddyReplicationTest
+{
+ Log log = LogFactory.getLog(ReplicatedTest.class);
+ PojoCache cache, cache1;
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ log.info("setUp() ....");
+ boolean toStart = false;
+ Configuration cfg1 = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
+ addBuddyReplication(cfg1);
+ cache = PojoCacheFactory.createCache(cfg1, toStart);
+ cache.start();
+ Configuration cfg2 = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
+ addBuddyReplication(cfg2);
+ cache1 = PojoCacheFactory.createCache(cfg2, toStart);
+ cache1.start();
+
+ // Enable gravitation
+ cache.getThreadContext().setGravitationEnabled(true);
+ cache1.getThreadContext().setGravitationEnabled(true);
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown() throws Exception
+ {
+ cache.stop();
+ cache1.stop();
+ }
+
+ private void addBuddyReplication(Configuration cfg)
+ {
+ BuddyReplicationConfig brc = new BuddyReplicationConfig();
+ brc.setAutoDataGravitation(false);
+ brc.setBuddyPoolName("test");
+ brc.setEnabled(true);
+ NextMemberBuddyLocatorConfig blc = new NextMemberBuddyLocatorConfig();
+ brc.setBuddyLocatorConfig(blc);
+
+ cfg.setBuddyReplicationConfig(brc);
+ cfg.setSyncCommitPhase(true);
+ }
+
+ private Person createPerson(String id, String name, int age)
+ {
+ Person p = new Person();
+ p.setName(name);
+ p.setAge(age);
+ cache.attach(id, p);
+ return p;
+ }
+
+ private Person getReplicatedPerson(String id) throws PojoCacheException
+ {
+ Person repl = (Person) cache1.find(id);
+ assertNotNull("Person found at " + id, repl);
+ return repl;
+ }
+
+ public void testSimple() throws Exception
+ {
+ log.info("testSimple() ....");
+ Person ben = createPerson("/person/test1", "Ben Wang", 40);
+ assertEquals("Ben Wang", ben.getName());
+ Person repl = getReplicatedPerson("/person/test1");
+ assertEquals("Ben Wang", repl.getName());
+ cache.detach("/person/test1");
+ }
+
+
+ public void testDynamicRefSwapping() throws Exception
+ {
+ Person person = createPerson("/person/test3", "Joe", 32);
+ try
+ {
+ person.setAge(30);
+ List<String> med = person.getMedication();
+ assertNull("Medication should be null ", med);
+ person.setAge(61);
+ med = person.getMedication();
+ assertEquals("Medication ", (Object) "Lipitor", (Object) med.get(0));
+ assertEquals("Medication on cache1 ", "Lipitor",
+ person.getMedication().get(0));
+
+ person.setAge(71);
+ assertEquals("Medication ", "Vioxx", med.get(1));
+ Person repl = getReplicatedPerson("/person/test3");
+ assertEquals("Medication on cache1 ", "Vioxx",
+ repl.getMedication().get(1));
+ cache.detach("/person/test3");
+
+ } catch (Exception e)
+ {
+ // should be thrown
+ }
+ }
+
+ public void testTransient() throws Exception
+ {
+ log.info("testTransient() ....");
+ Person ben = createPerson("/person/test1", "Ben Wang", 40);
+ ben.setCurrentStatus("Idle");
+ assertEquals("Cache 1 ", "Idle", ben.getCurrentStatus());
+ Person repl = getReplicatedPerson("/person/test1");
+ assertEquals("Cache 2 ", "Active",
+ repl.getCurrentStatus());
+ cache.detach("/person/test1");
+ }
+
+ public void testModification() throws Exception
+ {
+ Person ben = createPerson("/person/test2", "Ben Wang", 40);
+ ben.setName("Harald Gliebe");
+ assertEquals(ben.getName(), "Harald Gliebe");
+ Person repl = getReplicatedPerson("/person/test2");
+ assertEquals("Harald Gliebe", repl.getName());
+ cache.detach("/person/test2");
+ }
+}
16 years, 2 months