尝试使Hazelcast集群与JCache兼容的客户端一起工作时出现异常

时间:2014-12-30 10:04:11

标签: java hazelcast jcache

我正在努力让一个小型Hazelcast集群与简单的JCache兼容客户端合作。不幸的是,我得到了例外:" java.lang.IllegalArgumentException:没有使用名称注册的服务:hz:impl:cacheService"。 我很感激如何解决这个问题。

我使用的是Hazelcast版本3.4(与3.3和3.4-EA有相同的行为)。

以下是来自hazelcast-client.xml的代码段:

<group>
    <name>group1</name>
</group>

<network>
    <cluster-members>
        <address>192.168.56.10:5701</address>
        <address>192.168.56.20:5701</address>
    </cluster-members>
</network>

来自Hazelcast群集节点的日志:

Dec 30, 2014 9:21:06 AM com.hazelcast.config.XmlConfigLocator
INFO: Loading configuration /vagrant/resources/hazelcast.xml from System property 'hazelcast.config'
Dec 30, 2014 9:21:06 AM com.hazelcast.config.XmlConfigLocator
INFO: Using configuration file at /vagrant/resources/hazelcast.xml
Dec 30, 2014 9:21:07 AM com.hazelcast.instance.DefaultAddressPicker
INFO: [LOCAL] [group1] [3.4] Prefer IPv4 stack is true.
Dec 30, 2014 9:21:07 AM com.hazelcast.instance.DefaultAddressPicker
INFO: [LOCAL] [group1] [3.4] Picked Address[192.168.56.10]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
Dec 30, 2014 9:21:08 AM com.hazelcast.spi.OperationService
INFO: [192.168.56.10]:5701 [group1] [3.4] Backpressure is disabled
Dec 30, 2014 9:21:08 AM com.hazelcast.spi.impl.BasicOperationScheduler
INFO: [192.168.56.10]:5701 [group1] [3.4] Starting with 2 generic operation threads and 2 partition operation threads.
Dec 30, 2014 9:21:08 AM com.hazelcast.system
INFO: [192.168.56.10]:5701 [group1] [3.4] Hazelcast 3.4 (20141224 - 3dc5214) starting at Address[192.168.56.10]:5701
Dec 30, 2014 9:21:08 AM com.hazelcast.system
INFO: [192.168.56.10]:5701 [group1] [3.4] Copyright (C) 2008-2014 Hazelcast.com
Dec 30, 2014 9:21:08 AM com.hazelcast.instance.Node
INFO: [192.168.56.10]:5701 [group1] [3.4] Creating MulticastJoiner
Dec 30, 2014 9:21:08 AM com.hazelcast.core.LifecycleService
INFO: [192.168.56.10]:5701 [group1] [3.4] Address[192.168.56.10]:5701 is STARTING
Dec 30, 2014 9:21:14 AM com.hazelcast.cluster.impl.MulticastJoiner
INFO: [192.168.56.10]:5701 [group1] [3.4] Trying to join to discovered node: Address[192.168.56.20]:5701
Dec 30, 2014 9:21:14 AM com.hazelcast.nio.tcp.SocketConnector
INFO: [192.168.56.10]:5701 [group1] [3.4] Connecting to /192.168.56.20:5701, timeout: 0, bind-any: true
Dec 30, 2014 9:21:14 AM com.hazelcast.nio.tcp.TcpIpConnectionManager
INFO: [192.168.56.10]:5701 [group1] [3.4] Established socket connection between /192.168.56.10:50374 and 192.168.56.20/192.168.56.20:5701
Dec 30, 2014 9:21:20 AM com.hazelcast.cluster.ClusterService
INFO: [192.168.56.10]:5701 [group1] [3.4]

Members [2] {
        Member [192.168.56.20]:5701
        Member [192.168.56.10]:5701 this
}

Dec 30, 2014 9:21:22 AM com.hazelcast.core.LifecycleService
INFO: [192.168.56.10]:5701 [group1] [3.4] Address[192.168.56.10]:5701 is STARTED
Dec 30, 2014 9:22:17 AM com.hazelcast.nio.tcp.SocketAcceptor
INFO: [192.168.56.10]:5701 [group1] [3.4] Accepting socket connection from /192.168.56.1:39715
Dec 30, 2014 9:22:17 AM com.hazelcast.nio.tcp.TcpIpConnectionManager
INFO: [192.168.56.10]:5701 [group1] [3.4] Established socket connection between /192.168.56.10:5701 and 192.168.56.1/192.168.56.1:39715
Dec 30, 2014 9:22:17 AM com.hazelcast.client.impl.client.AuthenticationRequest
INFO: [192.168.56.10]:5701 [group1] [3.4] Received auth from Connection [/192.168.56.10:5701 -> 192.168.56.1/192.168.56.1:39715], endpoint=null, live=true, type=JAVA_CLIENT, successfully authenticated
Dec 30, 2014 9:22:17 AM com.hazelcast.client.ClientEngine
SEVERE: [192.168.56.10]:5701 [group1] [3.4] While executing request: com.hazelcast.client.impl.client.ClientCreateRequest@1256d778 -> No service registered with name: hz:impl:cacheService
java.lang.IllegalArgumentException: No service registered with name: hz:impl:cacheService
        at com.hazelcast.client.impl.ClientEngineImpl$ClientPacketProcessor.initService(ClientEngineImpl.java:477)
        at com.hazelcast.client.impl.ClientEngineImpl$ClientPacketProcessor.processRequest(ClientEngineImpl.java:427)
        at com.hazelcast.client.impl.ClientEngineImpl$ClientPacketProcessor.run(ClientEngineImpl.java:353)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
        at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:76)
        at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:92)

以下是来自客户的日志:

Dec 30, 2014 10:22:16 AM com.hazelcast.client.config.XmlClientConfigLocator
INFO: Loading 'hazelcast-client.xml' from classpath.
Dec 30, 2014 10:22:17 AM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_group1][3.4] is STARTING
Dec 30, 2014 10:22:17 AM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_group1][3.4] is STARTED
Dec 30, 2014 10:22:17 AM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_group1][3.4] is CLIENT_CONNECTED
Dec 30, 2014 10:22:17 AM com.hazelcast.client.spi.impl.ClusterListenerThread
INFO: 

Members [2] {
    Member [192.168.56.20]:5701
    Member [192.168.56.10]:5701
}

Exception in thread "main" javax.cache.CacheException: Error opening URI [hazelcast]
        at com.hazelcast.cache.impl.AbstractHazelcastCachingProvider.getCacheManager(AbstractHazelcastCachingProvider.java:89)
        at com.hazelcast.cache.impl.AbstractHazelcastCachingProvider.getCacheManager(AbstractHazelcastCachingProvider.java:118)
        at com.hazelcast.cache.HazelcastCachingProvider.getCacheManager(HazelcastCachingProvider.java:158)
        at com.example.JCacheSample.main(JCacheSample.java:16)
Caused by: java.lang.IllegalArgumentException: No service registered with name: hz:impl:cacheService
        at com.hazelcast.client.impl.ClientEngineImpl$ClientPacketProcessor.initService(ClientEngineImpl.java:477)
        at com.hazelcast.client.impl.ClientEngineImpl$ClientPacketProcessor.processRequest(ClientEngineImpl.java:427)
        at com.hazelcast.client.impl.ClientEngineImpl$ClientPacketProcessor.run(ClientEngineImpl.java:353)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
        at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:76)
        at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:92)
        at ------ End remote and begin local stack-trace ------.(Unknown Source)
        at com.hazelcast.client.spi.impl.ClientCallFuture.resolveResponse(ClientCallFuture.java:201)
        at com.hazelcast.client.spi.impl.ClientCallFuture.get(ClientCallFuture.java:142)
        at com.hazelcast.client.spi.impl.ClientCallFuture.get(ClientCallFuture.java:118)
        at com.hazelcast.client.spi.ProxyManager.initialize(ProxyManager.java:200)
        at com.hazelcast.client.spi.ProxyManager.getOrCreateProxy(ProxyManager.java:183)
        at com.hazelcast.client.impl.HazelcastClientInstanceImpl.getDistributedObject(HazelcastClientInstanceImpl.java:391)
        at com.hazelcast.client.impl.HazelcastClientProxy.getDistributedObject(HazelcastClientProxy.java:234)
        at com.hazelcast.client.cache.impl.HazelcastClientCacheManager.<init>(HazelcastClientCacheManager.java:62)
        at com.hazelcast.client.cache.impl.HazelcastClientCachingProvider.createHazelcastCacheManager(HazelcastClientCachingProvider.java:75)
        at com.hazelcast.client.cache.impl.HazelcastClientCachingProvider.createHazelcastCacheManager(HazelcastClientCachingProvider.java:38)
        at com.hazelcast.cache.impl.AbstractHazelcastCachingProvider.getCacheManager(AbstractHazelcastCachingProvider.java:86)
        ... 3 more

2 个答案:

答案 0 :(得分:4)

服务器端的激活缓存? :)

所有需要的是将cache-api-1.0.0.jar添加到Hazelcast节点的类路径中。

答案 1 :(得分:0)

我在 OSGi 上下文中收到了相同的错误消息。 cache-api在类路径上(我前往使用'org.apache.servicemix.bundles:org.apache.servicemix.bundles.javax-cache-api:1.0.0_1',因为在其他lib中缺少导出)。

问题是,错误的ClassLoader用于检查JCache是​​否在类路径上。因此,我必须像这样初始化Hazelcast实例:

ClassLoader hazelClassLoader = hazelcastOSGiService.getOwnerBundle().adapt(BundleWiring.class).getClassLoader();
Config config = new Config();
// set the classloader that is used by hazelcast to check for JCache Classes
config.setClassLoader(hazelClassLoader);

// Create a HazelcastInstance
hazelcastInstance = hazelcastOSGiService.newHazelcastInstance(config);