Resolves checkstyle errors for guarded-suspension, half-sync-half-async, hexagonal (#1064)

* Reduces checkstyle errors in guarded-suspension

* Reduces checkstyle errors in half-sync-half-async

* Reduces checkstyle errors in hexagonal
This commit is contained in:
Anurag Agarwal
2019-11-10 22:31:32 +05:30
committed by Ilkka Seppälä
parent 4f9ee0189c
commit dda09535e6
34 changed files with 382 additions and 359 deletions

View File

@ -21,15 +21,6 @@
* THE SOFTWARE.
*/
/**
* Guarded-suspension is a concurrent design pattern for handling situation when to execute some action we need
* condition to be satisfied.
* <p>
* Implementation is based on GuardedQueue, which has two methods: get and put,
* the condition is that we cannot get from empty queue so when thread attempt
* to break the condition we invoke Object's wait method on him and when other thread put an element
* to the queue he notify the waiting one that now he can get from queue.
*/
package com.iluwatar.guarded.suspension;
import java.util.concurrent.ExecutorService;
@ -38,10 +29,18 @@ import java.util.concurrent.TimeUnit;
/**
* Created by robertt240 on 1/26/17.
*
* <p>Guarded-suspension is a concurrent design pattern for handling situation when to execute some
* action we need condition to be satisfied.
*
* <p>Implementation is based on GuardedQueue, which has two methods: get and put, the condition is
* that we cannot get from empty queue so when thread attempt to break the condition we invoke
* Object's wait method on him and when other thread put an element to the queue he notify the
* waiting one that now he can get from queue.
*/
public class App {
/**
* Example pattern execution
* Example pattern execution.
*
* @param args - command line args
*/
@ -55,13 +54,15 @@ public class App {
}
);
//here we wait two seconds to show that the thread which is trying to get from guardedQueue will be waiting
// here we wait two seconds to show that the thread which is trying
// to get from guardedQueue will be waiting
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//now we execute second thread which will put number to guardedQueue and notify first thread that it could get
// now we execute second thread which will put number to guardedQueue
// and notify first thread that it could get
executorService.execute(() -> {
guardedQueue.put(20);
}

View File

@ -23,16 +23,16 @@
package com.iluwatar.guarded.suspension;
import java.util.LinkedList;
import java.util.Queue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.LinkedList;
import java.util.Queue;
/**
* Guarded Queue is an implementation for Guarded Suspension Pattern
* Guarded suspension pattern is used to handle a situation when you want to execute a method
* on an object which is not in a proper state.
* Guarded Queue is an implementation for Guarded Suspension Pattern Guarded suspension pattern is
* used to handle a situation when you want to execute a method on an object which is not in a
* proper state.
*
* @see <a href="http://java-design-patterns.com/patterns/guarded-suspension/">http://java-design-patterns.com/patterns/guarded-suspension/</a>
*/
public class GuardedQueue {
@ -44,6 +44,8 @@ public class GuardedQueue {
}
/**
* Get the last element of the queue is exists.
*
* @return last element of a queue if queue is not empty
*/
public synchronized Integer get() {
@ -60,6 +62,8 @@ public class GuardedQueue {
}
/**
* Put a value in the queue.
*
* @param e number which we want to put to our queue
*/
public synchronized void put(Integer e) {