私の設定:
<bean parent="cache-template">
<property name="name" value="yagoLabel" />
<property name="cacheMode" value="PARTITIONED" />
<property name="atomicityMode" value="TRANSACTIONAL" />
<property name="distributionMode" value="PARTITIONED_ONLY" />
<property name="backups" value="1" />
<property name="store">
<bean class="id.ac.itb.ee.lskk.lumen.yago.YagoLabelCacheStore" autowire="byType" init-method="init" />
</property>
<property name="writeBehindEnabled" value="true" />
<property name="writeBehindFlushSize" value="102380" />
<property name="writeBehindFlushFrequency" value="30000" />
<property name="writeBehindBatchSize" value="10240" />
<property name="swapEnabled" value="false" />
<property name="evictionPolicy">
<bean class="org.gridgain.grid.cache.eviction.lru.GridCacheLruEvictionPolicy">
<property name="maxSize" value="102400" />
</bean>
</property>
</bean>
そして、次のように GridGain を開始します。
私のGridCacheStore
実装:
public class YagoLabelCacheStore extends GridCacheStoreAdapter<String, YagoLabel> {
private static final Logger log = LoggerFactory
.getLogger(YagoLabelCacheStore.class);
private DBCollection labelColl;
@GridSpringResource(resourceName="mongoDb")
private DB db;
@Inject
private GridGainSpring grid;
@PostConstruct
public void init() {
log.info("Grid is {}", grid);
labelColl = db.getCollection("label");
}
次のように GridGain を起動します。
String entityId = "Muhammad";
try (AnnotationConfigApplicationContext appCtx
= new AnnotationConfigApplicationContext(LumenConfig.class)) {
Grid grid = appCtx.getBean(Grid.class);
GridCache<String, YagoLabel> labelCache = YagoLabel.cache(grid);
log.info("Label for {}: {}", entityId, labelCache.get(entityId));
}
LumenConfig
Spring 構成には、DB
という名前の Beanが含まれていますmongoDb
。
ただし、適切に注入されていないNullPointerException
ため、これはスローされます。db
テスト用に試し@Inject GridGainSpring
ただけで、GridGainSpring
それ自体も注入されていません。
私も<property name="db" ref="mongoDb"/>
GridGain Config XML で設定しようとしましたが、Spring は Bean を見つけることができません。
私の回避策は、public static
フィールド内に配置することですが、それは非常にハックです:ルーメン/屋号/YagoLabelCacheStore.java