< prev index next >

src/java.desktop/share/classes/com/sun/media/sound/EventDispatcher.java

Print this page

        

*** 33,44 **** import javax.sound.midi.MetaMessage; import javax.sound.midi.ShortMessage; import javax.sound.sampled.LineEvent; import javax.sound.sampled.LineListener; - - /** * EventDispatcher. Used by various classes in the Java Sound implementation * to send events. * * @author David Rivas --- 33,42 ----
*** 47,89 **** */ final class EventDispatcher implements Runnable { /** * time of inactivity until the auto closing clips ! * are closed */ private static final int AUTO_CLOSE_TIME = 5000; - /** ! * List of events */ private final ArrayList<EventInfo> eventQueue = new ArrayList<>(); - /** ! * Thread object for this EventDispatcher instance */ private Thread thread = null; - /* * support for auto-closing Clips */ ! private final ArrayList<ClipInfo> autoClosingClips = new ArrayList<ClipInfo>(); /* * support for monitoring data lines */ ! private final ArrayList<LineMonitor> lineMonitors = new ArrayList<LineMonitor>(); /** * Approximate interval between calls to LineMonitor.checkLine */ static final int LINE_MONITOR_TIME = 400; - /** * This start() method starts an event thread if one is not already active. */ synchronized void start() { --- 45,83 ---- */ final class EventDispatcher implements Runnable { /** * time of inactivity until the auto closing clips ! * are closed. */ private static final int AUTO_CLOSE_TIME = 5000; /** ! * List of events. */ private final ArrayList<EventInfo> eventQueue = new ArrayList<>(); /** ! * Thread object for this EventDispatcher instance. */ private Thread thread = null; /* * support for auto-closing Clips */ ! private final ArrayList<ClipInfo> autoClosingClips = new ArrayList<>(); /* * support for monitoring data lines */ ! private final ArrayList<LineMonitor> lineMonitors = new ArrayList<>(); /** * Approximate interval between calls to LineMonitor.checkLine */ static final int LINE_MONITOR_TIME = 400; /** * This start() method starts an event thread if one is not already active. */ synchronized void start() {
*** 94,104 **** -1, // priority true); // doStart } } - /** * Invoked when there is at least one event in the queue. * Implement this as a callback to process one event. */ void processEvent(EventInfo eventInfo) { --- 88,97 ----
*** 151,161 **** } Printer.err("Unknown event type: " + eventInfo.getEvent()); } - /** * Wait until there is something in the event queue to process. Then * dispatch the event to the listeners.The entire method does not * need to be synchronized since this includes taking the event out * from the queue and processing the event. We only need to provide --- 144,153 ----
*** 200,222 **** monitorLines(); } } } - /** * Queue the given event in the event queue. */ private synchronized void postEvent(EventInfo eventInfo) { eventQueue.add(eventInfo); notifyAll(); } - /** * A loop to dispatch events. */ public void run() { while (true) { try { dispatchEvents(); --- 192,213 ---- monitorLines(); } } } /** * Queue the given event in the event queue. */ private synchronized void postEvent(EventInfo eventInfo) { eventQueue.add(eventInfo); notifyAll(); } /** * A loop to dispatch events. */ + @Override public void run() { while (true) { try { dispatchEvents();
*** 224,234 **** if (Printer.err) t.printStackTrace(); } } } - /** * Send audio and MIDI events. */ void sendAudioEvents(Object event, List<Object> listeners) { if ((listeners == null) --- 215,224 ----
*** 241,251 **** EventInfo eventInfo = new EventInfo(event, listeners); postEvent(eventInfo); } - /* * go through the list of registered auto-closing * Clip instances and close them, if appropriate * * This method is called in regular intervals --- 231,240 ----
*** 289,299 **** } return -1; } /** ! * called from auto-closing clips when one of their open() method is called */ void autoClosingClipOpened(AutoClosingClip clip) { if (Printer.debug)Printer.debug("> EventDispatcher.autoClosingClipOpened "); int index = 0; synchronized(autoClosingClips) { --- 278,288 ---- } return -1; } /** ! * called from auto-closing clips when one of their open() method is called. */ void autoClosingClipOpened(AutoClosingClip clip) { if (Printer.debug)Printer.debug("> EventDispatcher.autoClosingClipOpened "); int index = 0; synchronized(autoClosingClips) {
*** 314,324 **** } if (Printer.debug)Printer.debug("< EventDispatcher.autoClosingClipOpened finished("+autoClosingClips.size()+" clips)"); } /** ! * called from auto-closing clips when their closed() method is called */ void autoClosingClipClosed(AutoClosingClip clip) { // nothing to do -- is removed from arraylist above } --- 303,313 ---- } if (Printer.debug)Printer.debug("< EventDispatcher.autoClosingClipOpened finished("+autoClosingClips.size()+" clips)"); } /** ! * called from auto-closing clips when their closed() method is called. */ void autoClosingClipClosed(AutoClosingClip clip) { // nothing to do -- is removed from arraylist above }
*** 338,350 **** } } if (Printer.debug)Printer.debug("< EventDispatcher.monitorLines("+lineMonitors.size()+" monitors)"); } - /** ! * Add this LineMonitor instance to the list of monitors */ void addLineMonitor(LineMonitor lm) { if (Printer.trace)Printer.trace("> EventDispatcher.addLineMonitor("+lm+")"); synchronized(lineMonitors) { if (lineMonitors.indexOf(lm) >= 0) { --- 327,338 ---- } } if (Printer.debug)Printer.debug("< EventDispatcher.monitorLines("+lineMonitors.size()+" monitors)"); } /** ! * Add this LineMonitor instance to the list of monitors. */ void addLineMonitor(LineMonitor lm) { if (Printer.trace)Printer.trace("> EventDispatcher.addLineMonitor("+lm+")"); synchronized(lineMonitors) { if (lineMonitors.indexOf(lm) >= 0) {
*** 360,370 **** } if (Printer.debug)Printer.debug("< EventDispatcher.addLineMonitor finished -- now ("+lineMonitors.size()+" monitors)"); } /** ! * Remove this LineMonitor instance from the list of monitors */ void removeLineMonitor(LineMonitor lm) { if (Printer.trace)Printer.trace("> EventDispatcher.removeLineMonitor("+lm+")"); synchronized(lineMonitors) { if (lineMonitors.indexOf(lm) < 0) { --- 348,358 ---- } if (Printer.debug)Printer.debug("< EventDispatcher.addLineMonitor finished -- now ("+lineMonitors.size()+" monitors)"); } /** ! * Remove this LineMonitor instance from the list of monitors. */ void removeLineMonitor(LineMonitor lm) { if (Printer.trace)Printer.trace("> EventDispatcher.removeLineMonitor("+lm+")"); synchronized(lineMonitors) { if (lineMonitors.indexOf(lm) < 0) {
*** 375,386 **** lineMonitors.remove(lm); } if (Printer.debug)Printer.debug("< EventDispatcher.removeLineMonitor finished -- now ("+lineMonitors.size()+" monitors)"); } - // /////////////////////////////////// INNER CLASSES ////////////////////////////////////////// // - /** * Container for an event and a set of listeners to deliver it to. */ private class EventInfo { --- 363,372 ----
*** 411,429 **** } // class EventInfo /** ! * Container for a clip with its expiration time */ private class ClipInfo { private final AutoClosingClip clip; private final long expiration; /** ! * Create a new instance of this clip Info class */ ClipInfo(AutoClosingClip clip) { this.clip = clip; this.expiration = System.currentTimeMillis() + AUTO_CLOSE_TIME; } --- 397,415 ---- } // class EventInfo /** ! * Container for a clip with its expiration time. */ private class ClipInfo { private final AutoClosingClip clip; private final long expiration; /** ! * Create a new instance of this clip Info class. */ ClipInfo(AutoClosingClip clip) { this.clip = clip; this.expiration = System.currentTimeMillis() + AUTO_CLOSE_TIME; }
*** 438,452 **** } // class ClipInfo /** * Interface that a class that wants to get regular ! * line monitor events implements */ interface LineMonitor { /** ! * Called by event dispatcher in regular intervals */ ! public void checkLine(); } } // class EventDispatcher --- 424,438 ---- } // class ClipInfo /** * Interface that a class that wants to get regular ! * line monitor events implements. */ interface LineMonitor { /** ! * Called by event dispatcher in regular intervals. */ ! void checkLine(); } } // class EventDispatcher
< prev index next >