01: /*
02: * Bossa Workflow System
03: *
04: * $Id: NotificationQueue.java,v 1.3 2004/01/29 17:07:10 gdvieira Exp $
05: *
06: * Copyright (C) 2004 OpenBR Sistemas S/C Ltda.
07: *
08: * This file is part of Bossa.
09: *
10: * Bossa is free software; you can redistribute it and/or modify it
11: * under the terms of version 2 of the GNU General Public License as
12: * published by the Free Software Foundation.
13: *
14: * This program is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: * General Public License for more details.
18: *
19: * You should have received a copy of the GNU General Public
20: * License along with this program; if not, write to the
21: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22: * Boston, MA 02111-1307, USA.
23: */
24:
25: package com.bigbross.bossa.notify;
26:
27: import java.io.Serializable;
28: import java.util.ArrayList;
29: import java.util.Iterator;
30: import java.util.List;
31:
32: import com.bigbross.bossa.Bossa;
33:
34: /**
35: * This class implements a notification queue. It is intended to be used by
36: * other Bossa packages to queue and send notifications in a atomic
37: * way. <p>
38: *
39: * @author <a href="http://www.bigbross.com">BigBross Team</a>
40: */
41: public abstract class NotificationQueue implements Serializable {
42:
43: private List queue;
44:
45: /**
46: * Creates new empty notification queue. <p>
47: */
48: public NotificationQueue() {
49: queue = new ArrayList();
50: }
51:
52: /**
53: * Adds an event to this notification queue. <p>
54: *
55: * @param event the event to be added.
56: */
57: protected void addEvent(Event event) {
58: queue.add(event);
59: }
60:
61: /**
62: * Notifies all events currently present in this queue and flushes it.
63: * <p>
64: *
65: * @param bossa the root of the bossa system.
66: */
67: public void notifyAll(Bossa bossa) {
68: if (bossa != null) {
69: NotificationBus bus = bossa.getNotificationBus();
70: for (Iterator i = queue.iterator(); i.hasNext();) {
71: Event e = (Event) i.next();
72: bus.notifyEvent(e);
73: i.remove();
74: }
75: }
76: }
77: }
|