1 25 26 package org.snipsnap.notification; 27 28 import org.snipsnap.app.Application; 29 import org.snipsnap.config.Configuration; 30 import org.snipsnap.notification.jabber.JabberNotifier; 31 import org.snipsnap.snip.Snip; 32 import org.snipsnap.user.User; 33 34 import java.util.ArrayList ; 35 import java.util.Iterator ; 36 import java.util.List ; 37 38 46 47 public class MessageService { 48 private List consumers; 49 50 public MessageService() { 51 consumers = new ArrayList (); 52 } 53 54 public synchronized void send(Message message) { 55 Iterator iterator = consumers.iterator(); 56 while (iterator.hasNext()) { 57 Consumer consumer = (Consumer) iterator.next(); 58 consumer.consume(message); 59 } 60 } 61 62 public synchronized void register(Consumer consumer) { 63 if (! consumers.contains(consumer)) { 64 consumers.add(consumer); 65 } 66 } 67 68 public synchronized void deregister(Consumer consumer) { 69 if (consumers.contains(consumer)) { 70 consumers.add(consumer); 71 } 72 } 73 } 74 | Popular Tags |