Ehcache使用TCP进行Jgroups复制

时间:2015-01-09 06:40:04

标签: java eclipse replication ehcache jgroups

我正在尝试使用Ehcache中的Jgroups设置复制缓存。我在缓存集群时遇到问题。我在eclipse中创建了2个项目,每个项目都引用了不同的ehcache.xml配置文件。

两个配置文件都是相同的,并且给出了beolw。

<?xml version="1.0"?>

<cacheManagerPeerProviderFactory
    class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
    properties="connect=TCP(bind_port=7800):
    TCPPING(initial_hosts=localhost[7800],localhost[7801];port_range=10;timeout=3000;
    num_initial_members=3):
    VERIFY_SUSPECT(timeout=1500):
    pbcast.NAKACK(retransmit_timeout=3000):
    pbcast.GMS(join_timeout=50000;print_local_addr=true)"
propertySeparator="::" />

 <cache name="sampleCache"
        maxElementsInMemory="1000000"
        eternal="true"
        overflowToDisk="false">
        <cacheEventListenerFactory
        class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
        properties="replicateAsynchronously=true"/>
</cache>

我在类路径中使用以下jar文件。

-ehcache-2.9.0.jar -ehcache-jgroupsreplication-1.7.jar -jgroups-3.6.0.Final.jar -log4j-1.2.16

当我运行程序时,project1显示

63511 [main] DEBUG org.jgroups.protocols.pbcast.NAKACK  - 
[SBSPBWSVM110-42986 setDigest()]
existing digest:  []
new digest:       SBSPBWSVM110-42986: [0 (0)]
resulting digest: SBSPBWSVM110-42986: [0 (0)]
63511 [main] DEBUG org.jgroups.protocols.pbcast.GMS  - SBSPBWSVM110-42986: installing view [SBSPBWSVM110-42986|0] (1) [SBSPBWSVM110-42986]
63543 [main] DEBUG org.jgroups.protocols.pbcast.GMS  - SBSPBWSVM110-42986: created cluster (first member). My view is [SBSPBWSVM110-42986|0], impl is org.jgroups.protocols.pbcast.CoordGmsImpl
Jan 09, 2015 11:49:51 AM net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProvider init

INFO:JGroups Replication started for 'EH_CACHE'. JChannel: local_addr=SBSPBWSVM110-42986
cluster_name=EH_CACHE
my_view=[SBSPBWSVM110-42986|0] (1) [SBSPBWSVM110-42986]
state=CONNECTED
discard_own_messages=true
state_transfer_supported=false

当我运行程序时,project2显示

63451 [main] DEBUG org.jgroups.protocols.pbcast.NAKACK  - 
[SBSPBWSVM110-20554 setDigest()]
existing digest:  []
new digest:       SBSPBWSVM110-20554: [0 (0)]
resulting digest: SBSPBWSVM110-20554: [0 (0)]
63451 [main] DEBUG org.jgroups.protocols.pbcast.GMS  - SBSPBWSVM110-20554: installing view [SBSPBWSVM110-20554|0] (1) [SBSPBWSVM110-20554]
63452 [main] DEBUG org.jgroups.protocols.pbcast.GMS  - SBSPBWSVM110-20554: created cluster (first member). My view is [SBSPBWSVM110-20554|0], impl is org.jgroups.protocols.pbcast.CoordGmsImpl
Jan 09, 2015 11:49:51 AM net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProvider init

INFO: JGroups Replication started for 'EH_CACHE'. JChannel: local_addr=SBSPBWSVM110-20554
cluster_name=EH_CACHE
my_view=[SBSPBWSVM110-20554|0] (1) [SBSPBWSVM110-20554]
state=CONNECTED
discard_own_messages=true
state_transfer_supported=false

但是复制根本就没有发生。我已经使用Ehcache完成了RMIreplication,并且也遵循相同的方法。所以我假设我的java代码没有任何问题。

我无法在这里找到问题。我的配置错了吗?请帮我解决这个问题..

1 个答案:

答案 0 :(得分:2)

您使用的配置很奇怪:它正在修改某些协议。 Can&#thhcache可以引用JGroups配置文件,例如udp.xml? 您还可以在TCP中设置bind_addr或使用-Djgroups.bind_addr = 1.2.3.4,其中1.2.3.4是网络接口。 然后,在TCPPING.initial_hosts中,您需要列出具有您在上面使用的绑定地址的所有成员,例如1.2.3.4 [7800],5.6.7.8 [7800]等。