Reputation: 549
Since Infinispan no longer maintains the official cassandra cache store, I'm trying to make one of my own (for Infinispan 7.1.1).
I'm not sure what I'm supposed to implement since I haven't found anything in the documentation about creating a custom cache store.
These are the classes I have (inspired by the latest version of infinispan-cachestore-mongodb - which is also deprecated since Infinispan 6.0.0 :D):
public class CassandraCache<K, V> {
private Cluster cluster;
private Session session;
...
}
public class CassandraEntry<K, V>
public class CassandraStore<K, V> implements AdvancedLoadWriteStore<K, V> {
private InitializationContext context;
private CassandraCache<K, V> cache;
private CassandraStoreConfiguration configuration;
@Override
public void init(InitializationContext ctx) {
context = ctx;
configuration = ctx.getConfiguration();
try {
cache = new CassandraCache<K, V>(configuration);
} catch (Exception e) {
throw new PersistenceException(e);
}
}
...
}
public class CassandraStoreConfiguration extends AbstractStoreConfiguration {
private String hosts;
private String keyspace;
...
}
public class CassandraStoreConfigurationBuilder extends AbstractStoreConfigurationBuilder<CassandraStoreConfiguration, CassandraStoreConfigurationBuilder> {
private String hosts;
private String keyspace;
...
}
I'm trying to set it up like so (in scala):
object Infinispan {
val m: EmbeddedCacheManager = new DefaultCacheManager(globalConfig, cacheConfig)
def globalConfig = {
new GlobalConfigurationBuilder()
.transport()
.defaultTransport()
.build()
}
def cacheConfig = {
new ConfigurationBuilder()
.persistence().addStore(classOf[CassandraStoreConfigurationBuilder])
.fetchPersistentState(true)
.preload(true)
.shared(true)
.hosts("localhost:9160")
.keyspace("mykeyspace")
.transaction()
.transactionMode(TransactionMode.TRANSACTIONAL)
.transactionManagerLookup(new GenericTransactionManagerLookup)
.autoCommit(false).transactionProtocol(TransactionProtocol.DEFAULT)
.lockingMode(LockingMode.PESSIMISTIC)
.build()
}
}
But I get an exception:
java.lang.ClassCastException: org.infinispan.persistence.cassandra.configuration.CassandraStoreConfiguration cannot be cast to org.infinispan.configuration.cache.CustomStoreConfiguration
So I changed CassandraStoreConfiguration to extend CustomStoreConfiguration and CassandraStoreConfigurationBuilder to extend CustomStoreConfigurationBuilder
Now I get this exception:
java.lang.ClassCastException: org.infinispan.configuration.cache.CustomStoreConfiguration cannot be cast to org.infinispan.persistence.cassandra.configuration.CassandraStoreConfiguration
Why would it try to cast CustomStoreConfiguration to CassandraStoreConfiguration?
Is there a decent guide to creating a custom cache store somewhere?
Upvotes: 0
Views: 704
Reputation: 549
I was simply missing a couple of annotations:
@BuiltBy(CassandraStoreConfigurationBuilder.class)
@ConfigurationFor(CassandraStore.class)
public class CassandraStoreConfiguration extends AbstractStoreConfiguration
@ConfiguredBy(CassandraStoreConfiguration.class)
public class CassandraStore<K, V> implements AdvancedLoadWriteStore<K, V>
Once these were added, everything started to work just fine.
Upvotes: 3
Reputation: 733
I strongly believe that our brand new Infinispan custom cache store archetype can really help you with your effort.
Please check it out: https://github.com/infinispan/infinispan-cachestore-archetype
The README file contains necessary information how to use it.
Upvotes: 4