[infinispan-dev] Async Notification API

Manik Surtani manik at jboss.org
Fri May 15 19:27:05 EDT 2009


While the new async API has been getting rave reviews, someone did  
bring up async notifications.  E.g.,

	Future f = cache.putAsync(k, v);
	f.get();

But what if I don't want to wait on f.get(), I'd rather be told when  
the future is done so I can do an f.get()?

Sounds pretty useful to me.  But just wanted to sound you guys on the  
API choices for notifications.

My immediate thought was to use the existing notification API.  You  
register a cache listener, annotate a method with @RpcCallMade,  
receive an RpcCallMadeEvent.  But this is probably pretty useless,  
since you couldn't associate the notification with the specific put  
you've just done.  Even if you have the key in the event (which is  
unlikely - since we need to use the same event for all cache  
operations, some which take > 1 key such as putAll()), multiple  
threads could be working on the same key.

Another approach is to design a sub-interface to Future.   
NotifyingFuture.

public interface NotifyingFuture extends Future {
   void addListener(NotifyingFutureListener l);
}

public interface NotifyingFutureListener {
   void futureDone(Future f);
}

WDYT?
--
Manik Surtani
manik at jboss.org
Lead, Infinispan
Lead, JBoss Cache
http://www.infinispan.org
http://www.jbosscache.org







More information about the infinispan-dev mailing list