Bucket4j + Hazelcast ClassNotFoundException
See original GitHub issueI am trying to use the bucket4j with Hazelcast, but the follow exception is throw:
mar 13, 2018 11:24:27 AM com.hazelcast.core.LifecycleService INFORMAÇÕES: hz.client_0 [dev] [3.9.3] HazelcastClient 3.9.3 (20180216 - 539b124) is STARTING mar 13, 2018 11:24:27 AM com.hazelcast.core.LifecycleService INFORMAÇÕES: hz.client_0 [dev] [3.9.3] HazelcastClient 3.9.3 (20180216 - 539b124) is STARTED mar 13, 2018 11:24:28 AM com.hazelcast.client.connection.ClientConnectionManager INFORMAÇÕES: hz.client_0 [dev] [3.9.3] Trying to connect to [localhost]:5701 as owner member mar 13, 2018 11:24:28 AM com.hazelcast.client.connection.ClientConnectionManager INFORMAÇÕES: hz.client_0 [dev] [3.9.3] Authenticated with server [127.0.0.1]:5701, server version:3.7.5 Local address: /127.0.0.1:50624 mar 13, 2018 11:24:28 AM com.hazelcast.client.spi.impl.ClientMembershipListener INFORMAÇÕES: hz.client_0 [dev] [3.9.3]
Members [1] { Member [127.0.0.1]:5701 - f37ba1b2-7b20-4b6d-83ac-8e6f4f79a4d8 }
mar 13, 2018 11:24:28 AM com.hazelcast.client.connection.ClientConnectionManager INFORMAÇÕES: hz.client_0 [dev] [3.9.3] Setting ClientConnection{alive=true, connectionId=1, channel=NioChannel{/127.0.0.1:50624->localhost/127.0.0.1:5701}, remoteEndpoint=[127.0.0.1]:5701, lastReadTime=2018-03-13 11:24:28.062, lastWriteTime=2018-03-13 11:24:28.059, closedTime=never, lastHeartbeatRequested=never, lastHeartbeatReceived=never, connected server version=3.7.5} as owner with principal ClientPrincipal{uuid=‘e27ac329-05f0-474b-b8d8-7295009cc862’, ownerUuid=‘f37ba1b2-7b20-4b6d-83ac-8e6f4f79a4d8’} mar 13, 2018 11:24:28 AM com.hazelcast.core.LifecycleService INFORMAÇÕES: hz.client_0 [dev] [3.9.3] HazelcastClient 3.9.3 (20180216 - 539b124) is CLIENT_CONNECTED mar 13, 2018 11:24:28 AM com.hazelcast.internal.diagnostics.Diagnostics INFORMAÇÕES: hz.client_0 [dev] [3.9.3] Diagnostics disabled. To enable add -Dhazelcast.diagnostics.enabled=true to the JVM arguments. Exception in thread “main” com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: io.github.bucket4j.grid.hazelcast.HazelcastEntryProcessorAdapter at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:224) at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48) at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:172) at com.hazelcast.client.impl.protocol.task.map.MapExecuteOnKeyMessageTask.prepareOperation(MapExecuteOnKeyMessageTask.java:42) at com.hazelcast.client.impl.protocol.task.AbstractPartitionMessageTask.processMessage(AbstractPartitionMessageTask.java:62) at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.initializeAndProcessMessage(AbstractMessageTask.java:128) at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.run(AbstractMessageTask.java:108) at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:137) at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:127) at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:102) at ------ submitted from ------.(Unknown Source) at com.hazelcast.client.spi.impl.ClientInvocationFuture.resolveAndThrowIfException(ClientInvocationFuture.java:96) at com.hazelcast.client.spi.impl.ClientInvocationFuture.resolveAndThrowIfException(ClientInvocationFuture.java:33) at com.hazelcast.spi.impl.AbstractInvocationFuture.get(AbstractInvocationFuture.java:155) at com.hazelcast.client.spi.ClientProxy.invokeOnPartition(ClientProxy.java:204) at com.hazelcast.client.spi.ClientProxy.invoke(ClientProxy.java:198) at com.hazelcast.client.proxy.ClientMapProxy.executeOnKeyInternal(ClientMapProxy.java:1294) at com.hazelcast.client.proxy.ClientMapProxy.executeOnKey(ClientMapProxy.java:1287) at io.github.bucket4j.grid.hazelcast.HazelcastProxy.createInitialState(HazelcastProxy.java:52) at io.github.bucket4j.grid.GridBucket.<init>(GridBucket.java:56) at io.github.bucket4j.grid.GridBucket.createInitializedBucket(GridBucket.java:43) at io.github.bucket4j.grid.hazelcast.HazelcastBucketBuilder.build(HazelcastBucketBuilder.java:57) at luankevinferreira.Bucket4jHazelcast.main(Bucket4jHazelcast.java:34) Caused by: java.lang.ClassNotFoundException at com.hazelcast.client.impl.protocol.ClientExceptionFactory$12.createException(ClientExceptionFactory.java:203) at com.hazelcast.client.impl.protocol.ClientExceptionFactory.createException(ClientExceptionFactory.java:744) at com.hazelcast.client.impl.protocol.ClientExceptionFactory.createException(ClientExceptionFactory.java:690) at com.hazelcast.client.spi.impl.AbstractClientInvocationService$ResponseThread.handleClientMessage(AbstractClientInvocationService.java:319) at com.hazelcast.client.spi.impl.AbstractClientInvocationService$ResponseThread.process(AbstractClientInvocationService.java:302) at com.hazelcast.client.spi.impl.AbstractClientInvocationService$ResponseThread.doRun(AbstractClientInvocationService.java:295) at com.hazelcast.client.spi.impl.AbstractClientInvocationService$ResponseThread.run(AbstractClientInvocationService.java:279)
My code is just like this:
public class Bucket4jHazelcast {
/**
* @param args
*/
public static void main(String[] args) {
ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().addAddress("localhost");
HazelcastInstance instance = HazelcastClient.newHazelcastClient(clientConfig);
Bucket bucket = Bucket4j.extension(Hazelcast.class).builder()//
.addLimit(Bandwidth.simple(10, Duration.ofMinutes(1)))//
.build(instance.getMap("test"), "test", RecoveryStrategy.RECONSTRUCT);
bucket.tryConsume(1);
}
}
Can you help me?
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
I never seen before the HazelcastInstance, looks like it has been introduced within
Hazelcast 3.9
. Based on common sense I suppose that you are trying to connect as ligh-weight client to the another hazelcast server node. If I am right then check that following jars present in classpath of the Hazelcast server node:These jars should present on both client and server nodes.
Thanks a lot, it works!