Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed sonar issue and converted Audio to eager singleton for simpli…
…city
  • Loading branch information
npathai committed Oct 16, 2018
commit c0da4b3165e62f88b3385cf3e0a32578af4fbccc
23 changes: 9 additions & 14 deletions event-queue/src/main/java/com/iluwatar/event/queue/Audio.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

package com.iluwatar.event.queue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;

Expand All @@ -38,6 +41,8 @@
*
*/
public class Audio {
private static final Logger LOGGER = LoggerFactory.getLogger(Audio.class);
private static final Audio INSTANCE = new Audio();

private static final int MAX_PENDING = 16;

Expand All @@ -55,7 +60,7 @@ public class Audio {
}

public static Audio getInstance() {
return SingletonHolder.getAudioInstance();
return INSTANCE;
}

/**
Expand Down Expand Up @@ -141,14 +146,11 @@ private void update() {
clip.open(audioStream);
clip.start();
} catch (LineUnavailableException e) {
System.err.println("Error occoured while loading the audio: The line is unavailable");
e.printStackTrace();
LOGGER.trace("Error occoured while loading the audio: The line is unavailable", e);
} catch (IOException e) {
System.err.println("Input/Output error while loading the audio");
e.printStackTrace();
LOGGER.trace("Input/Output error while loading the audio", e);
} catch (IllegalArgumentException e) {
System.err.println("The system doesn't support the sound: " + e.getMessage());
e.printStackTrace();
LOGGER.trace("The system doesn't support the sound: " + e.getMessage(), e);
}
}

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

private static class SingletonHolder {
private static final Audio INSTANCE = new Audio();

static Audio getAudioInstance() {
return INSTANCE;
}
}
}