我正在尝试使用由Cassandra支持的Map商店。为此,使用clientusercodedeploymentconfig将这些mapstore和maploader实现推送到hazelcast成员,如下所示
public class CassandraMapStoreFactory implements MapStoreFactory<String, Long> {
@Override
public MapLoader<String, Long> newMapStore(String mapName, Properties properties) {
return new CassandraPersistence(buildSession());
}
private Session buildSession() {
try {
ConsistencyLevel consistencyLevel = ConsistencyLevel.LOCAL_QUORUM;
PoolingOptions poolingOptions = new PoolingOptions()
.setMaxRequestsPerConnection(HostDistance.LOCAL, 1024)
.setMaxRequestsPerConnection(HostDistance.REMOTE, 256);
Cluster cluster = Cluster.builder()
.addContactPoints("15.207.180.45")
.withQueryOptions(new QueryOptions().setConsistencyLevel(consistencyLevel))
.withSocketOptions(new SocketOptions().setReadTimeoutMillis(12000))
.withPoolingOptions(poolingOptions)
.withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(10000, 2))
.build();
return cluster.connect("sample");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
下面是将客户机代码推送到hazelcast成员/服务器的代码
public static void main(String[] args) {
ClientConfig config = new ClientConfig();
ClientUserCodeDeploymentConfig codeDeploymentConfig = new ClientUserCodeDeploymentConfig().setEnabled(true)
.addClass(CounterEntryProcessor.class).addClass(CassandraMapStoreFactory.class).addClass(CassandraPersistence.class).addJar("cassandra-driver-core-3.1.2.jar");
config.setUserCodeDeploymentConfig(codeDeploymentConfig);
config.setClassLoader(MapIdGeneratorWithClient.class.getClassLoader());
HazelcastInstance hazelcastInstance = HazelcastClient.newHazelcastClient(config);
// map processing logic
hazelcastInstance.shutdown();
}
我在初始化CassandrampStoreFactory时看到以下问题。这似乎是Java9模块特性的问题,我使用的是Java11。请指导我如何在客户机/服务器部署方法中使用hazelcast map store中的cassandra驱动程序
Caused by: java.lang.IllegalAccessError: class com.datastax.driver.core.AbstractAddressableByIndexData cannot access its abstract superclass com.datastax.driver.core.AbstractGettableByIndexData (com.datastax.driver.core.AbstractAddressableByIndexData is in unnamed module of loader com.hazelcast.internal.usercodedeployment.impl.ClassSource @3614246c; com.datastax.driver.core.AbstractGettableByIndexData is in unnamed module of loader com.hazelcast.internal.usercodedeployment.impl.ClassSource @4890c0d0)
1条答案
按热度按时间s6fujrry1#
除非您绝对需要动态,否则我建议不要使用用户代码部署。名义上的路径实际上是在成员的类路径上用必要的类来启动成员。
添加jar和设置
CLASSPATH
环境变量。它将与zip发行版和docker映像一起工作。这是一个
docker-compose.yaml
显示它的文件: