[concurrency-interest] Managing subscription aggregation

Richard Zschech richard.zschech at velsys.com
Mon Jan 7 23:54:50 EST 2008



I have a problem where I want to managing subscription aggregation. I
have multiple clients subscribing to multiple topics in my system and I
want to establish a single subscription to another system per topic.


To handle setup the subscriptions I'm using a Memoizer
(http://www.javaconcurrencyinpractice.com/listings/Memoizer.java) style
system where the first client subscription for a topic establishes the
subscription to the other system. My Computable establishes the
subscription and  returns a list of clients which get added to for
subsequent subscriptions:


public void subscribe(String topic, String client) {

                List<Subscription> list = subscriptions. compute(topic);




public class Subcriber implements Computable<String, List<String>> {

                public List<String> compute(String topic) {


                                return new




This works nicely but the problem comes when trying to handle the
unsubscriptions. I'm not sure how I can atomically remove the other
system subscription when the last client subscription is removed.
Somehow I need to do the following atomically:


public void unsubscribe(String topic, String client) {

                List<Subscription> list = subscriptions.get(topic);

                If(list.remove(client) {

                                If(list.isEmpty()) {







Obviously I can stick synchronized on the methods to get them to happen
atomically but I would like a more concurrent solution.


I was wondering if someone has come up with an aggregation management
class which manages when the first subscribe request comes in some user
code can be invoked and when the last unsubscribe request comes in some
user code can be executed.


Thanks in advance,

>From Richard.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20080108/1aebca23/attachment-0001.html 

More information about the Concurrency-interest mailing list