[jboss-user] [JBoss Cache: Core Edition] - Writing custom Async Loader
do-not-reply at jboss.com
Wed Feb 18 06:42:14 EST 2009
First a little intro to my persistence problem:
I'm writing data to a couple of different nodes in JBoss Cache. I'm doing this in a batch (afaik this is interpreted as a transaction by JBoss) since the different cache nodes in fact contain a memory snapshot of a parsing process.
The parsing process is fast, that is, there can be lots of put operations per second. Thus I use async. replication, to replicate the data only every ~500ms. The problem is, I do not need the database to be hit that often. It would be absolutely sufficient to write the last snapshot (without the intermediate stages) to the DB every 5 seconds. I cannot see any possibility to do this without custom coding.
First I tried "cache.getInvocationContext().getOptionOverrides().setSuppressPersistence(true);" but this does not work for transactions. (Even if it worked, I still would have the little issue that if I suppress persistence for 5 seconds, and the parsing stopped for a while, the last message would not be persisted (because suppression is on), even if 10 hours had passed. But I could live with that.)
Then I tried to write a custom cache loader based on the async loader. I tried both: extending AbstractDelegatingCacheLoader and extending AsyncCacheLoader.
But start() e.g. never gets called in my implementation. I inserted log outputs in multiple methods. When the constructor is invoked, log output appears. Also, for setConfig(), and setCache() I can produce log output. But start() is never invoked. Nor are any of the put() methods invoked. Persistence via JDBC works, though.
This is a cache configuration xml fragment:
| <loaders passivation="false" shared="true">
| <loader class="mypackage.CustomJDBCCacheLoader" async="false" fetchPersistentState="false"
| ignoreModifications="false" purgeOnStartup="false">
So, does anybody know why start() isn't invoked by the framework?
| import org.apache.commons.logging.LogFactory;
| public class CustomJDBCCacheLoader extends org.jboss.cache.loader.AsyncCacheLoader
| private static final Log log = LogFactory.getLog(CustomJDBCCacheLoader.class);
| public CustomJDBCCacheLoader()
| super(new org.jboss.cache.loader.JDBCCacheLoader());
| log.info("ASYNC JDBC LOADER Constructor");
| public void start() throws Exception
| log.info("-----------------Async cache loader starting: " + this);
| System.out.println("-----------------Async cache loader starting: " + this);
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4211033#4211033
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4211033
More information about the jboss-user