Resolves checkstyle errors for event-* (#1070)

* Reduces checkstyle errors in event-aggregator

* Reduces checkstyle errors in event-asynchronous

* Reduces checkstyle errors in event-driven-architecture

* Reduces checkstyle errors in event-queue

* Reduces checkstyle errors in event-sourcing
This commit is contained in:
Anurag Agarwal
2019-11-10 23:07:10 +05:30
committed by Ilkka Seppälä
parent 7c888e8886
commit 5ae2ce6e2e
38 changed files with 208 additions and 229 deletions

View File

@ -23,40 +23,40 @@
package com.iluwatar.event.queue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.sound.sampled.UnsupportedAudioFileException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Event or message queues provide an asynchronous communications protocol, meaning that the sender
* and receiver of the message do not need to interact with the message queue at the same time.
* Events or messages placed onto the queue are stored until the recipient retrieves them. Event
* or message queues have implicit or explicit limits on the size of data that may be transmitted
* in a single message and the number of messages that may remain outstanding on the queue.
* A queue stores a series of notifications or requests in first-in, first-out order.
* Sending a notification enqueues the request and returns. The request processor then processes
* items from the queue at a later time.
* and receiver of the message do not need to interact with the message queue at the same time.
* Events or messages placed onto the queue are stored until the recipient retrieves them. Event or
* message queues have implicit or explicit limits on the size of data that may be transmitted in a
* single message and the number of messages that may remain outstanding on the queue. A queue
* stores a series of notifications or requests in first-in, first-out order. Sending a notification
* enqueues the request and returns. The request processor then processes items from the queue at a
* later time.
*/
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Program entry point.
*
*
* @param args command line args
* @throws IOException when there is a problem with the audio file loading
* @throws UnsupportedAudioFileException when the loaded audio file is unsupported
* @throws IOException when there is a problem with the audio file loading
* @throws UnsupportedAudioFileException when the loaded audio file is unsupported
*/
public static void main(String[] args) throws UnsupportedAudioFileException, IOException, InterruptedException {
public static void main(String[] args) throws UnsupportedAudioFileException, IOException,
InterruptedException {
Audio audio = Audio.getInstance();
audio.playSound(audio.getAudioStream("./etc/Bass-Drum-1.wav"), -10.0f);
audio.playSound(audio.getAudioStream("./etc/Closed-Hi-Hat-1.wav"), -8.0f);
LOGGER.info("Press Enter key to stop the program...");
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
br.read();

View File

@ -23,22 +23,20 @@
package com.iluwatar.event.queue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class implements the Event Queue pattern.
* @author mkuprivecz
*
* @author mkuprivecz
*/
public class Audio {
private static final Logger LOGGER = LoggerFactory.getLogger(Audio.class);
@ -73,9 +71,10 @@ public class Audio {
updateThread.join();
updateThread = null;
}
/**
* This method check the Update Method's thread is started.
*
* @return boolean
*/
public synchronized boolean isServiceRunning() {
@ -83,8 +82,8 @@ public class Audio {
}
/**
* Starts the thread for the Update Method pattern if it was not started previously.
* Also when the thread is is ready initializes the indexes of the queue
* Starts the thread for the Update Method pattern if it was not started previously. Also when the
* thread is is ready initializes the indexes of the queue
*/
public void init() {
if (updateThread == null) {
@ -96,9 +95,9 @@ public class Audio {
}
startThread();
}
/**
* This is a synchronized thread starter
* This is a synchronized thread starter.
*/
private synchronized void startThread() {
if (!updateThread.isAlive()) {
@ -110,8 +109,9 @@ public class Audio {
/**
* This method adds a new audio into the queue.
*
* @param stream is the AudioInputStream for the method
* @param volume is the level of the audio's volume
* @param volume is the level of the audio's volume
*/
public void playSound(AudioInputStream stream, float volume) {
init();
@ -128,10 +128,9 @@ public class Audio {
getPendingAudio()[tailIndex] = new PlayMessage(stream, volume);
tailIndex = (tailIndex + 1) % MAX_PENDING;
}
/**
* This method uses the Update Method pattern.
* It takes the audio from the queue and plays it
* This method uses the Update Method pattern. It takes the audio from the queue and plays it
*/
private void update() {
// If there are no pending requests, do nothing.
@ -155,11 +154,12 @@ public class Audio {
}
/**
* Returns the AudioInputStream of a file
* Returns the AudioInputStream of a file.
*
* @param filePath is the path of the audio file
* @return AudioInputStream
* @throws UnsupportedAudioFileException when the audio file is not supported
* @throws IOException when the file is not readable
* @throws UnsupportedAudioFileException when the audio file is not supported
* @throws IOException when the file is not readable
*/
public AudioInputStream getAudioStream(String filePath)
throws UnsupportedAudioFileException, IOException {
@ -167,7 +167,8 @@ public class Audio {
}
/**
* Returns with the message array of the queue
* Returns with the message array of the queue.
*
* @return PlayMessage[]
*/
public PlayMessage[] getPendingAudio() {

View File

@ -27,15 +27,15 @@ import javax.sound.sampled.AudioInputStream;
/**
* The Event Queue's queue will store the instances of this class.
* @author mkuprivecz
*
* @author mkuprivecz
*/
public class PlayMessage {
private AudioInputStream stream;
private float volume;
public PlayMessage(AudioInputStream stream, float volume) {
setStream(stream);
setVolume(volume);