@PaniniJ

Better Modularity ⇒ Better Concurrency


Map-Reduce Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
@Capsule
class SupervisorCore {
    static final M = 10;
    static final R = 5;

    @Local Mapper[] mappers;
    @Local Reducer[] reducers;

    void run() {
        Future<Void>[] mapFutures = new Future<>[M];
        Result[] results = new Result[R];

        for (int i = 0; i < M; i++) {
            futures[i] = mappers.getItems(i);
        }
        for (Future<Void> f : mapFutures) {
            f.get();  // Wait until each mapper is done.
        }
        for (int i = 0; idx < R; idx++) {
            results[i] = reduce();
        }
        for (Result r : results) {
            System.out.println(r.toString());
        }
    }
}
1
2
3
4
5
6
7
8
9
10
@Capsule
class MapperCore {
    @Imported Reducer reducers;
    @Future Void map(Items w) {
        for (Item i : w) {

        }
        return null;
    }
}
1
2
3
4
5
6
7
8
@Capsule
class ReducerCore {
    private State s;
    Result reduce() {
        ...
        return result;
    }
}