由於Infinispan不再維護官方cassandra緩存存儲,因此我正在嘗試自己製作一個(用於Infinispan 7.1.1)。Infinispan - 創建自定義緩存存儲
我不知道我應該實現什麼,因爲我沒有在有關創建自定義緩存存儲的文檔中找到任何內容。
這是我所(由Infinispan的-cachestore-MongoDB的最新版本的啓發 - 這也是因爲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;
...
}
我試圖將其設置像這樣(在斯卡拉):
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()
}
}
但我得到一個異常:
java.lang.ClassCastException: org.infinispan.persistence.cassandra.configuration.CassandraStoreConfiguration cannot be cast to org.infinispan.configuration.cache.CustomStoreConfiguration
因此,我改變CassandraStoreConfiguration延長CustomStoreConfiguration和CassandraStoreConfigurationBuilder擴展CustomStoreConfigurationBuilder
現在我得到這個例外:
java.lang.ClassCastException: org.infinispan.configuration.cache.CustomStoreConfiguration cannot be cast to org.infinispan.persistence.cassandra.configuration.CassandraStoreConfiguration
它爲什麼會嘗試將CustomStoreConfiguration投射到CassandraStoreConfiguration?
有沒有一個體面的指南來創建一個自定義緩存存儲的地方?
根據我的愚見,你最好把[現有的卡桑德拉商店](https://github.com/infinispan/infinispan-cachestore-cassandra)並使其更新。在Infinispan主倉庫中有大量的緩存存儲實現(https://github.com/infinispan/infinispan/tree/master/persistence)來指導你,這些保證是最新的。 –