JBoss Cache SVN: r7156 - enterprise-docs/trunk/Cache_Tutorial/en-US.
by jbosscache-commits@lists.jboss.org
Author: irooskov(a)redhat.com
Date: 2008-11-17 20:10:44 -0500 (Mon, 17 Nov 2008)
New Revision: 7156
Added:
enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP04.ent
enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP04.xml
Removed:
enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP03.ent
enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP03.xml
Modified:
enterprise-docs/trunk/Cache_Tutorial/en-US/Book_Info.xml
Log:
updated for 4.3.4
Modified: enterprise-docs/trunk/Cache_Tutorial/en-US/Book_Info.xml
===================================================================
--- enterprise-docs/trunk/Cache_Tutorial/en-US/Book_Info.xml 2008-11-18 01:09:42 UTC (rev 7155)
+++ enterprise-docs/trunk/Cache_Tutorial/en-US/Book_Info.xml 2008-11-18 01:10:44 UTC (rev 7156)
@@ -2,8 +2,8 @@
<!DOCTYPE bookinfo PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
<bookinfo id="JBoss_Cache">
- <title>JBoss Cache Tutorial CP03</title>
- <subtitle>for Use with JBoss Enterprise Application Platform 4.3 Cumulative Patch 3</subtitle>
+ <title>JBoss Cache Tutorial CP04</title>
+ <subtitle>for Use with JBoss Enterprise Application Platform 4.3 Cumulative Patch 4</subtitle>
<edition>2.0</edition>
<pubsnumber>1</pubsnumber>
<productname>JBoss Enterprise Application Platform</productname>
Deleted: enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP03.ent
===================================================================
--- enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP03.ent 2008-11-18 01:09:42 UTC (rev 7155)
+++ enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP03.ent 2008-11-18 01:10:44 UTC (rev 7156)
@@ -1,3 +0,0 @@
-<!ENTITY HOLDER "Red Hat, Inc">
-<!ENTITY YEAR "2008">
-<!ENTITY VERSION "">
Deleted: enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP03.xml
===================================================================
--- enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP03.xml 2008-11-18 01:09:42 UTC (rev 7155)
+++ enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP03.xml 2008-11-18 01:10:44 UTC (rev 7156)
@@ -1,503 +0,0 @@
-<?xml version='1.0'?>
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
-
-<book id="JBossCache_Tutorial">
- <title>JBossCache Tutorial</title>
- <xi:include href="Book_Info.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <chapter id="JBossCache_Tutorial-Introduction">
- <title>Introduction</title>
- <para>
- JBossCache is an in-memory replicated (synchronous or asynchronous), transactional, and fine-grained cache. It consists of two subsystems: TreeCache (plain cache) and PojoCache (object-oriented POJO cache). In this tutorial, we will demonstrate the usage of both cache features. For details of the usage and APIs, please refer to the user manuals for <ulink url="http://labs.jboss.org/portal/jbosscache/docs/index.html">TreeCache</ulink> and <ulink url="http://labs.jboss.org/portal/jbosscache/docs/index.html">PojoCache</ulink>.
- </para>
- <section id="Introduction-Scope">
- <title>Scope</title>
- <itemizedlist>
- <listitem>
- <para>
- Cache creation and modification
- </para>
- </listitem>
- <listitem>
- <para>
- Replication
- </para>
- </listitem>
- <listitem>
- <para>
- PojoCache
- </para>
- </listitem>
- <listitem>
- <para>
- Transaction
- </para>
- </listitem>
- </itemizedlist>
- </section>
-
- </chapter>
- <chapter id="JBossCache_Tutorial-Configuration">
- <title>Configuration</title>
- <para>
- First download the standalone TreeCache code from <ulink url="http://labs.jboss.org/portal/jbosscache/download/index.html">here</ulink>. Unzip it, and you will get a root directory (jboss-cache in our example).
- </para>
- <para>
- The configuration files are located under the etc directory. You can modify the behavior of TreeCache through editing the various configuration files.
- </para>
- <itemizedlist>
- <listitem>
- <para>
- <literal>log4j.xml</literal>. Logging output. You can turn on logging level or change log file directory (default is <literal>/tmp/jbosscache.log</literal>).
- </para>
- </listitem>
- <listitem>
- <para>
- <literal>replSync-service.xml</literal>. Tree cache configuration file (file name is not fixed. You specify the file to be read in <literal>PropertyConfigurator</literal>). The settings are for a replicated, synchronous, and transactional cache. The default DummyTransactionManager is used with a transaction isolation level of REPEATABLE_READ. For details of the configuration parameters, please refer to the <ulink url="http://www.jboss.org/products/jbosscache/docs">Treecache</ulink>. Note that this file is used in the BSH ( <ulink url="http://www.beanshell.org/">BeanShell</ulink>, a lightweight Java compatible scripting language) script to configure the cache.
- </para>
- </listitem>
- <listitem>
- <para>
- <literal>jboss-aop.xml</literal>. AOP pointcut and advice definition for the example POJO classes, Person and Address, respectively. For details of how to put your own class under AOP, please refer to the <ulink url="http://www.jboss.org/products/jbosscache/docs">PojoCache</ulink>. This file is read in when the process is started.
- </para>
- </listitem>
- </itemizedlist>
- </chapter>
- <chapter id="JBossCache_Tutorial-Script">
- <title>Script</title>
- <para>
- The script files that are needed (located under install directory) in this tutorial are:
- </para>
- <itemizedlist>
- <listitem>
- <para>
- <literal>build.sh</literal> (or <literal>build.bat</literal> for DOS/Windows). Simple build script that wraps around ant. Users can simply type <literal>sh build.sh</literal> for help. Note from now on, we will only refer to the Unix version with the understanding that there is a corresponding DOS counterpart. The same goes for runDemoShell explained next.
- </para>
- </listitem>
- <listitem>
- <para>
- <literal>runDemoShell.sh</literal>. Simple run script that wraps around BeanShell. This is used to operate the replicated cache through interactive command line.
- </para>
- </listitem>
- <listitem>
- <para>
- <literal>plain.bsh</literal>. Java code that instantiate and configure the cache. It also creates an example cache entry.
- </para>
- </listitem>
- <listitem>
- <para>
- <literal>aop.bsh</literal>. Java codes that instantiate and configure the aop cache. In addition, it also sets up the example POJO (plain old Java object) classes (e.g., Person and Address).
- </para>
- </listitem>
- <listitem>
- <para>
- <literal>aopWithTx.bsh</literal>. Same with aop.bsh except it also instantiates a transaction context.
- </para>
- </listitem>
- </itemizedlist>
- </chapter>
- <chapter id="JBossCache_Tutorial-Example_POJO">
- <title>Example POJO</title>
- <para>
- The example POJO classes used for PojoCache demo are: <literal>Person</literal> and <literal>Address</literal>. They are located under <literal>tests/org/jboss/cache/aop</literal> directory. <literal>Person</literal> has attributes of <literal>String age, Address addr, List languages </literal> , etc. We will demonstrate that once you put the POJO instance in 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> .
- </para>
-<programlisting>public class Person {
- String name=null;
- int age=0;
- Map hobbies=null;
- Address address=null;
- Set skills;
- List languages;
-
- public String getName() { return name; }
- public void setName(String name) { this.name=name; }
- ...
- }
-
-</programlisting>
-<programlisting>public class Address {
- String street=null;
- String city=null;
- int zip=0;
-
- public String getStreet() { return street; }
- public void setStreet(String street) { this.street=street; }
- ...
- }
-
-</programlisting>
- </chapter>
- <chapter id="JBossCache_Tutorial-Demo">
- <title>Demo</title>
- <para>
- To run the demo, you will need at least two windows: one to peruse the cache contents (plus non-aop operations) and the other to operate the cache directly. Of course, you can also open more than one GUI window to see the cache replication at work to multiple members. You will also need to run the scripts under jboss-cache installation directory after you unzip the release package (jboss-cache-dist.zip). Due to the limitation of the GUI, please note that:
- </para>
- <itemizedlist>
- <listitem>
- <para>
- For each demo example, it'd be best if you re-start the whole setup.
- </para>
- </listitem>
- <listitem>
- <para>
- While you can modify the cache content on the GUI window and it will show up on the BSH cache content (e.g., through <literal>cache.printDetails()</literal> ), this won't work on PojoCache demo. That is, you can only modify the cache content on the BSH window.
- </para>
- </listitem>
- </itemizedlist>
- <para>
- The two demo programs to run are:
- </para>
- <itemizedlist>
- <listitem>
- <para>
- On the first window for the GUI, type <literal>sh build.sh </literal> to see the available commands. To run the GUI, type <literal>sh build.sh run.demo</literal> . It will startup a PojoCache GUI. Later on, you can click on a node to view the the contents. Note that you can also add/modify the node contents for non-AOP cache entries. Since the GUI entry only accepts String for now, operation on aop cache from the GUI will not always work (unless it is a String type).
- </para>
- </listitem>
- <listitem>
- <para>
- On the second window for the interactive Java commands, type sh runShellDemo.sh to fire off the BeanShell interactive command shell (you can use either ^D or ^Z in Windows and Unix to exit afterward). You can then read in the Java code scripts to showcase the cache capabilities (e.g., plain.bsh, aop.bsh, and aopWithTx.bsh). See the following for details.
- </para>
- </listitem>
- </itemizedlist>
- </chapter>
- <chapter id="JBossCache_Tutorial-Plain_cache">
- <title>Plain cache</title>
- <para>
- Once you are in the shell, you can either execute the script to populate the cache, or type it in manually by command line. To run the script, type <literal>sourceRelative("plain.bsh");</literal> under the interactive BSH shell. For this to work, you'll need to have your working directory set to the directory in which plain.bsh resides (otherwise give the full pathname of plain.bsh). Basically, the script will create cache entries that will be replicated onto the GUI. (You may have to type show() into the resulting beanshell window yourself) Here are the snippets for the script:
- </para>
-<programlisting>import org.jboss.cache.*;
- show(); // verbose mode for bean shell
- TreeCache tree = new TreeCache();
- PropertyConfigurator config = new PropertyConfigurator();
- // configure tree cache. Needs to be in the classpath
- config.configure(tree, "META-INF/replSync-service.xml");
- tree.startService();
- // kick start tree cache
- tree.put("/a/b/c", "ben", "me");
- // create a cache entry.
- // Node "/a/b/c" will be created if it does not yet exist.
-
-</programlisting>
- <para>
- You should see in the GUI that a new entry of <literal>/a/b/c</literal> has been created. Click on the node c to see the content. You can modify the contents from the GUI as well. To create another node, for example, you can type in the shell:
- </para>
-<programlisting>tree.put("/a/b/c/d", "JBoss", "Open Source");
- tree.get("/a/b/c/d", "JBoss");
-
-</programlisting>
- </chapter>
- <chapter id="JBossCache_Tutorial-PojoCache">
- <title>PojoCache</title>
- <para>
- Once you are in the shell, type <literal>sourceRelative("aop.bsh");</literal> to execute the shell script. Basically, aop.bsh illustrates the steps to instantiate a cache, configure it, and then create entries under it. Here are the snippets:
- </para>
-<programlisting>import org.jboss.cache.PropertyConfigurator;
- import org.jboss.cache.aop.PojoCache;
- import org.jboss.cache.aop.test.Person;
- import org.jboss.cache.aop.test.Address;
- show(); // verbose mode for bean shell
- PojoCache tree = new PojoCache();
- PropertyConfigurator config = new PropertyConfigurator(); // configure tree cache.
- config.configure(tree, "META-INF/replSync-service.xml");
- Person joe = new Person(); // instantiate a Person object named joe
- joe.setName("Joe Black");
- joe.setAge(31);
- Address addr = new Address(); // instantiate a Address object named addr
- addr.setCity("Sunnyvale");
- addr.setStreet("123 Albert Ave");
- addr.setZip(94086); joe.setAddress(addr); // set the address reference
- tree.startService(); // kick start tree cache
- tree.putObject("/aop/joe", joe);
- // add aop sanctioned object (and sub-objects) into cache.
- // since it is aop-sanctioned, use of plain get/set methods will take care
- // of cache contents automatically.
- joe.setAge(41);
-
-</programlisting>
- <para>
- Note the API needed to put the object (and its dependent ones) into cache is putObject. Once the second window finishes execution, you should see the first GUI window has been populated with entries of /aop/joe/address. Click on each tree node will display different values associated with that node.
- </para>
- <para>
- Next step to see AOP in action, you can do plain get/set methods without ever worrying about put it in the cache. For example, you can do in the shell window joe.setAge(20); and see that GUI gets updated with the age field automatically (if not, click away and back will refresh the GUI content). Also to demonstrate the object graph replication, you can modify Joe's address and see the cache will update it automatically. For example, type addr.setCity("San Jose"); in the interactive shell, you should see in the GUI that the address got modified.
- </para>
- <para>
- Finally, PojoCache also supports get/set with parameter type of Collection classes (i.e., List, Map, and Set). For example, type the following in the shell command line:
- </para>
-<programlisting>ArrayList lang = new ArrayList();
- lang.add("Ensligh");
- lang.add("Mandarin");
- joe.setLanguages(lang);
-
-</programlisting>
- </chapter>
- <chapter id="JBossCache_Tutorial-PojoCache_with_Transaction">
- <title>PojoCache with Transaction</title>
- <para>
- To see TreeCache transaction at work, you start with the same setup with last section except you load the bsh of aopWithTx.bsh instead of aop.bsh. The additional snippets are:
- </para>
-<programlisting>import org.jboss.cache.PropertyConfigurator;
- import org.jboss.cache.aop.PojoCache;
- import org.jboss.cache.aop.test.Person;
- import org.jboss.cache.aop.test.Address;// Tx imports
- import javax.transaction.UserTransaction; import javax.naming.*;
- import org.jboss.cache.transaction.DummyTransactionManager;
- show(); // verbose mode for bean shell
- // Set up transaction manager
- DummyTransactionManager.getInstance();
- Properties prop = new Properties();
- prop.put(Context.INITIAL_CONTEXT_FACTORY,
- "org.jboss.cache.transaction.DummyContextFactory");
- UserTransaction tx = (UserTransaction)new
- InitialContext(prop).lookup("UserTransaction");
- PojoCache tree = new PojoCache();
- PropertyConfigurator config = new PropertyConfigurator();
- // configure tree cache.
- config.configure(tree, "META-INF/replSync-service.xml");
- joe = new Person();
- joe.setName("Joe Black");
- joe.setAge(31);
-
- Address addr = new Address();
- addr.setCity("Sunnyvale");
- addr.setStreet("123 Albert Ave");
- addr.setZip(94086);
- joe.setAddress(addr);
-
- tree.startService(); // kick start tree cache
- tree.putObject("/aop/joe", joe); // add aop sanctioned object
- // since it is aop-sanctioned, use of plain get/set methods will take care
- of cache contents automatically.
- // Also it is transacted
- tx.begin();
- joe.setAge(41);
- joe.getAddress().setZip(95124);
- tx.commit();
-
-</programlisting>
- <para>
- In this example, a default dummy transaction manager is used.
- </para>
-<programlisting>tx.begin();
- addr.setZip(95131);
- tx.rollback();
-
-</programlisting>
- </chapter>
- <chapter id="JBossCache_Tutorial-CacheLoader_examples">
- <title>CacheLoader examples</title>
- <para>
- All the examples below are based on the JBossCache standalone distribution. We assume the ZIP file has been unzipped into a directory <literal>jboss-cache</literal> .
- </para>
- <section id="CacheLoader_examples-Local_cache_with_CacheLoader">
- <title>Local cache with CacheLoader</title>
- <para>
- This demo shows a local PojoCache with a CacheLoader. We will insert a POJO into the cache, and see that the POJO is transparently saved using the CacheLoader.
- </para>
- <para>
- To run this, you have to modify <literal>jboss-cache/output/etc/META-INF/oodb-service.xml</literal> : change <literal>CacheLoaderConfig</literal> to point to a valid directory (create it if it doesn't yet exist):
- </para>
-<programlisting><attribute name="CacheLoaderConfig">
- location=c:\\tmp\\oodb
- </attribute>
-
-</programlisting>
- <para>
- Then start the beanshell and source <literal>oodb.bsh</literal> into it. Note that <literal>oodb.bsh</literal> already contains code to create and retrieve POJO from the cache. So remember to comment them out if you decide to create the Person instance yourself.
- </para>
-<programlisting>bela@laptop /cygdrive/c/jboss-cache
- $ ./runShellDemo.sh
- BeanShell 1.3.0 - by Pat Niemeyer (pat(a)pat.net)
- bsh % sourceRelative("oodb.bsh");
- interceptor chain is:
- class org.jboss.cache.interceptors.CallInterceptor
- class org.jboss.cache.interceptors.CacheLoaderInterceptor
- class org.jboss.cache.interceptors.TransactionInterceptor
- <null>
- bsh %
-
-</programlisting>
- <para>
- Next, create an instance of Person, and set its address and other fields:
- </para>
-<programlisting>bsh % p=new Person();
- <name=null, age=0, hobbies=, address=null, skills=null, languages=null>
- bsh % p.age=3;
- <3>
- bsh % p.name="Michelle";
- <Michelle>
- bsh % addr=new Address();
- <street=null, city=null, zip=0>
- bsh % addr.city="San Jose";
- <San Jose>
- bsh % addr.zip=95124;
- <95124>
- bsh % addr.street="1704 Almond Blossom Lane";
- <1704 Almond Blossom Lane>
- bsh % p.setAddress(addr);
- bsh % tree.putObject("/person/me", p);
- bsh % p;
- <name=Michelle, age=3, hobbies=, address=street=1704 Almond Blossom Lane,
- city=San Jose, zip=95124, skills=null, languages=null>
- bsh %
-
-</programlisting>
- <para>
- The <literal>Person</literal> object with all of its fields and subobjects is now saved. Let's kill beanshell and restart it. At this point, because the instance of <literal>Person</literal> we created was given the name "p", we can retrieve it again:
- </para>
-<programlisting>bela@laptop /cygdrive/c/jboss-cache
- $ ./runShellDemo.sh
- BeanShell 1.3.0 - by Pat Niemeyer (pat(a)pat.net)
- bsh % sourceRelative("oodb.bsh");
- interceptor chain is:
- class org.jboss.cache.interceptors.CallInterceptor
- class org.jboss.cache.interceptors.CacheLoaderInterceptor
- class org.jboss.cache.interceptors.TransactionInterceptor
- <null>
- bsh % tree;
- </>
- bsh % p=tree.getObject("/person/me");
- <name=Michelle, age=3, hobbies=, address=street=1704 Almond Blossom Lane,
- city=San Jose, zip=95124, skills=null, languages=null>
- bsh % tree;
- </p
- /address
- >
- bsh %
-
-</programlisting>
- <para>
- The interesting thing here is that the cache was initially empty ("/"). Only when we loaded "p", did it get populated (lazy loading). You can see that the values of "p" are loaded from the datastore where they were previously saved.
- </para>
- </section>
-
- </chapter>
- <chapter id="JBossCache_Tutorial-Replicated_cache_with_shared_datastore">
- <title>Replicated cache with shared datastore</title>
- <para>
- The scenario that we'll run in this example is described in the documentation for JBossCache. It consists of 2 separate nodes that replicate their contents between each other. In addition, they both point to the <emphasis>same</emphasis> datastore. The configuration is in file <literal>jboss-cache/output/etc/META-INF/replAsyncSharedCacheLoader-service.xml</literal> :
- </para>
-<programlisting><!-- Whether or not to fetch state on joining a cluster -->
- <attribute name="FetchStateOnStartup">false</attribute>
- <attribute name="CacheLoaderClass">org.jboss.cache.loader.FileCacheLoader</attribute>
- <attribute name="CacheLoaderConfig">
- location=c:\\tmp
- </attribute>
- <attribute name="CacheLoaderShared">true</attribute>
- <attribute name="CacheLoaderPreload">/</attribute>
- <attribute name="CacheLoaderFetchTransientState">false</attribute>
- <attribute name="CacheLoaderFetchPersistentState">true</attribute>
-</programlisting>
- <para>
- The <literal>FetchStateOnStartup</literal> attribute set to <literal>false</literal> means that a newly started cache will <emphasis>not</emphasis> attempt to fetch the state (neither transient nor persistent). Therefore, attributes <literal>CacheLoaderFetchTransientState</literal> and <literal>CacheLoaderFetchPersistentState</literal> will be ignored. <literal>CacheLoaderShared</literal> set to <literal>true</literal> means that both nodes will share the same datastore, which resides in <literal>c:\tmp</literal> in the example (this assumes that both nodes have access to the same file system). Please make sure that <literal>c:\tmp</literal> exists, or point the config string to a different existing directory.
- </para>
- <para>
- This configuration would essentially provide for two <literal>cold</literal> nodes, in the sense that all contents of a new cache is in the datastore, and is lazy-loaded via the CacheLoader when accessed. However, this is not true, as <literal>CacheLoaderPreload</literal> points to "/", which is the root of the entire tree. Therefore, all of the contents of the cache are recursively pre-loaded. This is probably a bad configuration when you have a lot of data in the cache, because <emphasis>all</emphasis> of your data will be loaded into the cache.
- </para>
- <para>
- Note that with a shared datastore, the node that makes a modification is the one who writes it to the store using the CacheLoader. This prevents both nodes from writing the same data twice.
- </para>
- <para>
- We can now start 2 instances by opening two shells and executing the following ANT target:
- </para>
-<programlisting>bela@laptop /cygdrive/c/jboss-cache
- $ ./build.sh run.demo.async.shared.cacheloader
- Buildfile: build.xml
-
- init:
-
- compile:
-
- run.demo.async.shared.cacheloader:
- [java] ** node loaded: /a
- [java] ** node loaded: /a/b
- [java] ** node loaded: /a/b/c
- [java] ** node loaded: /uno
- [java] ** node loaded: /uno/due
-
- [java] -------------------------------------------------------
- [java] GMS: address is 192.168.1.184:1357
- [java] -------------------------------------------------------
- [java] interceptor chain is:
- [java] class org.jboss.cache.interceptors.CallInterceptor
- [java] class org.jboss.cache.interceptors.ReplicationInterceptor
- [java] class org.jboss.cache.interceptors.CacheLoaderInterceptor
- [java] class org.jboss.cache.interceptors.TransactionInterceptor
- [java] ** view change: [192.168.1.184:1355|1] [192.168.1.184:1355,
- 192.168.1.184:1357]
- [java] ** node modified: /
-
-</programlisting>
- <para>
- 2 GUI instances will appear, showing the tree structure of the cache graphically. Nodes can be added, modified or removed by right-clicking or using the menu. Any modification is replicated between the two nodes. If both nodes are killed, and subsequently one or both nodes are restarted, the state is the same as before shutdown as it was persisted to the shared store via the CacheLoader.
- </para>
- <para>
- Note that the example above shows the 2 nodes running on the same machine (192.168.1.184) on ports 1355 and 1357.
- </para>
- </chapter>
- <chapter id="JBossCache_Tutorial-Replicated_cache_with_unshared_local_datastore">
- <title>Replicated cache with unshared (local) datastore</title>
- <para>
- In this example, we'll run 2 nodes again, but this time, instead of sharing the same datastore, each node has its own datastore. The configuration is in file <literal>jboss-cache/output/etc/META-INF/node{1,2}.xml</literal> . We'll look at node1.xml:
- </para>
-<programlisting><attribute name="CacheLoaderClass">org.jboss.cache.loader.bdbje.BdbjeCacheLoader</attribute>
- <attribute name="CacheLoaderConfig">
- location=c:\\tmp\\node1
- </attribute>
- <attribute name="CacheLoaderShared">false</attribute>
- <attribute name="CacheLoaderPreload">/</attribute>
- <attribute name="CacheLoaderFetchTransientState">false</attribute>
- <attribute name="CacheLoaderFetchPersistentState">true</attribute>
-
-</programlisting>
- <para>
- Again, we use the Sleepycat CacheLoader implementation in <literal>CacheLoaderClass</literal> . The <literal>CacheLoaderConfig</literal> points to <literal>c:\tmp\node1</literal> . This is the directory in which the Sleepycat DB for node1 will reside. File node2.xml has a configuration that points to <literal>c:\tmp\node2</literal> , so we have 2 different unshared datastores. Note that, of course, we still have the same filesystem in our case, because we run the 2 nodes on the same machine. In practice those two directories would reside on two different machines, and each machine would run one JBossCache process. Note that the 2 directories have to exis
- </para>
- <para>
- To create an unshared datastore, we set the <literal>CacheLoaderShared</literal> attribute to <literal>false</literal> .
- </para>
- <para>
- The example can be run by again opening 2 shells, and running 2 ANT targets (here we show the target for node1):
- </para>
-<programlisting>bela@laptop /cygdrive/c/jboss-cache
- $ ./build.sh run.demo.unshared.node2
- Buildfile: build.xml
-
- init:
-
- compile:
-
- run.demo.unshared.node2:
- [java] ** node loaded: /a
- [java] ** node loaded: /a/a2
- ...
-
-</programlisting>
- <para>
- The <literal>run.demo.unshared.node2</literal> target runs node2, which will have its own store located at <literal>c:\tmp\node2</literal> (shown above). Whenever a change is made on either of the 2 nodes, it is replicated to the other node, and persisted in both local datastores. You can kill and restart a node, or even both nodes, and the data will still be available due to the persistent backend store(s).
- </para>
- </chapter>
- <chapter id="JBossCache_Tutorial-Troubleshooting">
- <title>Troubleshooting</title>
- <para>
- Here are some tips for troubleshooting, if you encounter problems during this demo.
- </para>
- <itemizedlist>
- <listitem>
- <para>
- Most of the time, the problem will come from cache replication layer, i.e., JGroups package. On the output window, you can see the JGroups membership view. See if it is updated when you run the BSH commands. It should show a view with at least two members. For example, on my window, I see
- </para>
-<programlisting>[java] ** view change: [BWANG-HOME:4381|1] [BWANG-HOME:4381, BWANG-HOME:4383]
-
-</programlisting>
- <para>
- with 2 members: 4381 and 4383. On the other hand, if you don't close the previous running cache instance, the membership view will also include the previous existing ones. This can corrupt the states. So you will have to make sure there is no running TreeCache processes before each demo. If you have problem with this, please consult the <ulink url="http://www.jgroups.org/javagroupsnew/docs/index.html">JGroups website </ulink>
- </para>
- </listitem>
- </itemizedlist>
- </chapter>
-<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Revision_History.xml"/>
-
-</book>
-
Added: enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP04.ent
===================================================================
--- enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP04.ent (rev 0)
+++ enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP04.ent 2008-11-18 01:10:44 UTC (rev 7156)
@@ -0,0 +1,3 @@
+<!ENTITY HOLDER "Red Hat, Inc">
+<!ENTITY YEAR "2008">
+<!ENTITY VERSION "">
Added: enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP04.xml
===================================================================
--- enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP04.xml (rev 0)
+++ enterprise-docs/trunk/Cache_Tutorial/en-US/JBoss_Cache_Tutorial_CP04.xml 2008-11-18 01:10:44 UTC (rev 7156)
@@ -0,0 +1,503 @@
+<?xml version='1.0'?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
+
+<book id="JBossCache_Tutorial">
+ <title>JBossCache Tutorial</title>
+ <xi:include href="Book_Info.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <chapter id="JBossCache_Tutorial-Introduction">
+ <title>Introduction</title>
+ <para>
+ JBossCache is an in-memory replicated (synchronous or asynchronous), transactional, and fine-grained cache. It consists of two subsystems: TreeCache (plain cache) and PojoCache (object-oriented POJO cache). In this tutorial, we will demonstrate the usage of both cache features. For details of the usage and APIs, please refer to the user manuals for <ulink url="http://labs.jboss.org/portal/jbosscache/docs/index.html">TreeCache</ulink> and <ulink url="http://labs.jboss.org/portal/jbosscache/docs/index.html">PojoCache</ulink>.
+ </para>
+ <section id="Introduction-Scope">
+ <title>Scope</title>
+ <itemizedlist>
+ <listitem>
+ <para>
+ Cache creation and modification
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Replication
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ PojoCache
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Transaction
+ </para>
+ </listitem>
+ </itemizedlist>
+ </section>
+
+ </chapter>
+ <chapter id="JBossCache_Tutorial-Configuration">
+ <title>Configuration</title>
+ <para>
+ First download the standalone TreeCache code from <ulink url="http://labs.jboss.org/portal/jbosscache/download/index.html">here</ulink>. Unzip it, and you will get a root directory (jboss-cache in our example).
+ </para>
+ <para>
+ The configuration files are located under the etc directory. You can modify the behavior of TreeCache through editing the various configuration files.
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ <literal>log4j.xml</literal>. Logging output. You can turn on logging level or change log file directory (default is <literal>/tmp/jbosscache.log</literal>).
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <literal>replSync-service.xml</literal>. Tree cache configuration file (file name is not fixed. You specify the file to be read in <literal>PropertyConfigurator</literal>). The settings are for a replicated, synchronous, and transactional cache. The default DummyTransactionManager is used with a transaction isolation level of REPEATABLE_READ. For details of the configuration parameters, please refer to the <ulink url="http://www.jboss.org/products/jbosscache/docs">Treecache</ulink>. Note that this file is used in the BSH ( <ulink url="http://www.beanshell.org/">BeanShell</ulink>, a lightweight Java compatible scripting language) script to configure the cache.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <literal>jboss-aop.xml</literal>. AOP pointcut and advice definition for the example POJO classes, Person and Address, respectively. For details of how to put your own class under AOP, please refer to the <ulink url="http://www.jboss.org/products/jbosscache/docs">PojoCache</ulink>. This file is read in when the process is started.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </chapter>
+ <chapter id="JBossCache_Tutorial-Script">
+ <title>Script</title>
+ <para>
+ The script files that are needed (located under install directory) in this tutorial are:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ <literal>build.sh</literal> (or <literal>build.bat</literal> for DOS/Windows). Simple build script that wraps around ant. Users can simply type <literal>sh build.sh</literal> for help. Note from now on, we will only refer to the Unix version with the understanding that there is a corresponding DOS counterpart. The same goes for runDemoShell explained next.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <literal>runDemoShell.sh</literal>. Simple run script that wraps around BeanShell. This is used to operate the replicated cache through interactive command line.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <literal>plain.bsh</literal>. Java code that instantiate and configure the cache. It also creates an example cache entry.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <literal>aop.bsh</literal>. Java codes that instantiate and configure the aop cache. In addition, it also sets up the example POJO (plain old Java object) classes (e.g., Person and Address).
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <literal>aopWithTx.bsh</literal>. Same with aop.bsh except it also instantiates a transaction context.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </chapter>
+ <chapter id="JBossCache_Tutorial-Example_POJO">
+ <title>Example POJO</title>
+ <para>
+ The example POJO classes used for PojoCache demo are: <literal>Person</literal> and <literal>Address</literal>. They are located under <literal>tests/org/jboss/cache/aop</literal> directory. <literal>Person</literal> has attributes of <literal>String age, Address addr, List languages </literal> , etc. We will demonstrate that once you put the POJO instance in 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> .
+ </para>
+<programlisting>public class Person {
+ String name=null;
+ int age=0;
+ Map hobbies=null;
+ Address address=null;
+ Set skills;
+ List languages;
+
+ public String getName() { return name; }
+ public void setName(String name) { this.name=name; }
+ ...
+ }
+
+</programlisting>
+<programlisting>public class Address {
+ String street=null;
+ String city=null;
+ int zip=0;
+
+ public String getStreet() { return street; }
+ public void setStreet(String street) { this.street=street; }
+ ...
+ }
+
+</programlisting>
+ </chapter>
+ <chapter id="JBossCache_Tutorial-Demo">
+ <title>Demo</title>
+ <para>
+ To run the demo, you will need at least two windows: one to peruse the cache contents (plus non-aop operations) and the other to operate the cache directly. Of course, you can also open more than one GUI window to see the cache replication at work to multiple members. You will also need to run the scripts under jboss-cache installation directory after you unzip the release package (jboss-cache-dist.zip). Due to the limitation of the GUI, please note that:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ For each demo example, it'd be best if you re-start the whole setup.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ While you can modify the cache content on the GUI window and it will show up on the BSH cache content (e.g., through <literal>cache.printDetails()</literal> ), this won't work on PojoCache demo. That is, you can only modify the cache content on the BSH window.
+ </para>
+ </listitem>
+ </itemizedlist>
+ <para>
+ The two demo programs to run are:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ On the first window for the GUI, type <literal>sh build.sh </literal> to see the available commands. To run the GUI, type <literal>sh build.sh run.demo</literal> . It will startup a PojoCache GUI. Later on, you can click on a node to view the the contents. Note that you can also add/modify the node contents for non-AOP cache entries. Since the GUI entry only accepts String for now, operation on aop cache from the GUI will not always work (unless it is a String type).
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ On the second window for the interactive Java commands, type sh runShellDemo.sh to fire off the BeanShell interactive command shell (you can use either ^D or ^Z in Windows and Unix to exit afterward). You can then read in the Java code scripts to showcase the cache capabilities (e.g., plain.bsh, aop.bsh, and aopWithTx.bsh). See the following for details.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </chapter>
+ <chapter id="JBossCache_Tutorial-Plain_cache">
+ <title>Plain cache</title>
+ <para>
+ Once you are in the shell, you can either execute the script to populate the cache, or type it in manually by command line. To run the script, type <literal>sourceRelative("plain.bsh");</literal> under the interactive BSH shell. For this to work, you'll need to have your working directory set to the directory in which plain.bsh resides (otherwise give the full pathname of plain.bsh). Basically, the script will create cache entries that will be replicated onto the GUI. (You may have to type show() into the resulting beanshell window yourself) Here are the snippets for the script:
+ </para>
+<programlisting>import org.jboss.cache.*;
+ show(); // verbose mode for bean shell
+ TreeCache tree = new TreeCache();
+ PropertyConfigurator config = new PropertyConfigurator();
+ // configure tree cache. Needs to be in the classpath
+ config.configure(tree, "META-INF/replSync-service.xml");
+ tree.startService();
+ // kick start tree cache
+ tree.put("/a/b/c", "ben", "me");
+ // create a cache entry.
+ // Node "/a/b/c" will be created if it does not yet exist.
+
+</programlisting>
+ <para>
+ You should see in the GUI that a new entry of <literal>/a/b/c</literal> has been created. Click on the node c to see the content. You can modify the contents from the GUI as well. To create another node, for example, you can type in the shell:
+ </para>
+<programlisting>tree.put("/a/b/c/d", "JBoss", "Open Source");
+ tree.get("/a/b/c/d", "JBoss");
+
+</programlisting>
+ </chapter>
+ <chapter id="JBossCache_Tutorial-PojoCache">
+ <title>PojoCache</title>
+ <para>
+ Once you are in the shell, type <literal>sourceRelative("aop.bsh");</literal> to execute the shell script. Basically, aop.bsh illustrates the steps to instantiate a cache, configure it, and then create entries under it. Here are the snippets:
+ </para>
+<programlisting>import org.jboss.cache.PropertyConfigurator;
+ import org.jboss.cache.aop.PojoCache;
+ import org.jboss.cache.aop.test.Person;
+ import org.jboss.cache.aop.test.Address;
+ show(); // verbose mode for bean shell
+ PojoCache tree = new PojoCache();
+ PropertyConfigurator config = new PropertyConfigurator(); // configure tree cache.
+ config.configure(tree, "META-INF/replSync-service.xml");
+ Person joe = new Person(); // instantiate a Person object named joe
+ joe.setName("Joe Black");
+ joe.setAge(31);
+ Address addr = new Address(); // instantiate a Address object named addr
+ addr.setCity("Sunnyvale");
+ addr.setStreet("123 Albert Ave");
+ addr.setZip(94086); joe.setAddress(addr); // set the address reference
+ tree.startService(); // kick start tree cache
+ tree.putObject("/aop/joe", joe);
+ // add aop sanctioned object (and sub-objects) into cache.
+ // since it is aop-sanctioned, use of plain get/set methods will take care
+ // of cache contents automatically.
+ joe.setAge(41);
+
+</programlisting>
+ <para>
+ Note the API needed to put the object (and its dependent ones) into cache is putObject. Once the second window finishes execution, you should see the first GUI window has been populated with entries of /aop/joe/address. Click on each tree node will display different values associated with that node.
+ </para>
+ <para>
+ Next step to see AOP in action, you can do plain get/set methods without ever worrying about put it in the cache. For example, you can do in the shell window joe.setAge(20); and see that GUI gets updated with the age field automatically (if not, click away and back will refresh the GUI content). Also to demonstrate the object graph replication, you can modify Joe's address and see the cache will update it automatically. For example, type addr.setCity("San Jose"); in the interactive shell, you should see in the GUI that the address got modified.
+ </para>
+ <para>
+ Finally, PojoCache also supports get/set with parameter type of Collection classes (i.e., List, Map, and Set). For example, type the following in the shell command line:
+ </para>
+<programlisting>ArrayList lang = new ArrayList();
+ lang.add("Ensligh");
+ lang.add("Mandarin");
+ joe.setLanguages(lang);
+
+</programlisting>
+ </chapter>
+ <chapter id="JBossCache_Tutorial-PojoCache_with_Transaction">
+ <title>PojoCache with Transaction</title>
+ <para>
+ To see TreeCache transaction at work, you start with the same setup with last section except you load the bsh of aopWithTx.bsh instead of aop.bsh. The additional snippets are:
+ </para>
+<programlisting>import org.jboss.cache.PropertyConfigurator;
+ import org.jboss.cache.aop.PojoCache;
+ import org.jboss.cache.aop.test.Person;
+ import org.jboss.cache.aop.test.Address;// Tx imports
+ import javax.transaction.UserTransaction; import javax.naming.*;
+ import org.jboss.cache.transaction.DummyTransactionManager;
+ show(); // verbose mode for bean shell
+ // Set up transaction manager
+ DummyTransactionManager.getInstance();
+ Properties prop = new Properties();
+ prop.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.jboss.cache.transaction.DummyContextFactory");
+ UserTransaction tx = (UserTransaction)new
+ InitialContext(prop).lookup("UserTransaction");
+ PojoCache tree = new PojoCache();
+ PropertyConfigurator config = new PropertyConfigurator();
+ // configure tree cache.
+ config.configure(tree, "META-INF/replSync-service.xml");
+ joe = new Person();
+ joe.setName("Joe Black");
+ joe.setAge(31);
+
+ Address addr = new Address();
+ addr.setCity("Sunnyvale");
+ addr.setStreet("123 Albert Ave");
+ addr.setZip(94086);
+ joe.setAddress(addr);
+
+ tree.startService(); // kick start tree cache
+ tree.putObject("/aop/joe", joe); // add aop sanctioned object
+ // since it is aop-sanctioned, use of plain get/set methods will take care
+ of cache contents automatically.
+ // Also it is transacted
+ tx.begin();
+ joe.setAge(41);
+ joe.getAddress().setZip(95124);
+ tx.commit();
+
+</programlisting>
+ <para>
+ In this example, a default dummy transaction manager is used.
+ </para>
+<programlisting>tx.begin();
+ addr.setZip(95131);
+ tx.rollback();
+
+</programlisting>
+ </chapter>
+ <chapter id="JBossCache_Tutorial-CacheLoader_examples">
+ <title>CacheLoader examples</title>
+ <para>
+ All the examples below are based on the JBossCache standalone distribution. We assume the ZIP file has been unzipped into a directory <literal>jboss-cache</literal> .
+ </para>
+ <section id="CacheLoader_examples-Local_cache_with_CacheLoader">
+ <title>Local cache with CacheLoader</title>
+ <para>
+ This demo shows a local PojoCache with a CacheLoader. We will insert a POJO into the cache, and see that the POJO is transparently saved using the CacheLoader.
+ </para>
+ <para>
+ To run this, you have to modify <literal>jboss-cache/output/etc/META-INF/oodb-service.xml</literal> : change <literal>CacheLoaderConfig</literal> to point to a valid directory (create it if it doesn't yet exist):
+ </para>
+<programlisting><attribute name="CacheLoaderConfig">
+ location=c:\\tmp\\oodb
+ </attribute>
+
+</programlisting>
+ <para>
+ Then start the beanshell and source <literal>oodb.bsh</literal> into it. Note that <literal>oodb.bsh</literal> already contains code to create and retrieve POJO from the cache. So remember to comment them out if you decide to create the Person instance yourself.
+ </para>
+<programlisting>bela@laptop /cygdrive/c/jboss-cache
+ $ ./runShellDemo.sh
+ BeanShell 1.3.0 - by Pat Niemeyer (pat(a)pat.net)
+ bsh % sourceRelative("oodb.bsh");
+ interceptor chain is:
+ class org.jboss.cache.interceptors.CallInterceptor
+ class org.jboss.cache.interceptors.CacheLoaderInterceptor
+ class org.jboss.cache.interceptors.TransactionInterceptor
+ <null>
+ bsh %
+
+</programlisting>
+ <para>
+ Next, create an instance of Person, and set its address and other fields:
+ </para>
+<programlisting>bsh % p=new Person();
+ <name=null, age=0, hobbies=, address=null, skills=null, languages=null>
+ bsh % p.age=3;
+ <3>
+ bsh % p.name="Michelle";
+ <Michelle>
+ bsh % addr=new Address();
+ <street=null, city=null, zip=0>
+ bsh % addr.city="San Jose";
+ <San Jose>
+ bsh % addr.zip=95124;
+ <95124>
+ bsh % addr.street="1704 Almond Blossom Lane";
+ <1704 Almond Blossom Lane>
+ bsh % p.setAddress(addr);
+ bsh % tree.putObject("/person/me", p);
+ bsh % p;
+ <name=Michelle, age=3, hobbies=, address=street=1704 Almond Blossom Lane,
+ city=San Jose, zip=95124, skills=null, languages=null>
+ bsh %
+
+</programlisting>
+ <para>
+ The <literal>Person</literal> object with all of its fields and subobjects is now saved. Let's kill beanshell and restart it. At this point, because the instance of <literal>Person</literal> we created was given the name "p", we can retrieve it again:
+ </para>
+<programlisting>bela@laptop /cygdrive/c/jboss-cache
+ $ ./runShellDemo.sh
+ BeanShell 1.3.0 - by Pat Niemeyer (pat(a)pat.net)
+ bsh % sourceRelative("oodb.bsh");
+ interceptor chain is:
+ class org.jboss.cache.interceptors.CallInterceptor
+ class org.jboss.cache.interceptors.CacheLoaderInterceptor
+ class org.jboss.cache.interceptors.TransactionInterceptor
+ <null>
+ bsh % tree;
+ </>
+ bsh % p=tree.getObject("/person/me");
+ <name=Michelle, age=3, hobbies=, address=street=1704 Almond Blossom Lane,
+ city=San Jose, zip=95124, skills=null, languages=null>
+ bsh % tree;
+ </p
+ /address
+ >
+ bsh %
+
+</programlisting>
+ <para>
+ The interesting thing here is that the cache was initially empty ("/"). Only when we loaded "p", did it get populated (lazy loading). You can see that the values of "p" are loaded from the datastore where they were previously saved.
+ </para>
+ </section>
+
+ </chapter>
+ <chapter id="JBossCache_Tutorial-Replicated_cache_with_shared_datastore">
+ <title>Replicated cache with shared datastore</title>
+ <para>
+ The scenario that we'll run in this example is described in the documentation for JBossCache. It consists of 2 separate nodes that replicate their contents between each other. In addition, they both point to the <emphasis>same</emphasis> datastore. The configuration is in file <literal>jboss-cache/output/etc/META-INF/replAsyncSharedCacheLoader-service.xml</literal> :
+ </para>
+<programlisting><!-- Whether or not to fetch state on joining a cluster -->
+ <attribute name="FetchStateOnStartup">false</attribute>
+ <attribute name="CacheLoaderClass">org.jboss.cache.loader.FileCacheLoader</attribute>
+ <attribute name="CacheLoaderConfig">
+ location=c:\\tmp
+ </attribute>
+ <attribute name="CacheLoaderShared">true</attribute>
+ <attribute name="CacheLoaderPreload">/</attribute>
+ <attribute name="CacheLoaderFetchTransientState">false</attribute>
+ <attribute name="CacheLoaderFetchPersistentState">true</attribute>
+</programlisting>
+ <para>
+ The <literal>FetchStateOnStartup</literal> attribute set to <literal>false</literal> means that a newly started cache will <emphasis>not</emphasis> attempt to fetch the state (neither transient nor persistent). Therefore, attributes <literal>CacheLoaderFetchTransientState</literal> and <literal>CacheLoaderFetchPersistentState</literal> will be ignored. <literal>CacheLoaderShared</literal> set to <literal>true</literal> means that both nodes will share the same datastore, which resides in <literal>c:\tmp</literal> in the example (this assumes that both nodes have access to the same file system). Please make sure that <literal>c:\tmp</literal> exists, or point the config string to a different existing directory.
+ </para>
+ <para>
+ This configuration would essentially provide for two <literal>cold</literal> nodes, in the sense that all contents of a new cache is in the datastore, and is lazy-loaded via the CacheLoader when accessed. However, this is not true, as <literal>CacheLoaderPreload</literal> points to "/", which is the root of the entire tree. Therefore, all of the contents of the cache are recursively pre-loaded. This is probably a bad configuration when you have a lot of data in the cache, because <emphasis>all</emphasis> of your data will be loaded into the cache.
+ </para>
+ <para>
+ Note that with a shared datastore, the node that makes a modification is the one who writes it to the store using the CacheLoader. This prevents both nodes from writing the same data twice.
+ </para>
+ <para>
+ We can now start 2 instances by opening two shells and executing the following ANT target:
+ </para>
+<programlisting>bela@laptop /cygdrive/c/jboss-cache
+ $ ./build.sh run.demo.async.shared.cacheloader
+ Buildfile: build.xml
+
+ init:
+
+ compile:
+
+ run.demo.async.shared.cacheloader:
+ [java] ** node loaded: /a
+ [java] ** node loaded: /a/b
+ [java] ** node loaded: /a/b/c
+ [java] ** node loaded: /uno
+ [java] ** node loaded: /uno/due
+
+ [java] -------------------------------------------------------
+ [java] GMS: address is 192.168.1.184:1357
+ [java] -------------------------------------------------------
+ [java] interceptor chain is:
+ [java] class org.jboss.cache.interceptors.CallInterceptor
+ [java] class org.jboss.cache.interceptors.ReplicationInterceptor
+ [java] class org.jboss.cache.interceptors.CacheLoaderInterceptor
+ [java] class org.jboss.cache.interceptors.TransactionInterceptor
+ [java] ** view change: [192.168.1.184:1355|1] [192.168.1.184:1355,
+ 192.168.1.184:1357]
+ [java] ** node modified: /
+
+</programlisting>
+ <para>
+ 2 GUI instances will appear, showing the tree structure of the cache graphically. Nodes can be added, modified or removed by right-clicking or using the menu. Any modification is replicated between the two nodes. If both nodes are killed, and subsequently one or both nodes are restarted, the state is the same as before shutdown as it was persisted to the shared store via the CacheLoader.
+ </para>
+ <para>
+ Note that the example above shows the 2 nodes running on the same machine (192.168.1.184) on ports 1355 and 1357.
+ </para>
+ </chapter>
+ <chapter id="JBossCache_Tutorial-Replicated_cache_with_unshared_local_datastore">
+ <title>Replicated cache with unshared (local) datastore</title>
+ <para>
+ In this example, we'll run 2 nodes again, but this time, instead of sharing the same datastore, each node has its own datastore. The configuration is in file <literal>jboss-cache/output/etc/META-INF/node{1,2}.xml</literal> . We'll look at node1.xml:
+ </para>
+<programlisting><attribute name="CacheLoaderClass">org.jboss.cache.loader.bdbje.BdbjeCacheLoader</attribute>
+ <attribute name="CacheLoaderConfig">
+ location=c:\\tmp\\node1
+ </attribute>
+ <attribute name="CacheLoaderShared">false</attribute>
+ <attribute name="CacheLoaderPreload">/</attribute>
+ <attribute name="CacheLoaderFetchTransientState">false</attribute>
+ <attribute name="CacheLoaderFetchPersistentState">true</attribute>
+
+</programlisting>
+ <para>
+ Again, we use the Sleepycat CacheLoader implementation in <literal>CacheLoaderClass</literal> . The <literal>CacheLoaderConfig</literal> points to <literal>c:\tmp\node1</literal> . This is the directory in which the Sleepycat DB for node1 will reside. File node2.xml has a configuration that points to <literal>c:\tmp\node2</literal> , so we have 2 different unshared datastores. Note that, of course, we still have the same filesystem in our case, because we run the 2 nodes on the same machine. In practice those two directories would reside on two different machines, and each machine would run one JBossCache process. Note that the 2 directories have to exis
+ </para>
+ <para>
+ To create an unshared datastore, we set the <literal>CacheLoaderShared</literal> attribute to <literal>false</literal> .
+ </para>
+ <para>
+ The example can be run by again opening 2 shells, and running 2 ANT targets (here we show the target for node1):
+ </para>
+<programlisting>bela@laptop /cygdrive/c/jboss-cache
+ $ ./build.sh run.demo.unshared.node2
+ Buildfile: build.xml
+
+ init:
+
+ compile:
+
+ run.demo.unshared.node2:
+ [java] ** node loaded: /a
+ [java] ** node loaded: /a/a2
+ ...
+
+</programlisting>
+ <para>
+ The <literal>run.demo.unshared.node2</literal> target runs node2, which will have its own store located at <literal>c:\tmp\node2</literal> (shown above). Whenever a change is made on either of the 2 nodes, it is replicated to the other node, and persisted in both local datastores. You can kill and restart a node, or even both nodes, and the data will still be available due to the persistent backend store(s).
+ </para>
+ </chapter>
+ <chapter id="JBossCache_Tutorial-Troubleshooting">
+ <title>Troubleshooting</title>
+ <para>
+ Here are some tips for troubleshooting, if you encounter problems during this demo.
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ Most of the time, the problem will come from cache replication layer, i.e., JGroups package. On the output window, you can see the JGroups membership view. See if it is updated when you run the BSH commands. It should show a view with at least two members. For example, on my window, I see
+ </para>
+<programlisting>[java] ** view change: [BWANG-HOME:4381|1] [BWANG-HOME:4381, BWANG-HOME:4383]
+
+</programlisting>
+ <para>
+ with 2 members: 4381 and 4383. On the other hand, if you don't close the previous running cache instance, the membership view will also include the previous existing ones. This can corrupt the states. So you will have to make sure there is no running TreeCache processes before each demo. If you have problem with this, please consult the <ulink url="http://www.jgroups.org/javagroupsnew/docs/index.html">JGroups website </ulink>
+ </para>
+ </listitem>
+ </itemizedlist>
+ </chapter>
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Revision_History.xml"/>
+
+</book>
+
16 years, 1 month
JBoss Cache SVN: r7155 - enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US.
by jbosscache-commits@lists.jboss.org
Author: irooskov(a)redhat.com
Date: 2008-11-17 20:09:42 -0500 (Mon, 17 Nov 2008)
New Revision: 7155
Added:
enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP04.ent
enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP04.xml
Removed:
enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP03.ent
enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP03.xml
Modified:
enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/Book_Info.xml
Log:
updated for 4.3.4
Modified: enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/Book_Info.xml
===================================================================
--- enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/Book_Info.xml 2008-11-18 01:00:04 UTC (rev 7154)
+++ enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/Book_Info.xml 2008-11-18 01:09:42 UTC (rev 7155)
@@ -2,8 +2,8 @@
<!DOCTYPE bookinfo PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
<bookinfo id="JBoss_Cache_Tree_Cache___A_Structured_Replicated_Transactional_Cache">
- <title>JBoss Cache Tree Cache Guide CP03</title>
- <subtitle>for Use with JBoss Enterprise Application Platform 4.3 Cumulative Patch 3</subtitle>
+ <title>JBoss Cache Tree Cache Guide CP04</title>
+ <subtitle>for Use with JBoss Enterprise Application Platform 4.3 Cumulative Patch 4</subtitle>
<edition>2.0</edition>
<pubsnumber>1</pubsnumber>
<productname>JBoss Enterprise Application Platform</productname>
Deleted: enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP03.ent
===================================================================
--- enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP03.ent 2008-11-18 01:00:04 UTC (rev 7154)
+++ enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP03.ent 2008-11-18 01:09:42 UTC (rev 7155)
@@ -1,3 +0,0 @@
-<!ENTITY HOLDER "Red Hat, Inc">
-<!ENTITY YEAR "2008">
-<!ENTITY VERSION "">
Deleted: enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP03.xml
===================================================================
--- enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP03.xml 2008-11-18 01:00:04 UTC (rev 7154)
+++ enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP03.xml 2008-11-18 01:09:42 UTC (rev 7155)
@@ -1,53 +0,0 @@
-<?xml version='1.0'?>
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
-
-<book>
- <xi:include href="Book_Info.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <preface id="Preface" revision="1"><title>Preface</title>
- <para>
- This and its accompanying documents describe JBoss Cache's TreeCache, a tree-structured replicated, transactional cache. JBoss Cache's PojoCache, an "object-oriented" cache that is the AOP-enabled subclass of TreeCache, allowing for Plain Old Java Objects (POJOs) to be inserted and replicated transactionally in a cluster, is described separately in a similar user guide.
- </para>
- <para>
- The TreeCache is fully configurable. Aspects of the system such as replication mechanisms, transaction isolation levels, eviction policies, and transaction managers are all configurable. The TreeCache can be used in a standalone fashion - independent of JBoss Application Server or any other application server. PojoCache on the other hand requires both TreeCache and the JBossAOP standalone subsystem. PojoCache, documented separately, is the first in the market to provide a POJO cache functionality.
- </para>
- <para>
- This document is meant to be a user guide to explain the architecture, api, configuration, and examples for JBoss Cache's TreeCache. Good knowledge of the Java programming language along with a string appreciation and understanding of transactions and concurrent threads is presumed. No prior knowledge of JBoss Application Server is expected or required.
- </para>
- <para>
- If you have questions, use the <ulink url="http://www.jboss.com/index.html?module=bb&op=viewforum&f=157">user forum </ulink> linked on the <ulink url="http://labs.jboss.com/jbosscache">JBoss Cache website</ulink> . We also provide a mechanism for tracking bug reports and feature requests on the <ulink url="http://jira.jboss.com">JBoss JIRA issue tracker </ulink> . If you are interested in the development of JBoss Cache or in translating this documentation into other languages, we'd love to hear from you. Please post a message on the user forum or contact us on the <ulink url="http://lists.jboss.org">developer mailing list </ulink> .
- </para>
- <para>
- JBoss Cache is an open-source product based on LGPL. Commercial development support, production support and training for JBoss Cache is available through <ulink url="http://www.jboss.com">JBoss Inc.</ulink> JBoss Cache is a product in JBoss Professional Open Source <ulink url="http://www.jboss.com/products/index">JEMS</ulink> (JBoss Enterprise Middleware Suite).
- </para>
- </preface>
-
- <xi:include href="Introduction.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-
- <xi:include href="Architecture.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-
- <xi:include href="Basic_api.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-
- <xi:include href="Replication.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-
- <xi:include href="Transactions.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-
- <xi:include href="Eviction_policies.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-
- <xi:include href="Cache_loaders.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-
- <xi:include href="Treecache_marshaller.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-
- <xi:include href="State_transfer.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-
- <xi:include href="Compatibility.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-
- <xi:include href="Configuration.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-
- <xi:include href="Mgmt_information.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-
- <xi:include href="Jboss_integration.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-
-<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Revision_History.xml"/>
-
-</book>
-
Added: enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP04.ent
===================================================================
--- enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP04.ent (rev 0)
+++ enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP04.ent 2008-11-18 01:09:42 UTC (rev 7155)
@@ -0,0 +1,3 @@
+<!ENTITY HOLDER "Red Hat, Inc">
+<!ENTITY YEAR "2008">
+<!ENTITY VERSION "">
Added: enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP04.xml
===================================================================
--- enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP04.xml (rev 0)
+++ enterprise-docs/trunk/Cache_Tree_Cache_Guide/en-US/JBoss_Cache_Tree_Cache_Guide_CP04.xml 2008-11-18 01:09:42 UTC (rev 7155)
@@ -0,0 +1,53 @@
+<?xml version='1.0'?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
+
+<book>
+ <xi:include href="Book_Info.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <preface id="Preface" revision="1"><title>Preface</title>
+ <para>
+ This and its accompanying documents describe JBoss Cache's TreeCache, a tree-structured replicated, transactional cache. JBoss Cache's PojoCache, an "object-oriented" cache that is the AOP-enabled subclass of TreeCache, allowing for Plain Old Java Objects (POJOs) to be inserted and replicated transactionally in a cluster, is described separately in a similar user guide.
+ </para>
+ <para>
+ The TreeCache is fully configurable. Aspects of the system such as replication mechanisms, transaction isolation levels, eviction policies, and transaction managers are all configurable. The TreeCache can be used in a standalone fashion - independent of JBoss Application Server or any other application server. PojoCache on the other hand requires both TreeCache and the JBossAOP standalone subsystem. PojoCache, documented separately, is the first in the market to provide a POJO cache functionality.
+ </para>
+ <para>
+ This document is meant to be a user guide to explain the architecture, api, configuration, and examples for JBoss Cache's TreeCache. Good knowledge of the Java programming language along with a string appreciation and understanding of transactions and concurrent threads is presumed. No prior knowledge of JBoss Application Server is expected or required.
+ </para>
+ <para>
+ If you have questions, use the <ulink url="http://www.jboss.com/index.html?module=bb&op=viewforum&f=157">user forum </ulink> linked on the <ulink url="http://labs.jboss.com/jbosscache">JBoss Cache website</ulink> . We also provide a mechanism for tracking bug reports and feature requests on the <ulink url="http://jira.jboss.com">JBoss JIRA issue tracker </ulink> . If you are interested in the development of JBoss Cache or in translating this documentation into other languages, we'd love to hear from you. Please post a message on the user forum or contact us on the <ulink url="http://lists.jboss.org">developer mailing list </ulink> .
+ </para>
+ <para>
+ JBoss Cache is an open-source product based on LGPL. Commercial development support, production support and training for JBoss Cache is available through <ulink url="http://www.jboss.com">JBoss Inc.</ulink> JBoss Cache is a product in JBoss Professional Open Source <ulink url="http://www.jboss.com/products/index">JEMS</ulink> (JBoss Enterprise Middleware Suite).
+ </para>
+ </preface>
+
+ <xi:include href="Introduction.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="Architecture.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="Basic_api.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="Replication.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="Transactions.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="Eviction_policies.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="Cache_loaders.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="Treecache_marshaller.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="State_transfer.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="Compatibility.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="Configuration.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="Mgmt_information.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <xi:include href="Jboss_integration.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Revision_History.xml"/>
+
+</book>
+
16 years, 1 month
JBoss Cache SVN: r7153 - enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US.
by jbosscache-commits@lists.jboss.org
Author: irooskov(a)redhat.com
Date: 2008-11-17 19:58:51 -0500 (Mon, 17 Nov 2008)
New Revision: 7153
Added:
enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP04.ent
enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP04.xml
Removed:
enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP03.ent
enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP03.xml
Modified:
enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/Book_Info.xml
Log:
updated book for 4.3.4
Modified: enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/Book_Info.xml
===================================================================
--- enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/Book_Info.xml 2008-11-18 00:57:44 UTC (rev 7152)
+++ enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/Book_Info.xml 2008-11-18 00:58:51 UTC (rev 7153)
@@ -2,8 +2,8 @@
<!DOCTYPE bookinfo PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
<bookinfo id="Pojo_Cache">
- <title>JBoss Cache Pojo Cache Guide CP03</title>
- <subtitle>for Use with JBoss Enterprise Application Platform 4.3 Cumulative Patch 3</subtitle>
+ <title>JBoss Cache Pojo Cache Guide CP04</title>
+ <subtitle>for Use with JBoss Enterprise Application Platform 4.3 Cumulative Patch 4</subtitle>
<edition>2.0</edition>
<pubsnumber>1</pubsnumber>
<productname>JBoss Enterprise Application Platform</productname>
Deleted: enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP03.ent
===================================================================
--- enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP03.ent 2008-11-18 00:57:44 UTC (rev 7152)
+++ enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP03.ent 2008-11-18 00:58:51 UTC (rev 7153)
@@ -1,3 +0,0 @@
-<!ENTITY HOLDER "Red Hat, Inc">
-<!ENTITY YEAR "2008">
-<!ENTITY VERSION "">
Deleted: enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP03.xml
===================================================================
--- enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP03.xml 2008-11-18 00:57:44 UTC (rev 7152)
+++ enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP03.xml 2008-11-18 00:58:51 UTC (rev 7153)
@@ -1,45 +0,0 @@
-<?xml version='1.0'?>
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
-
-<book>
- <xi:include href="Book_Info.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <toc></toc><preface id="Preface" revision="1"><title>Preface</title>
- <para>
- PojoCache is an in-memomy, 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. PojoCache, a component of JBossCache (uses PojoCache class as an internal implementation, the old implementation TreeCacheAop has been deprecated.), is the first in the market to provide a POJO cache functionality. JBossCache by itself 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 guide to explain the architecture, api, configuration, and examples for PojoCache. We assume the readers are familiar with both JGroups and TreeCache usages. Since PojoCache uses JBossAop framework, an introduction will also be given there.
- </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 JBossCache 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 PojoCache, 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>
- JBossCache is an open-source product based on LGPL. Commercial development support, production support and training for JBoss Cache is available through JBoss Inc. (see <ulink url="http://www.jboss.com">JBoss web site</ulink> ). JBoss Cache is a project of the JBoss Professional Open Source product suite.
- </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: <programlisting>
- Let's pretend to have an extremely \
- long line that \
- does not fit
- This one is short
-
-</programlisting>
- Is really: <programlisting>
- Let's pretend to have an extremely long line that does not fit
- This one is short
-
-</programlisting>
- </para>
- </preface><xi:include href="Term.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="Introduction.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="Jbossaop.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="Architecture.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="Api.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="Configuration.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="Instrumentation.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="Troubleshooting.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="Appendix.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Revision_History.xml"/>
-
-</book>
-
Added: enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP04.ent
===================================================================
--- enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP04.ent (rev 0)
+++ enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP04.ent 2008-11-18 00:58:51 UTC (rev 7153)
@@ -0,0 +1,3 @@
+<!ENTITY HOLDER "Red Hat, Inc">
+<!ENTITY YEAR "2008">
+<!ENTITY VERSION "">
Added: enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP04.xml
===================================================================
--- enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP04.xml (rev 0)
+++ enterprise-docs/trunk/Cache_Pojo_Cache_Guide/en-US/JBoss_Cache_Pojo_Cache_Guide_CP04.xml 2008-11-18 00:58:51 UTC (rev 7153)
@@ -0,0 +1,45 @@
+<?xml version='1.0'?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
+
+<book>
+ <xi:include href="Book_Info.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <toc></toc><preface id="Preface" revision="1"><title>Preface</title>
+ <para>
+ PojoCache is an in-memomy, 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. PojoCache, a component of JBossCache (uses PojoCache class as an internal implementation, the old implementation TreeCacheAop has been deprecated.), is the first in the market to provide a POJO cache functionality. JBossCache by itself 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 guide to explain the architecture, api, configuration, and examples for PojoCache. We assume the readers are familiar with both JGroups and TreeCache usages. Since PojoCache uses JBossAop framework, an introduction will also be given there.
+ </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 JBossCache 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 PojoCache, 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>
+ JBossCache is an open-source product based on LGPL. Commercial development support, production support and training for JBoss Cache is available through JBoss Inc. (see <ulink url="http://www.jboss.com">JBoss web site</ulink> ). JBoss Cache is a project of the JBoss Professional Open Source product suite.
+ </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: <programlisting>
+ Let's pretend to have an extremely \
+ long line that \
+ does not fit
+ This one is short
+
+</programlisting>
+ Is really: <programlisting>
+ Let's pretend to have an extremely long line that does not fit
+ This one is short
+
+</programlisting>
+ </para>
+ </preface><xi:include href="Term.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="Introduction.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="Jbossaop.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="Architecture.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="Api.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="Configuration.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="Instrumentation.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="Troubleshooting.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="Appendix.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Revision_History.xml"/>
+
+</book>
+
16 years, 1 month
JBoss Cache SVN: r7152 - enterprise-docs/trunk/Cache_FAQ/en-US.
by jbosscache-commits@lists.jboss.org
Author: irooskov(a)redhat.com
Date: 2008-11-17 19:57:44 -0500 (Mon, 17 Nov 2008)
New Revision: 7152
Added:
enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP04.ent
enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP04.xml
Removed:
enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP03.ent
enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP03.xml
Modified:
enterprise-docs/trunk/Cache_FAQ/en-US/Book_Info.xml
Log:
updated book for 4.3.4
Modified: enterprise-docs/trunk/Cache_FAQ/en-US/Book_Info.xml
===================================================================
--- enterprise-docs/trunk/Cache_FAQ/en-US/Book_Info.xml 2008-11-17 23:35:40 UTC (rev 7151)
+++ enterprise-docs/trunk/Cache_FAQ/en-US/Book_Info.xml 2008-11-18 00:57:44 UTC (rev 7152)
@@ -2,8 +2,8 @@
<!DOCTYPE bookinfo PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
<bookinfo>
- <title>JBoss Cache Frequently Asked Questions CP03</title>
- <subtitle>for Use with JBoss Enterprise Application Platform 4.3 Cumulative Patch 3</subtitle>
+ <title>JBoss Cache Frequently Asked Questions CP04</title>
+ <subtitle>for Use with JBoss Enterprise Application Platform 4.3 Cumulative Patch 4</subtitle>
<edition>2.0</edition>
<pubsnumber>1</pubsnumber>
<productname>JBoss Enterprise Application Platform</productname>
Deleted: enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP03.ent
===================================================================
--- enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP03.ent 2008-11-17 23:35:40 UTC (rev 7151)
+++ enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP03.ent 2008-11-18 00:57:44 UTC (rev 7152)
@@ -1,3 +0,0 @@
-<!ENTITY HOLDER "Red Hat, Inc">
-<!ENTITY YEAR "2008">
-<!ENTITY VERSION "">
Deleted: enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP03.xml
===================================================================
--- enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP03.xml 2008-11-17 23:35:40 UTC (rev 7151)
+++ enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP03.xml 2008-11-18 00:57:44 UTC (rev 7152)
@@ -1,2252 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
-<book id="cache_faq">
- <xi:include href="Book_Info.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-
- <chapter id="general">
-
- <title>General Information</title>
- <qandaset>
- <qandaentry id="a1">
- <question>
- <para>What is JBoss Cache?</para>
- </question>
-
- <answer>
- <para>JBoss Cache is a replicated and transactional cache. It is
- replicated since multiple JBoss Cache instances can be distributed
- (either within the same JVM or across several JVMs whether they reside on
- the same machine or on different machines on a network) and data is
- replicated across the whole group. It is transactional because a
- user can configure a JTA compliant transaction manager and make the cache
- operation transactional. Note that the cache can also be run without
- any replication; this is the local mode.
- </para>
-
- <para>Currently, JBoss Cache consists of two components: a generic cache
- (implemented internally as
- <literal>org.jboss.cache.TreeCache</literal>
- ) and a POJO cache (implemented
- internally as
- <literal>org.jboss.cache.aop.PojoCache</literal>
- ).
- <literal>TreeCache</literal>
- is a tree-structured cache that provides replication and
- transaction context, while
- <literal>PojoCache</literal>
- extends the functionality of
- <literal>TreeCache</literal>
- but behaves as a true object cache providing transparent
- and finer-grained object mapping into internal cache.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a2">
- <question>
- <para>Who are the JBoss Cache developers?</para>
- </question>
-
- <answer>
- <para>JBossCache has been developed by Bela Ban, Ben Wang, Harald
- Gliebe, Manik Surtani and Brian Stansberry. Manik is the lead on JBoss Cache and Ben is the lead on
- PojoCache.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a3">
- <question>
- <para>What is the license for JBoss Cache?</para>
- </question>
-
- <answer>
- <para>JBoss Cache is licensed under
- <ulink url="http://www.gnu.org/licenses/lgpl.html">LGPL</ulink>
- .
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a4">
- <question>
- <para>Where can I download JBoss Cache?</para>
- </question>
-
- <answer>
- <para>The JBoss Cache
- <ulink url="http://www.jboss.com/products/jbosscache/downloads">product download page</ulink>
- has prebuilt binaries as well as source distributions. You can also grab snapshots from the JBoss CVS
- repository (see
- <ulink url="http://wiki.jboss.org/wiki/Wiki.jsp?page=CVSRepository">this wiki page</ulink>
- ) - the module name is
- <emphasis role="bold">JBossCache</emphasis>
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a5">
- <question>
- <para>How do I build JBoss Cache from CVS sources?</para>
- </question>
-
- <answer>
- <para>To build, do
- <literal>sh build.sh
- jar
- </literal>
- . This will produce
- <literal>jboss-cache.jar</literal>
- in the
- <literal>dist/lib</literal>
- directory. Or if you want to
- build the standalone package, do
- <literal>sh build.sh dist</literal>
- this will produce
- <literal>dist/jboss-cache-dist.zip</literal>
- Note that you will need to
- use JDK 5.0 to build the distribution. You can still use the binaries you build with J2SE 1.4.x
- though.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a6">
- <question>
- <para>Which JVMs are supported by JBoss Cache?</para>
- </question>
-
- <answer>
- <para>JBoss Cache has been tested and supported on J2SE 1.4.x and JDK 5.0.
- On jboss-3.2 CVS tree, it also compiles on JDK1.3, but there is no
- official support for this version and using this is not recommended.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a7">
- <question>
- <para>From JBoss Cache 1.3.0 onwards, there is a new directory
- <code>lib-50</code>
- ,
- what is it?
- </para>
- </question>
-
- <answer>
- <para>From JBoss Cache 1.3.0 onwards, we support the use of Java 5 annotations, used by PojoCache.
- As a result, there are
- <code>jboss-aop-jdk50.jar</code>
- and
- <code>jboss-cache-jdk50.jar</code>
- that
- are needed to work with the Java 5 annotations. You will need to replace
- <code>jboss-aop.jar</code>
- and
- <code>jboss-cache.jar</code>
- in the lib directory with the
- <code>-jdk50</code>
- versions if you intend
- to use PojoCache, Java 5 and annotations.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a8">
- <question>
- <para>How do I know the version of JBoss Cache that I am using?</para>
- </question>
-
- <answer>
- <para>Since release 1.2, you can check the jar version by running:
- <code>java -jar jboss-cache.jar org.jboss.cache.Version</code>
- .
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a9">
- <question>
- <para>Can I run JBoss Cache outside of JBoss Application
- Server?
- </para>
- </question>
-
- <answer>
- <para>Of course! JBoss Cache comes in two flavors:</para>
-
- <itemizedlist>
- <listitem>
- <para>Integrated with JBoss Application Server as an MBean service.</para>
- </listitem>
-
- <listitem>
- <para>Standalone, that can run in any Java EE server such
- as BEA WebLogic or IBM Websphere. Of course, it can also run in
- a standalone Java process (i.e., outside Java EE context).
- </para>
- </listitem>
- </itemizedlist>
- </answer>
- </qandaentry>
-
- <qandaentry id="a101">
- <question>
- <para>Where can I report bugs or problems?</para>
- </question>
-
- <answer>
- <para>Please report any bugs or problems to
- <ulink
- url="http://www.jboss.org/index.html?module=bb&op=viewforum&f=157">JBoss Cache
- User Forum
- </ulink>
- .
- </para>
- </answer>
- </qandaentry>
- </qandaset>
- </chapter>
- <chapter id="tree_cache">
- <title>JBoss Cache - Tree Cache</title>
- <qandaset>
- <qandaentry id="a10">
- <question>
- <para>How do I deploy JBoss Cache as a MBean service?</para>
- </question>
-
- <answer>
- <para>To deploy JBoss Cache as an MBean inside JBoss, you can copy the
- configuration xml file over to the
- <literal>deploy</literal>
- directory (from
- <literal>all</literal>
- configuration whereby the
- necessary jars are present). Under the standalone package
- <literal>etc/META-INF</literal>
- directory , there are example
- configuration files for different cache modes that can be used to
- deploy JBoss Cache as well.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a11">
- <question>
- <para>How do I know if my JBoss Cache MBean has been deployed?</para>
- </question>
-
- <answer>
- <para>To verify that your JBoss Cache MBean is deployed correctly,
- you can first check the log output under the command console. Next
- you can verify it from JBoss JMX console. Look for
- <literal>jboss.cache</literal>
- domain.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a12">
- <question>
- <para>How do I access the JBoss Cache MBean?</para>
- </question>
-
- <answer>
- <para>Accessing the JBoss Cache MBean is just like accessing any
- JBoss MBean. Here is a code snippet:
- </para>
-
- <programlisting>
- import org.jboss.mx.util.MBeanServerLocator;
- import org.jboss.mx.util.MBeanProxyExt;
- import org.jboss.cache.TreeCacheMBean;
- import javax.management.MBeanServer;
- ...
-
- MBeanServer server;
- TreeCacheMBean cache;
-
- public init() throws Exception
- {
- try
- {
- server = MBeanServerLocator.locateJBoss();
- cache = (TreeCacheMBean) MBeanProxyExt.create(TreeCacheMBean.class,
- "jboss.cache:service=TreeCache",
- server);
- }
- catch (Exception ex)
- {
- // handle exception
- }
- }
-
- public void myBusinessMethod()
- {
- Object value = cache.get("/my/node", "myKey");
-
- HashMap stuff = new HashMap();
- stuff.put("key1", "value1");
- stuff.put("key2", "value2");
- stuff.put("key3", "value3");
-
- cache.put("/my/new/node", stuff);
-
- cache.remove("/my/node");
-
- ...
- }
-
- </programlisting>
- </answer>
- </qandaentry>
-
- <qandaentry id="a13">
- <question>
- <para>Can I run JBoss Cache on JBoss AS 3.2.x releases?</para>
- </question>
-
- <answer>
- <para>Yes. The JBoss Cache source code is also up to date on the
- jboss-3.2 CVS branch. However, only TreeCache is supported there
- since JBossAop (which PojoCache relies on) is only available in JBoss AS 4.x onwards.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a14">
- <question>
- <para>Can I run multiple JBoss Cache instances on the same VM?</para>
- </question>
-
- <answer>
- <para>Yes. There are some scenarios where you may want to run
- multiple instances of JBoss Cache. For example, you want to run
- multiple local cache instances with each instance having its own
- configuration (e.g., different cache policy). In this case, you will
- need multiple xml configuration files.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a15">
- <question>
- <para>Can TreeCache run as a second level cache inside
- Hibernate?
- </para>
- </question>
-
- <answer>
- <para>Yes. Since Hibernate 3.0 release, you can configure it to use
- JBoss Cache (namely, TreeCache) as a second level cache. For details,
- see Hibernate documentation, and also see
- <ulink url="http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossCacheHibernate">
- http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossCacheHibernate
- </ulink>
- </para>
-
- <para>Note that since Hibernate 3.0.2 and JBossCache 1.2.2, we have
- fixed a critical bug that depending on the usage pattern can cause
- deadlock during query caching.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a16">
- <question>
- <para>What about using PojoCache as a Hibernate cache?</para>
- </question>
-
- <answer>
- <para>It is not necessary to use PojoCache for second level
- cache inside Hibernate because Hibernate
- manages fine-grained fields in Java objects. So using PojoCache won't
- provide any advantage.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a17">
- <question>
- <para>How can I configure JBoss Cache?</para>
- </question>
-
- <answer>
- <para>You can configure the JBoss Cache through a configuration xml
- file. Or you can set it programmatically through its get/set methods.
- Check with the documentation for both examples.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a18">
- <question>
- <para>In the configuration xml file, there are tags such as
- <literal>class</literal>
- ,
- <literal>MBean</literal>
- , etc. What are
- these?
- </para>
- </question>
-
- <answer>
- <para>These are tags for deploying JBoss Cache as a JBoss MBean
- service. For consistency, we have kept them in the
- standalone package as well, specifically, the
- <literal>MBean</literal>
- tag. If you run in standalone mode,
- JBoss Cache will ignore these elements.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a19">
- <question>
- <para>What is the difference between the different cache
- modes?
- </para>
- </question>
-
- <answer>
- <para>JBossCache has five different cache modes, i.e.,
- <literal>LOCAL</literal>
- ,
- <literal>REPL_SYNC</literal>
- ,
- <literal>REPL_ASYNC</literal>
- ,
- <literal>INVALIDATION_SYNC</literal>
- and
- <literal>INVALIDATION_ASYNC</literal>
- . If you want to run JBoss Cache as a
- single instance, then you should set the cache mode to
- <literal>LOCAL</literal>
- so that it won't attempt to replicate anything.
- If you want to have synchronous replication among different
- JBoss Cache instances, you set it to
- <literal>REPL_SYNC</literal>
- .
- For asynchronous replication, use
- <literal>AYSNC_REPL</literal>
- . If you do not wish to replicate cached data but simply inform other caches in a cluster that data
- under
- specific addresses are now stale and should be evicted from memory, use
- <literal>INVALIDATION_SYNC</literal>
- or
- <literal>INVALIDTAION_ASYNC</literal>
- . Synchronous and asynchronous behavior applies to invalidation as well as replication.
- </para>
-
- <para>Note that
- <literal>ASYNC_REPL</literal>
- and
- <literal>INVALIDATION_ASYNC</literal>
- are non-blocking. This
- can be useful when you want to have another JBoss Cache serving as a
- mirror or backup and you don't want to wait for confirmation that this mirror has received your
- messages.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a20">
- <question>
- <para>How does JBoss Cache's replication mechanism work?</para>
- </question>
-
- <answer>
- <para>JBoss Cache leverages
- <ulink url="http://www.jgroups.org">JGroups</ulink>
- as a replication layer. A user
- can configure the cluster of JBoss Cache instances by sharing the
- same cluster name (
- <literal>cluster name</literal>
- ). There is also
- an option of whether to populate the cache data upon starting a new
- instance in the
- <literal>ClusterConfig</literal>
- attribute.
- </para>
-
- <para>Note that once all instances join the same replication group,
- every replication change is propagated to all participating members.
- There is no mechanism for sub-partitioning where some replication
- can be done within only a subset of members. This is on our to do
- list.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a21">
- <question>
- <para>I run a 2 node cluster. If the network dies, do the caches continue to run?</para>
- </question>
-
- <answer>
- <para>Yes, both will continue to run, but depending on your replication mode, all transactions or
- operations may not complete. If
- <literal>REPL_SYNC</literal>
- is used, operations will fail while if
- <literal>REPL_ASYNC</literal>
- is used they will succeed. Even if they succeed though, caches will be out of sync.
- </para>
- </answer>
- </qandaentry>
-
-
- <qandaentry id="a22">
- <question>
- <para>Can I plug in library X instead of JGroups to handle remote calls and group communications?</para>
- </question>
-
- <answer>
- <para>At this stage (JBoss Cache 1.x) the answer is no. We do have an abstraction layer between the
- communication suite and JBoss Cache in the pipelines, and this may appear as a feature at some stage
- in
- the future.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a23">
- <question>
- <para>Does the cache need to replicate to every other instance in the cluster? Isn't this slow if the
- cluster is large?
- </para>
- </question>
-
- <answer>
- <para>As of JBoss Cache 1.4.0, replication need not occur to every node in the cluster. This feature -
- called Buddy Replication -
- allows each node to pick one or more 'buddies' in the cluster and only replicate to its buddies. This
- allows a cluster to scale
- very easily with no extra impact on memory or network traffic with each node added.
- </para>
- <para>
- See the User Guide for more information on Buddy Replication, and how it can be used to achieve very
- high
- scalability.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a24">
- <question>
- <para>If I have the need for different TreeCache properties (e.g.,
- <literal>CacheMode</literal>
- and
- <literal>IsolationLevel</literal>
- ), do I simply need to create multiple
- TreeCache instances with the appropriate configuration?
- </para>
- </question>
-
- <answer>
- <para>Yes. All the above mentioned properties are per cache
- instance. Therefore you will need a separate JBoss Cache
- instance.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a25">
- <question>
- <para>Does the Tree Cache config
- <literal>ClusterName</literal>
- have
- any relation to the JBoss AS cluster
- <literal>PartitionName</literal>
- ?
- </para>
- </question>
-
- <answer>
- <para>Yes. They are both JGroups group names. Besides the notion of
- a channel in JGroups, it also can partition the channel into different
- group names.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a26">
- <question>
- <para>When using multiple JGroups based components
- [cluster-service.xml, treecache (multiple instances)], what is the
- correct/valid way to configure those components to make sure my
- multicast addresses don't conflict?
- </para>
- </question>
-
- <answer>
- <para>There are two parameters to consider: multicast address (plus
- port) and the group name. At minimum, you will have to run
- components using a different group name. But whether to run them on
- the same channel depends upon whether the communication performance
- is critical for you or not. If it is, then it'd be best to run them
- on different channels.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a27">
- <question>
- <para>Does JBoss Cache currently support cache persistence
- storage?
- </para>
- </question>
-
- <answer>
- <para>Yes. Starting with release 1.1, JBoss Cache has a CacheLoader
- interface that supports cache persistence. See below.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a28">
- <question>
- <para>Does JBoss Cache currently support cache passivation/ overflow
- to a data store?
- </para>
- </question>
-
- <answer>
- <para>Yes. Starting with release 1.2.4, JBoss Cache uses the
- CacheLoader to support cache passivation/ overflow. See
- documentation on how to configure and use this feature.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a29">
- <question>
- <para>Is JBoss Cache thread safe?</para>
- </question>
-
- <answer>
- <para>Yes, it is thread safe.</para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a30">
- <question>
- <para>Does JBoss Cache support XA (2PC) transactions now?</para>
- </question>
-
- <answer>
- <para>No, although it is also on our to do list. Our internal
- implementation does use a similar 2PC procedure to coordinate a
- transaction among different instances.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a31">
- <question>
- <para>Which TransactionManagers are supported by
- JBoss Cache?
- </para>
- </question>
-
- <answer>
- <para>JBoss Cache supports any TransactionManager that is JTA
- compliant such as JBossTM. A user can configure the transaction
- manager through the configuration xml setting. JBossCache also has a
- built in dummy transaction manager
- (
- <literal>org.jboss.cache.tm.DummyTransactionManager</literal>
- ) for
- testing purposes only. But note that
- <literal>DummyTransactionManager</literal>
- is not thread safe .i.e.,
- it does not support concurrent transactions. Instead, only one
- transaction is allowed at a time.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a32">
- <question>
- <para>How do I set up the cache to be transactional?</para>
- </question>
-
- <answer>
- <para>You either use the default (JBoss) TransactionManager to run
- JBossCache inside JBoss, or you have to implement the
- <literal>TransactionManagerLookup</literal>
- interface, and return an
- instance of your javax.transaction.TransactionManager. The
- configuration property
- <literal>TransactionManagerLookupClass</literal>
- defines the class
- to be used by the cache to fetch a reference to a
- TransactionManager. It is trivial to implement this class to support
- other TransactionManagers. Once this attribute is specified, the
- cache will look up the transaction context from this transaction
- manager.
- </para>
-
- <para>For the client code, here is a snippet to start and commit a
- transaction:
- </para>
-
- <programlisting>tx = (UserTransaction)new InitialContext(prop).lookup("UserTransaction");
- tree = new TreeCache();
- config = new PropertyConfigurator();
- config.configure(tree, "META-INF/replSync-service.xml");
-
- tx.begin()
- tree.put(fqn, key, value);
- tx.commit();
- </programlisting>
- </answer>
- </qandaentry>
-
- <qandaentry id="a33">
- <question>
- <para>How do I control the cache locking level?</para>
- </question>
-
- <answer>
- <para>JBossCache lets you control the cache locking level through
- the transaction isolation level. This is configured through the
- attribute
- <literal>IsolationLevel</literal>
- . Currently, JBossCache
- employs pessimistic locking internally. And the transaction
- isolation level from the pessimist locking corresponds to JDBC
- isolation levels, namely,
- <literal>NONE</literal>
- ,
- <literal>READ_UNCOMMITTED</literal>
- ,
- <literal>READ_COMMITTED</literal>
- ,
- <literal>REPEATABLE_READ</literal>
- , and
- <literal>SERIALIZABLE</literal>
- . Note that these isolation levels are ignored if optimistic locking is used. For details, please
- refer
- to the
- user manual.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a34">
- <question>
- <para>How does JBoss Cache lock data for concurrent access?</para>
- </question>
-
- <answer>
- <para>By default JBoss Cache uses pessimistic locking to lock data nodes, based on the isolation level
- configured. Since JBoss Cache 1.3.0, we also offer optimistic locking to allow for greater concurrency
- at
- the cost of slight processing overhead and performance. See the documentation for a more detailed
- discussion on concurrency and locking in JBoss Cache.
- </para>
- </answer>
- </qandaentry>
-
-
- <qandaentry id="a35">
- <question>
- <para>How do I enable Optimistic Locking in JBoss Cache?</para>
- </question>
-
- <answer>
- <para>Use the XMl attribute
- <code>NodeLockingScheme</code>
- . Note that
- <code>IsolationLevel</code>
- is ignored if
- <code>NodeLockingScheme</code>
- is set to
- <code>OPTIMISTIC</code>
- . Also note that
- <code>NodeLockingScheme</code>
- defaults to
- <code>PESSIMISTIC</code>
- if omitted.
- </para>
- </answer>
- </qandaentry>
-
-
- <qandaentry id="a36">
- <question>
- <para>How does the write lock apply to an Fqn node, say,
- "/org/jboss/test"?
- </para>
- </question>
-
- <answer>
- <para>First of all, JBossCache has a notion of
- <literal>root</literal>
- that serves as a starting point for every navigational operation.
- The default is "/" (since the default separator is "/" for the fqn).
- The locking then is applied to the node under root, for example
- "/org" (no locking "/").
- </para>
-
- <para>Furthermore, let's say when JBossCache needs to apply a write
- lock on node "/org/jboss/test", it will first try to obtain read
- lock from the parent nodes recursively (in this example, "/org", and
- "/org/jboss"). Only when it succeeds then it will try to obtain a
- write lock on "/org/jboss/test".
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a37">
- <question>
- <para>Can I use the cache locking level even without a transaction
- context?
- </para>
- </question>
-
- <answer>
- <para>Yes. JBossCache controls the individual node locking behavior
- through the isolation level semantics. This means even if you don't
- use a transaction, you can specify the lock level via isolation
- level. You can think of the node locking behavior outside of a
- transaction as if it is under transaction with
- <literal>auto_commit</literal>
- on.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a38">
- <question>
- <para>With replication (REPL_SYNC/REPL_ASYNC) or invalidation (INVALIDATION_SYNC/INVALIDATION_ASYNC), how
- often does the cache broadcast messages over the network?
- </para>
- </question>
-
- <answer>
- <para>If the updates are under transaction, then the broadcasts
- happen only when the transaction is about to commit (actually
- during the prepare stage internally). That is, it will be a batch
- update. However, if the operations are not under transaction
- context, then each update will trigger replication. Note that this
- has performance implication if network transport is heavy (it
- usually is).
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a39">
- <question>
- <para>How can I do a mass removal?</para>
- </question>
-
- <answer>
- <para>If you do a cache.remove("/root"), it will recursively remove
- all the entries under "/root".
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a40">
- <question>
- <para>Can I monitor and manage the JBoss Cache?</para>
- </question>
-
- <answer>
- <para>With JBoss Cache 1.3.0, you can if you are running JBoss Cache within JBoss AS or are using JDK
- 5.0's
- <literal>jconsole</literal>
- utility. See the chapter titled
- <emphasis role="bold">Management Information</emphasis>
- in the JBoss Cache user guide for more details.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a41">
- <question>
- <para>Can I disable JBoss Cache management attributes in JBoss Cache 1.3.0?</para>
- </question>
-
- <answer>
- <para>Yes, you can. Set the
- <literal>UseInterceptorMbeans</literal>
- configuration attribute to
- <literal>false</literal>
- (this defaults to
- <literal>true</literal>
- ). See the chapter titled
- <emphasis role="bold">Management Information</emphasis>
- in the JBoss Cache user guide for more details.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a42">
- <question>
- <para>What is jboss-serialization.jar, introduced in JBoss Cache 1.4.x and do I need this?</para>
- </question>
- <answer>
- <para>jboss-serialization.jar is the
- <ulink url="http://labs.jboss.org/portal/index.html?ctrl:id=page.default.info&pro...">
- JBoss Serialization
- </ulink>
- library, which is much more efficient in terms
- of speed and CPU usage as well as the generated byte stream size than standard Java serialization.
- This
- very
- significantly improves replication performance of custom objects placed in the cache.
- </para>
- <para>
- From 1.4.x, JBoss Cache relies on this library and it is needed to run JBoss Cache.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a43">
- <question>
- <para>Can I disable JBoss Serialization and revert back to standard Java serialization?</para>
- </question>
-
- <answer>
- <para>Yes you can, by passing in the
- <literal>-Dserialization.jboss=false</literal>
- environment variable to your JVM.
- </para>
- </answer>
- </qandaentry>
-
-
- <qandaentry id="a44">
- <question>
- <para>Does JBoss Cache support partitioning?</para>
- </question>
-
- <answer>
- <para>Not right now. JBoss Cache does not support partitioning that a
- user can configure to have different set of data residing on
- different cache instances while still participating as a replication
- group.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a45">
- <question>
- <para>Does JBoss Cache handle the concept of application classloading
- inside, say, a J2EE container?
- </para>
- </question>
-
- <answer>
- <para>Application-specific classloading is used widely inside a J2EE
- container. For example, a web application may require a new
- classloader to scope a specific version of the user library.
- However, by default JBoss Cache is agnostic to the classloader. In
- general, this leads to two kinds of problems:
- </para>
-
- <itemizedlist>
- <listitem>
- <para>Object instance is stored in cache1 and replicated to
- cache2. As a result, the instance in cache2 is created by the
- system classloader. The replication may fail if the system
- classloader on cache2 does not have access to the required
- class. Even if replication doesn't fail, a user thread in cache2
- may not be able to access the object if the user thread is
- expecting a type defined by the application classloader.
- </para>
- </listitem>
-
- <listitem>
- <para>Object instance is created by thread 1 and will be
- accessed by thread 2 (with two different classloaders).
- JBossCache has no notion of the different classloaders involved.
- As a result, you will have a
- <literal>ClassCastException</literal>
- . This is a standard
- problem in passing an object from one application space to
- another; JBossCache just adds a level of indirection in passing
- the object.
- </para>
- </listitem>
- </itemizedlist>
-
- <para>To solve the first kind of issue, in JBoss Cache 1.2.4 we
- introduced the concept of a
- <literal>TreeCacheMarshaller</literal>
- .
- Basically, this allows application code to register a classloader
- with a portion of the cache tree for use in handling objects
- replicated to that portion. See the TreeCacheMarshaller section of
- the user guide for more details.
- </para>
-
- <para>To solve the second kind of issue, the only solution (that we
- know of) is to cache "serialized" byte code and only de-serialize it
- during every object get (and this will be expensive!). That is,
- during a put operation, the object instance will be serialized and
- therefore can be deserialized safely by a "foreign" classloader.
- However, the performance penalty of this approach is quite severe so
- in general another local in-vm version will need to be used as a
- "near-line" cache. Note also that each time the serialized bytes are
- deserialized, a new instance of the object is created.
- </para>
-
- <para>To help with this kind of handling, JBoss has a utility class
- called
- <literal>MarshalledValue</literal>
- that wraps around the
- serialized object. Here is a code snippet that illustrates how you
- can create a wrapper around JBossCache to handle the classloader
- issue:
- </para>
-
- <programlisting>import org.jboss.invocation.MarshalledValue;
-
- public class CacheService {
- private TreeCache cache_;
-
- public object get(Fqn fqn, String key) {
- return getUnMarshalledValue(cache_.get(fqn, key));
- }
-
- public object set(Fqn fqn, String key, Object value) {
- cache_.put(fqn, key, getMarshalledValue(value));
- return value; // only if successful
- }
-
- ...
-
- private Object getUnMarshalledValue(object value) {
- // assuming we use the calling thread context classloader
- return ((MarshalledValue)value).get();
- }
-
- private Object getMarshalledValue(Object value) {
- return new MarshalledValue(value);
- }
- }
-
- </programlisting>
- </answer>
- </qandaentry>
-
- <qandaentry id="a46">
- <question>
- <para>Does JBoss Cache currently support pre-event and post-event
- notification?
- </para>
- </question>
-
- <answer>
- <para>Yes. Starting with release 1.2.4, JBoss Cache has introduced
- ExtendedTreeCacheListener which takes in consideration pre and post
- event notification. See documentation for more details. Note that
- TreeCacheListener and ExtendedTreeCacheListener will be merged into
- TreeCacheListener in release 1.3.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry id="a47">
- <question>
- <para>How do I implement a custom listener to listen to
- <literal>TreeCache</literal>
- events?
- </para>
- </question>
-
- <answer>
- <para>You create a class (myListener) that extends
- AbstractTreeCacheListener and provide concrete implementation for
- the node events that you are interested in. Then you add this
- listener to the TreeCache instance on startup to listen to the
- events as they occur by calling
- TreeCache.addTreeCacheListener(myListener).
- </para>
-
- <programlisting>
- public class MyListener extends AbstractTreeCacheListener
- {
- ...
-
- public void nodeModify(Fqn fqn, boolean pre, boolean isLocal) {
- if(log.isTraceEnabled()){
- if(pre)
- log.trace("Event DataNode about to be modified: " + fqn);
- else
- log.trace("Event DataNode modified: " + fqn);
- }
- }
-
- ...
- }
- </programlisting>
- </answer>
- </qandaentry>
-
- <qandaentry id="a48">
- <question>
- <para>Can I use <literal>useRegionBasedMarshalling</literal> attribute in JBoss Cache in order to get
- around ClassCastExceptions happening when accessing data in the cache that has just been redeployed?
- </para>
- </question>
-
- <answer>
- <para>Yes, you can. Originally, <literal>TreeCache</literal> Marshalling was designed as a
- workaround for those replicated caches that upon state transfer did not have access to the
- classloaders defining the objects in the cache.
- </para>
-
- <para>On each deployment, JBoss creates a new classloader per the top level deployment artifact, for
- example an EAR. You also have to bear in mind that a class in an application server is defined not
- only by the class name but also its classloader. So, assuming that the cache is not deployed as part
- of your deployment, you could deploy an application and put instances of classes belonging to this
- deployment inside the cache. If you did a redeployment and try to do a get operation of the data
- previously put, this would result on a ClassCastException. This is because even though the class names
- are the same, the class definitions are not. The current classloader is different to the one when
- the classes were originally put.
- </para>
-
- <para>By enabling marshalling, you can control the lifecycle of the data in the cache and if on
- undeployment, you inactivate the region and unregister the classloader that you'd have registered on
- deployment, you'd evict the data in the cache locally. That means that in the next deployment, the
- data won't be in the cache, therefore avoiding the problem. Obviously, using marshalling to get
- around this problem is only recommended when you have some kind of persistence backing where the data
- survives, for example using CacheLoaders, or when JBossCache is used as a second level cache in a
- persistence framework.
- </para>
-
- <para>To implement this feature, please follow the instructions indicated in the example located
- in the TreeCacheMarshaller section of the user's guide. It's worth noting that instead of a
- <literal>ServletContextListener</literal>, you could add this code into an <literal>MBean</literal>
- that contained lifecycle methods, such as <literal>start()</literal> and <literal>stop()</literal>.
- The key would be for this MBean to depend on the target cache, so that it can operate as long as the
- cache is up and running.
- </para>
- </answer>
- </qandaentry>
-
- </qandaset>
- </chapter>
- <chapter
- id="PojoCache">
- <title>JBoss Cache - Pojo Cache</title>
- <qandaset>
-
-
- <qandaentry>
- <question>
- <para>What is PojoCache?</para>
- </question>
-
- <answer>
- <para>PojoCache (currently implemented PojoCache as a sub-class of
- TreeCache) 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 PojoCache (by
- calling putObject, for example), then any get/set method will be
- intercepted by PojoCache to provide the data from the
- cache.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>What's the relationship between PojoCache and TreeCacheAop classes?</para>
- </question>
-
- <answer>
- <para>Since release 1.4, we have created a new class called PojoCache (to better reflect the
- cache nature). The old implementation TreeCacheAop has been deprecated.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Does PojoCache have all the functional capabilities of
- TreeCache?
- </para>
- </question>
-
- <answer>
- <para>Yes. PojoCache extends TreeCache so it has all the same
- features TreeCache such as cache mode, transaction isolation level,
- and eviction policy.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>What is the difference between TreeCache and
- PojoCache?
- </para>
- </question>
-
- <answer>
- <para>Think of PojoCache as a TreeCache on steroids. :-)
- Seriously, both are cache stores-- one is a generic cache and the other other one POJO Cache.
- However, while TreeCache only
- provides pure object reference storage (e.g.,
- <literal>put(FQN fqn,
- Object key, Object value)
- </literal>
- ), PojoCache 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 PojoCache 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.
- Furthermore, this is true in replication mode as well.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>What are the steps to use the PojoCache feature?</para>
- </question>
-
- <answer>
- <para>Starting from release 1.3, depends on the JDK you use, it has slightly different steps. But in
- general,
- in order to use PojoCache, you will need to:
- </para>
-
- <itemizedlist>
- <listitem>
- <para>prepare POJO. You can do either via xml declaration or annotation. For annotation, you can
- use either the JDK1.4 style or JDK50 one (of which is part of JVM spec). If you use JDK14, you
- will
- also need
- a annotation pre-compiler (annoc) to pre-process it.
- </para>
- </listitem>
- <listitem>
- <para>instrumentation. You will need to instrument your POJO either at compile-time or load-time.
- If you do it during compile-time, you use so-called aop pre-compiler (aopc) to do bytecode
- manipulation.
- If you do it via load-time, however, you need either a special system class loader or, in JDK50,
- you can
- use the javaagent option.
- </para>
- </listitem>
- </itemizedlist>
- <para>So if you use JDK50, for example, with annotation and load-time instrumentation, then you won't
- need
- any pre-processing step to use PojoCache. For a full example, please refer to the distro examples
- directory.
- There are numerous PojoCache examples that uses different options.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Can I run PojoCache in JBoss AS 3.2.x application
- server?
- </para>
- </question>
-
- <answer>
- <para>Yes and no. Yes, since JBossAop can also be back-ported to
- 3.2.x (see JBossAop wiki for details). However, it will take some
- effort. Therefore, the recommended JBoss version is 4.x to run
- PojoCache.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Can PojoCache run as a MBean as well?</para>
- </question>
-
- <answer>
- <para>Yes. It is almost the same as TreeCache MBean. The only
- difference is the object name and the class name. E.g., instead
- of
- <programlisting><mbean code="org.jboss.cache.TreeCache"
- name="jboss.cache:service=TreeCache"></programlisting>
- you will have:
- <programlisting><mbean code="org.jboss.cache.aop.PojoCache"
- name="jboss.cache:service=PojoCache"></programlisting>
- in the xml configuration file.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Can I pre-compile the aop classes such that I don't need to
- use the system classloader and jboss-aop configuration xml?
- </para>
- </question>
-
- <answer>
- <para>Yes. The latest versions of JBossCache have a pre-compiler
- option called
- <literal>aopc</literal>
- . You can use this option to
- pre-compile your "aspectized" POJO. Once the classes have been byte
- code generated, they can be treated as regular class files, i.e.,
- you will not need to include any
- <literal>jboss-aop.xml</literal>
- that specifies the advisable POJO and to specify the JBossAop system
- class loader.
- </para>
-
- <para>For an example of how to use
- <literal>aopc</literal>
- , please
- see 1)
- <literal>tools</literal>
- directory for PojoCacheTasks14.xml
- and PojoCacheTasks50.xml. Both contain Ant tasks that you can
- import to your regular project for
- <literal>annoc</literal>
- and
- <literal>aopc</literal>
- . In addition, please also check out the
- <literal>examples</literal>
- directory for concrete examples.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <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>
- <para>What's in the
- <literal>jboss-aop.xml</literal>
- configuration?
- </para>
- </question>
-
- <answer>
- <para>
- <literal>jboss-aop.xml</literal>
- is needed for POJO
- instrumentation. In
- <literal>jboss-aop.xml</literal>
- , you can
- declare your POJO (e.g.,
- <literal>Person</literal>
- ) to be
- "prepared", a JBossAop term to denote that the object will be
- "aspectized" by the system. After this declaration, JBossAop will
- invoke any interceptor that associates with this POJO. PojoCache
- will dynamically add an
- <literal>org.jboss.cache.aop.CacheInterceptor</literal>
- to this POJO
- to perform object mapping and relationship management.
- </para>
-
- <para>Note that to add your POJO, you should declare all the fields
- to be "prepared" as in the example.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Can I use annotation instead of the xml declaration?</para>
- </question>
-
- <answer>
- <para>Yes, starting with JBossCache 1.3, you can use annotation to
- instrument your POJO for both JDK1.4 and 1.5. Check the documentation for details.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>What are the pro and con of xml vs. annotation?</para>
- </question>
-
- <answer>
- <para>It really depends on your organization environment, I'd say, since this can be turned into a
- hot debate. Having said that, I feel strongly that POJO annotation is well suited for PojoCache. This
- is
- because once you specify the annotation, you'd probably change it rarely since there is no parameters
- to
- tune, for example.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>What are the
- <literal>@org.jboss.cache.aop.annotation.Transient</literal>
- and
- <literal>@org.jboss.cache.aop.annotation.Serializable</literal>
- field level annotations?
- </para>
- </question>
-
- <answer>
- <para>Starting in 1.4, we also offer two additional field-level annotations. The first one,
- <literal>@Transient</literal>
- ,
- when applied has the same effect as declaring a field
- <literal>transient</literal>
- . PojoCache
- won't put this field under management.
- </para>
- <para>The second one,
- <literal>@Serializable</literal>
- when applied, will cause PojoCache to
- treat the field as a Serializable object even when it is
- <literal>@PojoCacheable</literal>
- .
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>What about compile-time vs. load-time instrumentation then?</para>
- </question>
-
- <answer>
- <para>Again it depends. But my preference is to do compile-time instrumentation via aopc. I prefer this
- approach because it is easier to debug (at least at the development stage). In addition, once I
- generate
- the
- new class, there is no more steps needed.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <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 PojoCache to do that. It supports the
- notion of object reference. PojoCache manages the unique object
- through association of the dynamic cache interceptor.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Do I need to declare all my objects "prepared" in
- <literal>jboss-aop.xml</literal>
- ?
- </para>
- </question>
-
- <answer>
- <para>Not necessarily. If there is an object that you don't need the
- cache to manage for you, you can leave it out of the declaration.
- The cache will treat this object as a "primitive" type. However, the
- object will need to implement
- <literal>Serializable</literal>
- interface for replication.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Can the cache aop intercept update via reflection?</para>
- </question>
-
- <answer>
- <para>No. The update via reflection will not be intercepted in
- JBossAop and therefore PojoCache will not be able to perform the
- necessary synchronization.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>When I declare my POJO to be "aspectized", what happens to the
- fields with transient, static, and final modifiers?
- </para>
- </question>
-
- <answer>
- <para>PojoCache 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>
- <para>What are those keys such as
- <literal>JBoss:internal:class</literal>
- and
- <literal>AOPInstance</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>
- <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, PojoCache will generate
- a dynamic class proxy for the Collection classes (upon the
- <literal>putObject</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 PojoCache.
- </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>
- <para>How do I use
- <literal>List</literal>
- ,
- <literal>Set</literal>
- ,
- and
- <literal>Map</literal>
- dynamic proxy?
- </para>
- </question>
-
- <answer>
- <para>PojoCache supports classes extending from
- <literal>List</literal>
- ,
- <literal>Set</literal>
- , and
- <literal>Map</literal>
- without users to declare them "aspectized".
- It is done via a dynamic proxy. Here is a code snippet to use an
- <literal>ArrayList</literal>
- proxy class.
- </para>
-
- <programlisting>ArrayList list = new ArrayList();
- list.add("first");
-
- cache.putObject("/list/test", list);
- // Put the list under the aop cache
- list.add("second");
- // Won't work since AOP intercepts the dynamic proxy not the original POJO.
-
- ArrayList myList = (List)cache.getObject("/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>
- <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>ArrayList list = new ArrayList();
- list.add("first");
-
- cache.putObject("/list", list);
- // Put the list under the aop cache
-
- ArrayList myList = (List)cache.getObject("/list");
- // we are getting a dynamic proxy instead
- myList.add("second");
- // it works now
-
- cache.putObject("/list_alias", myList);
- // Note you will need to use the proxy here!!
- myList.remove("second");
- </programlisting>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <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 2 Pojos?
- </para>
- </question>
-
- <answer>
- <para>Pojos 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 the users.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>What happens when my "aspectized" POJO has field members that
- are of Collection class ?
- </para>
- </question>
-
- <answer>
- <para>When a user puts a POJO into the cache through the call
- <literal>putObject</literal>
- , it will recursively map the field
- members into the cache store as well. When the field member is of a
- Collection class (e.g., List, Set, or Map), PojoCache will first
- map the collection into cache. Then, it will swap out dynamically
- 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>
- <para>What are the limitation of Collection classes in PojoCache?</para>
- </question>
-
- <answer>
- <para>Use of Collection class in PojoCache helps you to track fine-grained changes
- in your collection fields automatically. However, current implementation has the follow
- limitation that we plan to address soon.
- </para>
- <para>Currently, we only support a limited implementation of Collection classes. That is,
- we support APIs in List, Set, and Map. However, since the APIs do not stipulate
- of constraints like NULL key or value, it makes mapping of user instance to our proxy tricky.
- For example, ArrayList would allow NULL value and some other implementation would not.
- The Set interface maps to java.util.HashSet implementation. The List interface maps
- to java.util.ArrayList implementation. The Map interface maps to java.util.HashMap
- implementation.
- </para>
- <para>Another related issue is the expected performance. For example, the current implementation is
- ordered,
- so
- that makes insert/delete from the Collection slow. Performance between Set, Map and List collections
- also
- vary.
- Adding items to a Set is slower than a List or Map, since Set does not allow duplicate entries.
- </para>
- </answer>
- </qandaentry>
-
-
- <qandaentry>
- <question>
- <para>What are the pros and cons of PojoCache?</para>
- </question>
-
- <answer>
- <para>As mentioned in the reference doc, PojoCache has the following advantages:</para>
- <itemizedlist>
- <listitem>
- <para>Fine-grained replication and/or persistency. If you use a distributed PojoCache
- and once your POJO is put in the cache store, there is no need to use another API to
- trigger your changes. Furthermore, the replication are fine-grained field level. Note this
- also applies to persistency.
- </para>
- </listitem>
- <listitem>
- <para>Fine-grained replication can have potential performance gain if your POJO is big and
- the changes are fine-grained, e.g., only to some selected fields.
- </para>
- </listitem>
- <listitem>
- <para>POJO can posses object relationship, e.g., multiple referenced. Distributed
- PojoCache will handle this transparently for you.
- </para>
- </listitem>
- </itemizedlist>
- <para>And here are some cases that you may not want to use PojoCache:</para>
- <itemizedlist>
- <listitem>
- <para>You use only cache. That is you don't need replication or persistency. Then since
- everything is operated on the in-memory POJO reference, there is no need for PojoCache.
- </para>
- </listitem>
- <listitem>
- <para>You have simple and small POJOs. Your POJO is small in size and also there is no
- object relationship, then PojoCache possess not clear advantage to plain cache.
- </para>
- </listitem>
- <listitem>
- <para>Your application is bounded by memory usage. Because PojoCache need almost twice as much
- of memory (the original POJO in-memory space and also the additional cache store for the
- primitive fields), you may not want to use PojoCache.
- </para>
- </listitem>
- <listitem>
- <para>Your POJO lifetime is short. That is, you need to create and destroy your POJO often.
- Then you need to do "pubObject" and "removeObject" often, it will be slow in performance.
- </para>
- </listitem>
- </itemizedlist>
- </answer>
- </qandaentry>
- </qandaset>
- </chapter>
- <chapter id="eviction">
- <title>Eviction Policies</title>
-
- <qandaset>
-
-
- <qandaentry>
- <question>
- <para>Does JBoss Cache support eviction policies?</para>
- </question>
-
- <answer>
- <para>Yes. JBoss Cache currently implements a LRU eviction policy for
- both TreeCache
- (
- <literal>org.jboss.cache.eviction.LRUPolicy</literal>
- ) and
- PojoCache
- (
- <literal>org.jboss.cache.aop.eviction.AopLRUPolicy</literal>
- ). Users
- can also plug in their own eviction policy algorithms. See user
- manual for details. Currently there is user-contributed policy
- called
- <literal>FIFOPolicy</literal>
- that evicts the node based on
- FIFO principle only.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Why can't I use
- <literal>org.jboss.cache.eviction.LRUPolicy</literal>
- for
- PojoCache as well?
- </para>
- </question>
-
- <answer>
- <para>For PojoCache, you will need to use
- <literal>org.jboss.cache.aop.eviction.AopLRUPolicy</literal>
- ) because
- AOP has its eviction algorithm, although is LRU but has totally
- different notion of an "object", for example.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Does JBoss Cache's implemented LRU eviction policy operates in
- replication mode?
- </para>
- </question>
-
- <answer>
- <para>Yes and no. :-)</para>
-
- <para>The LRU policy only operates in local mode. That is, nodes are
- only evicted locally. This may cause the cache contents not to be
- synchronized temporarily. But when a user tries to obtain the cached
- contents of an evicted node and finds out that is null (e.g.,
- <literal>get</literal>
- returns null), it should get it from the
- other data source and re-populate the data in the cache. During this
- moment, the node content will be propagated and the cache content
- will be in sync.
- </para>
-
- <para>However, you still can run eviction policies with cache mode
- set to either
- <literal>REPL_SYNC</literal>
- or
- <literal>REPL_ASYNC</literal>
- . Depending on your use case, you can
- set multiple cache instances to have their own eviction policy
- (which are applied locally) or just have selected instances with
- eviction policies activated.
- </para>
-
- <para>Also note that, with cache loader option, a locally evicted
- node can also be persisted to the backend store and a user can
- retrieve it from the store later on.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Does JBoss Cache support
- <literal>Region</literal>
- ?
- </para>
- </question>
-
- <answer>
- <para>Yes. JBoss Cache has the notion of region where a user can
- configure the eviction policy parameters (e.g.,
- <literal>maxNodes</literal>
- or
- <literal>timeToIdleSeconds</literal>
- )
- </para>
-
- <para>A region in JBoss Cache denotes a portion of tree hierarchy,
- e.g., a fully qualified name (
- <literal>FQN</literal>
- ). For example,
- a user can define
- <literal>/org/jboss</literal>
- and
- <literal>/org/foocom</literal>
- as two separate regions. But note
- that you can configure the region programmatically now, i.e.,
- everything has to be configured through the xml file.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>What are the
- <literal>EvictionPolicyConfig</literal>
- tag
- parameters for
- <literal>org.jboss.cache.eviction.LRUPolicy</literal>
- ?
- </para>
- </question>
-
- <answer>
- <para>They are:</para>
-
-
- <table>
- <title>Parameters</title>
-
- <tgroup cols="2">
- <tbody>
- <row>
- <entry>wakeUpIntervalInSeconds</entry>
-
- <entry>Interval where the clean up thread wakes to process
- the sitting queue and sweep away the old data.
- </entry>
- </row>
-
- <row>
- <entry>region</entry>
-
- <entry>A area where each eviction policy parameters are
- specified. Note that it needs a minimum of
- <literal>/_default</literal>
- region.
- </entry>
- </row>
-
- <row>
- <entry>maxNodes</entry>
-
- <entry>Max number of nodes allowed in the eviction queue. 0
- means no limit.
- </entry>
- </row>
-
- <row>
- <entry>timeToLiveInSeconds</entry>
-
- <entry>Age (in seconds) for the node to be evicted in the
- queue. 0 denotes no limit.
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>I have turned on the eviction policy, why do I still get "out
- of memory" (OOM) exception?
- </para>
- </question>
-
- <answer>
- <para>OOM can happen when the speed of cache access exceeds the
- speed of eviction policy handling timer. Eviction policy handler
- will wake up every
- <literal>wakeUpIntervalInSeconds</literal>
- seconds to process the eviction event queue. And the queue size is
- fixed at 20000 now. So when the queue size is full, it will create a
- backlog and cause OOM to happen unless the eviction timer catches
- up. To address this problem, in addition to increase the VM heap
- size, you can also reduce the
- <literal>wakeUpIntervaleInSeconds</literal>
- so the timer thread
- processes the queue more frequently.
- </para>
-
- <para>We will also externalize the queue size so it will be
- configurable in the next release.
- </para>
- </answer>
- </qandaentry>
- </qandaset>
- </chapter>
- <chapter id="cacheloaders">
- <title>Cache Loaders</title>
-
- <qandaset>
-
-
- <qandaentry>
- <question>
- <para>What is a CacheLoader?</para>
- </question>
-
- <answer>
- <para>A CacheLoader is the connection of JBossCache to a
- (persistent) data store. The CacheLoader is called by JBossCache to
- fetch data from a store when that data is not in the cache, and when
- modifications are made to data in the cache the CacheLoader is
- called to store those modifications back to the store.
- </para>
-
- <para>In conjunction with eviction policies, JBossCache with a
- CacheLoader allows a user to maintain a bounded cache for a large
- backend datastore. Frequently used data is fetched from the
- datastore into the cache, and the least used data is evicted, in
- order to provide fast access to frequently accessed data. This is
- all configured through XML, and the programmer doesn't have to take
- care of loading and eviction.
- </para>
-
- <para>JBossCache currently ships with several CacheLoader
- implementations, including:
- </para>
-
- <para>
- <itemizedlist>
- <listitem>
- <para>FileCacheLoader: this implementation uses the file
- system to store and retrieve data. JBossCache nodes are mapped
- to directories, subnodes to subdirectories etc. Attributes of
- a node are mapped to a file
- <literal>data</literal>
- inside the
- directory.
- </para>
- </listitem>
-
- <listitem>
- <para>BdbjeCacheLoader: this implementation is based on the
- Sleepycat Java Edition database, a fast and efficient
- transactional database. It uses a single file for the entire
- store. Note that if you use Sleepycat's CacheLoader with
- JBoss Cache and wish to ship your product, you will have to acquire a
- <ulink url="http://www.sleepycat.com/jeforjbosscache">commercial license from Sleepycat
- </ulink>
- .
- </para>
- </listitem>
-
- <listitem>
- <para>JDBCCacheLoader: this implementation uses the relational database as the persistent
- storage.
- </para>
- </listitem>
-
- <listitem>
- <para>ClusteredCacheLoader: this implementation queries the rest of the cluster, treating other
- servers' in-memory state as a data store.
- </para>
- </listitem>
-
- <listitem>
- <para>And more. See the documentation for more details.</para>
- </listitem>
- </itemizedlist>
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Can writing to CacheLoaders be asynchronous?</para>
- </question>
-
- <answer>
- <para>As of JBossCache 1.2.4, yes. Set the CacheLoaderAsynchronous
- property to true. See the JBossCache documentation for a more
- detailed discussion. By default though, all cache loader writes are
- synchronous and will block.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Can I write my own CacheLoader ?</para>
- </question>
-
- <answer>
- <para>Yes. A CacheLoader is a class implementing
- <literal>org.jboss.cache.loader.CacheLoader</literal>
- . It is
- configured via the XML file (see JBossCache and Tutorial
- documentation).
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Does a CacheLoader have to use a persistent store ?</para>
- </question>
-
- <answer>
- <para>No, a CacheLoader could for example fetch (and possibly store)
- its data from a webdav-capable webserver. Another example is a
- caching proxy server, which fetches contents from the web. Note that
- an implementation of CacheLoader may not implement the 'store'
- functionality in this case, but just the 'load'
- functionality.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>What can I use a CacheLoader for?</para>
- </question>
-
- <answer>
- <para>Some applications:</para>
-
- <para>
- <itemizedlist>
- <listitem>
- <para>HTTP sessions can be persisted (besides being replicated
- by JBossCache). The CacheLoader can be configured to be
- shared, or unshared, meaning that every node in a cluster has
- its own local store. It is also possible to attach a
- CacheLoader to just
- <emphasis>one</emphasis>
- of the
- nodes.
- </para>
- </listitem>
-
- <listitem>
- <para>Simple persistence for POJOs. Use of JBossCache aop and
- a local CacheLoader persist POJOs transparently into the store
- provided by the CacheLoader.
- </para>
- </listitem>
-
- <listitem>
- <para>Highly available replicated and persisted data store.
- The service is up as long as at least 1 node is running, but
- even if all nodes are taken offline, when the first node is
- started again, the data previously saved will still be
- available (e.g. a shopping cart).
- </para>
- </listitem>
-
- <listitem>
- <para>A caching web proxy (a la Squid): all data are contents
- of URLs, users access the proxy, and if the URL is not in the
- cache, the CacheLoader fetches it from the web. This could
- actually be a replicated and transactional version of
- Squid.
- </para>
- </listitem>
- </itemizedlist>
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>How do I configure JBossCache with a CacheLoader?</para>
- </question>
-
- <answer>
- <para>Through XML: both the fully-qualified classname of the
- CacheLoader and its configuration string have to be given.
- JBossCache will then instantiate a CacheLoader. See JBossCache
- documentation for details.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Do I have to pay to use Sleepycat's CacheLoader?</para>
- </question>
-
- <answer>
- <para>Not if you use it only for personal use. As soon as you
- distribute your product with BdbjeCacheLoader, you have to purchase
- a commercial license from Sleepycat. See details at
- <ulink
- url="http://www.sleepycat.com/jeforjbosscache">http://www.sleepycat.com/jeforjbosscache
- </ulink>
- .
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Can I use more than one cache loader?</para>
- </question>
-
- <answer>
- <para>As of JBossCache 1.3.0, yes. With the new CacheLoaderConfiguration XML
- element (see user manual section on cache loaders) you can now
- describe several cache loaders. The impact is that the cache will
- look at all of the cache loaders in the order they've been
- configured, until it finds a valid, non-null element of data. When
- performing writes, all cache loaders are written to (except if the
- ignoreModifications element has been set to true for a specific
- cache loader.
- </para>
- </answer>
- </qandaentry>
-
- <qandaentry>
- <question>
- <para>Why do cache loaders go into an inconsistent state when I use transactions, pessimistic locking,
- and I
- attempt to read a node after removing it from within the same transaction scope?
- </para>
- </question>
-
- <answer>
- <para>This is a known bug (see
- <ulink url="http://jira.jboss.com/jira/browse/JBCACHE-477">JBCACHE-477</ulink>
- and
- <ulink url="http://jira.jboss.com/jira/browse/JBCACHE-352">JBCACHE-352</ulink>
- ), which have been fixed in JBoss Cache 1.4.0. A very simple workaround if you're using JBoss Cache
- 1.3.x
- is to use optimistic locking.
- </para>
- <para>
- One of the consequences of this bug is that, for example, if you use PojoCache with pojos that have
- private references to a List and you update and remove someelements of that List within a transaction
- (when using pessimistic locking and a cache loader), you may see IllegalStateExceptions thrown.
- </para>
- </answer>
- </qandaentry>
-
-
- </qandaset>
- </chapter>
- <chapter id="troubleshooting">
- <title>Troubleshooting</title>
- <qandaset>
-
- <qandaentry>
- <question>
- <para>I am having problems getting JBoss 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=JBossCacheTroubleshooting">wiki link</ulink>
- .
- </para>
- </answer>
- </qandaentry>
- </qandaset>
- </chapter>
-<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Revision_History.xml"/>
-
-</book>
Added: enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP04.ent
===================================================================
--- enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP04.ent (rev 0)
+++ enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP04.ent 2008-11-18 00:57:44 UTC (rev 7152)
@@ -0,0 +1,3 @@
+<!ENTITY HOLDER "Red Hat, Inc">
+<!ENTITY YEAR "2008">
+<!ENTITY VERSION "">
Added: enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP04.xml
===================================================================
--- enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP04.xml (rev 0)
+++ enterprise-docs/trunk/Cache_FAQ/en-US/JBoss_Cache_Frequently_Asked_Questions_CP04.xml 2008-11-18 00:57:44 UTC (rev 7152)
@@ -0,0 +1,2252 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
+<book id="cache_faq">
+ <xi:include href="Book_Info.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+ <chapter id="general">
+
+ <title>General Information</title>
+ <qandaset>
+ <qandaentry id="a1">
+ <question>
+ <para>What is JBoss Cache?</para>
+ </question>
+
+ <answer>
+ <para>JBoss Cache is a replicated and transactional cache. It is
+ replicated since multiple JBoss Cache instances can be distributed
+ (either within the same JVM or across several JVMs whether they reside on
+ the same machine or on different machines on a network) and data is
+ replicated across the whole group. It is transactional because a
+ user can configure a JTA compliant transaction manager and make the cache
+ operation transactional. Note that the cache can also be run without
+ any replication; this is the local mode.
+ </para>
+
+ <para>Currently, JBoss Cache consists of two components: a generic cache
+ (implemented internally as
+ <literal>org.jboss.cache.TreeCache</literal>
+ ) and a POJO cache (implemented
+ internally as
+ <literal>org.jboss.cache.aop.PojoCache</literal>
+ ).
+ <literal>TreeCache</literal>
+ is a tree-structured cache that provides replication and
+ transaction context, while
+ <literal>PojoCache</literal>
+ extends the functionality of
+ <literal>TreeCache</literal>
+ but behaves as a true object cache providing transparent
+ and finer-grained object mapping into internal cache.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a2">
+ <question>
+ <para>Who are the JBoss Cache developers?</para>
+ </question>
+
+ <answer>
+ <para>JBossCache has been developed by Bela Ban, Ben Wang, Harald
+ Gliebe, Manik Surtani and Brian Stansberry. Manik is the lead on JBoss Cache and Ben is the lead on
+ PojoCache.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a3">
+ <question>
+ <para>What is the license for JBoss Cache?</para>
+ </question>
+
+ <answer>
+ <para>JBoss Cache is licensed under
+ <ulink url="http://www.gnu.org/licenses/lgpl.html">LGPL</ulink>
+ .
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a4">
+ <question>
+ <para>Where can I download JBoss Cache?</para>
+ </question>
+
+ <answer>
+ <para>The JBoss Cache
+ <ulink url="http://www.jboss.com/products/jbosscache/downloads">product download page</ulink>
+ has prebuilt binaries as well as source distributions. You can also grab snapshots from the JBoss CVS
+ repository (see
+ <ulink url="http://wiki.jboss.org/wiki/Wiki.jsp?page=CVSRepository">this wiki page</ulink>
+ ) - the module name is
+ <emphasis role="bold">JBossCache</emphasis>
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a5">
+ <question>
+ <para>How do I build JBoss Cache from CVS sources?</para>
+ </question>
+
+ <answer>
+ <para>To build, do
+ <literal>sh build.sh
+ jar
+ </literal>
+ . This will produce
+ <literal>jboss-cache.jar</literal>
+ in the
+ <literal>dist/lib</literal>
+ directory. Or if you want to
+ build the standalone package, do
+ <literal>sh build.sh dist</literal>
+ this will produce
+ <literal>dist/jboss-cache-dist.zip</literal>
+ Note that you will need to
+ use JDK 5.0 to build the distribution. You can still use the binaries you build with J2SE 1.4.x
+ though.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a6">
+ <question>
+ <para>Which JVMs are supported by JBoss Cache?</para>
+ </question>
+
+ <answer>
+ <para>JBoss Cache has been tested and supported on J2SE 1.4.x and JDK 5.0.
+ On jboss-3.2 CVS tree, it also compiles on JDK1.3, but there is no
+ official support for this version and using this is not recommended.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a7">
+ <question>
+ <para>From JBoss Cache 1.3.0 onwards, there is a new directory
+ <code>lib-50</code>
+ ,
+ what is it?
+ </para>
+ </question>
+
+ <answer>
+ <para>From JBoss Cache 1.3.0 onwards, we support the use of Java 5 annotations, used by PojoCache.
+ As a result, there are
+ <code>jboss-aop-jdk50.jar</code>
+ and
+ <code>jboss-cache-jdk50.jar</code>
+ that
+ are needed to work with the Java 5 annotations. You will need to replace
+ <code>jboss-aop.jar</code>
+ and
+ <code>jboss-cache.jar</code>
+ in the lib directory with the
+ <code>-jdk50</code>
+ versions if you intend
+ to use PojoCache, Java 5 and annotations.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a8">
+ <question>
+ <para>How do I know the version of JBoss Cache that I am using?</para>
+ </question>
+
+ <answer>
+ <para>Since release 1.2, you can check the jar version by running:
+ <code>java -jar jboss-cache.jar org.jboss.cache.Version</code>
+ .
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a9">
+ <question>
+ <para>Can I run JBoss Cache outside of JBoss Application
+ Server?
+ </para>
+ </question>
+
+ <answer>
+ <para>Of course! JBoss Cache comes in two flavors:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>Integrated with JBoss Application Server as an MBean service.</para>
+ </listitem>
+
+ <listitem>
+ <para>Standalone, that can run in any Java EE server such
+ as BEA WebLogic or IBM Websphere. Of course, it can also run in
+ a standalone Java process (i.e., outside Java EE context).
+ </para>
+ </listitem>
+ </itemizedlist>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a101">
+ <question>
+ <para>Where can I report bugs or problems?</para>
+ </question>
+
+ <answer>
+ <para>Please report any bugs or problems to
+ <ulink
+ url="http://www.jboss.org/index.html?module=bb&op=viewforum&f=157">JBoss Cache
+ User Forum
+ </ulink>
+ .
+ </para>
+ </answer>
+ </qandaentry>
+ </qandaset>
+ </chapter>
+ <chapter id="tree_cache">
+ <title>JBoss Cache - Tree Cache</title>
+ <qandaset>
+ <qandaentry id="a10">
+ <question>
+ <para>How do I deploy JBoss Cache as a MBean service?</para>
+ </question>
+
+ <answer>
+ <para>To deploy JBoss Cache as an MBean inside JBoss, you can copy the
+ configuration xml file over to the
+ <literal>deploy</literal>
+ directory (from
+ <literal>all</literal>
+ configuration whereby the
+ necessary jars are present). Under the standalone package
+ <literal>etc/META-INF</literal>
+ directory , there are example
+ configuration files for different cache modes that can be used to
+ deploy JBoss Cache as well.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a11">
+ <question>
+ <para>How do I know if my JBoss Cache MBean has been deployed?</para>
+ </question>
+
+ <answer>
+ <para>To verify that your JBoss Cache MBean is deployed correctly,
+ you can first check the log output under the command console. Next
+ you can verify it from JBoss JMX console. Look for
+ <literal>jboss.cache</literal>
+ domain.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a12">
+ <question>
+ <para>How do I access the JBoss Cache MBean?</para>
+ </question>
+
+ <answer>
+ <para>Accessing the JBoss Cache MBean is just like accessing any
+ JBoss MBean. Here is a code snippet:
+ </para>
+
+ <programlisting>
+ import org.jboss.mx.util.MBeanServerLocator;
+ import org.jboss.mx.util.MBeanProxyExt;
+ import org.jboss.cache.TreeCacheMBean;
+ import javax.management.MBeanServer;
+ ...
+
+ MBeanServer server;
+ TreeCacheMBean cache;
+
+ public init() throws Exception
+ {
+ try
+ {
+ server = MBeanServerLocator.locateJBoss();
+ cache = (TreeCacheMBean) MBeanProxyExt.create(TreeCacheMBean.class,
+ "jboss.cache:service=TreeCache",
+ server);
+ }
+ catch (Exception ex)
+ {
+ // handle exception
+ }
+ }
+
+ public void myBusinessMethod()
+ {
+ Object value = cache.get("/my/node", "myKey");
+
+ HashMap stuff = new HashMap();
+ stuff.put("key1", "value1");
+ stuff.put("key2", "value2");
+ stuff.put("key3", "value3");
+
+ cache.put("/my/new/node", stuff);
+
+ cache.remove("/my/node");
+
+ ...
+ }
+
+ </programlisting>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a13">
+ <question>
+ <para>Can I run JBoss Cache on JBoss AS 3.2.x releases?</para>
+ </question>
+
+ <answer>
+ <para>Yes. The JBoss Cache source code is also up to date on the
+ jboss-3.2 CVS branch. However, only TreeCache is supported there
+ since JBossAop (which PojoCache relies on) is only available in JBoss AS 4.x onwards.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a14">
+ <question>
+ <para>Can I run multiple JBoss Cache instances on the same VM?</para>
+ </question>
+
+ <answer>
+ <para>Yes. There are some scenarios where you may want to run
+ multiple instances of JBoss Cache. For example, you want to run
+ multiple local cache instances with each instance having its own
+ configuration (e.g., different cache policy). In this case, you will
+ need multiple xml configuration files.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a15">
+ <question>
+ <para>Can TreeCache run as a second level cache inside
+ Hibernate?
+ </para>
+ </question>
+
+ <answer>
+ <para>Yes. Since Hibernate 3.0 release, you can configure it to use
+ JBoss Cache (namely, TreeCache) as a second level cache. For details,
+ see Hibernate documentation, and also see
+ <ulink url="http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossCacheHibernate">
+ http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossCacheHibernate
+ </ulink>
+ </para>
+
+ <para>Note that since Hibernate 3.0.2 and JBossCache 1.2.2, we have
+ fixed a critical bug that depending on the usage pattern can cause
+ deadlock during query caching.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a16">
+ <question>
+ <para>What about using PojoCache as a Hibernate cache?</para>
+ </question>
+
+ <answer>
+ <para>It is not necessary to use PojoCache for second level
+ cache inside Hibernate because Hibernate
+ manages fine-grained fields in Java objects. So using PojoCache won't
+ provide any advantage.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a17">
+ <question>
+ <para>How can I configure JBoss Cache?</para>
+ </question>
+
+ <answer>
+ <para>You can configure the JBoss Cache through a configuration xml
+ file. Or you can set it programmatically through its get/set methods.
+ Check with the documentation for both examples.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a18">
+ <question>
+ <para>In the configuration xml file, there are tags such as
+ <literal>class</literal>
+ ,
+ <literal>MBean</literal>
+ , etc. What are
+ these?
+ </para>
+ </question>
+
+ <answer>
+ <para>These are tags for deploying JBoss Cache as a JBoss MBean
+ service. For consistency, we have kept them in the
+ standalone package as well, specifically, the
+ <literal>MBean</literal>
+ tag. If you run in standalone mode,
+ JBoss Cache will ignore these elements.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a19">
+ <question>
+ <para>What is the difference between the different cache
+ modes?
+ </para>
+ </question>
+
+ <answer>
+ <para>JBossCache has five different cache modes, i.e.,
+ <literal>LOCAL</literal>
+ ,
+ <literal>REPL_SYNC</literal>
+ ,
+ <literal>REPL_ASYNC</literal>
+ ,
+ <literal>INVALIDATION_SYNC</literal>
+ and
+ <literal>INVALIDATION_ASYNC</literal>
+ . If you want to run JBoss Cache as a
+ single instance, then you should set the cache mode to
+ <literal>LOCAL</literal>
+ so that it won't attempt to replicate anything.
+ If you want to have synchronous replication among different
+ JBoss Cache instances, you set it to
+ <literal>REPL_SYNC</literal>
+ .
+ For asynchronous replication, use
+ <literal>AYSNC_REPL</literal>
+ . If you do not wish to replicate cached data but simply inform other caches in a cluster that data
+ under
+ specific addresses are now stale and should be evicted from memory, use
+ <literal>INVALIDATION_SYNC</literal>
+ or
+ <literal>INVALIDTAION_ASYNC</literal>
+ . Synchronous and asynchronous behavior applies to invalidation as well as replication.
+ </para>
+
+ <para>Note that
+ <literal>ASYNC_REPL</literal>
+ and
+ <literal>INVALIDATION_ASYNC</literal>
+ are non-blocking. This
+ can be useful when you want to have another JBoss Cache serving as a
+ mirror or backup and you don't want to wait for confirmation that this mirror has received your
+ messages.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a20">
+ <question>
+ <para>How does JBoss Cache's replication mechanism work?</para>
+ </question>
+
+ <answer>
+ <para>JBoss Cache leverages
+ <ulink url="http://www.jgroups.org">JGroups</ulink>
+ as a replication layer. A user
+ can configure the cluster of JBoss Cache instances by sharing the
+ same cluster name (
+ <literal>cluster name</literal>
+ ). There is also
+ an option of whether to populate the cache data upon starting a new
+ instance in the
+ <literal>ClusterConfig</literal>
+ attribute.
+ </para>
+
+ <para>Note that once all instances join the same replication group,
+ every replication change is propagated to all participating members.
+ There is no mechanism for sub-partitioning where some replication
+ can be done within only a subset of members. This is on our to do
+ list.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a21">
+ <question>
+ <para>I run a 2 node cluster. If the network dies, do the caches continue to run?</para>
+ </question>
+
+ <answer>
+ <para>Yes, both will continue to run, but depending on your replication mode, all transactions or
+ operations may not complete. If
+ <literal>REPL_SYNC</literal>
+ is used, operations will fail while if
+ <literal>REPL_ASYNC</literal>
+ is used they will succeed. Even if they succeed though, caches will be out of sync.
+ </para>
+ </answer>
+ </qandaentry>
+
+
+ <qandaentry id="a22">
+ <question>
+ <para>Can I plug in library X instead of JGroups to handle remote calls and group communications?</para>
+ </question>
+
+ <answer>
+ <para>At this stage (JBoss Cache 1.x) the answer is no. We do have an abstraction layer between the
+ communication suite and JBoss Cache in the pipelines, and this may appear as a feature at some stage
+ in
+ the future.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a23">
+ <question>
+ <para>Does the cache need to replicate to every other instance in the cluster? Isn't this slow if the
+ cluster is large?
+ </para>
+ </question>
+
+ <answer>
+ <para>As of JBoss Cache 1.4.0, replication need not occur to every node in the cluster. This feature -
+ called Buddy Replication -
+ allows each node to pick one or more 'buddies' in the cluster and only replicate to its buddies. This
+ allows a cluster to scale
+ very easily with no extra impact on memory or network traffic with each node added.
+ </para>
+ <para>
+ See the User Guide for more information on Buddy Replication, and how it can be used to achieve very
+ high
+ scalability.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a24">
+ <question>
+ <para>If I have the need for different TreeCache properties (e.g.,
+ <literal>CacheMode</literal>
+ and
+ <literal>IsolationLevel</literal>
+ ), do I simply need to create multiple
+ TreeCache instances with the appropriate configuration?
+ </para>
+ </question>
+
+ <answer>
+ <para>Yes. All the above mentioned properties are per cache
+ instance. Therefore you will need a separate JBoss Cache
+ instance.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a25">
+ <question>
+ <para>Does the Tree Cache config
+ <literal>ClusterName</literal>
+ have
+ any relation to the JBoss AS cluster
+ <literal>PartitionName</literal>
+ ?
+ </para>
+ </question>
+
+ <answer>
+ <para>Yes. They are both JGroups group names. Besides the notion of
+ a channel in JGroups, it also can partition the channel into different
+ group names.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a26">
+ <question>
+ <para>When using multiple JGroups based components
+ [cluster-service.xml, treecache (multiple instances)], what is the
+ correct/valid way to configure those components to make sure my
+ multicast addresses don't conflict?
+ </para>
+ </question>
+
+ <answer>
+ <para>There are two parameters to consider: multicast address (plus
+ port) and the group name. At minimum, you will have to run
+ components using a different group name. But whether to run them on
+ the same channel depends upon whether the communication performance
+ is critical for you or not. If it is, then it'd be best to run them
+ on different channels.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a27">
+ <question>
+ <para>Does JBoss Cache currently support cache persistence
+ storage?
+ </para>
+ </question>
+
+ <answer>
+ <para>Yes. Starting with release 1.1, JBoss Cache has a CacheLoader
+ interface that supports cache persistence. See below.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a28">
+ <question>
+ <para>Does JBoss Cache currently support cache passivation/ overflow
+ to a data store?
+ </para>
+ </question>
+
+ <answer>
+ <para>Yes. Starting with release 1.2.4, JBoss Cache uses the
+ CacheLoader to support cache passivation/ overflow. See
+ documentation on how to configure and use this feature.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a29">
+ <question>
+ <para>Is JBoss Cache thread safe?</para>
+ </question>
+
+ <answer>
+ <para>Yes, it is thread safe.</para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a30">
+ <question>
+ <para>Does JBoss Cache support XA (2PC) transactions now?</para>
+ </question>
+
+ <answer>
+ <para>No, although it is also on our to do list. Our internal
+ implementation does use a similar 2PC procedure to coordinate a
+ transaction among different instances.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a31">
+ <question>
+ <para>Which TransactionManagers are supported by
+ JBoss Cache?
+ </para>
+ </question>
+
+ <answer>
+ <para>JBoss Cache supports any TransactionManager that is JTA
+ compliant such as JBossTM. A user can configure the transaction
+ manager through the configuration xml setting. JBossCache also has a
+ built in dummy transaction manager
+ (
+ <literal>org.jboss.cache.tm.DummyTransactionManager</literal>
+ ) for
+ testing purposes only. But note that
+ <literal>DummyTransactionManager</literal>
+ is not thread safe .i.e.,
+ it does not support concurrent transactions. Instead, only one
+ transaction is allowed at a time.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a32">
+ <question>
+ <para>How do I set up the cache to be transactional?</para>
+ </question>
+
+ <answer>
+ <para>You either use the default (JBoss) TransactionManager to run
+ JBossCache inside JBoss, or you have to implement the
+ <literal>TransactionManagerLookup</literal>
+ interface, and return an
+ instance of your javax.transaction.TransactionManager. The
+ configuration property
+ <literal>TransactionManagerLookupClass</literal>
+ defines the class
+ to be used by the cache to fetch a reference to a
+ TransactionManager. It is trivial to implement this class to support
+ other TransactionManagers. Once this attribute is specified, the
+ cache will look up the transaction context from this transaction
+ manager.
+ </para>
+
+ <para>For the client code, here is a snippet to start and commit a
+ transaction:
+ </para>
+
+ <programlisting>tx = (UserTransaction)new InitialContext(prop).lookup("UserTransaction");
+ tree = new TreeCache();
+ config = new PropertyConfigurator();
+ config.configure(tree, "META-INF/replSync-service.xml");
+
+ tx.begin()
+ tree.put(fqn, key, value);
+ tx.commit();
+ </programlisting>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a33">
+ <question>
+ <para>How do I control the cache locking level?</para>
+ </question>
+
+ <answer>
+ <para>JBossCache lets you control the cache locking level through
+ the transaction isolation level. This is configured through the
+ attribute
+ <literal>IsolationLevel</literal>
+ . Currently, JBossCache
+ employs pessimistic locking internally. And the transaction
+ isolation level from the pessimist locking corresponds to JDBC
+ isolation levels, namely,
+ <literal>NONE</literal>
+ ,
+ <literal>READ_UNCOMMITTED</literal>
+ ,
+ <literal>READ_COMMITTED</literal>
+ ,
+ <literal>REPEATABLE_READ</literal>
+ , and
+ <literal>SERIALIZABLE</literal>
+ . Note that these isolation levels are ignored if optimistic locking is used. For details, please
+ refer
+ to the
+ user manual.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a34">
+ <question>
+ <para>How does JBoss Cache lock data for concurrent access?</para>
+ </question>
+
+ <answer>
+ <para>By default JBoss Cache uses pessimistic locking to lock data nodes, based on the isolation level
+ configured. Since JBoss Cache 1.3.0, we also offer optimistic locking to allow for greater concurrency
+ at
+ the cost of slight processing overhead and performance. See the documentation for a more detailed
+ discussion on concurrency and locking in JBoss Cache.
+ </para>
+ </answer>
+ </qandaentry>
+
+
+ <qandaentry id="a35">
+ <question>
+ <para>How do I enable Optimistic Locking in JBoss Cache?</para>
+ </question>
+
+ <answer>
+ <para>Use the XMl attribute
+ <code>NodeLockingScheme</code>
+ . Note that
+ <code>IsolationLevel</code>
+ is ignored if
+ <code>NodeLockingScheme</code>
+ is set to
+ <code>OPTIMISTIC</code>
+ . Also note that
+ <code>NodeLockingScheme</code>
+ defaults to
+ <code>PESSIMISTIC</code>
+ if omitted.
+ </para>
+ </answer>
+ </qandaentry>
+
+
+ <qandaentry id="a36">
+ <question>
+ <para>How does the write lock apply to an Fqn node, say,
+ "/org/jboss/test"?
+ </para>
+ </question>
+
+ <answer>
+ <para>First of all, JBossCache has a notion of
+ <literal>root</literal>
+ that serves as a starting point for every navigational operation.
+ The default is "/" (since the default separator is "/" for the fqn).
+ The locking then is applied to the node under root, for example
+ "/org" (no locking "/").
+ </para>
+
+ <para>Furthermore, let's say when JBossCache needs to apply a write
+ lock on node "/org/jboss/test", it will first try to obtain read
+ lock from the parent nodes recursively (in this example, "/org", and
+ "/org/jboss"). Only when it succeeds then it will try to obtain a
+ write lock on "/org/jboss/test".
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a37">
+ <question>
+ <para>Can I use the cache locking level even without a transaction
+ context?
+ </para>
+ </question>
+
+ <answer>
+ <para>Yes. JBossCache controls the individual node locking behavior
+ through the isolation level semantics. This means even if you don't
+ use a transaction, you can specify the lock level via isolation
+ level. You can think of the node locking behavior outside of a
+ transaction as if it is under transaction with
+ <literal>auto_commit</literal>
+ on.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a38">
+ <question>
+ <para>With replication (REPL_SYNC/REPL_ASYNC) or invalidation (INVALIDATION_SYNC/INVALIDATION_ASYNC), how
+ often does the cache broadcast messages over the network?
+ </para>
+ </question>
+
+ <answer>
+ <para>If the updates are under transaction, then the broadcasts
+ happen only when the transaction is about to commit (actually
+ during the prepare stage internally). That is, it will be a batch
+ update. However, if the operations are not under transaction
+ context, then each update will trigger replication. Note that this
+ has performance implication if network transport is heavy (it
+ usually is).
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a39">
+ <question>
+ <para>How can I do a mass removal?</para>
+ </question>
+
+ <answer>
+ <para>If you do a cache.remove("/root"), it will recursively remove
+ all the entries under "/root".
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a40">
+ <question>
+ <para>Can I monitor and manage the JBoss Cache?</para>
+ </question>
+
+ <answer>
+ <para>With JBoss Cache 1.3.0, you can if you are running JBoss Cache within JBoss AS or are using JDK
+ 5.0's
+ <literal>jconsole</literal>
+ utility. See the chapter titled
+ <emphasis role="bold">Management Information</emphasis>
+ in the JBoss Cache user guide for more details.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a41">
+ <question>
+ <para>Can I disable JBoss Cache management attributes in JBoss Cache 1.3.0?</para>
+ </question>
+
+ <answer>
+ <para>Yes, you can. Set the
+ <literal>UseInterceptorMbeans</literal>
+ configuration attribute to
+ <literal>false</literal>
+ (this defaults to
+ <literal>true</literal>
+ ). See the chapter titled
+ <emphasis role="bold">Management Information</emphasis>
+ in the JBoss Cache user guide for more details.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a42">
+ <question>
+ <para>What is jboss-serialization.jar, introduced in JBoss Cache 1.4.x and do I need this?</para>
+ </question>
+ <answer>
+ <para>jboss-serialization.jar is the
+ <ulink url="http://labs.jboss.org/portal/index.html?ctrl:id=page.default.info&pro...">
+ JBoss Serialization
+ </ulink>
+ library, which is much more efficient in terms
+ of speed and CPU usage as well as the generated byte stream size than standard Java serialization.
+ This
+ very
+ significantly improves replication performance of custom objects placed in the cache.
+ </para>
+ <para>
+ From 1.4.x, JBoss Cache relies on this library and it is needed to run JBoss Cache.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a43">
+ <question>
+ <para>Can I disable JBoss Serialization and revert back to standard Java serialization?</para>
+ </question>
+
+ <answer>
+ <para>Yes you can, by passing in the
+ <literal>-Dserialization.jboss=false</literal>
+ environment variable to your JVM.
+ </para>
+ </answer>
+ </qandaentry>
+
+
+ <qandaentry id="a44">
+ <question>
+ <para>Does JBoss Cache support partitioning?</para>
+ </question>
+
+ <answer>
+ <para>Not right now. JBoss Cache does not support partitioning that a
+ user can configure to have different set of data residing on
+ different cache instances while still participating as a replication
+ group.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a45">
+ <question>
+ <para>Does JBoss Cache handle the concept of application classloading
+ inside, say, a J2EE container?
+ </para>
+ </question>
+
+ <answer>
+ <para>Application-specific classloading is used widely inside a J2EE
+ container. For example, a web application may require a new
+ classloader to scope a specific version of the user library.
+ However, by default JBoss Cache is agnostic to the classloader. In
+ general, this leads to two kinds of problems:
+ </para>
+
+ <itemizedlist>
+ <listitem>
+ <para>Object instance is stored in cache1 and replicated to
+ cache2. As a result, the instance in cache2 is created by the
+ system classloader. The replication may fail if the system
+ classloader on cache2 does not have access to the required
+ class. Even if replication doesn't fail, a user thread in cache2
+ may not be able to access the object if the user thread is
+ expecting a type defined by the application classloader.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>Object instance is created by thread 1 and will be
+ accessed by thread 2 (with two different classloaders).
+ JBossCache has no notion of the different classloaders involved.
+ As a result, you will have a
+ <literal>ClassCastException</literal>
+ . This is a standard
+ problem in passing an object from one application space to
+ another; JBossCache just adds a level of indirection in passing
+ the object.
+ </para>
+ </listitem>
+ </itemizedlist>
+
+ <para>To solve the first kind of issue, in JBoss Cache 1.2.4 we
+ introduced the concept of a
+ <literal>TreeCacheMarshaller</literal>
+ .
+ Basically, this allows application code to register a classloader
+ with a portion of the cache tree for use in handling objects
+ replicated to that portion. See the TreeCacheMarshaller section of
+ the user guide for more details.
+ </para>
+
+ <para>To solve the second kind of issue, the only solution (that we
+ know of) is to cache "serialized" byte code and only de-serialize it
+ during every object get (and this will be expensive!). That is,
+ during a put operation, the object instance will be serialized and
+ therefore can be deserialized safely by a "foreign" classloader.
+ However, the performance penalty of this approach is quite severe so
+ in general another local in-vm version will need to be used as a
+ "near-line" cache. Note also that each time the serialized bytes are
+ deserialized, a new instance of the object is created.
+ </para>
+
+ <para>To help with this kind of handling, JBoss has a utility class
+ called
+ <literal>MarshalledValue</literal>
+ that wraps around the
+ serialized object. Here is a code snippet that illustrates how you
+ can create a wrapper around JBossCache to handle the classloader
+ issue:
+ </para>
+
+ <programlisting>import org.jboss.invocation.MarshalledValue;
+
+ public class CacheService {
+ private TreeCache cache_;
+
+ public object get(Fqn fqn, String key) {
+ return getUnMarshalledValue(cache_.get(fqn, key));
+ }
+
+ public object set(Fqn fqn, String key, Object value) {
+ cache_.put(fqn, key, getMarshalledValue(value));
+ return value; // only if successful
+ }
+
+ ...
+
+ private Object getUnMarshalledValue(object value) {
+ // assuming we use the calling thread context classloader
+ return ((MarshalledValue)value).get();
+ }
+
+ private Object getMarshalledValue(Object value) {
+ return new MarshalledValue(value);
+ }
+ }
+
+ </programlisting>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a46">
+ <question>
+ <para>Does JBoss Cache currently support pre-event and post-event
+ notification?
+ </para>
+ </question>
+
+ <answer>
+ <para>Yes. Starting with release 1.2.4, JBoss Cache has introduced
+ ExtendedTreeCacheListener which takes in consideration pre and post
+ event notification. See documentation for more details. Note that
+ TreeCacheListener and ExtendedTreeCacheListener will be merged into
+ TreeCacheListener in release 1.3.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a47">
+ <question>
+ <para>How do I implement a custom listener to listen to
+ <literal>TreeCache</literal>
+ events?
+ </para>
+ </question>
+
+ <answer>
+ <para>You create a class (myListener) that extends
+ AbstractTreeCacheListener and provide concrete implementation for
+ the node events that you are interested in. Then you add this
+ listener to the TreeCache instance on startup to listen to the
+ events as they occur by calling
+ TreeCache.addTreeCacheListener(myListener).
+ </para>
+
+ <programlisting>
+ public class MyListener extends AbstractTreeCacheListener
+ {
+ ...
+
+ public void nodeModify(Fqn fqn, boolean pre, boolean isLocal) {
+ if(log.isTraceEnabled()){
+ if(pre)
+ log.trace("Event DataNode about to be modified: " + fqn);
+ else
+ log.trace("Event DataNode modified: " + fqn);
+ }
+ }
+
+ ...
+ }
+ </programlisting>
+ </answer>
+ </qandaentry>
+
+ <qandaentry id="a48">
+ <question>
+ <para>Can I use <literal>useRegionBasedMarshalling</literal> attribute in JBoss Cache in order to get
+ around ClassCastExceptions happening when accessing data in the cache that has just been redeployed?
+ </para>
+ </question>
+
+ <answer>
+ <para>Yes, you can. Originally, <literal>TreeCache</literal> Marshalling was designed as a
+ workaround for those replicated caches that upon state transfer did not have access to the
+ classloaders defining the objects in the cache.
+ </para>
+
+ <para>On each deployment, JBoss creates a new classloader per the top level deployment artifact, for
+ example an EAR. You also have to bear in mind that a class in an application server is defined not
+ only by the class name but also its classloader. So, assuming that the cache is not deployed as part
+ of your deployment, you could deploy an application and put instances of classes belonging to this
+ deployment inside the cache. If you did a redeployment and try to do a get operation of the data
+ previously put, this would result on a ClassCastException. This is because even though the class names
+ are the same, the class definitions are not. The current classloader is different to the one when
+ the classes were originally put.
+ </para>
+
+ <para>By enabling marshalling, you can control the lifecycle of the data in the cache and if on
+ undeployment, you inactivate the region and unregister the classloader that you'd have registered on
+ deployment, you'd evict the data in the cache locally. That means that in the next deployment, the
+ data won't be in the cache, therefore avoiding the problem. Obviously, using marshalling to get
+ around this problem is only recommended when you have some kind of persistence backing where the data
+ survives, for example using CacheLoaders, or when JBossCache is used as a second level cache in a
+ persistence framework.
+ </para>
+
+ <para>To implement this feature, please follow the instructions indicated in the example located
+ in the TreeCacheMarshaller section of the user's guide. It's worth noting that instead of a
+ <literal>ServletContextListener</literal>, you could add this code into an <literal>MBean</literal>
+ that contained lifecycle methods, such as <literal>start()</literal> and <literal>stop()</literal>.
+ The key would be for this MBean to depend on the target cache, so that it can operate as long as the
+ cache is up and running.
+ </para>
+ </answer>
+ </qandaentry>
+
+ </qandaset>
+ </chapter>
+ <chapter
+ id="PojoCache">
+ <title>JBoss Cache - Pojo Cache</title>
+ <qandaset>
+
+
+ <qandaentry>
+ <question>
+ <para>What is PojoCache?</para>
+ </question>
+
+ <answer>
+ <para>PojoCache (currently implemented PojoCache as a sub-class of
+ TreeCache) 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 PojoCache (by
+ calling putObject, for example), then any get/set method will be
+ intercepted by PojoCache to provide the data from the
+ cache.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>What's the relationship between PojoCache and TreeCacheAop classes?</para>
+ </question>
+
+ <answer>
+ <para>Since release 1.4, we have created a new class called PojoCache (to better reflect the
+ cache nature). The old implementation TreeCacheAop has been deprecated.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Does PojoCache have all the functional capabilities of
+ TreeCache?
+ </para>
+ </question>
+
+ <answer>
+ <para>Yes. PojoCache extends TreeCache so it has all the same
+ features TreeCache such as cache mode, transaction isolation level,
+ and eviction policy.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>What is the difference between TreeCache and
+ PojoCache?
+ </para>
+ </question>
+
+ <answer>
+ <para>Think of PojoCache as a TreeCache on steroids. :-)
+ Seriously, both are cache stores-- one is a generic cache and the other other one POJO Cache.
+ However, while TreeCache only
+ provides pure object reference storage (e.g.,
+ <literal>put(FQN fqn,
+ Object key, Object value)
+ </literal>
+ ), PojoCache 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 PojoCache 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.
+ Furthermore, this is true in replication mode as well.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>What are the steps to use the PojoCache feature?</para>
+ </question>
+
+ <answer>
+ <para>Starting from release 1.3, depends on the JDK you use, it has slightly different steps. But in
+ general,
+ in order to use PojoCache, you will need to:
+ </para>
+
+ <itemizedlist>
+ <listitem>
+ <para>prepare POJO. You can do either via xml declaration or annotation. For annotation, you can
+ use either the JDK1.4 style or JDK50 one (of which is part of JVM spec). If you use JDK14, you
+ will
+ also need
+ a annotation pre-compiler (annoc) to pre-process it.
+ </para>
+ </listitem>
+ <listitem>
+ <para>instrumentation. You will need to instrument your POJO either at compile-time or load-time.
+ If you do it during compile-time, you use so-called aop pre-compiler (aopc) to do bytecode
+ manipulation.
+ If you do it via load-time, however, you need either a special system class loader or, in JDK50,
+ you can
+ use the javaagent option.
+ </para>
+ </listitem>
+ </itemizedlist>
+ <para>So if you use JDK50, for example, with annotation and load-time instrumentation, then you won't
+ need
+ any pre-processing step to use PojoCache. For a full example, please refer to the distro examples
+ directory.
+ There are numerous PojoCache examples that uses different options.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Can I run PojoCache in JBoss AS 3.2.x application
+ server?
+ </para>
+ </question>
+
+ <answer>
+ <para>Yes and no. Yes, since JBossAop can also be back-ported to
+ 3.2.x (see JBossAop wiki for details). However, it will take some
+ effort. Therefore, the recommended JBoss version is 4.x to run
+ PojoCache.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Can PojoCache run as a MBean as well?</para>
+ </question>
+
+ <answer>
+ <para>Yes. It is almost the same as TreeCache MBean. The only
+ difference is the object name and the class name. E.g., instead
+ of
+ <programlisting><mbean code="org.jboss.cache.TreeCache"
+ name="jboss.cache:service=TreeCache"></programlisting>
+ you will have:
+ <programlisting><mbean code="org.jboss.cache.aop.PojoCache"
+ name="jboss.cache:service=PojoCache"></programlisting>
+ in the xml configuration file.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Can I pre-compile the aop classes such that I don't need to
+ use the system classloader and jboss-aop configuration xml?
+ </para>
+ </question>
+
+ <answer>
+ <para>Yes. The latest versions of JBossCache have a pre-compiler
+ option called
+ <literal>aopc</literal>
+ . You can use this option to
+ pre-compile your "aspectized" POJO. Once the classes have been byte
+ code generated, they can be treated as regular class files, i.e.,
+ you will not need to include any
+ <literal>jboss-aop.xml</literal>
+ that specifies the advisable POJO and to specify the JBossAop system
+ class loader.
+ </para>
+
+ <para>For an example of how to use
+ <literal>aopc</literal>
+ , please
+ see 1)
+ <literal>tools</literal>
+ directory for PojoCacheTasks14.xml
+ and PojoCacheTasks50.xml. Both contain Ant tasks that you can
+ import to your regular project for
+ <literal>annoc</literal>
+ and
+ <literal>aopc</literal>
+ . In addition, please also check out the
+ <literal>examples</literal>
+ directory for concrete examples.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <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>
+ <para>What's in the
+ <literal>jboss-aop.xml</literal>
+ configuration?
+ </para>
+ </question>
+
+ <answer>
+ <para>
+ <literal>jboss-aop.xml</literal>
+ is needed for POJO
+ instrumentation. In
+ <literal>jboss-aop.xml</literal>
+ , you can
+ declare your POJO (e.g.,
+ <literal>Person</literal>
+ ) to be
+ "prepared", a JBossAop term to denote that the object will be
+ "aspectized" by the system. After this declaration, JBossAop will
+ invoke any interceptor that associates with this POJO. PojoCache
+ will dynamically add an
+ <literal>org.jboss.cache.aop.CacheInterceptor</literal>
+ to this POJO
+ to perform object mapping and relationship management.
+ </para>
+
+ <para>Note that to add your POJO, you should declare all the fields
+ to be "prepared" as in the example.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Can I use annotation instead of the xml declaration?</para>
+ </question>
+
+ <answer>
+ <para>Yes, starting with JBossCache 1.3, you can use annotation to
+ instrument your POJO for both JDK1.4 and 1.5. Check the documentation for details.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>What are the pro and con of xml vs. annotation?</para>
+ </question>
+
+ <answer>
+ <para>It really depends on your organization environment, I'd say, since this can be turned into a
+ hot debate. Having said that, I feel strongly that POJO annotation is well suited for PojoCache. This
+ is
+ because once you specify the annotation, you'd probably change it rarely since there is no parameters
+ to
+ tune, for example.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>What are the
+ <literal>@org.jboss.cache.aop.annotation.Transient</literal>
+ and
+ <literal>@org.jboss.cache.aop.annotation.Serializable</literal>
+ field level annotations?
+ </para>
+ </question>
+
+ <answer>
+ <para>Starting in 1.4, we also offer two additional field-level annotations. The first one,
+ <literal>@Transient</literal>
+ ,
+ when applied has the same effect as declaring a field
+ <literal>transient</literal>
+ . PojoCache
+ won't put this field under management.
+ </para>
+ <para>The second one,
+ <literal>@Serializable</literal>
+ when applied, will cause PojoCache to
+ treat the field as a Serializable object even when it is
+ <literal>@PojoCacheable</literal>
+ .
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>What about compile-time vs. load-time instrumentation then?</para>
+ </question>
+
+ <answer>
+ <para>Again it depends. But my preference is to do compile-time instrumentation via aopc. I prefer this
+ approach because it is easier to debug (at least at the development stage). In addition, once I
+ generate
+ the
+ new class, there is no more steps needed.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <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 PojoCache to do that. It supports the
+ notion of object reference. PojoCache manages the unique object
+ through association of the dynamic cache interceptor.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Do I need to declare all my objects "prepared" in
+ <literal>jboss-aop.xml</literal>
+ ?
+ </para>
+ </question>
+
+ <answer>
+ <para>Not necessarily. If there is an object that you don't need the
+ cache to manage for you, you can leave it out of the declaration.
+ The cache will treat this object as a "primitive" type. However, the
+ object will need to implement
+ <literal>Serializable</literal>
+ interface for replication.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Can the cache aop intercept update via reflection?</para>
+ </question>
+
+ <answer>
+ <para>No. The update via reflection will not be intercepted in
+ JBossAop and therefore PojoCache will not be able to perform the
+ necessary synchronization.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>When I declare my POJO to be "aspectized", what happens to the
+ fields with transient, static, and final modifiers?
+ </para>
+ </question>
+
+ <answer>
+ <para>PojoCache 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>
+ <para>What are those keys such as
+ <literal>JBoss:internal:class</literal>
+ and
+ <literal>AOPInstance</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>
+ <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, PojoCache will generate
+ a dynamic class proxy for the Collection classes (upon the
+ <literal>putObject</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 PojoCache.
+ </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>
+ <para>How do I use
+ <literal>List</literal>
+ ,
+ <literal>Set</literal>
+ ,
+ and
+ <literal>Map</literal>
+ dynamic proxy?
+ </para>
+ </question>
+
+ <answer>
+ <para>PojoCache supports classes extending from
+ <literal>List</literal>
+ ,
+ <literal>Set</literal>
+ , and
+ <literal>Map</literal>
+ without users to declare them "aspectized".
+ It is done via a dynamic proxy. Here is a code snippet to use an
+ <literal>ArrayList</literal>
+ proxy class.
+ </para>
+
+ <programlisting>ArrayList list = new ArrayList();
+ list.add("first");
+
+ cache.putObject("/list/test", list);
+ // Put the list under the aop cache
+ list.add("second");
+ // Won't work since AOP intercepts the dynamic proxy not the original POJO.
+
+ ArrayList myList = (List)cache.getObject("/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>
+ <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>ArrayList list = new ArrayList();
+ list.add("first");
+
+ cache.putObject("/list", list);
+ // Put the list under the aop cache
+
+ ArrayList myList = (List)cache.getObject("/list");
+ // we are getting a dynamic proxy instead
+ myList.add("second");
+ // it works now
+
+ cache.putObject("/list_alias", myList);
+ // Note you will need to use the proxy here!!
+ myList.remove("second");
+ </programlisting>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <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 2 Pojos?
+ </para>
+ </question>
+
+ <answer>
+ <para>Pojos 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 the users.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>What happens when my "aspectized" POJO has field members that
+ are of Collection class ?
+ </para>
+ </question>
+
+ <answer>
+ <para>When a user puts a POJO into the cache through the call
+ <literal>putObject</literal>
+ , it will recursively map the field
+ members into the cache store as well. When the field member is of a
+ Collection class (e.g., List, Set, or Map), PojoCache will first
+ map the collection into cache. Then, it will swap out dynamically
+ 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>
+ <para>What are the limitation of Collection classes in PojoCache?</para>
+ </question>
+
+ <answer>
+ <para>Use of Collection class in PojoCache helps you to track fine-grained changes
+ in your collection fields automatically. However, current implementation has the follow
+ limitation that we plan to address soon.
+ </para>
+ <para>Currently, we only support a limited implementation of Collection classes. That is,
+ we support APIs in List, Set, and Map. However, since the APIs do not stipulate
+ of constraints like NULL key or value, it makes mapping of user instance to our proxy tricky.
+ For example, ArrayList would allow NULL value and some other implementation would not.
+ The Set interface maps to java.util.HashSet implementation. The List interface maps
+ to java.util.ArrayList implementation. The Map interface maps to java.util.HashMap
+ implementation.
+ </para>
+ <para>Another related issue is the expected performance. For example, the current implementation is
+ ordered,
+ so
+ that makes insert/delete from the Collection slow. Performance between Set, Map and List collections
+ also
+ vary.
+ Adding items to a Set is slower than a List or Map, since Set does not allow duplicate entries.
+ </para>
+ </answer>
+ </qandaentry>
+
+
+ <qandaentry>
+ <question>
+ <para>What are the pros and cons of PojoCache?</para>
+ </question>
+
+ <answer>
+ <para>As mentioned in the reference doc, PojoCache has the following advantages:</para>
+ <itemizedlist>
+ <listitem>
+ <para>Fine-grained replication and/or persistency. If you use a distributed PojoCache
+ and once your POJO is put in the cache store, there is no need to use another API to
+ trigger your changes. Furthermore, the replication are fine-grained field level. Note this
+ also applies to persistency.
+ </para>
+ </listitem>
+ <listitem>
+ <para>Fine-grained replication can have potential performance gain if your POJO is big and
+ the changes are fine-grained, e.g., only to some selected fields.
+ </para>
+ </listitem>
+ <listitem>
+ <para>POJO can posses object relationship, e.g., multiple referenced. Distributed
+ PojoCache will handle this transparently for you.
+ </para>
+ </listitem>
+ </itemizedlist>
+ <para>And here are some cases that you may not want to use PojoCache:</para>
+ <itemizedlist>
+ <listitem>
+ <para>You use only cache. That is you don't need replication or persistency. Then since
+ everything is operated on the in-memory POJO reference, there is no need for PojoCache.
+ </para>
+ </listitem>
+ <listitem>
+ <para>You have simple and small POJOs. Your POJO is small in size and also there is no
+ object relationship, then PojoCache possess not clear advantage to plain cache.
+ </para>
+ </listitem>
+ <listitem>
+ <para>Your application is bounded by memory usage. Because PojoCache need almost twice as much
+ of memory (the original POJO in-memory space and also the additional cache store for the
+ primitive fields), you may not want to use PojoCache.
+ </para>
+ </listitem>
+ <listitem>
+ <para>Your POJO lifetime is short. That is, you need to create and destroy your POJO often.
+ Then you need to do "pubObject" and "removeObject" often, it will be slow in performance.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </answer>
+ </qandaentry>
+ </qandaset>
+ </chapter>
+ <chapter id="eviction">
+ <title>Eviction Policies</title>
+
+ <qandaset>
+
+
+ <qandaentry>
+ <question>
+ <para>Does JBoss Cache support eviction policies?</para>
+ </question>
+
+ <answer>
+ <para>Yes. JBoss Cache currently implements a LRU eviction policy for
+ both TreeCache
+ (
+ <literal>org.jboss.cache.eviction.LRUPolicy</literal>
+ ) and
+ PojoCache
+ (
+ <literal>org.jboss.cache.aop.eviction.AopLRUPolicy</literal>
+ ). Users
+ can also plug in their own eviction policy algorithms. See user
+ manual for details. Currently there is user-contributed policy
+ called
+ <literal>FIFOPolicy</literal>
+ that evicts the node based on
+ FIFO principle only.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Why can't I use
+ <literal>org.jboss.cache.eviction.LRUPolicy</literal>
+ for
+ PojoCache as well?
+ </para>
+ </question>
+
+ <answer>
+ <para>For PojoCache, you will need to use
+ <literal>org.jboss.cache.aop.eviction.AopLRUPolicy</literal>
+ ) because
+ AOP has its eviction algorithm, although is LRU but has totally
+ different notion of an "object", for example.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Does JBoss Cache's implemented LRU eviction policy operates in
+ replication mode?
+ </para>
+ </question>
+
+ <answer>
+ <para>Yes and no. :-)</para>
+
+ <para>The LRU policy only operates in local mode. That is, nodes are
+ only evicted locally. This may cause the cache contents not to be
+ synchronized temporarily. But when a user tries to obtain the cached
+ contents of an evicted node and finds out that is null (e.g.,
+ <literal>get</literal>
+ returns null), it should get it from the
+ other data source and re-populate the data in the cache. During this
+ moment, the node content will be propagated and the cache content
+ will be in sync.
+ </para>
+
+ <para>However, you still can run eviction policies with cache mode
+ set to either
+ <literal>REPL_SYNC</literal>
+ or
+ <literal>REPL_ASYNC</literal>
+ . Depending on your use case, you can
+ set multiple cache instances to have their own eviction policy
+ (which are applied locally) or just have selected instances with
+ eviction policies activated.
+ </para>
+
+ <para>Also note that, with cache loader option, a locally evicted
+ node can also be persisted to the backend store and a user can
+ retrieve it from the store later on.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Does JBoss Cache support
+ <literal>Region</literal>
+ ?
+ </para>
+ </question>
+
+ <answer>
+ <para>Yes. JBoss Cache has the notion of region where a user can
+ configure the eviction policy parameters (e.g.,
+ <literal>maxNodes</literal>
+ or
+ <literal>timeToIdleSeconds</literal>
+ )
+ </para>
+
+ <para>A region in JBoss Cache denotes a portion of tree hierarchy,
+ e.g., a fully qualified name (
+ <literal>FQN</literal>
+ ). For example,
+ a user can define
+ <literal>/org/jboss</literal>
+ and
+ <literal>/org/foocom</literal>
+ as two separate regions. But note
+ that you can configure the region programmatically now, i.e.,
+ everything has to be configured through the xml file.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>What are the
+ <literal>EvictionPolicyConfig</literal>
+ tag
+ parameters for
+ <literal>org.jboss.cache.eviction.LRUPolicy</literal>
+ ?
+ </para>
+ </question>
+
+ <answer>
+ <para>They are:</para>
+
+
+ <table>
+ <title>Parameters</title>
+
+ <tgroup cols="2">
+ <tbody>
+ <row>
+ <entry>wakeUpIntervalInSeconds</entry>
+
+ <entry>Interval where the clean up thread wakes to process
+ the sitting queue and sweep away the old data.
+ </entry>
+ </row>
+
+ <row>
+ <entry>region</entry>
+
+ <entry>A area where each eviction policy parameters are
+ specified. Note that it needs a minimum of
+ <literal>/_default</literal>
+ region.
+ </entry>
+ </row>
+
+ <row>
+ <entry>maxNodes</entry>
+
+ <entry>Max number of nodes allowed in the eviction queue. 0
+ means no limit.
+ </entry>
+ </row>
+
+ <row>
+ <entry>timeToLiveInSeconds</entry>
+
+ <entry>Age (in seconds) for the node to be evicted in the
+ queue. 0 denotes no limit.
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>I have turned on the eviction policy, why do I still get "out
+ of memory" (OOM) exception?
+ </para>
+ </question>
+
+ <answer>
+ <para>OOM can happen when the speed of cache access exceeds the
+ speed of eviction policy handling timer. Eviction policy handler
+ will wake up every
+ <literal>wakeUpIntervalInSeconds</literal>
+ seconds to process the eviction event queue. And the queue size is
+ fixed at 20000 now. So when the queue size is full, it will create a
+ backlog and cause OOM to happen unless the eviction timer catches
+ up. To address this problem, in addition to increase the VM heap
+ size, you can also reduce the
+ <literal>wakeUpIntervaleInSeconds</literal>
+ so the timer thread
+ processes the queue more frequently.
+ </para>
+
+ <para>We will also externalize the queue size so it will be
+ configurable in the next release.
+ </para>
+ </answer>
+ </qandaentry>
+ </qandaset>
+ </chapter>
+ <chapter id="cacheloaders">
+ <title>Cache Loaders</title>
+
+ <qandaset>
+
+
+ <qandaentry>
+ <question>
+ <para>What is a CacheLoader?</para>
+ </question>
+
+ <answer>
+ <para>A CacheLoader is the connection of JBossCache to a
+ (persistent) data store. The CacheLoader is called by JBossCache to
+ fetch data from a store when that data is not in the cache, and when
+ modifications are made to data in the cache the CacheLoader is
+ called to store those modifications back to the store.
+ </para>
+
+ <para>In conjunction with eviction policies, JBossCache with a
+ CacheLoader allows a user to maintain a bounded cache for a large
+ backend datastore. Frequently used data is fetched from the
+ datastore into the cache, and the least used data is evicted, in
+ order to provide fast access to frequently accessed data. This is
+ all configured through XML, and the programmer doesn't have to take
+ care of loading and eviction.
+ </para>
+
+ <para>JBossCache currently ships with several CacheLoader
+ implementations, including:
+ </para>
+
+ <para>
+ <itemizedlist>
+ <listitem>
+ <para>FileCacheLoader: this implementation uses the file
+ system to store and retrieve data. JBossCache nodes are mapped
+ to directories, subnodes to subdirectories etc. Attributes of
+ a node are mapped to a file
+ <literal>data</literal>
+ inside the
+ directory.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>BdbjeCacheLoader: this implementation is based on the
+ Sleepycat Java Edition database, a fast and efficient
+ transactional database. It uses a single file for the entire
+ store. Note that if you use Sleepycat's CacheLoader with
+ JBoss Cache and wish to ship your product, you will have to acquire a
+ <ulink url="http://www.sleepycat.com/jeforjbosscache">commercial license from Sleepycat
+ </ulink>
+ .
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>JDBCCacheLoader: this implementation uses the relational database as the persistent
+ storage.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>ClusteredCacheLoader: this implementation queries the rest of the cluster, treating other
+ servers' in-memory state as a data store.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>And more. See the documentation for more details.</para>
+ </listitem>
+ </itemizedlist>
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Can writing to CacheLoaders be asynchronous?</para>
+ </question>
+
+ <answer>
+ <para>As of JBossCache 1.2.4, yes. Set the CacheLoaderAsynchronous
+ property to true. See the JBossCache documentation for a more
+ detailed discussion. By default though, all cache loader writes are
+ synchronous and will block.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Can I write my own CacheLoader ?</para>
+ </question>
+
+ <answer>
+ <para>Yes. A CacheLoader is a class implementing
+ <literal>org.jboss.cache.loader.CacheLoader</literal>
+ . It is
+ configured via the XML file (see JBossCache and Tutorial
+ documentation).
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Does a CacheLoader have to use a persistent store ?</para>
+ </question>
+
+ <answer>
+ <para>No, a CacheLoader could for example fetch (and possibly store)
+ its data from a webdav-capable webserver. Another example is a
+ caching proxy server, which fetches contents from the web. Note that
+ an implementation of CacheLoader may not implement the 'store'
+ functionality in this case, but just the 'load'
+ functionality.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>What can I use a CacheLoader for?</para>
+ </question>
+
+ <answer>
+ <para>Some applications:</para>
+
+ <para>
+ <itemizedlist>
+ <listitem>
+ <para>HTTP sessions can be persisted (besides being replicated
+ by JBossCache). The CacheLoader can be configured to be
+ shared, or unshared, meaning that every node in a cluster has
+ its own local store. It is also possible to attach a
+ CacheLoader to just
+ <emphasis>one</emphasis>
+ of the
+ nodes.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>Simple persistence for POJOs. Use of JBossCache aop and
+ a local CacheLoader persist POJOs transparently into the store
+ provided by the CacheLoader.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>Highly available replicated and persisted data store.
+ The service is up as long as at least 1 node is running, but
+ even if all nodes are taken offline, when the first node is
+ started again, the data previously saved will still be
+ available (e.g. a shopping cart).
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>A caching web proxy (a la Squid): all data are contents
+ of URLs, users access the proxy, and if the URL is not in the
+ cache, the CacheLoader fetches it from the web. This could
+ actually be a replicated and transactional version of
+ Squid.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>How do I configure JBossCache with a CacheLoader?</para>
+ </question>
+
+ <answer>
+ <para>Through XML: both the fully-qualified classname of the
+ CacheLoader and its configuration string have to be given.
+ JBossCache will then instantiate a CacheLoader. See JBossCache
+ documentation for details.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Do I have to pay to use Sleepycat's CacheLoader?</para>
+ </question>
+
+ <answer>
+ <para>Not if you use it only for personal use. As soon as you
+ distribute your product with BdbjeCacheLoader, you have to purchase
+ a commercial license from Sleepycat. See details at
+ <ulink
+ url="http://www.sleepycat.com/jeforjbosscache">http://www.sleepycat.com/jeforjbosscache
+ </ulink>
+ .
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Can I use more than one cache loader?</para>
+ </question>
+
+ <answer>
+ <para>As of JBossCache 1.3.0, yes. With the new CacheLoaderConfiguration XML
+ element (see user manual section on cache loaders) you can now
+ describe several cache loaders. The impact is that the cache will
+ look at all of the cache loaders in the order they've been
+ configured, until it finds a valid, non-null element of data. When
+ performing writes, all cache loaders are written to (except if the
+ ignoreModifications element has been set to true for a specific
+ cache loader.
+ </para>
+ </answer>
+ </qandaentry>
+
+ <qandaentry>
+ <question>
+ <para>Why do cache loaders go into an inconsistent state when I use transactions, pessimistic locking,
+ and I
+ attempt to read a node after removing it from within the same transaction scope?
+ </para>
+ </question>
+
+ <answer>
+ <para>This is a known bug (see
+ <ulink url="http://jira.jboss.com/jira/browse/JBCACHE-477">JBCACHE-477</ulink>
+ and
+ <ulink url="http://jira.jboss.com/jira/browse/JBCACHE-352">JBCACHE-352</ulink>
+ ), which have been fixed in JBoss Cache 1.4.0. A very simple workaround if you're using JBoss Cache
+ 1.3.x
+ is to use optimistic locking.
+ </para>
+ <para>
+ One of the consequences of this bug is that, for example, if you use PojoCache with pojos that have
+ private references to a List and you update and remove someelements of that List within a transaction
+ (when using pessimistic locking and a cache loader), you may see IllegalStateExceptions thrown.
+ </para>
+ </answer>
+ </qandaentry>
+
+
+ </qandaset>
+ </chapter>
+ <chapter id="troubleshooting">
+ <title>Troubleshooting</title>
+ <qandaset>
+
+ <qandaentry>
+ <question>
+ <para>I am having problems getting JBoss 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=JBossCacheTroubleshooting">wiki link</ulink>
+ .
+ </para>
+ </answer>
+ </qandaentry>
+ </qandaset>
+ </chapter>
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Revision_History.xml"/>
+
+</book>
16 years, 1 month
JBoss Cache SVN: r7151 - core/branches/flat/src/main/java/org/jboss/starobrno/tree.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-11-17 18:35:40 -0500 (Mon, 17 Nov 2008)
New Revision: 7151
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/tree/Node.java
core/branches/flat/src/main/java/org/jboss/starobrno/tree/NodeImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeCache.java
Log:
Javadocs
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/tree/Node.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/tree/Node.java 2008-11-17 23:26:21 UTC (rev 7150)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/tree/Node.java 2008-11-17 23:35:40 UTC (rev 7151)
@@ -27,7 +27,7 @@
import java.util.Set;
/**
- * A Node is a {@link Fqn named} logical grouping of data in the JBoss {@link Cache}.
+ * A Node is a {@link Fqn named} logical grouping of data in the {@link TreeCache} API of JBoss {@link Cache}.
* A node should be used to contain data for a single data record, for example
* information about a particular person or account.
* <p/>
@@ -35,9 +35,6 @@
* locking interference, and increase concurrency. So for example, when multiple threads or
* possibly distributed caches are acccessing different accounts simultaneously.
* <p/>
- * Another is that when making changes to this node, its data might be kept in a single
- * database row or file on disk. (Persisted via the use of a {@link org.jboss.cache.loader.CacheLoader}.)
- * <p/>
* A node has references to its children, parent (each node except the root - defined by {@link Fqn#ROOT} - has
* a single parent) and data contained within the node (as key/value pairs). The
* data access methods are similar to the collections {@link Map} interface,
@@ -45,8 +42,7 @@
* <p/>
*
* @author <a href="mailto:manik AT jboss DOT org">Manik Surtani (manik AT jboss DOT org)</a>
- * @see Cache
- * @since 2.0.0
+ * @see org.jboss.starobrno.tree.TreeCache
*/
@ThreadSafe
public interface Node<K, V>
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/tree/NodeImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/tree/NodeImpl.java 2008-11-17 23:26:21 UTC (rev 7150)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/tree/NodeImpl.java 2008-11-17 23:35:40 UTC (rev 7151)
@@ -30,10 +30,9 @@
import java.util.Set;
/**
- * // TODO: MANIK: Document this
+ * Implementation backed by an {@link AtomicMap}
*
* @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
- * @since 3.0
*/
public class NodeImpl<K, V> extends TreeStructureSupport implements Node<K, V>
{
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeCache.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeCache.java 2008-11-17 23:26:21 UTC (rev 7150)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeCache.java 2008-11-17 23:35:40 UTC (rev 7151)
@@ -37,10 +37,23 @@
import java.util.Set;
/**
- * // TODO: MANIK: Document this
+ * This is a tree-like facade around a {@link Cache} allowing for efficient tree-style access to cached data.
+ * <p/>
+ * The primary purpose of this interface is to allow for efficient caching of tree-like structures such as directories,
+ * as well as to provide a compatibility layer with JBoss Cache 3.x and earlier.
+ * <p/>
+ * For most purposes, we expect people to use the {@link Cache} interface directly as it is simpler.
+ * <p/>
+ * The tree API assumes that a collection of {@link Node}s, organized in a tree structure underneath a root node,
+ * contains key/value attributes of data.
+ * <p/>
+ * Any locking happens on a node-level granularity, which means that all attributes on a node are atomic and in terms of
+ * locking, is coarse grained. At the same time, replication is fine grained, and only modified attributes in a Node
+ * are replicated.
+ * <p/>
*
* @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
- * @since 3.0
+ * @see Node
*/
public interface TreeCache<K, V> extends Lifecycle
{
16 years, 1 month
JBoss Cache SVN: r7150 - in core/branches/flat/src: main/java/org/jboss/starobrno and 9 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-11-17 18:26:21 -0500 (Mon, 17 Nov 2008)
New Revision: 7150
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMap.java
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMapDelta.java
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMapProxy.java
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicMap.java
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicMapCache.java
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/ClearOperation.java
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/Delta.java
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/DeltaAware.java
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/NullDelta.java
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/Operation.java
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/PutOperation.java
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/RemoveOperation.java
core/branches/flat/src/main/java/org/jboss/starobrno/batch/AutoBatchSupport.java
core/branches/flat/src/test/java/org/jboss/starobrno/atomic/
core/branches/flat/src/test/java/org/jboss/starobrno/atomic/APITest.java
Removed:
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/Delta.java
core/branches/flat/src/main/java/org/jboss/starobrno/atomic/DeltaHashMap.java
core/branches/flat/src/main/java/org/jboss/starobrno/delta/
Modified:
core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.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/batch/BatchContainer.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/RootElementBuilder.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java
core/branches/flat/src/main/java/org/jboss/starobrno/marshall/CacheMarshallerStarobrno.java
core/branches/flat/src/main/java/org/jboss/starobrno/tree/NodeImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeCacheImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeStructureSupport.java
core/branches/flat/src/test/java/org/jboss/starobrno/tree/api/NodeAPITest.java
core/branches/flat/src/test/java/org/jboss/starobrno/tree/api/TreeCacheAPITest.java
Log:
AtomicMap and Tree facade based on AtomicMap
Modified: core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2008-11-17 23:15:11 UTC (rev 7149)
+++ core/branches/flat/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -23,9 +23,9 @@
import org.jboss.cache.annotations.Compat;
import org.jboss.cache.jmx.PlatformMBeanServerRegistration;
+import org.jboss.starobrno.Cache;
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;
@@ -137,7 +137,7 @@
/**
* Bootstraps this factory with a Configuration and a ComponentRegistry.
*/
- private void bootstrap( CacheSPI spi, Configuration configuration)
+ private void bootstrap(CacheSPI spi, Configuration configuration)
{
// injection bootstrap stuff
componentRegistry = new ComponentRegistry(configuration, spi);
@@ -166,7 +166,7 @@
return createCache(c);
}
- public 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/starobrno/Cache.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java 2008-11-17 23:15:11 UTC (rev 7149)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -53,7 +53,10 @@
CacheStatus getCacheStatus();
- public void startBatch();
+ /**
+ * @return true if a batch was successfully started; false if one was available and already running.
+ */
+ public boolean startBatch();
public void endBatch(boolean successful);
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2008-11-17 23:15:11 UTC (rev 7149)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -27,6 +27,9 @@
import org.jboss.cache.buddyreplication.GravitateResult;
import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.marshall.Marshaller;
+import org.jboss.starobrno.atomic.AtomicHashMap;
+import org.jboss.starobrno.atomic.AtomicMap;
+import org.jboss.starobrno.atomic.AtomicMapCache;
import org.jboss.starobrno.batch.BatchContainer;
import org.jboss.starobrno.commands.CommandsFactory;
import org.jboss.starobrno.commands.read.GetKeyValueCommand;
@@ -64,7 +67,7 @@
* @author Mircea.Markus(a)jboss.com
*/
@NonVolatile
-public class CacheDelegate<K, V> implements CacheSPI<K, V>
+public class CacheDelegate<K, V> implements CacheSPI<K, V>, AtomicMapCache<K, V>
{
protected InvocationContextContainer invocationContextContainer;
protected CommandsFactory commandsFactory;
@@ -357,11 +360,11 @@
return componentRegistry.getState();
}
- public void startBatch()
+ public boolean startBatch()
{
if (!config.isInvocationBatchingEnabled())
throw new ConfigurationException("Invocation batching not enabled in current configuration! Please use the <invocationBatching /> element.");
- batchContainer.startBatch();
+ return batchContainer.startBatch();
}
public void endBatch(boolean successful)
@@ -406,4 +409,16 @@
{
return dataContainer == null ? super.toString() : dataContainer.toString();
}
+
+ public AtomicMap getAtomicMap(K key) throws ClassCastException
+ {
+ Object value = get(key);
+ if (value == null) value = AtomicHashMap.newInstance(this, key);
+ return ((AtomicHashMap) value).getProxy(this, key);
+ }
+
+ public <AMK, AMV> AtomicMap<AMK, AMV> getAtomicMap(K key, Class<AMK> atomicMapKeyType, Class<AMV> atomicMapValueType) throws ClassCastException
+ {
+ return getAtomicMap(key);
+ }
}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/atomic (from rev 7145, core/branches/flat/src/main/java/org/jboss/starobrno/delta)
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMap.java (from rev 7145, core/branches/flat/src/main/java/org/jboss/starobrno/delta/DeltaHashMap.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMap.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMap.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -0,0 +1,186 @@
+/*
+ * 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.atomic;
+
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.starobrno.Cache;
+import org.jboss.starobrno.util.FastCopyHashMap;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Note that for replication to work properly, this class <b><i>requires</i></b> that all writes take place within the
+ * scope of an ongoing transaction or batch.
+ * <p/>
+ *
+ * @param <K>
+ * @param <V>
+ */
+@NotThreadSafe
+public class AtomicHashMap<K, V> implements AtomicMap<K, V>, DeltaAware
+{
+ FastCopyHashMap<K, V> delegate;
+ AtomicHashMapDelta delta = null;
+ AtomicHashMapProxy proxy;
+
+ /**
+ * Construction only allowed through this factory method. This factory is intended for use internally by the
+ * CacheDelegate. User code should use {@link AtomicMapCache#getAtomicMap(Object)}.
+ */
+ public static AtomicHashMap newInstance(Cache cache, Object cacheKey)
+ {
+ AtomicHashMap value = new AtomicHashMap();
+ Object oldValue = cache.putIfAbsent(cacheKey, value);
+ if (oldValue != null) value = (AtomicHashMap) oldValue;
+ return value;
+ }
+
+ AtomicHashMap()
+ {
+ delegate = new FastCopyHashMap<K, V>();
+ }
+
+ public void rollback()
+ {
+ // replay reversal operations on the changelog, in reverse order
+
+// ListIterator<AtomicHashMapDelta.Operation> li = delta.changelog.listIterator(delta.changelog.size());
+// while (li.hasPrevious()) li.previous().rollback(delegate);
+
+ // surely a no-op?
+ }
+
+ public void commit()
+ {
+ if (delta != null) delta.changelog.clear();
+ }
+
+ public int size()
+ {
+ return delegate.size();
+ }
+
+ public boolean isEmpty()
+ {
+ return delegate.isEmpty();
+ }
+
+ public boolean containsKey(Object key)
+ {
+ return delegate.containsKey(key);
+ }
+
+ public boolean containsValue(Object value)
+ {
+ return delegate.containsValue(value);
+ }
+
+ public V get(Object key)
+ {
+ return delegate.get(key);
+ }
+
+ public V put(K key, V value)
+ {
+ PutOperation<K, V> op = new PutOperation<K, V>();
+ op.key = key;
+ op.newValue = value;
+ op.oldValue = delegate.put(key, value);
+ delta.changelog.add(op);
+ return op.oldValue;
+ }
+
+ public V remove(Object key)
+ {
+ RemoveOperation<K, V> op = new RemoveOperation<K, V>();
+ op.key = (K) key;
+ op.oldValue = delegate.remove(key);
+ delta.changelog.add(op);
+ return op.oldValue;
+ }
+
+ public void putAll(Map<? extends K, ? extends V> t)
+ {
+ // this is crappy - need to do this more efficiently!
+ for (Entry<? extends K, ? extends V> e : t.entrySet()) put(e.getKey(), e.getValue());
+ }
+
+ public void clear()
+ {
+ ClearOperation<K, V> op = new ClearOperation<K, V>();
+ op.originalEntries = (FastCopyHashMap<K, V>) delegate.clone();
+ delta.changelog.add(op);
+ delegate.clear();
+ }
+
+ public Set<K> keySet()
+ {
+ return delegate.keySet();
+ }
+
+ public Collection<V> values()
+ {
+ return delegate.values();
+ }
+
+ public Set<Entry<K, V>> entrySet()
+ {
+ return delegate.entrySet();
+ }
+
+ public AtomicMap getProxy(Cache cache, Object mapKey)
+ {
+ // construct the proxy lazily
+ if (proxy == null) // DCL is OK here since proxy is volatile (and we live in a post-JDK 5 world)
+ {
+ synchronized (this)
+ {
+ if (proxy == null) proxy = new AtomicHashMapProxy(cache, mapKey);
+ }
+ }
+ return proxy;
+ }
+
+ public Delta delta()
+ {
+ return delta == null ? NullDelta.INSTANCE : delta;
+ }
+
+ public AtomicHashMap copyForWrite()
+ {
+ AtomicHashMap clone = new AtomicHashMap();
+ clone.delegate = (FastCopyHashMap) delegate.clone();
+ clone.proxy = proxy;
+ clone.delta = new AtomicHashMapDelta();
+ return clone;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "AtomicHashMap{" +
+ "delegate=" + delegate +
+ '}';
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMapDelta.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMapDelta.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMapDelta.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -0,0 +1,76 @@
+/*
+ * 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.atomic;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Changes that have occured on an AtomicHashMap
+ *
+ * @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
+ */
+public class AtomicHashMapDelta implements Delta
+{
+ List<Operation> changelog = new LinkedList<Operation>();
+ private static final Log log = LogFactory.getLog(AtomicHashMapDelta.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ public DeltaAware merge(DeltaAware d)
+ {
+ AtomicHashMap other;
+ if (d != null && (d instanceof AtomicHashMap))
+ other = (AtomicHashMap) d;
+ else
+ other = new AtomicHashMap();
+
+ for (Operation o : changelog) o.replay(other.delegate);
+ other.commit();
+ return other;
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ if (trace) log.trace("Serializing changelog " + changelog);
+ out.writeObject(changelog);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ changelog = (List<Operation>) in.readObject();
+ if (trace) log.trace("Deserialized changelog " + changelog);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "AtomicHashMapDelta{" +
+ "changelog=" + changelog +
+ '}';
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMapProxy.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMapProxy.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicHashMapProxy.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -0,0 +1,170 @@
+/*
+ * 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.atomic;
+
+import org.jboss.starobrno.Cache;
+import org.jboss.starobrno.batch.AutoBatchSupport;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A layer of indirection around an {@link org.jboss.starobrno.atomic.AtomicHashMap} to provide reader consistency
+ *
+ * @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
+ */
+public class AtomicHashMapProxy<K, V> extends AutoBatchSupport implements AtomicMap<K, V>
+{
+ Object deltaMapKey;
+
+ public AtomicHashMapProxy(Cache cache, Object deltaMapKey)
+ {
+ this.cache = cache;
+ this.deltaMapKey = deltaMapKey;
+ }
+
+ // internal helper, reduces lots of casts.
+ private AtomicHashMap<K, V> getDeltaMapForRead()
+ {
+ return (AtomicHashMap<K, V>) cache.get(deltaMapKey);
+ }
+
+ private AtomicHashMap<K, V> getDeltaMapForWrite()
+ {
+ if (ownsLock())
+ {
+ return (AtomicHashMap<K, V>) cache.get(deltaMapKey);
+ }
+ else
+ {
+ // acquire WL
+ cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true);
+ AtomicHashMap map = getDeltaMapForRead();
+ // copy for write
+ AtomicHashMap copy = map == null ? new AtomicHashMap() : map.copyForWrite();
+ cache.put(deltaMapKey, copy);
+ return copy;
+ }
+ }
+
+ private boolean ownsLock()
+ {
+ return cache.getInvocationContext().hasLockedKey(deltaMapKey);
+ }
+
+ // readers
+
+ public Set<K> keySet()
+ {
+ return getDeltaMapForRead().keySet();
+ }
+
+ public Collection<V> values()
+ {
+ return getDeltaMapForRead().values();
+ }
+
+ public Set<Entry<K, V>> entrySet()
+ {
+ return getDeltaMapForRead().entrySet();
+ }
+
+ public int size()
+ {
+ return getDeltaMapForRead().size();
+ }
+
+ public boolean isEmpty()
+ {
+ return getDeltaMapForRead().isEmpty();
+ }
+
+ public boolean containsKey(Object key)
+ {
+ return getDeltaMapForRead().containsKey(key);
+ }
+
+ public boolean containsValue(Object value)
+ {
+ return getDeltaMapForRead().containsValue(value);
+ }
+
+ public V get(Object key)
+ {
+ return getDeltaMapForRead().get(key);
+ }
+
+ // writers
+
+ public V put(K key, V value)
+ {
+ try
+ {
+ startAtomic();
+ return getDeltaMapForWrite().put(key, value);
+ }
+ finally
+ {
+ endAtomic();
+ }
+ }
+
+ public V remove(Object key)
+ {
+ try
+ {
+ startAtomic();
+ return getDeltaMapForWrite().remove(key);
+ }
+ finally
+ {
+ endAtomic();
+ }
+ }
+
+ public void putAll(Map<? extends K, ? extends V> m)
+ {
+ try
+ {
+ startAtomic();
+ getDeltaMapForWrite().putAll(m);
+ }
+ finally
+ {
+ endAtomic();
+ }
+ }
+
+ public void clear()
+ {
+ try
+ {
+ startAtomic();
+ getDeltaMapForWrite().clear();
+ }
+ finally
+ {
+ endAtomic();
+ }
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicMap.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicMap.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicMap.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -0,0 +1,41 @@
+/*
+ * 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.atomic;
+
+import java.util.Map;
+
+/**
+ * This is a special type of Map geared for use in JBoss Cache. This map type supports JBoss Cache atomicizing writes
+ * on the cache such that a coarse grained locking is used if this map is stored in the cache, such that the entire map
+ * is locked for writes or is isolated for safe concurrent read.
+ * <p/>
+ * This is, for all practical purposes, a marker interface that indicates that Maps of this type will be locked
+ * atomically in the cache and replicated in a fine grained manner.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
+ * @see DeltaAware
+ * @see AtomicHashMap
+ */
+public interface AtomicMap<K, V> extends Map<K, V>
+{
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicMapCache.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicMapCache.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/atomic/AtomicMapCache.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -0,0 +1,56 @@
+/*
+ * 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.atomic;
+
+import org.jboss.starobrno.Cache;
+
+/**
+ * This interface adds the getAtomicMap() method which allows users to get a hold of a map type where operations on its
+ * elements are all atomic. Refer to the {@link AtomicMap} javadocs for more details.
+ *
+ * @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
+ * @see AtomicMap
+ */
+public interface AtomicMapCache<K, V> extends Cache<K, V>
+{
+ /**
+ * Returns an atomic map. The classes passed in are used to parameterize the Map returned.
+ *
+ * @param key key under which to obtain and store this map in the cache
+ * @param mapKeyType type of the key used for this map
+ * @param mapValueType type of the value used for this map.
+ * @param <X> map keys
+ * @param <Y> map values
+ * @return a new or existing atomic map. Never null.
+ * @throws ClassCastException if there already is a value stored under the given key and the type of value cannot be used as an AtomicMap.
+ */
+ <AMK, AMV> AtomicMap<AMK, AMV> getAtomicMap(K key, Class<AMK> atomicMapKeyType, Class<AMV> atomicMapValueType) throws ClassCastException;
+
+ /**
+ * Un-parameterized version of {@link #getAtomicMap(Object, Class, Class)} which returns an un-parameterized map.
+ *
+ * @param key key under which to obtain and store this map in the cache
+ * @return a new or existing atomic map. Never null.
+ * @throws ClassCastException if there already is a value stored under the given key and the type of value cannot be used as an AtomicMap.
+ */
+ AtomicMap getAtomicMap(K key) throws ClassCastException;
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/atomic/ClearOperation.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/atomic/ClearOperation.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/atomic/ClearOperation.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -0,0 +1,42 @@
+/*
+ * 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.atomic;
+
+import org.jboss.starobrno.util.FastCopyHashMap;
+
+import java.util.Map;
+
+
+public class ClearOperation<K, V> extends Operation<K, V>
+{
+ FastCopyHashMap<K, V> originalEntries;
+
+ public void rollback(Map<K, V> delegate)
+ {
+ if (!originalEntries.isEmpty()) delegate.putAll(originalEntries);
+ }
+
+ public void replay(Map<K, V> delegate)
+ {
+ delegate.clear();
+ }
+}
\ No newline at end of file
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/atomic/Delta.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/delta/Delta.java 2008-11-17 10:43:05 UTC (rev 7145)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/atomic/Delta.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -1,97 +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.delta;
-
-import java.io.Externalizable;
-
-/**
- * This interface allows for implementations to be palced as values in the cache, and report what has changed. This
- * allows for finer grained replication messages.
- * <p/>
- * Basically, the first time a <tt>Delta</tt> object is placed in the cache, it is cached in its entirity. When a
- * <tt>Delta</tt> is removed, similarly, it is removed in its entirity.
- * <p/>
- * Special behavior is seen when a <tt>Delta</tt> object is changed and replicated though. For example, consider the
- * following code:
- * <code>
- * Person p = cache.get("personName");
- * p.setAge(p.getAge() + 1);
- * cache.put("personName", p);
- * </code>
- * <p/>
- * where <tt>Person</tt> implements Delta.
- * <p/>
- * Normally, the put() call would involve serializing and replicating the entire <tt>Person</tt> instance, but since
- * <tt>Person</tt> implements <tt>Delta</tt>, instead the marshaller will only expect the changes to be marshalled (when
- * calling the {@link Externalizable} interfaces. As such, implementations could safely only marshall modified fields when
- * {@link Externalizable#writeExternal(java.io.ObjectOutput)} is called, thereby reducing the time taken serializing
- * and replicating changes.
- * <p/>
- * On the receiving end, changes are applied as such. In a {@link org.jboss.starobrno.commands.write.PutKeyValueCommand},
- * if the value being put is a <tt>Delta</tt> and there is already a <tt>Delta</tt> under the same key, a merge operation
- * is called by invoking {@link Delta#merge(Delta)} on the <i>replicated</i> <tt>Delta</tt> value and passing in the
- * <i>original</i> <tt>Delta</tt> instance. It would then be up to the implementation to efficiently and correctly merge
- * in state, and return a coherent and complete <tt>Delta</tt> instance that could be placed in the cache.
- * <p/>
- * If the command does not find anything under the key - or emor importantly, finds an object that does not implement
- * <tt>Delta</tt> - it would pass a null into the {@link #merge(Delta)} method.
- * <p/>
- * It is important to note that {@link #merge(Delta)} is <b>only</b> called on remote nodes, after replication when
- * merging state. This is never used on the local cache instance.
- * <p/>
- * In addition to {@link #merge(Delta)}, other important methods on this interface are {@link #rollback()}. If running
- * within a JTA transaction scope, and a rollback occurs, no replication takes place so nothing needs to happen on
- * remote instances. However, on your local cache instance, you may have changed internal state of a reference
- * which already exists in the cache, such as in the above example. To correctly deal with JTA transaction rollbacks,
- * all {@link #rollback()} methods on <tt>Delta</tt> instances involved in a transaction will be called and it is
- * up to the implementation to reset internal state. There is a corresponding {@link #commit()} method where changes
- * should be considered as accepted, are flushed and rollback information can be cleared.
- * <p/>
- * For an example of a <tt>Delta</tt> implementation, and for typical use cases, please refer to {@link org.jboss.starobrno.delta.DeltaHashMap}.
- *
- * @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
- * @see org.jboss.starobrno.delta.DeltaHashMap
- */
-public interface Delta extends Externalizable
-{
- /**
- * Invoked if a transaction involving modifying state on this instance has rolled back, and state needs to be reverted.
- */
- void rollback();
-
- /**
- * Invoked if a transaction involving modifying state on this instance completes successfully, and any recorded
- * rollback information can safely be discarded.
- */
- void commit();
-
- /**
- * Merges changes. Important to note that this method is always called on remote nodes, after replication, and is
- * called on the de-serialized instance read off the wire. What is passed in is an extisting <tt>Delta</tt> instance
- * to merge with, or a null. This method should return a fully coherent <tt>Delta</tt> instance than can be placed
- * in the cache
- *
- * @param toMergeInto
- * @return a fully coherent <tt>Delta</tt> instance
- */
- Delta merge(Delta toMergeInto);
-}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/atomic/Delta.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/atomic/Delta.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/atomic/Delta.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -0,0 +1,44 @@
+/*
+ * 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.atomic;
+
+import java.io.Externalizable;
+
+/**
+ * Represents changes made to a {@link DeltaAware} implementation. Should be efficiently externalizable.
+ *
+ * @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
+ */
+public interface Delta extends Externalizable
+{
+ /**
+ * Merge the current set of deltas with a given {@link DeltaAware} instance, and return a coherent and complete
+ * {@link DeltaAware} instance. Implementations should be able to deal with null values passed in, or values of a
+ * different type from the expected DeltaAware instance. Usually the approach would be to ignore what is passed in,
+ * create a new instance of the DeltaAware implementation that the current Delta implementation is written for,
+ * apply changes and pass it back.
+ *
+ * @param d instance to merge with, or null if no merging is needed
+ * @return a fully coherent and usable instance of DeltaAware which may or may not be the same instance passed in
+ */
+ DeltaAware merge(DeltaAware d);
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/atomic/DeltaAware.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/atomic/DeltaAware.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/atomic/DeltaAware.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -0,0 +1,53 @@
+/*
+ * 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.atomic;
+
+/**
+ * This interface allows the extraction of deltas.
+ * <p/>
+ * Implementations would be closely coupled to a corresponding {@link Delta} implementation, since {@link org.jboss.starobrno.atomic.Delta#instantiate()}
+ * would need to know how to recreate this instance of DeltaAware if needed.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
+ * @see Delta
+ */
+public interface DeltaAware
+{
+ /**
+ * Extracts changes made to implementations, in an efficient format that can easily and cheaply be serialized and
+ * deserialized.
+ *
+ * @return an instance of Delta
+ */
+ Delta delta();
+
+ /**
+ * Indicate that all deltas collected to date can be applied and discarded.
+ */
+ void commit();
+
+ /**
+ * Indicate that all deltas collected to date can be discarded.
+ */
+ void rollback();
+}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/atomic/DeltaHashMap.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/delta/DeltaHashMap.java 2008-11-17 10:43:05 UTC (rev 7145)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/atomic/DeltaHashMap.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -1,301 +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.delta;
-
-import org.jboss.starobrno.util.FastCopyHashMap;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Set;
-
-public class DeltaHashMap<K, V> implements Delta, Map<K, V>
-{
- FastCopyHashMap<K, V> delegate;
- List<Operation> changelog = new LinkedList<Operation>();
-
- /**
- * Constructs an empty <tt>HashMap</tt> with the specified initial
- * capacity and load factor.
- *
- * @param initialCapacity The initial capacity.
- * @param loadFactor The load factor.
- * @throws IllegalArgumentException if the initial capacity is negative
- * or the load factor is nonpositive.
- */
- public DeltaHashMap(int initialCapacity, float loadFactor)
- {
- delegate = new FastCopyHashMap(initialCapacity, loadFactor);
- }
-
- /**
- * Constructs an empty <tt>HashMap</tt> with the specified initial
- * capacity and the default load factor (0.75).
- *
- * @param initialCapacity the initial capacity.
- * @throws IllegalArgumentException if the initial capacity is negative.
- */
- public DeltaHashMap(int initialCapacity)
- {
- delegate = new FastCopyHashMap<K, V>(initialCapacity);
- }
-
- /**
- * Constructs an empty <tt>HashMap</tt> with the default initial capacity
- * (16) and the default load factor (0.75).
- */
- public DeltaHashMap()
- {
- delegate = new FastCopyHashMap<K, V>();
- }
-
- /**
- * Constructs a new <tt>HashMap</tt> with the same mappings as the
- * specified <tt>Map</tt>. The <tt>HashMap</tt> is created with
- * default load factor (0.75) and an initial capacity sufficient to
- * hold the mappings in the specified <tt>Map</tt>.
- *
- * @param m the map whose mappings are to be placed in this map.
- * @throws NullPointerException if the specified map is null.
- */
- public DeltaHashMap(Map<? extends K, ? extends V> m)
- {
- delegate = new FastCopyHashMap<K, V>(m);
- }
-
-
- public void rollback()
- {
- // replay reversal operations on the changelog, in reverse order
- ListIterator<Operation> li = changelog.listIterator(changelog.size());
- while (li.hasPrevious()) li.previous().rollback(delegate);
- }
-
- public void commit()
- {
- changelog.clear();
- }
-
- public Delta merge(Delta toMergeInto)
- {
- if (toMergeInto != null)
- {
- if (toMergeInto instanceof DeltaHashMap)
- {
- DeltaHashMap other = (DeltaHashMap) toMergeInto;
- for (Operation o : changelog) o.replay(other.delegate);
- commit();
- other.commit();
- return toMergeInto;
- }
- else
- {
- throw new IllegalArgumentException("This instance of " + getClass().getSimpleName() + " can only merge with other instances of the same type. Don't know how to deal with " + toMergeInto.getClass());
- }
- }
- else
- {
- // use the current instance, since there is nothing to merge into.
- for (Operation o : changelog) o.replay(delegate);
- commit();
- return this;
- }
- }
-
- public void writeExternal(ObjectOutput out) throws IOException
- {
- out.writeObject(changelog);
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- {
- changelog = (List<Operation>) in.readObject();
- }
-
- public int size()
- {
- return delegate.size();
- }
-
- public boolean isEmpty()
- {
- return delegate.isEmpty();
- }
-
- public boolean containsKey(Object key)
- {
- return delegate.containsKey(key);
- }
-
- public boolean containsValue(Object value)
- {
- return delegate.containsValue(value);
- }
-
- public V get(Object key)
- {
- return delegate.get(key);
- }
-
- public V put(K key, V value)
- {
- PutOperation<K, V> op = new PutOperation<K, V>();
- op.key = key;
- op.newValue = value;
- op.oldValue = delegate.put(key, value);
- changelog.add(op);
- return op.oldValue;
- }
-
- public V remove(Object key)
- {
- RemoveOperation<K, V> op = new RemoveOperation<K, V>();
- op.key = (K) key;
- op.oldValue = delegate.remove(key);
- changelog.add(op);
- return op.oldValue;
- }
-
- public void putAll(Map<? extends K, ? extends V> t)
- {
- // this is crappy - need to do this more efficiently!
- for (Entry<? extends K, ? extends V> e : t.entrySet()) put(e.getKey(), e.getValue());
- }
-
- public void clear()
- {
- ClearOperation<K, V> op = new ClearOperation<K, V>();
- op.originalEntries = (FastCopyHashMap<K, V>) delegate.clone();
- changelog.add(op);
- delegate.clear();
- }
-
- public Set<K> keySet()
- {
- return delegate.keySet();
- }
-
- public Collection<V> values()
- {
- return delegate.values();
- }
-
- public Set<Entry<K, V>> entrySet()
- {
- return delegate.entrySet();
- }
-
- private static abstract class Operation<K, V> implements Externalizable
- {
- abstract void rollback(Map<K, V> delegate);
-
- abstract void replay(Map<K, V> delegate);
-
- public void writeExternal(ObjectOutput out) throws IOException
- {
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- {
- }
- }
-
- private static class PutOperation<K, V> extends Operation<K, V>
- {
- K key;
- V oldValue;
- V newValue;
-
- void rollback(Map<K, V> delegate)
- {
- if (oldValue == null)
- delegate.remove(key);
- else
- delegate.put(key, oldValue);
- }
-
- void replay(Map<K, V> delegate)
- {
- delegate.put(key, newValue);
- }
-
- public void writeExternal(ObjectOutput out) throws IOException
- {
- // don't bother writing out the old value since it will never be rolled back
- out.writeObject(key);
- out.writeObject(newValue);
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- {
- key = (K) in.readObject();
- newValue = (V) in.readObject();
- }
- }
-
- private static class RemoveOperation<K, V> extends Operation<K, V>
- {
- K key;
- V oldValue;
-
- void rollback(Map<K, V> delegate)
- {
- if (oldValue != null) delegate.put(key, oldValue);
- }
-
- void replay(Map<K, V> delegate)
- {
- delegate.remove(key);
- }
-
- public void writeExternal(ObjectOutput out) throws IOException
- {
- out.writeObject(key);
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- {
- key = (K) in.readObject();
- }
- }
-
- private static class ClearOperation<K, V> extends Operation<K, V>
- {
- FastCopyHashMap<K, V> originalEntries;
-
- void rollback(Map<K, V> delegate)
- {
- if (!originalEntries.isEmpty()) delegate.putAll(originalEntries);
- }
-
- void replay(Map<K, V> delegate)
- {
- delegate.clear();
- }
- }
-}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/atomic/NullDelta.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/atomic/NullDelta.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/atomic/NullDelta.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -0,0 +1,52 @@
+/*
+ * 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.atomic;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+/**
+ * Represents no changes.
+ *
+ * @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
+ */
+public class NullDelta implements Externalizable, Delta
+{
+ static final NullDelta INSTANCE = new NullDelta();
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ // don't bother writing anything
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ // nothing to read
+ }
+
+ public DeltaAware merge(DeltaAware d)
+ {
+ return (d != null && d instanceof AtomicHashMap) ? d : new AtomicHashMap();
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/atomic/Operation.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/atomic/Operation.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/atomic/Operation.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -0,0 +1,45 @@
+/*
+ * 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.atomic;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Map;
+
+public abstract class Operation<K, V> implements Externalizable
+{
+ public abstract void replay(Map<K, V> delegate);
+
+ public abstract void rollback(Map<K, V> delegate);
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ //no op
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ //no op
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/atomic/PutOperation.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/atomic/PutOperation.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/atomic/PutOperation.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -0,0 +1,63 @@
+/*
+ * 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.atomic;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Map;
+
+
+public class PutOperation<K, V> extends Operation<K, V>
+{
+ K key;
+ V oldValue;
+ V newValue;
+
+ public void rollback(Map<K, V> delegate)
+ {
+ if (oldValue == null)
+ delegate.remove(key);
+ else
+ delegate.put(key, oldValue);
+ }
+
+ public void replay(Map<K, V> delegate)
+ {
+ delegate.put(key, newValue);
+ }
+
+ @Override
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ // don't bother writing out the old value since it will never be rolled back
+ out.writeObject(key);
+ out.writeObject(newValue);
+ }
+
+ @Override
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ key = (K) in.readObject();
+ newValue = (V) in.readObject();
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/atomic/RemoveOperation.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/atomic/RemoveOperation.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/atomic/RemoveOperation.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -0,0 +1,56 @@
+/*
+ * 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.atomic;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Map;
+
+
+public class RemoveOperation<K, V> extends Operation<K, V>
+{
+ K key;
+ V oldValue;
+
+ public void rollback(Map<K, V> delegate)
+ {
+ if (oldValue != null) delegate.put(key, oldValue);
+ }
+
+ public void replay(Map<K, V> delegate)
+ {
+ delegate.remove(key);
+ }
+
+ @Override
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeObject(key);
+ }
+
+ @Override
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ key = (K) in.readObject();
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/batch/AutoBatchSupport.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/batch/AutoBatchSupport.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/batch/AutoBatchSupport.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -0,0 +1,45 @@
+/*
+ * 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.batch;
+
+import org.jboss.starobrno.Cache;
+
+/**
+ * Enables for automatic batching.
+ *
+ * @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
+ */
+public abstract class AutoBatchSupport
+{
+ boolean startedBatch;
+ protected Cache cache;
+
+ protected void startAtomic()
+ {
+ if (!startedBatch) startedBatch = cache.startBatch();
+ }
+
+ protected void endAtomic()
+ {
+ if (startedBatch) cache.endBatch(true);
+ }
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/batch/BatchContainer.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/batch/BatchContainer.java 2008-11-17 23:15:11 UTC (rev 7149)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/batch/BatchContainer.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -45,16 +45,23 @@
this.transactionManager = transactionManager;
}
- public void startBatch() throws CacheException
+ /**
+ * Starts a batch
+ *
+ * @return true if a batch was started; false if one was already available.
+ * @throws CacheException
+ */
+ public boolean startBatch() throws CacheException
{
try
{
- if (transactionManager.getTransaction() != null) return;
- if (batchTransactionContainer.get() == null)
+ if (transactionManager.getTransaction() == null && batchTransactionContainer.get() == null)
{
transactionManager.begin();
batchTransactionContainer.set(transactionManager.suspend());
+ return true;
}
+ return false;
}
catch (Exception e)
{
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java 2008-11-17 23:15:11 UTC (rev 7149)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -21,6 +21,8 @@
*/
package org.jboss.starobrno.commands.write;
+import org.jboss.starobrno.atomic.Delta;
+import org.jboss.starobrno.atomic.DeltaAware;
import org.jboss.starobrno.commands.Visitor;
import org.jboss.starobrno.commands.read.AbstractDataCommand;
import org.jboss.starobrno.container.MVCCEntry;
@@ -77,7 +79,21 @@
{
notifier.notifyCacheEntryModified(key, true, ctx);
MVCCEntry e = ctx.lookupEntry(key);
- Object o = e.setValue(value);
+ Object o = null;
+ if (value instanceof Delta)
+ {
+ // magic
+ Delta dv = (Delta) value;
+ Object existing = e.getValue();
+ DeltaAware toMergeWith = null;
+ if (existing instanceof DeltaAware) toMergeWith = (DeltaAware) existing;
+ e.setValue(dv.merge(toMergeWith));
+ o = existing;
+ }
+ else
+ {
+ o = e.setValue(value);
+ }
notifier.notifyCacheEntryModified(key, false, ctx);
return o;
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/RootElementBuilder.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/RootElementBuilder.java 2008-11-17 23:15:11 UTC (rev 7149)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/RootElementBuilder.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -47,8 +47,8 @@
private static final JBossEntityResolver resolver = new JBossEntityResolver();
- public static final String JBOSSCACHE_CORE_NS = "urn:jboss:jbosscache-core:config:3.0";
- public static final String JBOSSCACHE_REPO_NS = "urn:jboss:jbosscache-core:cache-repo:3.0";
+ public static final String JBOSSCACHE_CORE_NS = "urn:jboss:starobrno-core:config:1.0";
+ public static final String JBOSSCACHE_REPO_NS = "urn:jboss:starobrno-core:cache-repo:1.0";
static
{
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java 2008-11-17 23:15:11 UTC (rev 7149)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/parsing/XmlConfigurationParser.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -19,7 +19,7 @@
* 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.config.parsing;
+package org.jboss.starobrno.config.parsing;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.util.FileLookup;
@@ -29,9 +29,6 @@
import org.jboss.starobrno.config.Configuration.CacheMode;
import org.jboss.starobrno.config.ConfigurationException;
import org.jboss.starobrno.config.CustomInterceptorConfig;
-import org.jboss.starobrno.config.parsing.JGroupsStackParser;
-import org.jboss.starobrno.config.parsing.RootElementBuilder;
-import org.jboss.starobrno.config.parsing.XmlParserBase;
import org.jboss.starobrno.config.parsing.element.BuddyElementParser;
import org.jboss.starobrno.config.parsing.element.CustomInterceptorsElementParser;
import org.jboss.starobrno.config.parsing.element.EvictionElementParser;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/marshall/CacheMarshallerStarobrno.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/marshall/CacheMarshallerStarobrno.java 2008-11-17 23:15:11 UTC (rev 7149)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/marshall/CacheMarshallerStarobrno.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -24,25 +24,40 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.starobrno.CacheException;
-import org.jboss.starobrno.io.ByteBuffer;
-import org.jboss.starobrno.io.ExposedByteArrayOutputStream;
+import org.jboss.starobrno.atomic.DeltaAware;
import org.jboss.starobrno.commands.CommandsFactory;
import org.jboss.starobrno.commands.ReplicableCommand;
import org.jboss.starobrno.config.Configuration;
-import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.io.ByteBuffer;
+import org.jboss.starobrno.io.ExposedByteArrayOutputStream;
import org.jboss.starobrno.transaction.GlobalTransaction;
import org.jboss.starobrno.util.FastCopyHashMap;
import org.jboss.starobrno.util.Immutables;
import org.jboss.util.NotImplementedException;
import org.jboss.util.stream.MarshalledValueInputStream;
-import org.jboss.cache.marshall.Marshaller;
import org.jgroups.Address;
import org.jgroups.stack.IpAddress;
import org.jgroups.util.Buffer;
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.lang.reflect.Array;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.IdentityHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
/**
* Abstract AbstractMarshaller for JBoss Cache.
@@ -129,7 +144,8 @@
if (o != null && o.getClass().isArray() && isKnownType(o.getClass().getComponentType()))
{
marshallArray(o, out, refMap);
- } else
+ }
+ else
{
if (o == null)
{
@@ -163,6 +179,13 @@
out.writeByte(MAGICNUMBER_MARSHALLEDVALUE);
((MarshalledValue) o).writeExternal(out);
}
+ else if (o instanceof DeltaAware)
+ {
+ // reading in should be nothing special.
+ out.writeByte(MAGICNUMBER_SERIALIZABLE);
+ // only write the delta for these maps.
+ out.writeObject(((DeltaAware) o).delta());
+ }
else if (o instanceof GlobalTransaction)
{
out.writeByte(MAGICNUMBER_GTX);
@@ -341,7 +364,8 @@
if (loader == null)
{
return unmarshallObject(in, refMap);
- } else
+ }
+ else
{
Thread currentThread = Thread.currentThread();
ClassLoader old = currentThread.getContextClassLoader();
@@ -372,7 +396,8 @@
{
reference = readReference(in);
return refMap.getReferencedObject(reference);
- } else break;
+ }
+ else break;
case MAGICNUMBER_SERIALIZABLE:
if (useRefs) reference = readReference(in);
retVal = in.readObject();
@@ -671,7 +696,8 @@
boolean[] a = new boolean[sz];
for (int i = 0; i < sz; i++) a[i] = in.readBoolean();
return a;
- } else
+ }
+ else
{
Boolean[] a = new Boolean[sz];
for (int i = 0; i < sz; i++) a[i] = in.readBoolean();
@@ -686,7 +712,8 @@
int[] a = new int[sz];
for (int i = 0; i < sz; i++) a[i] = in.readInt();
return a;
- } else
+ }
+ else
{
Integer[] a = new Integer[sz];
for (int i = 0; i < sz; i++) a[i] = in.readInt();
@@ -701,7 +728,8 @@
long[] a = new long[sz];
for (int i = 0; i < sz; i++) a[i] = in.readLong();
return a;
- } else
+ }
+ else
{
Long[] a = new Long[sz];
for (int i = 0; i < sz; i++) a[i] = in.readLong();
@@ -716,7 +744,8 @@
char[] a = new char[sz];
for (int i = 0; i < sz; i++) a[i] = in.readChar();
return a;
- } else
+ }
+ else
{
Character[] a = new Character[sz];
for (int i = 0; i < sz; i++) a[i] = in.readChar();
@@ -739,7 +768,8 @@
bytesLeft -= read;
}
return a;
- } else
+ }
+ else
{
Byte[] a = new Byte[sz];
for (int i = 0; i < sz; i++) a[i] = in.readByte();
@@ -754,7 +784,8 @@
short[] a = new short[sz];
for (int i = 0; i < sz; i++) a[i] = in.readShort();
return a;
- } else
+ }
+ else
{
Short[] a = new Short[sz];
for (int i = 0; i < sz; i++) a[i] = in.readShort();
@@ -769,7 +800,8 @@
float[] a = new float[sz];
for (int i = 0; i < sz; i++) a[i] = in.readFloat();
return a;
- } else
+ }
+ else
{
Float[] a = new Float[sz];
for (int i = 0; i < sz; i++) a[i] = in.readFloat();
@@ -784,7 +816,8 @@
double[] a = new double[sz];
for (int i = 0; i < sz; i++) a[i] = in.readDouble();
return a;
- } else
+ }
+ else
{
Double[] a = new Double[sz];
for (int i = 0; i < sz; i++) a[i] = in.readDouble();
@@ -814,7 +847,8 @@
{
out.writeByte(MAGICNUMBER_OBJECT);
for (int i = 0; i < sz; i++) marshallObject(Array.get(o, i), out, refMap);
- } else if (arrayTypeClass.equals(byte.class) || arrayTypeClass.equals(Byte.class))
+ }
+ else if (arrayTypeClass.equals(byte.class) || arrayTypeClass.equals(Byte.class))
{
out.writeByte(MAGICNUMBER_BYTE);
out.writeBoolean(isPrim);
@@ -822,7 +856,8 @@
out.write((byte[]) o);
else
for (int i = 0; i < sz; i++) out.writeByte((Byte) Array.get(o, i));
- } else if (arrayTypeClass.equals(int.class) || arrayTypeClass.equals(Integer.class))
+ }
+ else if (arrayTypeClass.equals(int.class) || arrayTypeClass.equals(Integer.class))
{
out.writeByte(MAGICNUMBER_INTEGER);
out.writeBoolean(isPrim);
@@ -830,7 +865,8 @@
for (int i = 0; i < sz; i++) out.writeInt(Array.getInt(o, i));
else
for (int i = 0; i < sz; i++) out.writeInt((Integer) Array.get(o, i));
- } else if (arrayTypeClass.equals(long.class) || arrayTypeClass.equals(Long.class))
+ }
+ else if (arrayTypeClass.equals(long.class) || arrayTypeClass.equals(Long.class))
{
out.writeByte(MAGICNUMBER_LONG);
out.writeBoolean(isPrim);
@@ -838,7 +874,8 @@
for (int i = 0; i < sz; i++) out.writeLong(Array.getLong(o, i));
else
for (int i = 0; i < sz; i++) out.writeLong((Long) Array.get(o, i));
- } else if (arrayTypeClass.equals(boolean.class) || arrayTypeClass.equals(Boolean.class))
+ }
+ else if (arrayTypeClass.equals(boolean.class) || arrayTypeClass.equals(Boolean.class))
{
out.writeByte(MAGICNUMBER_BOOLEAN);
out.writeBoolean(isPrim);
@@ -846,7 +883,8 @@
for (int i = 0; i < sz; i++) out.writeBoolean(Array.getBoolean(o, i));
else
for (int i = 0; i < sz; i++) out.writeBoolean((Boolean) Array.get(o, i));
- } else if (arrayTypeClass.equals(char.class) || arrayTypeClass.equals(Character.class))
+ }
+ else if (arrayTypeClass.equals(char.class) || arrayTypeClass.equals(Character.class))
{
out.writeByte(MAGICNUMBER_CHAR);
out.writeBoolean(isPrim);
@@ -854,7 +892,8 @@
for (int i = 0; i < sz; i++) out.writeChar(Array.getChar(o, i));
else
for (int i = 0; i < sz; i++) out.writeChar((Character) Array.get(o, i));
- } else if (arrayTypeClass.equals(short.class) || arrayTypeClass.equals(Short.class))
+ }
+ else if (arrayTypeClass.equals(short.class) || arrayTypeClass.equals(Short.class))
{
out.writeByte(MAGICNUMBER_SHORT);
out.writeBoolean(isPrim);
@@ -862,7 +901,8 @@
for (int i = 0; i < sz; i++) out.writeShort(Array.getShort(o, i));
else
for (int i = 0; i < sz; i++) out.writeShort((Short) Array.get(o, i));
- } else if (arrayTypeClass.equals(float.class) || arrayTypeClass.equals(Float.class))
+ }
+ else if (arrayTypeClass.equals(float.class) || arrayTypeClass.equals(Float.class))
{
out.writeByte(MAGICNUMBER_FLOAT);
out.writeBoolean(isPrim);
@@ -870,7 +910,8 @@
for (int i = 0; i < sz; i++) out.writeFloat(Array.getFloat(o, i));
else
for (int i = 0; i < sz; i++) out.writeFloat((Float) Array.get(o, i));
- } else if (arrayTypeClass.equals(double.class) || arrayTypeClass.equals(Double.class))
+ }
+ else if (arrayTypeClass.equals(double.class) || arrayTypeClass.equals(Double.class))
{
out.writeByte(MAGICNUMBER_DOUBLE);
out.writeBoolean(isPrim);
@@ -878,7 +919,8 @@
for (int i = 0; i < sz; i++) out.writeDouble(Array.getDouble(o, i));
else
for (int i = 0; i < sz; i++) out.writeDouble((Double) Array.get(o, i));
- } else throw new CacheException("Unknown array type!");
+ }
+ else throw new CacheException("Unknown array type!");
}
protected boolean isKnownType(Class c)
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/tree/NodeImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/tree/NodeImpl.java 2008-11-17 23:15:11 UTC (rev 7149)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/tree/NodeImpl.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -25,7 +25,6 @@
import org.jboss.starobrno.util.Immutables;
import org.jboss.starobrno.util.Util;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -41,9 +40,9 @@
Fqn fqn;
Key dataKey, structureKey;
- public NodeImpl(Fqn fqn, Cache cache, ThreadLocal<Boolean> atomicityContainer)
+ public NodeImpl(Fqn fqn, Cache cache)
{
- super(atomicityContainer, cache);
+ super(cache);
this.fqn = fqn;
dataKey = new Key(fqn, Type.DATA);
structureKey = new Key(fqn, Type.STRUCTURE);
@@ -52,7 +51,7 @@
public Node<K, V> getParent()
{
if (fqn.isRoot()) return this;
- return new NodeImpl(fqn.getParent(), cache, batchStarted);
+ return new NodeImpl(fqn.getParent(), cache);
}
public Set<Node<K, V>> getChildren()
@@ -63,7 +62,7 @@
Set set = new HashSet();
for (Fqn f : getStructure().children.values())
{
- NodeImpl n = new NodeImpl(f, cache, batchStarted);
+ NodeImpl n = new NodeImpl(f, cache);
set.add(n);
}
return Immutables.immutableSetWrap(set);
@@ -108,7 +107,7 @@
try
{
Fqn absoluteChildFqn = Fqn.fromRelativeFqn(fqn, f);
- NodeImpl child = new NodeImpl(absoluteChildFqn, cache, batchStarted);
+ NodeImpl child = new NodeImpl(absoluteChildFqn, cache);
Structure s = getStructure();
s.children.put(f.getLastElement(), absoluteChildFqn);
updateStructure(s);
@@ -135,7 +134,7 @@
Fqn childFqn = s.children.remove(childName);
if (childFqn != null)
{
- Node child = new NodeImpl(childFqn, cache, batchStarted);
+ Node child = new NodeImpl(childFqn, cache);
child.removeChildren();
cache.remove(new Key(childFqn, Type.DATA));
cache.remove(new Key(childFqn, Type.STRUCTURE));
@@ -157,7 +156,7 @@
try
{
if (hasChild(f))
- return new NodeImpl(Fqn.fromRelativeFqn(fqn, f), cache, batchStarted);
+ return new NodeImpl(Fqn.fromRelativeFqn(fqn, f), cache);
else
return null;
}
@@ -173,7 +172,7 @@
try
{
if (hasChild(name))
- return new NodeImpl(Fqn.fromRelativeElements(fqn, name), cache, batchStarted);
+ return new NodeImpl(Fqn.fromRelativeElements(fqn, name), cache);
else
return null;
}
@@ -225,10 +224,8 @@
startAtomic();
try
{
- Map data = getData();
- V old = (V) data.put(key, value);
- putData(data);
- return old;
+ Map<K, V> data = getDataInternal();
+ return data.put(key, value);
}
finally
{
@@ -263,7 +260,6 @@
{
Map data = getDataInternal();
data.putAll(map);
- putData(data);
}
finally
{
@@ -273,7 +269,17 @@
public void replaceAll(Map<? extends K, ? extends V> map)
{
- putData(map);
+ startAtomic();
+ try
+ {
+ Map data = getDataInternal();
+ data.clear();
+ data.putAll(map);
+ }
+ finally
+ {
+ endAtomic();
+ }
}
public V get(K key)
@@ -286,10 +292,8 @@
startAtomic();
try
{
- Map data = getDataInternal();
- V old = (V) data.remove(key);
- putData(data);
- return old;
+ Map<K, V> data = getDataInternal();
+ return data.remove(key);
}
finally
{
@@ -299,7 +303,7 @@
public void clearData()
{
- putData(Collections.emptyMap());
+ getDataInternal().clear();
}
public int dataSize()
@@ -359,14 +363,9 @@
}
}
- void putData(Map m)
- {
- cache.put(dataKey, m);
- }
-
Map<K, V> getDataInternal()
{
- return (Map<K, V>) cache.get(dataKey);
+ return (Map<K, V>) atomicMapCache.getAtomicMap(dataKey);
}
void updateStructure(Structure s)
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeCacheImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeCacheImpl.java 2008-11-17 23:15:11 UTC (rev 7149)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeCacheImpl.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -42,20 +42,13 @@
{
public TreeCacheImpl(Cache<K, V> cache)
{
- super(new ThreadLocal<Boolean>()
- {
- @Override
- protected Boolean initialValue()
- {
- return false;
- }
- }, cache);
+ super(cache);
createRoot();
}
public Node<K, V> getRoot()
{
- return new NodeImpl(Fqn.ROOT, cache, batchStarted);
+ return new NodeImpl(Fqn.ROOT, cache);
}
public V put(String fqn, K key, V value)
@@ -130,7 +123,7 @@
try
{
if (exists(fqn))
- return new NodeImpl(fqn, cache, batchStarted);
+ return new NodeImpl(fqn, cache);
else return null;
}
finally
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeStructureSupport.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeStructureSupport.java 2008-11-17 23:15:11 UTC (rev 7149)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/tree/TreeStructureSupport.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -22,42 +22,23 @@
package org.jboss.starobrno.tree;
import org.jboss.starobrno.Cache;
+import org.jboss.starobrno.atomic.AtomicMapCache;
+import org.jboss.starobrno.batch.AutoBatchSupport;
import org.jboss.starobrno.util.Util;
import java.util.HashMap;
import java.util.Map;
-public class TreeStructureSupport
+public class TreeStructureSupport extends AutoBatchSupport
{
- ThreadLocal<Boolean> batchStarted;
- Cache cache;
- boolean batchOwner;
+ AtomicMapCache atomicMapCache;
- public TreeStructureSupport(ThreadLocal<Boolean> batchStarted, Cache cache)
+ public TreeStructureSupport(Cache cache)
{
- this.batchStarted = batchStarted;
this.cache = cache;
+ atomicMapCache = (AtomicMapCache) cache;
}
- void startAtomic()
- {
- if (!batchStarted.get())
- {
- cache.startBatch();
- batchStarted.set(true);
- batchOwner = true;
- }
- }
-
- void endAtomic()
- {
- if (batchOwner)
- {
- cache.endBatch(true);
- batchStarted.set(false);
- }
- }
-
public boolean exists(Fqn f)
{
startAtomic();
@@ -89,7 +70,7 @@
if (cache.containsKey(dataKey) && cache.containsKey(structureKey)) return;
Structure s = new Structure();
s.parent = fqn.getParent();
- cache.put(dataKey, new HashMap());
+ atomicMapCache.getAtomicMap(dataKey);
cache.put(structureKey, s);
}
finally
Added: core/branches/flat/src/test/java/org/jboss/starobrno/atomic/APITest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/atomic/APITest.java (rev 0)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/atomic/APITest.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -0,0 +1,254 @@
+/*
+ * 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.atomic;
+
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.transaction.DummyTransactionManager;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.Configuration.CacheMode;
+import org.jboss.starobrno.util.TestingUtil;
+import org.testng.annotations.Test;
+
+import javax.transaction.Transaction;
+import java.util.Map;
+
+@Test(groups = "functional")
+public class APITest
+{
+
+ private void assertIsEmpty(Map map)
+ {
+ assert map.size() == 0;
+ assert map.get("blah") == null;
+ assert !map.containsKey("blah");
+ }
+
+ private void assertIsEmptyMap(AtomicMapCache cache, Object key)
+ {
+ assertIsEmpty(cache.getAtomicMap(key));
+ }
+
+ public void testAtomicMap()
+ {
+ Configuration c = new Configuration();
+ c.setInvocationBatchingEnabled(true);
+ AtomicMapCache cache = (AtomicMapCache) new DefaultCacheFactory().createCache(c);
+ try
+ {
+ AtomicMap map = cache.getAtomicMap("map");
+
+ assertIsEmpty(map);
+ assertIsEmptyMap(cache, "map");
+
+ map.put("blah", "blah");
+ assert map.size() == 1;
+ assert map.get("blah").equals("blah");
+ assert map.containsKey("blah");
+
+ map.clear();
+
+ assertIsEmpty(map);
+ assertIsEmptyMap(cache, "map");
+ }
+ finally
+ {
+ cache.stop();
+ }
+ }
+
+
+ public void testReadSafetyEmptyCache() throws Exception
+ {
+ Configuration c = new Configuration();
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ c.setInvocationBatchingEnabled(true);
+ AtomicMapCache cache = (AtomicMapCache) new DefaultCacheFactory().createCache(c);
+ try
+ {
+ AtomicMap map = cache.getAtomicMap("map");
+
+ assertIsEmpty(map);
+ assertIsEmptyMap(cache, "map");
+
+ DummyTransactionManager.getInstance().begin();
+ map.put("blah", "blah");
+ assert map.size() == 1;
+ assert map.get("blah").equals("blah");
+ assert map.containsKey("blah");
+ Transaction t = DummyTransactionManager.getInstance().suspend();
+
+ assertIsEmpty(map);
+ assertIsEmptyMap(cache, "map");
+
+ DummyTransactionManager.getInstance().resume(t);
+ DummyTransactionManager.getInstance().commit();
+
+ assert map.size() == 1;
+ assert map.get("blah").equals("blah");
+ assert map.containsKey("blah");
+
+ map.clear();
+
+ assertIsEmpty(map);
+ assertIsEmptyMap(cache, "map");
+ }
+ finally
+ {
+ cache.stop();
+ }
+ }
+
+ public void testReadSafetyNotEmptyCache() throws Exception
+ {
+ Configuration c = new Configuration();
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ c.setInvocationBatchingEnabled(true);
+ AtomicMapCache cache = (AtomicMapCache) new DefaultCacheFactory().createCache(c);
+ try
+ {
+ AtomicMap map = cache.getAtomicMap("map");
+
+ DummyTransactionManager.getInstance().begin();
+ map.put("blah", "blah");
+ assert map.size() == 1;
+ assert map.get("blah").equals("blah");
+ assert map.containsKey("blah");
+ Transaction t = DummyTransactionManager.getInstance().suspend();
+
+ assertIsEmpty(map);
+ assertIsEmptyMap(cache, "map");
+
+ DummyTransactionManager.getInstance().resume(t);
+ DummyTransactionManager.getInstance().commit();
+
+ assert map.size() == 1;
+ assert map.get("blah").equals("blah");
+ assert map.containsKey("blah");
+
+ map.clear();
+
+ assertIsEmpty(map);
+ assertIsEmptyMap(cache, "map");
+ }
+ finally
+ {
+ cache.stop();
+ }
+ }
+
+ public void testReadSafetyRollback() throws Exception
+ {
+ Configuration c = new Configuration();
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ c.setInvocationBatchingEnabled(true);
+ AtomicMapCache cache = (AtomicMapCache) new DefaultCacheFactory().createCache(c);
+ try
+ {
+ AtomicMap map = cache.getAtomicMap("map");
+
+ DummyTransactionManager.getInstance().begin();
+ map.put("blah", "blah");
+ assert map.size() == 1;
+ assert map.get("blah").equals("blah");
+ assert map.containsKey("blah");
+ Transaction t = DummyTransactionManager.getInstance().suspend();
+
+ assertIsEmpty(map);
+ assertIsEmptyMap(cache, "map");
+
+ DummyTransactionManager.getInstance().resume(t);
+ DummyTransactionManager.getInstance().rollback();
+
+ assertIsEmpty(map);
+ assertIsEmptyMap(cache, "map");
+ }
+ finally
+ {
+ cache.stop();
+ }
+ }
+
+ public void testReplicationCommit() throws Exception
+ {
+ Configuration c = new Configuration();
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ c.setCacheMode(CacheMode.REPL_SYNC);
+ c.setInvocationBatchingEnabled(true);
+ AtomicMapCache cache1 = (AtomicMapCache) new DefaultCacheFactory().createCache(c.clone());
+ AtomicMapCache cache2 = (AtomicMapCache) new DefaultCacheFactory().createCache(c.clone());
+
+ try
+ {
+ TestingUtil.blockUntilViewsReceived(20000, cache1, cache2);
+ AtomicMap map = cache1.getAtomicMap("map");
+
+ DummyTransactionManager.getInstance().begin();
+ map.put("existing", "existing");
+ map.put("blah", "blah");
+ DummyTransactionManager.getInstance().commit();
+
+ assert map.size() == 2;
+ assert map.get("blah").equals("blah");
+ assert map.containsKey("blah");
+
+ System.out.println("Map on cache 2 is " + cache2.getAtomicMap("map"));
+
+ assert cache2.getAtomicMap("map").size() == 2;
+ assert cache2.getAtomicMap("map").get("blah").equals("blah");
+ assert cache2.getAtomicMap("map").containsKey("blah");
+ }
+ finally
+ {
+ TestingUtil.killCaches(cache1, cache2);
+ }
+ }
+
+ public void testReplicationRollback() throws Exception
+ {
+ Configuration c = new Configuration();
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ c.setCacheMode(CacheMode.REPL_SYNC);
+ c.setInvocationBatchingEnabled(true);
+ AtomicMapCache cache1 = (AtomicMapCache) new DefaultCacheFactory().createCache(c.clone());
+ AtomicMapCache cache2 = (AtomicMapCache) new DefaultCacheFactory().createCache(c.clone());
+
+ try
+ {
+ TestingUtil.blockUntilViewsReceived(20000, cache1, cache2);
+ AtomicMap map = cache1.getAtomicMap("map");
+
+ DummyTransactionManager.getInstance().begin();
+ map.put("existing", "existing");
+ map.put("blah", "blah");
+ DummyTransactionManager.getInstance().rollback();
+
+ assertIsEmpty(map);
+ assertIsEmptyMap(cache1, "map");
+ assertIsEmptyMap(cache2, "map");
+ }
+ finally
+ {
+ TestingUtil.killCaches(cache1, cache2);
+ }
+ }
+}
Modified: core/branches/flat/src/test/java/org/jboss/starobrno/tree/api/NodeAPITest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/tree/api/NodeAPITest.java 2008-11-17 23:15:11 UTC (rev 7149)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/tree/api/NodeAPITest.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -1,7 +1,10 @@
package org.jboss.cache.api;
+import org.jboss.cache.transaction.DummyTransactionManager;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.starobrno.CacheSPI;
import org.jboss.starobrno.UnitTestCacheFactory;
+import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.tree.Fqn;
import org.jboss.starobrno.tree.Node;
import org.jboss.starobrno.tree.TreeCache;
@@ -37,7 +40,9 @@
public void setUp() throws Exception
{
// start a single cache instance
- CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache("configs/local-tx.xml", false);
+ Configuration c = new Configuration();
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(c, false);
cache.getConfiguration().setInvocationBatchingEnabled(true);
cache.start();
cacheTL.set(new TreeCacheImpl(cache));
@@ -355,7 +360,9 @@
{
TreeCache<Object, Object> cache = cacheTL.get();
+ assert DummyTransactionManager.getInstance().getTransaction() == null;
cache.put("/foo/1/2/3", "item", 1);
+ assert DummyTransactionManager.getInstance().getTransaction() == null;
assert 1 == (Integer) cache.get("/foo/1/2/3", "item");
tm.begin();
assert 1 == (Integer) cache.get("/foo/1/2/3", "item");
Modified: core/branches/flat/src/test/java/org/jboss/starobrno/tree/api/TreeCacheAPITest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/tree/api/TreeCacheAPITest.java 2008-11-17 23:15:11 UTC (rev 7149)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/tree/api/TreeCacheAPITest.java 2008-11-17 23:26:21 UTC (rev 7150)
@@ -1,8 +1,8 @@
package org.jboss.starobrno.tree.api;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.starobrno.CacheSPI;
import org.jboss.starobrno.config.Configuration;
-import org.jboss.starobrno.config.parsing.XmlConfigurationParser;
import org.jboss.starobrno.manager.CacheManager;
import org.jboss.starobrno.tree.Fqn;
import org.jboss.starobrno.tree.Node;
@@ -33,10 +33,8 @@
public void setUp() throws Exception
{
// start a single cache instance
- XmlConfigurationParser parser = new XmlConfigurationParser();
- Configuration c;
- c = parser.parseFile("configs/local-tx.xml");
- c.setEvictionConfig(null);
+ Configuration c = new Configuration();
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
CacheManager cm = new CacheManager(c);
cache = cm.createTreeCache(getClass().getSimpleName());
16 years, 1 month
JBoss Cache SVN: r7149 - in core/trunk/src: main/java/org/jboss/cache/buddyreplication and 6 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-11-17 18:15:11 -0500 (Mon, 17 Nov 2008)
New Revision: 7149
Modified:
core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/DisabledStateTransferTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/EvictionTestsBase.java
core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderStateTransferTest.java
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncInvalidationPessLocksTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/pessimistic/ConcurrentTransactionalTest.java
Log:
various test parallelization fixes
Modified: core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-11-17 18:08:06 UTC (rev 7148)
+++ core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-11-17 23:15:11 UTC (rev 7149)
@@ -452,7 +452,7 @@
log.trace("callRemoteMethods(): valid members are " + recipients + " methods: " + command + " Using OOB? " + useOutOfBandMessage);
if (channel.flushSupported() && !flushBlockGate.await(configuration.getStateRetrievalTimeout(), TimeUnit.MILLISECONDS))
{
- throw new TimeoutException("State retrieval timed out waiting for flush unblock.");
+ throw new TimeoutException("State retrieval timed out waiting for flush unblock. (timeout = " + configuration.getStateRetrievalTimeout() + " millis) ");
}
useOutOfBandMessage = false;
RspList rsps = rpcDispatcher.invokeRemoteCommands(recipients, command, modeToUse, timeout, isUsingBuddyReplication, useOutOfBandMessage, responseFilter);
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2008-11-17 18:08:06 UTC (rev 7148)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2008-11-17 23:15:11 UTC (rev 7149)
@@ -598,8 +598,7 @@
}
/**
- * Called by CacheImpl._remoteAssignToBuddyGroup(BuddyGroup g) when a method
- * call for this is received from a remote cache.
+ * Called by {@link AssignToBuddyGroupCommand} thic command is received from a remote cache.
*
* @param newGroup the buddy group
* @param state Map<Fqn, byte[]> of any state from the DataOwner. Cannot
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java 2008-11-17 18:08:06 UTC (rev 7148)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java 2008-11-17 23:15:11 UTC (rev 7149)
@@ -53,7 +53,7 @@
// ensure that, if configured, nodes are kept alive for at least a minimum period of time.
if (isYoungerThanMinimumTimeToLive(entry))
{
- log.trace("Do not evict - is younger than minimum TTL");
+ if (trace) log.trace("Do not evict - is younger than minimum TTL");
return false;
}
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/DisabledStateTransferTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/DisabledStateTransferTest.java 2008-11-17 18:08:06 UTC (rev 7148)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/DisabledStateTransferTest.java 2008-11-17 23:15:11 UTC (rev 7149)
@@ -30,7 +30,10 @@
c.put("/" + cacheNumber++, "k", "v");
}
- TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheSPI[0]), 60000);
+ waitForBuddy(caches.get(0), caches.get(1), true);
+ waitForBuddy(caches.get(1), caches.get(2), true);
+ waitForBuddy(caches.get(2), caches.get(0), true);
+ Thread.sleep(2000);//wait for state transfer
for (CacheSPI c : caches)
System.out.println("Cache (local address " + c.getLocalAddress() + ") contents: " + CachePrinter.printCacheLockingInfo(c));
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java 2008-11-17 18:08:06 UTC (rev 7148)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java 2008-11-17 23:15:11 UTC (rev 7149)
@@ -6,10 +6,7 @@
*/
package org.jboss.cache.eviction;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Node;
-import org.jboss.cache.NodeSPI;
+import org.jboss.cache.*;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
@@ -17,7 +14,6 @@
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.util.internals.EvictionWatcher;
import org.jboss.cache.util.internals.EvictionController;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
@@ -26,8 +22,6 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.TimeUnit;
-import org.jboss.cache.UnitTestCacheFactory;
/**
* @author Daniel Huang
@@ -48,11 +42,6 @@
{
initCaches();
wakeupIntervalMillis = cache.getConfiguration().getEvictionConfig().getWakeupInterval();
- if (wakeupIntervalMillis < 0)
- {
- fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis);
- }
-
t1_ex = t2_ex = null;
isTrue = true;
}
@@ -60,7 +49,7 @@
void initCaches() throws Exception
{
Configuration conf = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
- EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new ElementSizeAlgorithmConfig(5000, 100), 200000), 200);
+ EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new ElementSizeAlgorithmConfig(5000, 100), 200000), -1);
evConfig.addEvictionRegionConfig(new EvictionRegionConfig(Fqn.fromString("/org/jboss/data"), new ElementSizeAlgorithmConfig(10, 20)));
evConfig.addEvictionRegionConfig(new EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new ElementSizeAlgorithmConfig(-1, 5)));
evConfig.addEvictionRegionConfig(new EvictionRegionConfig(Fqn.fromString("/test/"), new ElementSizeAlgorithmConfig(5000, 1)));
@@ -144,7 +133,7 @@
for (int i = 0; i < 20; i++)
{
String str = rootStr + Integer.toString(i);
- Fqn fqn = Fqn.fromString(str);
+ Fqn fqn = Fqn.fromString(str);//"/org/jboss/data/i";
cache.put(fqn, i, str);
for (int k = 0; k < i; k++)
{
@@ -178,7 +167,7 @@
Node node = cache.getNode("/org/jboss/data/3");
assertEquals(21, node.getData().size());
- assert waitForEviction(cache, 30, TimeUnit.SECONDS, Fqn.fromString("/org/jboss/data/3")) : "Eviction event not received!";
+ evictionController.startEviction();
TestingUtil.sleepThread(200); // small grace period
assertNull(cache.getNode("/org/jboss/data/3"));
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/EvictionTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/EvictionTestsBase.java 2008-11-17 18:08:06 UTC (rev 7148)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/EvictionTestsBase.java 2008-11-17 23:15:11 UTC (rev 7149)
@@ -23,7 +23,9 @@
{
Fqn fqn = Fqn.fromString(fqnString);
Configuration c = new Configuration();
- c.setEvictionConfig(new EvictionConfig());
+ EvictionConfig evictionConfig = new EvictionConfig();
+ evictionConfig.setWakeupInterval(-1);
+ c.setEvictionConfig(evictionConfig);
EvictionRegionConfig erc = new EvictionRegionConfig(fqn, config);
c.getEvictionConfig().addEvictionRegionConfig(erc);
CacheSPI mockCache = EasyMock.createNiceMock(CacheSPI.class);
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java 2008-11-17 18:08:06 UTC (rev 7148)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java 2008-11-17 23:15:11 UTC (rev 7149)
@@ -195,14 +195,14 @@
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
config.setMaxNodes(-1);
config.setTimeToLive(-1);
- config.setMaxAge(100);
+ config.setMaxAge(1000);
region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #1: ", 3, algorithm.getEvictionQueue().getNumberOfNodes());
- TestingUtil.sleepThread(110);
+ TestingUtil.sleepThread(1100);
algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #2: ", 0, algorithm.getEvictionQueue().getNumberOfNodes());
}
@@ -212,7 +212,7 @@
*
* @throws Exception
*/
- public void testMaxAgeSeconds2() throws EvictionException
+ public void testMaxAgeSeconds2() throws Throwable
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
@@ -221,17 +221,17 @@
config.setMaxNodes(-1);
config.setTimeToLive(-1);
- config.setMaxAge(100);
+ config.setMaxAge(1000);
region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #1: ", 3, algorithm.getEvictionQueue().getNumberOfNodes());
- TestingUtil.sleepThread(50);
+ TestingUtil.sleepThread(500);
algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #2: ", 3, algorithm.getEvictionQueue().getNumberOfNodes());
- TestingUtil.sleepThread(60);
+ TestingUtil.sleepThread(600);
algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #3: ", 0, algorithm.getEvictionQueue().getNumberOfNodes());
}
@@ -249,8 +249,8 @@
// Should have a maximum of 2 nodes.
config.setMaxNodes(2);
- config.setTimeToLive(100);
- config.setMaxAge(300);
+ config.setTimeToLive(1000);
+ config.setMaxAge(3000);
region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn4, EvictionEvent.Type.ADD_NODE_EVENT);
@@ -262,7 +262,7 @@
assert 2 == numNodesInQueue : "Queue size #1: expected 2 but was " + numNodesInQueue;
// make sure all nodes now expire
- TestingUtil.sleepThread(110);
+ TestingUtil.sleepThread(1100);
region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
@@ -271,7 +271,7 @@
numNodesInQueue = eq.getNumberOfNodes();
assert 1 == numNodesInQueue : "Queue size #2: expected 1 but was " + numNodesInQueue;
- TestingUtil.sleepThread(310);
+ TestingUtil.sleepThread(3100);
// visit the node now to prevent the idle time from doing the pruning - node still gets pruned but by
// max age.
region.registerEvictionEvent(fqn3, EvictionEvent.Type.VISIT_NODE_EVENT);
@@ -293,8 +293,8 @@
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
config.setMaxNodes(2);
- config.setTimeToLive(100);
- config.setMaxAge(300);
+ config.setTimeToLive(1000);
+ config.setMaxAge(3000);
region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, EvictionEvent.Type.REMOVE_NODE_EVENT);
@@ -306,7 +306,7 @@
assert 1 == numNodesInQueue : "Queue size #1: expected 1 but was " + numNodesInQueue;
// make sure existing events all time out
- TestingUtil.sleepThread(110);
+ TestingUtil.sleepThread(1100);
region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
algorithm.process(region.getEvictionEventQueue());
@@ -314,7 +314,7 @@
numNodesInQueue = eq.getNumberOfNodes();
assert 1 == numNodesInQueue : "Queue size #2: expected 1 but was " + numNodesInQueue;
- TestingUtil.sleepThread(310);
+ TestingUtil.sleepThread(3100);
region.registerEvictionEvent(fqn3, EvictionEvent.Type.VISIT_NODE_EVENT);
algorithm.process(region.getEvictionEventQueue());
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java 2008-11-17 18:08:06 UTC (rev 7148)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java 2008-11-17 23:15:11 UTC (rev 7149)
@@ -34,11 +34,11 @@
public class LRUPolicyTest extends EvictionTestsBase
{
CacheSPI<Object, Object> cache;
- long wakeupIntervalMillis = 200;
- long dataRegionTTLMillis = 200;
- long testRegionTTLMillis = 200;
+ long wakeupIntervalMillis = 1000;
+ long dataRegionTTLMillis = 1000;
+ long testRegionTTLMillis = 1000;
private int baseRegionMaxNodes = 10;
- private int baseRegionTTLMillis = 200;
+ private int baseRegionTTLMillis = 1000;
final String ROOT_STR = "/test";
Throwable t1_ex, t2_ex;
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java 2008-11-17 18:08:06 UTC (rev 7148)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java 2008-11-17 23:15:11 UTC (rev 7149)
@@ -16,6 +16,7 @@
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.internals.EvictionController;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -27,7 +28,7 @@
* @author Daniel Huang (dhuang(a)jboss.org)
* @version $Revision$
*/
-@Test(groups = {"functional"}, sequential = true, testName = "eviction.MRUPolicyTest")
+@Test(groups = {"functional"}, testName = "eviction.MRUPolicyTest")
public class MRUPolicyTest
{
CacheSPI<Object, Object> cache;
@@ -82,7 +83,7 @@
cache.put("/org/jboss/test/data/d", "/org/jboss/test/data/d", "/org/jboss/test/data/d");
cache.put("/org/jboss/test/data/e", "/org/jboss/test/data/e", "/org/jboss/test/data/e");
- TestingUtil.sleepThread(wakeupIntervalMillis + 500);
+ TestingUtil.sleepThread(wakeupIntervalMillis + 800);
cache.put("/org/jboss/test/data/f", "/org/jboss/test/data/f", "/org/jboss/test/data/f");
cache.put("/org/jboss/test/data/g", "/org/jboss/test/data/g", "/org/jboss/test/data/g");
@@ -90,7 +91,7 @@
assertNotNull(cache.get("/org/jboss/test/data/a", "/org/jboss/test/data/a"));
assertNotNull(cache.get("/org/jboss/test/data/b", "/org/jboss/test/data/b"));
- TestingUtil.sleepThread(wakeupIntervalMillis + 500);
+ TestingUtil.sleepThread(wakeupIntervalMillis + 800);
assertNull(cache.get("/org/jboss/test/data/a", "/org/jboss/test/data/a"));
assertNull(cache.get("/org/jboss/test/data/b", "/org/jboss/test/data/b"));
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2008-11-17 18:08:06 UTC (rev 7148)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2008-11-17 23:15:11 UTC (rev 7149)
@@ -28,7 +28,7 @@
*
* @author fhenning
*/
-@Test(groups = {"functional"}, sequential = true, testName = "eviction.OptimisticEvictionTest")
+@Test(groups = {"functional"}, testName = "eviction.OptimisticEvictionTest")
public class OptimisticEvictionTest extends EvictionTestsBase
{
private CacheSPI<Object, Object> cache;
@@ -46,7 +46,7 @@
{
EvictionConfig result = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new LRUAlgorithmConfig(0, 0, 10)), 200);
result.addEvictionRegionConfig(new EvictionRegionConfig(Fqn.fromString("/testingRegion"), new LRUAlgorithmConfig(0, 0, 10)));
- result.addEvictionRegionConfig(new EvictionRegionConfig(Fqn.fromString("/timeBased"), new LRUAlgorithmConfig(1, 1, 0)));
+ result.addEvictionRegionConfig(new EvictionRegionConfig(Fqn.fromString("/timeBased"), new LRUAlgorithmConfig(1000, 1000, 0)));
return result;
}
@@ -57,12 +57,11 @@
cache = null;
}
- @Test(invocationCount = 10)
public void testEvictionOccurence() throws Exception
{
cache.put("/timeBased/test", "key", "value");
assertTrue(cache.exists("/timeBased/test"));
- TestingUtil.sleepThread(100);
+ TestingUtil.sleepThread(2000);
new EvictionController(cache).startEviction();
assertTrue(!cache.exists("/timeBased/test"));
}
Modified: core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderStateTransferTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderStateTransferTest.java 2008-11-17 18:08:06 UTC (rev 7148)
+++ core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderStateTransferTest.java 2008-11-17 23:15:11 UTC (rev 7149)
@@ -63,6 +63,7 @@
clc.getFirstCacheLoaderConfig().setPurgeOnStartup(true);
c.setCacheLoaderConfig(clc);
c.setCacheMode(CacheMode.REPL_SYNC);
+ c.setStateRetrievalTimeout(1000 * 120);//allow 2 minutes for before state transfer timeouts
return c;
}
Modified: core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncInvalidationPessLocksTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncInvalidationPessLocksTest.java 2008-11-17 18:08:06 UTC (rev 7148)
+++ core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/AsyncInvalidationPessLocksTest.java 2008-11-17 23:15:11 UTC (rev 7149)
@@ -31,4 +31,9 @@
{
TestingUtil.sleepThread(500);
}
+
+ public void testPutKeyValueViaNodeAPI() throws Exception
+ {
+ super.testPutDataViaNodeAPI();
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/pessimistic/ConcurrentTransactionalTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/pessimistic/ConcurrentTransactionalTest.java 2008-11-17 18:08:06 UTC (rev 7148)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/pessimistic/ConcurrentTransactionalTest.java 2008-11-17 23:15:11 UTC (rev 7149)
@@ -36,7 +36,7 @@
*
* @version $Id$
*/
-@Test(groups = {"functional", "transaction"}, sequential = true, testName = "transaction.pessimistic.ConcurrentTransactionalTest")
+@Test(groups = {"functional", "transaction"}, testName = "transaction.pessimistic.ConcurrentTransactionalTest")
public class ConcurrentTransactionalTest
{
private CacheSPI<Integer, String> cache;
@@ -51,7 +51,7 @@
private void createCache(IsolationLevel level)
{
- Configuration conf = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
+ Configuration conf = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, false);
conf.setCacheMode(Configuration.CacheMode.LOCAL);
conf.setIsolationLevel(level);
conf.setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
@@ -118,7 +118,7 @@
System.out.println("keys: " + l);
for (int i = 0; i < NUM; i++)
{
- if (!l.contains(new Integer(i)))
+ if (!l.contains(i))
{
System.out.println("missing: " + i);
}
16 years, 1 month
JBoss Cache SVN: r7148 - in core/trunk/src: test/java/org/jboss/cache/buddyreplication and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-11-17 13:08:06 -0500 (Mon, 17 Nov 2008)
New Revision: 7148
Modified:
core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyPoolBroadcastTest.java
core/trunk/src/test/resources/unit-test-cache-service.xml
Log:
fix tests
Modified: core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java 2008-11-17 16:07:21 UTC (rev 7147)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java 2008-11-17 18:08:06 UTC (rev 7148)
@@ -29,9 +29,7 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.ComponentRegistry;
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
+import javax.management.*;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.List;
@@ -135,7 +133,14 @@
ObjectName objectName = new ObjectName(getObjectName(resourceName));
if (!mBeanServer.isRegistered(objectName))
{
- mBeanServer.registerMBean(resource, objectName);
+ try
+ {
+ mBeanServer.registerMBean(resource, objectName);
+ }
+ catch (InstanceAlreadyExistsException e)
+ {
+ log.warn("There same instance is already registred!", e);
+ }
}
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyPoolBroadcastTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyPoolBroadcastTest.java 2008-11-17 16:07:21 UTC (rev 7147)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyPoolBroadcastTest.java 2008-11-17 18:08:06 UTC (rev 7148)
@@ -138,40 +138,61 @@
public void testConcurrency() throws Exception
{
- log.debug("Running testConcurrency");
- int numCaches = 4;
- List<CacheSPI<Object, Object>> caches = new ArrayList<CacheSPI<Object, Object>>(4);
- cachesTL.set(caches);
- CountDownLatch latch = new CountDownLatch(1);
- CacheStarter[] starters = new CacheStarter[numCaches];
+ int numCaches = 4;
+ List<CacheSPI<Object, Object>> caches = new ArrayList<CacheSPI<Object, Object>>(4);
+ cachesTL.set(caches);
+ CountDownLatch latch = new CountDownLatch(1);
+ CacheStarter[] starters = new CacheStarter[numCaches];
- for (int i = 0; i < numCaches; i++)
- {
- caches.add(createCache(1, new String(new char[]{(char) ('A' + i)}), false, false));
- starters[i] = new CacheStarter("CacheStarter-" + i, latch, caches.get(i));
- starters[i].start();
- }
+ for (int i = 0; i < numCaches; i++)
+ {
+ caches.add(createCache(1, new String(new char[]{(char) ('A' + i)}), false, false));
+ starters[i] = new CacheStarter("CacheStarter-" + i, latch, caches.get(i));
+ starters[i].start();
+ }
- // now have the lot start simultaneously
-// TestingUtil.sleepThread(500);
- latch.countDown();
+ // now have the lot start simultaneously
+ latch.countDown();
- // allow a generous sleep time
- TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheSPI[0]), 240000);
- TestingUtil.sleepThread(1000 * numCaches); // the max timeout we can expect is 2500ms * 10 nodes
+ // allow a generous sleep time
+ TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheSPI[0]), 240000);
- // and now look at the state of things.
- Map map = caches.get(0).getBuddyManager().buddyPool;
- System.out.println(map);
- for (int i = 0; i < numCaches; i++)
- {
- if (caches.get(i) != null)
- assertEquals("Failed on cache " + i + "(" + caches.get(i).getLocalAddress() + ")", new String(new char[]{(char) ('A' + i)}), map.get(caches.get(i).getLocalAddress()));
- else
- System.out.println("Cache " + i + " is null!??");
- }
- checkConsistentPoolState(caches);
+ long timeout = System.currentTimeMillis() + 5000 * numCaches;
+ while (System.currentTimeMillis() < timeout)
+ {
+ boolean allPoolNameBroadcasted = true;
+ for (int i = 0; i < numCaches; i++)
+ {
+ boolean receivedFromAll = caches.get(i).getBuddyManager().buddyPool.size() == numCaches;
+ allPoolNameBroadcasted &= receivedFromAll;
+ }
+ if (allPoolNameBroadcasted)
+ {
+ System.out.println("Received from all!!!");
+ break;
+ }
+ if (System.currentTimeMillis() >= timeout)
+ {
+ log.error("********* pool membership was not brodcasted in " + (timeout - System.currentTimeMillis()) + " millis!");
+
+ assert false : "pool membership was not brodcasted in " + timeout + " millis!";
+ }
+ Thread.sleep(50);
+ }
+
+ //and now look at the state of things.
+ Map map = caches.get(0).getBuddyManager().buddyPool;
+ System.out.println(map);
+ for (int i = 0; i < numCaches; i++)
+ {
+ if (caches.get(i) != null)
+ assertEquals("Failed on cache " + i + "(" + caches.get(i).getLocalAddress() + ")", new String(new char[]{(char) ('A' + i)}), map.get(caches.get(i).getLocalAddress()));
+ else
+ System.out.println("Cache " + i + " is null!??");
+ }
+
+ checkConsistentPoolState(caches);
}
public class CacheStarter extends Thread
Modified: core/trunk/src/test/resources/unit-test-cache-service.xml
===================================================================
--- core/trunk/src/test/resources/unit-test-cache-service.xml 2008-11-17 16:07:21 UTC (rev 7147)
+++ core/trunk/src/test/resources/unit-test-cache-service.xml 2008-11-17 18:08:06 UTC (rev 7148)
@@ -121,7 +121,7 @@
max_bundle_timeout="30"
use_incoming_packet_handler="true"
ip_ttl="2"
- enable_bundling="true"
+ enable_bundling="false"
enable_diagnostics="true"
use_concurrent_stack="true"
@@ -257,7 +257,7 @@
max_bundle_size="64000"
max_bundle_timeout="30"
use_incoming_packet_handler="true"
- enable_bundling="true"
+ enable_bundling="false"
use_send_queues="false"
sock_conn_timeout="300"
skip_suspected_members="true"
16 years, 1 month
JBoss Cache SVN: r7147 - core/trunk.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-11-17 11:07:21 -0500 (Mon, 17 Nov 2008)
New Revision: 7147
Modified:
core/trunk/pom.xml
Log:
UPdated JGroups
Modified: core/trunk/pom.xml
===================================================================
--- core/trunk/pom.xml 2008-11-17 16:06:32 UTC (rev 7146)
+++ core/trunk/pom.xml 2008-11-17 16:07:21 UTC (rev 7147)
@@ -27,7 +27,7 @@
<dependency>
<groupId>jgroups</groupId>
<artifactId>jgroups</artifactId>
- <version>2.6.5.GA</version>
+ <version>2.6.7.GA</version>
</dependency>
<!-- For the JTA 1.1 API; consuming projects can safely
@@ -449,7 +449,7 @@
<dependency>
<groupId>jgroups</groupId>
<artifactId>jgroups</artifactId>
- <version>2.6.5.GA</version>
+ <version>2.6.7.GA</version>
</dependency>
<!-- Replaces javax.transaction/jta -->
<dependency>
16 years, 1 month