我正在执行https://apacheignite.readme.io/docs/streaming-example中的步骤。探索Ignite流式字数统计示例。当我运行查询时,不会查询任何数据。 以下是我的代码:
public class CacheConfig {
public static CacheConfiguration<String, Long> createWordCache() {
CacheConfiguration<String, Long> cfg = new CacheConfiguration<String, Long>("words");
cfg.setIndexedTypes(String.class, Long.class);
return cfg;
}
}
public class WorkStreamIntoCache {
public static void main(String[] args) throws Exception {
Ignition.setClientMode(true);
String configPath = "D:/apache-ignite-fabric-1.7.0-bin/config/default-config.xml";
Ignite ignite = Ignition.start(configPath);
IgniteCache<String, Long> cache = ignite.getOrCreateCache(CacheConfig.createWordCache());
IgniteDataStreamer<String, Long> streamer = ignite.dataStreamer(cache.getName());
streamer.allowOverwrite(true);
streamer.receiver(StreamTransformer.from(new CacheEntryProcessor<String, Long, Object>() {
public Object process(MutableEntry<String, Long> mutableEntry, Object... objects) throws EntryProcessorException {
Long preValue = mutableEntry.getValue();
if (preValue == null) {
mutableEntry.setValue(1L);
} else {
mutableEntry.setValue(preValue + 1);
}
return null;
}
}));
while (true) {
InputStream in = WorkStreamIntoCache.class.getResourceAsStream("/words.txt");
List<String> lines = IOUtils.readAsLines(in);
for (String line : lines) {
String[] words = line.split(" ");
for (String word : words) {
word = word.trim();
if (word != null && word.length() > 0) {
streamer.addData(word, 1L);
System.out.println(word + " is writing to the cache @" + new SimpleDateFormat("yyyyMMdd HHmmss").format(new Date()));
}
}
}
Thread.sleep(120 * 1000);
}
}
}
public class QueryWords {
public static void main(String[] args) throws Exception {
Ignition.setClientMode(true);
String configPath = "D:/apache-ignite-fabric-1.7.0-bin/config/default-config.xml";
Ignite ignite = Ignition.start(configPath);
IgniteCache<String, Long> cache = ignite.getOrCreateCache(CacheConfig.createWordCache());
SqlFieldsQuery sql = new SqlFieldsQuery("select * from Long");
while (true) {
List<List<?>> data = cache.query(sql).getAll();
if (data == null || data.size() <= 0) {
System.out.println("No data is found in the cache");
}
for (List<?> datum : data) {
for (Object record : datum) {
System.out.println("record: " + record);
}
}
Thread.sleep(3000);
}
}
}
运行示例的步骤:
bin/ignite.bat D:/apache-ignite-fabric-1.7.0-bin/config/default-config.xml
No data is found in the cache
。问题出在哪里有帮助?谢谢!