diff options
author | Michiel Van Der Kolk <not.valid@email.address> | 2005-07-11 15:42:37 +0000 |
---|---|---|
committer | Michiel Van Der Kolk <not.valid@email.address> | 2005-07-11 15:42:37 +0000 |
commit | 9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e (patch) | |
tree | 4c304cd4151020bd5494d279ee68a105ae3a5a3a /songdbj/org/tritonus/share/TNotifier.java | |
parent | dfa8ecbe609ca8ea194d08560a44fb9a92e94b4b (diff) | |
download | rockbox-9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e.tar.gz rockbox-9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e.zip |
Songdb java version, source. only 1.5 compatible
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7101 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'songdbj/org/tritonus/share/TNotifier.java')
-rw-r--r-- | songdbj/org/tritonus/share/TNotifier.java | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/songdbj/org/tritonus/share/TNotifier.java b/songdbj/org/tritonus/share/TNotifier.java new file mode 100644 index 0000000000..822b30c305 --- /dev/null +++ b/songdbj/org/tritonus/share/TNotifier.java | |||
@@ -0,0 +1,140 @@ | |||
1 | /* | ||
2 | * TNotifier.java | ||
3 | * | ||
4 | * This file is part of Tritonus: http://www.tritonus.org/ | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * Copyright (c) 1999 by Matthias Pfisterer | ||
9 | * | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU Library General Public License as published | ||
13 | * by the Free Software Foundation; either version 2 of the License, or | ||
14 | * (at your option) any later version. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | * GNU Library General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU Library General Public | ||
22 | * License along with this program; if not, write to the Free Software | ||
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
24 | * | ||
25 | */ | ||
26 | |||
27 | /* | ||
28 | |<--- this code is formatted to fit into 80 columns --->| | ||
29 | */ | ||
30 | |||
31 | package org.tritonus.share; | ||
32 | |||
33 | import java.util.EventObject; | ||
34 | import java.util.Collection; | ||
35 | import java.util.ArrayList; | ||
36 | import java.util.List; | ||
37 | import java.util.Iterator; | ||
38 | |||
39 | import javax.sound.sampled.LineListener; | ||
40 | import javax.sound.sampled.LineEvent; | ||
41 | |||
42 | |||
43 | |||
44 | public class TNotifier | ||
45 | extends Thread | ||
46 | { | ||
47 | public static class NotifyEntry | ||
48 | { | ||
49 | private EventObject m_event; | ||
50 | private List<LineListener> m_listeners; | ||
51 | |||
52 | |||
53 | |||
54 | public NotifyEntry(EventObject event, Collection<LineListener> listeners) | ||
55 | { | ||
56 | m_event = event; | ||
57 | m_listeners = new ArrayList<LineListener>(listeners); | ||
58 | } | ||
59 | |||
60 | |||
61 | public void deliver() | ||
62 | { | ||
63 | // TDebug.out("%% TNotifier.NotifyEntry.deliver(): called."); | ||
64 | Iterator<LineListener> iterator = m_listeners.iterator(); | ||
65 | while (iterator.hasNext()) | ||
66 | { | ||
67 | LineListener listener = iterator.next(); | ||
68 | listener.update((LineEvent) m_event); | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | |||
73 | |||
74 | public static TNotifier notifier = null; | ||
75 | |||
76 | static | ||
77 | { | ||
78 | notifier = new TNotifier(); | ||
79 | notifier.setDaemon(true); | ||
80 | notifier.start(); | ||
81 | } | ||
82 | |||
83 | |||
84 | |||
85 | /** The queue of events to deliver. | ||
86 | * The entries are of class NotifyEntry. | ||
87 | */ | ||
88 | private List<NotifyEntry> m_entries; | ||
89 | |||
90 | |||
91 | public TNotifier() | ||
92 | { | ||
93 | super("Tritonus Notifier"); | ||
94 | m_entries = new ArrayList<NotifyEntry>(); | ||
95 | } | ||
96 | |||
97 | |||
98 | |||
99 | public void addEntry(EventObject event, Collection<LineListener> listeners) | ||
100 | { | ||
101 | // TDebug.out("%% TNotifier.addEntry(): called."); | ||
102 | synchronized (m_entries) | ||
103 | { | ||
104 | m_entries.add(new NotifyEntry(event, listeners)); | ||
105 | m_entries.notifyAll(); | ||
106 | } | ||
107 | // TDebug.out("%% TNotifier.addEntry(): completed."); | ||
108 | } | ||
109 | |||
110 | |||
111 | public void run() | ||
112 | { | ||
113 | while (true) | ||
114 | { | ||
115 | NotifyEntry entry = null; | ||
116 | synchronized (m_entries) | ||
117 | { | ||
118 | while (m_entries.size() == 0) | ||
119 | { | ||
120 | try | ||
121 | { | ||
122 | m_entries.wait(); | ||
123 | } | ||
124 | catch (InterruptedException e) | ||
125 | { | ||
126 | if (TDebug.TraceAllExceptions) | ||
127 | { | ||
128 | TDebug.out(e); | ||
129 | } | ||
130 | } | ||
131 | } | ||
132 | entry = m_entries.remove(0); | ||
133 | } | ||
134 | entry.deliver(); | ||
135 | } | ||
136 | } | ||
137 | } | ||
138 | |||
139 | |||
140 | /*** TNotifier.java ***/ | ||