Skip to content

Commit c0da4b3

Browse files
committed
Removed sonar issue and converted Audio to eager singleton for simplicity
1 parent 9bbb4da commit c0da4b3

File tree

1 file changed

+9
-14
lines changed
  • event-queue/src/main/java/com/iluwatar/event/queue

1 file changed

+9
-14
lines changed

event-queue/src/main/java/com/iluwatar/event/queue/Audio.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
package com.iluwatar.event.queue;
2525

26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
28+
2629
import java.io.File;
2730
import java.io.IOException;
2831

@@ -38,6 +41,8 @@
3841
*
3942
*/
4043
public class Audio {
44+
private static final Logger LOGGER = LoggerFactory.getLogger(Audio.class);
45+
private static final Audio INSTANCE = new Audio();
4146

4247
private static final int MAX_PENDING = 16;
4348

@@ -55,7 +60,7 @@ public class Audio {
5560
}
5661

5762
public static Audio getInstance() {
58-
return SingletonHolder.getAudioInstance();
63+
return INSTANCE;
5964
}
6065

6166
/**
@@ -141,14 +146,11 @@ private void update() {
141146
clip.open(audioStream);
142147
clip.start();
143148
} catch (LineUnavailableException e) {
144-
System.err.println("Error occoured while loading the audio: The line is unavailable");
145-
e.printStackTrace();
149+
LOGGER.trace("Error occoured while loading the audio: The line is unavailable", e);
146150
} catch (IOException e) {
147-
System.err.println("Input/Output error while loading the audio");
148-
e.printStackTrace();
151+
LOGGER.trace("Input/Output error while loading the audio", e);
149152
} catch (IllegalArgumentException e) {
150-
System.err.println("The system doesn't support the sound: " + e.getMessage());
151-
e.printStackTrace();
153+
LOGGER.trace("The system doesn't support the sound: " + e.getMessage(), e);
152154
}
153155
}
154156

@@ -172,11 +174,4 @@ public PlayMessage[] getPendingAudio() {
172174
return pendingAudio;
173175
}
174176

175-
private static class SingletonHolder {
176-
private static final Audio INSTANCE = new Audio();
177-
178-
static Audio getAudioInstance() {
179-
return INSTANCE;
180-
}
181-
}
182177
}

0 commit comments

Comments
 (0)