JBossCache 2.0.0的使用及注意事项

作者:lizongbo 发表于:15:42. 星期一, 十一月 5th, 2007
版权声明:可以任意转载,转载时请务必以超链接形式标明文章和作者信息及本版权声明。

2.0.0的使用及注意事项

1.首先是下载 JBossCache 2.0.0 GA.
下载地址为 :http://jaist.dl.sourceforge.net/sourceforge/jboss/JBossCache-all-2.0.0.GA.zip

来源 : http://sourceforge.net/project/showfiles.php?group_id=22866&package_id=102339

(目前最新版为: JBossCache 2.1.0.CR1 http://jaist.dl.sourceforge.net/sourceforge/jboss/jbosscache-core-2.1.0.CR1-all.zip)

2.解压到 D:\Java\JBossCache-all-2.0.0.GA。
D:\Java\JBossCache-all-2.0.0.GA\lib下是JbossCache需要用到的lib。

D:\Java\JBossCache-all-2.0.0.GA\docs\JBossCache-UserGuide\en\pdf\JBossCache-UserGuide.pdf是用户手册。
3.创建 Cache可以通过配置文件和默认的Cache工厂 。

[code]
XmlConfigurationParser parser = new XmlConfigurationParser();
Configuration conf = parser.parseFile("E://JbossCacheservice.xml");
cache = DefaultCacheFactory.getInstance().createCache(conf, true);
[/code]

不过我遇到过郁闷的问题:
[code]
XmlConfigurationParser parser = new XmlConfigurationParser();
Configuration conf = parser.parseFile("E://JbossCacheservice.xml");
DefaultCacheFactory dcf=DefaultCacheFactory.getInstance();
Cache cache = dcf.createCache(conf, true);
[/code]
用DefaultCacheFactory.getInstance()来获取CacheFactory,却编译不了,会被提示:
“TestJbossCache.java”: incompatible types; no instance(s) of type variable(s) K,V exist so that org.jboss.cache.CacheFactory<K,V> conforms to org.jboss.cache.DefaultCacheFactory; found : <K,V>org.jboss.cache.CacheFactory<K,V>, required: org.jboss.cache.DefaultCacheFactory at line 13, column 49
4.配置文件

由于jbossCache 2.0 与 1.4 版本相比 变化较大,很多属性配置都已经被废弃或使用新的属性配置来代替了 。

CacheLoaderConfiguration被CacheLoaderConfig替代了。

集群的配置参数也有所变化 。

2007-11-05 10:59:24,671 WARN [org.jboss.cache.factories.XmlConfigurationParser]
- <Found non-existent JBC 1.x attribute ‘CacheLoaderConfiguration’ and replaced with ‘CacheLoaderConfig’. Please update your config to use the new attribute name>

缓存启动的时候不会把缓存在文件的内容加载到内存,如果此时遍历缓存节点,cache.getRoot()将得不到节点信息。
5.java测试代码:

[code]
package com.lizongbo.jbosscache;

import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Cache;

import java.util.*;

public class TestJbossCacheMaster {
public static void main(String[] args) throws InterruptedException {
XmlConfigurationParser parser = new XmlConfigurationParser();
Configuration conf = parser.parseFile("E://JbossCacheservice_master.xml");
Cache cache = DefaultCacheFactory.getInstance().createCache(conf, true);
Fqn fqn = Fqn.fromString("/domains/nsinfo");
JbossCacheTestListener listener = new JbossCacheTestListener();
cache.addCacheListener(listener);
System.out.println(" root is:" + cache.getRoot());
System.out.println("缓存的 name server为: " + cache.get(fqn, "618119.com"));
System.out.println(" after cache.get root is:" + cache.getRoot());
List<String> l = new ArrayList<String> ();
l.add("ns1.dnspod.net");
l.add("ns2.dnspod.net");
l.add("ns3.dnspod.net");
l.add("ns4.dnspod.net");
l.add("ns5.dnspod.net");
l.add("ns6.dnspod.net");
cache.put(fqn, "618119.com", l);
System.out.println("缓存的 name server为: " + cache.get(fqn, "618119.com"));
Thread.sleep(500000);
}
}
[/code]

xml配置文件:

[code]

<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.cache.jmx.CacheJmxWrapper" name="jboss.cache:service=Cache">
<depends>jboss:service=Naming</depends>
<depends>jboss:service=TransactionManager</depends>
<attribute name="TransactionManagerLookupClass">org.jboss.cache.transaction.GenericTransactionManagerLookup</attribute>
<attribute name="IsolationLevel">REPEATABLE_READ</attribute>
<attribute name="CacheMode">REPL_ASYNC</attribute>
<attribute name="UseReplQueue">false</attribute>
<attribute name="ReplQueueInterval">0</attribute>
<attribute name="ReplQueueMaxElements">0</attribute>
<attribute name="ClusterName">JBossCache-Cluster</attribute>
<depends optional-attribute-name="MultiplexerService"
proxy-type="attribute">jgroups.mux:name=Multiplexer</depends>
<attribute name="MultiplexerStack">udp</attribute>
<attribute name="ClusterConfig">
<config>
<UDP mcast_addr="228.1.2.3" mcast_port="48866"
ip_ttl="64" ip_mcast="true"
mcast_send_buf_size="150000" mcast_recv_buf_size="80000"
ucast_send_buf_size="150000" ucast_recv_buf_size="80000"
loopback="false"/>
<PING timeout="2000" num_initial_members="3"
up_thread="false" down_thread="false"/>
<MERGE2 min_interval="10000" max_interval="20000"/>
<FD_SOCK/>
<VERIFY_SUSPECT timeout="1500"
up_thread="false" down_thread="false"/>
<pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800"
max_xmit_size="8192" up_thread="false" down_thread="false"/>
<UNICAST timeout="600,1200,2400" down_thread="false"/>
<pbcast.STABLE desired_avg_gossip="20000"
up_thread="false" down_thread="false"/>
<pbcast.GMS join_timeout="5000" join_retry_timeout="2000"
shun="true" print_local_addr="true"/>
<FC max_credits="2000000" down_thread="false" up_thread="false"
min_threshold="0.20"/>
<FRAG frag_size="8192" down_thread="false" up_thread="true"/>
<pbcast.STATE_TRANSFER up_thread="true" down_thread="true"/>
</config>
</attribute>
<attribute name="InitialStateRetrievalTimeout">20000</attribute>
<attribute name="SyncReplTimeout">20000</attribute>
<attribute name="LockAcquisitionTimeout">15000</attribute>
<attribute name="FetchInMemoryState">false</attribute>
<attribute name="CacheLoaderConfig">
<config>
<passivation>false</passivation>
<shared>false</shared>
<cacheloader>
<class>org.jboss.cache.loader.FileCacheLoader</class>
<properties>
location=/tmp/filecacheloader_master
</properties>
<async>false</async>
<fetchPersistentState>false</fetchPersistentState>
<ignoreModifications>false</ignoreModifications>
<purgeOnStartup>false</purgeOnStartup>
</cacheloader>
</config>
</attribute>
</mbean>
</server>

[/code]

Tags: ,

标签: ,


分享到 Google Buzz
点此分享到QQ空间
点此分享到腾讯微博

与《JBossCache 2.0.0的使用及注意事项》相关的搜索:

留下回复