I am using Ignite tutorial code (link below), but I want to modify it such that it operates on a different type of data and the counts are done differently - rather than incrementing counter by 1 I want to add a current value.
So let's assume I have number of occurences of a certain word in different documents, so let's assume I have something like this:
'the' 6586
'the' 925
So I want Cache to hold 'the' 7511
So given this:
try (Stream<String> lines = Files.lines(path)) {
lines.forEach(line -> {
Stream<String> words = Stream.of(line.split(" "));
List<String> tokens = words.collect(Collectors.toList());
// this is just to emphasize that I want to pass value
Long value = Long.parseLong(tokens.get(1));
stmr.addData(tokens.get(0), Long.parseLong(tokens.get(1));
I would like the value to be passed to the stmr.receiver() method, so I can add it to the val .
I have even tried creating a class variable in StreamWords that would store the value, but the value does not get updated, and in stmr.receiver() it is still 0 ( as initialized).
Link to tutorial: Word Count Ignite Example
I managed to figure it out. In stmr.receiver(), arg is actually the value that I would like to insert, so just cast it to the object of your desire and you should be able to get the value.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.