【问题标题】:RMI replication with unicast of ehcache does not work使用 ehcache 单播的 RMI 复制不起作用
【发布时间】:2023-10-15 19:31:01
【问题描述】:

这是我在 10.0.110.134 机器上的 ehcache 配置 xml:

    <cache name="sessionIds" maxElementsInMemory="5000" eternal="false"
            overflowToDisk="false" timeToIdleSeconds="0" timeToLiveSeconds="0"
            memoryStoreEvictionPolicy="LRU">
<bootstrapCacheLoaderFactory
            class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"/>

    </cache>

    <!-- Cluster Configuration -->

        <cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,
rmiUrls=//10.0.110.133:40001/sessionIds"/>


<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=10.0.110.134, port=40001,
 socketTimeoutMillis=20000"/>

这是我在启动两台机器后遇到的错误:

DEBUG ConfigurationFactory - Configuring ehcache from InputStream
[MyAPP] 01 Sep 2015 12:36:58 DEBUG CacheManager - Creating new   CacheManager with Configuration Object
[MyAPP] 01 Sep 2015 12:36:58 DEBUG PropertyUtil - propertiesString is   null.
[MyAPP] 01 Sep 2015 12:36:58 DEBUG ConfigurationHelper - No CacheManagerEventListenerFactory class specified. Skipping...
[MyAPP] 01 Sep 2015 12:36:58 DEBUG PropertyUtil - Value found for hostName: 10.0.110.134
[MyAPP] 01 Sep 2015 12:36:58 DEBUG PropertyUtil - Value found for port: 40001
[MyAPP] 01 Sep 2015 12:36:58 DEBUG PropertyUtil - Value found for remoteObjectPort: null
[MyAPP] 01 Sep 2015 12:36:58 DEBUG PropertyUtil - Value found for socketTimeoutMillis: 20000
[MyAPP] 01 Sep 2015 12:36:58 DEBUG PropertyUtil - Value found for peerDiscovery: manual
[MyAPP] 01 Sep 2015 12:36:58 DEBUG PropertyUtil - Value found for rmiUrls: //10.0.110.133:40001/sessionIds
[MyAPP] 01 Sep 2015 12:36:58 DEBUG RMICacheManagerPeerProviderFactory - Registering peer //10.0.110.133:40001/sessionIds
[MyAPP] 01 Sep 2015 12:36:58 DEBUG RMICacheManagerPeerListener - 0 RMICachePeers bound in registry for RMI listener
[MyAPP] 01 Sep 2015 12:36:58 DEBUG PropertyUtil - propertiesString is null.
[MyAPP] 01 Sep 2015 12:36:58 DEBUG Cache - CacheWriter factory not configured. Skipping...
[MyAPP] 01 Sep 2015 12:36:58 DEBUG ConfigurationHelper - No CacheExceptionHandlerFactory class specified. Skipping...
[MyAPP] 01 Sep 2015 12:36:58 DEBUG MemoryStore - Initialized    net.sf.ehcache.store.NotifyingMemoryStore for sessionIds
[MyAPP] 01 Sep 2015 12:36:58 DEBUG Cache - Initialised cache: sessionIds
[MyAPP] 01 Sep 2015 12:36:58 DEBUG RMICacheManagerPeerListener - Adding to RMI listener
[MyAPP] 01 Sep 2015 12:36:58 DEBUG RMICacheManagerPeerListener - 0 RMICachePeers bound in registry for RMI listener
[MyAPP] 01 Sep 2015 12:36:58 DEBUG ConfigurationHelper - CacheDecoratorFactory not configured. Skipping for 'sessionIds'.
[MyAPP] 01 Sep 2015 12:36:58 DEBUG ConfigurationHelper - CacheDecoratorFactory not configured for defaultCache. Skipping for   'sessionIds'.
[MyAPP] 01 Sep 2015 12:36:58 DEBUG RMIBootstrapCacheLoader - Attempting to acquire cache peers for cache sessionIds to bootstrap from. Will wait up to  0ms for cache to join cluster.
[MyAPP] 01 Sep 2015 12:36:58 DEBUG RMICacheManagerPeerProvider - Lookup URL //10.0.110.133:40001/sessionIds
[MyAPP] 01 Sep 2015 12:36:58 DEBUG ManualRMICacheManagerPeerProvider - Looking up rmiUrl //10.0.110.133:40001/sessionIds through exception sessionIds. This may be normal if a node has gone offline. Or it may indicate network connectivity difficulties
java.rmi.NotBoundException: sessionIds
    at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:137)
    at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
    at   sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:409)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
    at sun.rmi.transport.Transport$2.run(Transport.java:202)
    at sun.rmi.transport.Transport$2.run(Transport.java:199)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:198)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:567)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.access$400(TCPTransport.java:619)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$1.run(TCPTransport.java:684)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$1.run(TCPTransport.java:681)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:681)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:275)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:252)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:378)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at java.rmi.Naming.lookup(Naming.java:101)
    at net.sf.ehcache.distribution.RMICacheManagerPeerProvider.lookupRemoteCachePeer(RMICacheManagerPeerProvider.java:127)
    at net.sf.ehcache.distribution.ManualRMICacheManagerPeerProvider.listRemoteCachePeers(ManualRMICacheManagerPeerProvider.java:95)
    at net.sf.ehcache.distribution.RMIBootstrapCacheLoader.listRemoteCachePeers(RMIBootstrapCacheLoader.java:245)
    at net.sf.ehcache.distribution.RMIBootstrapCacheLoader.acquireCachePeers(RMIBootstrapCacheLoader.java:198)
    at net.sf.ehcache.distribution.RMIBootstrapCacheLoader.doLoad(RMIBootstrapCacheLoader.java:132)
    at net.sf.ehcache.distribution.RMIBootstrapCacheLoader$BootstrapThread.run(RMIBootstrapCacheLoader.java:107)
[MyAPP] 01 Sep 2015 12:36:59 DEBUG RMIBootstrapCacheLoader - cache peers: []
[MyAPP] 01 Sep 2015 12:36:59 DEBUG RMIBootstrapCacheLoader - Empty list of cache peers for cache sessionIds. No cache peer to bootstrap from.
[MyAPP] 01 Sep 2015 12:37:14 DEBUG CacheManager - Attempting to create an existing singleton. Existing singleton returned.

【问题讨论】:

  • 你有解决这个问题的办法吗?我面临同样的问题,根据下面的回复,仍然无法正常工作。任何帮助将不胜感激。谢谢。

标签: java spring replication rmi ehcache


【解决方案1】:

虽然这对于 OP 来说可能为时已晚,但缓存本身需要向 RMIReplicatorCacheFactory 注册,例如。

<cache name="sessionIds" maxElementsInMemory="5000" eternal="false"
    overflowToDisk="false" timeToIdleSeconds="0" timeToLiveSeconds="0"
            memoryStoreEvictionPolicy="LRU">    
    <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/>
    ...
</cache>

【讨论】: