< prev index next >
src/java.desktop/share/classes/com/sun/media/sound/EventDispatcher.java
Print this page
@@ -33,12 +33,10 @@
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
@@ -47,43 +45,39 @@
*/
final class EventDispatcher implements Runnable {
/**
* time of inactivity until the auto closing clips
- * are closed
+ * are closed.
*/
private static final int AUTO_CLOSE_TIME = 5000;
-
/**
- * List of events
+ * List of events.
*/
private final ArrayList<EventInfo> eventQueue = new ArrayList<>();
-
/**
- * Thread object for this EventDispatcher instance
+ * Thread object for this EventDispatcher instance.
*/
private Thread thread = null;
-
/*
* support for auto-closing Clips
*/
- private final ArrayList<ClipInfo> autoClosingClips = new ArrayList<ClipInfo>();
+ private final ArrayList<ClipInfo> autoClosingClips = new ArrayList<>();
/*
* support for monitoring data lines
*/
- private final ArrayList<LineMonitor> lineMonitors = new ArrayList<LineMonitor>();
+ 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,11 +88,10 @@
-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) {
@@ -151,11 +144,10 @@
}
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
@@ -200,23 +192,22 @@
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,11 +215,10 @@
if (Printer.err) t.printStackTrace();
}
}
}
-
/**
* Send audio and MIDI events.
*/
void sendAudioEvents(Object event, List<Object> listeners) {
if ((listeners == null)
@@ -241,11 +231,10 @@
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
@@ -289,11 +278,11 @@
}
return -1;
}
/**
- * called from auto-closing clips when one of their open() method is called
+ * 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,11 +303,11 @@
}
if (Printer.debug)Printer.debug("< EventDispatcher.autoClosingClipOpened finished("+autoClosingClips.size()+" clips)");
}
/**
- * called from auto-closing clips when their closed() method is called
+ * called from auto-closing clips when their closed() method is called.
*/
void autoClosingClipClosed(AutoClosingClip clip) {
// nothing to do -- is removed from arraylist above
}
@@ -338,13 +327,12 @@
}
}
if (Printer.debug)Printer.debug("< EventDispatcher.monitorLines("+lineMonitors.size()+" monitors)");
}
-
/**
- * Add this LineMonitor instance to the list of 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,11 +348,11 @@
}
if (Printer.debug)Printer.debug("< EventDispatcher.addLineMonitor finished -- now ("+lineMonitors.size()+" monitors)");
}
/**
- * Remove this LineMonitor instance from the list of 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,12 +363,10 @@
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 {
@@ -411,19 +397,19 @@
} // class EventInfo
/**
- * Container for a clip with its expiration time
+ * 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
+ * Create a new instance of this clip Info class.
*/
ClipInfo(AutoClosingClip clip) {
this.clip = clip;
this.expiration = System.currentTimeMillis() + AUTO_CLOSE_TIME;
}
@@ -438,15 +424,15 @@
} // class ClipInfo
/**
* Interface that a class that wants to get regular
- * line monitor events implements
+ * line monitor events implements.
*/
interface LineMonitor {
/**
- * Called by event dispatcher in regular intervals
+ * Called by event dispatcher in regular intervals.
*/
- public void checkLine();
+ void checkLine();
}
} // class EventDispatcher
< prev index next >