KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > prevayler > implementation > publishing > AbstractPublisher


1 //Prevayler(TM) - The Free-Software Prevalence Layer.
2
//Copyright (C) 2001-2003 Klaus Wuestefeld
3
//This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
4
//Contributions: Frederic Langlet
5

6 package org.prevayler.implementation.publishing;
7
8 import java.io.IOException JavaDoc;
9 import java.util.*;
10
11 import org.prevayler.Clock;
12 import org.prevayler.Transaction;
13
14
15 /** This class provides basic subscriber addition and notification.
16  */

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 JavaDoc, ClassNotFoundException JavaDoc {
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