To avoid this problem in GridGain we created our own future which allows for asynchronous listening for future completion. In addition to that we have also resolved the inconveniences of error handling and added 'duration()'method to tell users how long the future took to execute. Here is how you can add a listener to get notified, say for completion of putAsync(..) operation on distributed cache:
...
GridCache<Integer, String> cache = grid.cache();
// Asynchronously put a value into cache.
GridFuture<String> fut = cache.putAsync(1, "1");
// Pass in a closure which will be called whenever future completes.
fut.listenAsync(new GridInClosureX<GridFuture<String>>() {
public void applyx(GridFuture<String> fut) throws GridException {
V previousValue = fut.get();
long duration = fut.duration();
System.out.println("Finished cache put operation [prev=" +
previousValue + ", duration=" + duration + "ms]");
}
});
...
GridFuture is used for all asynchronous operations in GridGain, including both, compute and data grid features. Hope you find it useful.
View comments