1 6 package org.prevayler.implementation.publishing; 7 8 import java.io.IOException ; 9 import java.util.*; 10 11 import org.prevayler.Clock; 12 import org.prevayler.Transaction; 13 14 15 17 public abstract class AbstractPublisher implements TransactionPublisher { 18 19 protected final Clock _clock; 20 private final List _subscribers = new LinkedList(); 21 22 23 public AbstractPublisher(Clock clock) { 24 _clock = clock; 25 } 26 27 public Clock clock() { 28 return _clock; 29 } 30 31 public synchronized void addSubscriber(TransactionSubscriber subscriber) throws IOException , ClassNotFoundException { 32 _subscribers.add(subscriber); 33 } 34 35 public synchronized void removeSubscriber(TransactionSubscriber subscriber) { 36 _subscribers.remove(subscriber); 37 } 38 39 protected synchronized void notifySubscribers(Transaction transaction, Date timestamp) { 40 Iterator i = _subscribers.iterator(); 41 while (i.hasNext()) ((TransactionSubscriber) i.next()).receive(transaction, timestamp); 42 } 43 44 } 45 | Popular Tags |