2

我正在尝试使一个小型 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
4

2 回答 2

4

在服务器端也激活了 JCache?:)

只需将 cache-api-1.0.0.jar 添加到 Hazelcast 节点的类路径。

于 2014-12-30T10:16:35.223 回答
0

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

问题是,错误的 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);
于 2016-06-15T09:22:23.010 回答