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

@ -23,42 +23,35 @@
package com.iluwatar.halfsynchalfasync;
import java.util.concurrent.LinkedBlockingQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.LinkedBlockingQueue;
/**
*
* This application demonstrates Half-Sync/Half-Async pattern. Key parts of the pattern are
* {@link AsyncTask} and {@link AsynchronousService}.
*
* <p>
* <i>PROBLEM</i> <br>
* This application demonstrates Half-Sync/Half-Async pattern. Key parts of the pattern are {@link
* AsyncTask} and {@link AsynchronousService}.
*
* <p><i>PROBLEM</i> <br>
* A concurrent system have a mixture of short duration, mid duration and long duration tasks. Mid
* or long duration tasks should be performed asynchronously to meet quality of service
* requirements.
*
* <p>
* <i>INTENT</i> <br>
*
* <p><i>INTENT</i> <br>
* The intent of this pattern is to separate the the synchronous and asynchronous processing in the
* concurrent application by introducing two intercommunicating layers - one for sync and one for
* async. This simplifies the programming without unduly affecting the performance.
*
* <p>
* <i>APPLICABILITY</i> <br>
* UNIX network subsystems - In operating systems network operations are carried out
* asynchronously with help of hardware level interrupts.<br>
* CORBA - At the asynchronous layer one thread is associated with each socket that is connected
* to the client. Thread blocks waiting for CORBA requests from the client. On receiving request it
* is inserted in the queuing layer which is then picked up by synchronous layer which processes the
* request and sends response back to the client.<br>
* Android AsyncTask framework - Framework provides a way to execute long running blocking
* calls, such as downloading a file, in background threads so that the UI thread remains free to
* respond to user inputs.<br>
*
* <p>
* <i>IMPLEMENTATION</i> <br>
*
* <p><i>APPLICABILITY</i> <br>
* UNIX network subsystems - In operating systems network operations are carried out asynchronously
* with help of hardware level interrupts.<br> CORBA - At the asynchronous layer one thread is
* associated with each socket that is connected to the client. Thread blocks waiting for CORBA
* requests from the client. On receiving request it is inserted in the queuing layer which is then
* picked up by synchronous layer which processes the request and sends response back to the
* client.<br> Android AsyncTask framework - Framework provides a way to execute long running
* blocking calls, such as downloading a file, in background threads so that the UI thread remains
* free to respond to user inputs.<br>
*
* <p><i>IMPLEMENTATION</i> <br>
* The main method creates an asynchronous service which does not block the main thread while the
* task is being performed. The main thread continues its work which is similar to Async Method
* Invocation pattern. The difference between them is that there is a queuing layer between
@ -66,15 +59,14 @@ import java.util.concurrent.LinkedBlockingQueue;
* between both layers. Such as Priority Queue can be used as queuing layer to prioritize the way
* tasks are executed. Our implementation is just one simple way of implementing this pattern, there
* are many variants possible as described in its applications.
*
*/
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Program entry point
*
* Program entry point.
*
* @param args command line args
*/
public static void main(String[] args) {
@ -100,15 +92,13 @@ public class App {
}
/**
*
* ArithmeticSumTask
*
* ArithmeticSumTask.
*/
static class ArithmeticSumTask implements AsyncTask<Long> {
private long n;
private long numberOfElements;
public ArithmeticSumTask(long n) {
this.n = n;
public ArithmeticSumTask(long numberOfElements) {
this.numberOfElements = numberOfElements;
}
/*
@ -117,7 +107,7 @@ public class App {
*/
@Override
public Long call() throws Exception {
return ap(n);
return ap(numberOfElements);
}
/*
@ -128,7 +118,7 @@ public class App {
*/
@Override
public void onPreCall() {
if (n < 0) {
if (numberOfElements < 0) {
throw new IllegalArgumentException("n is less than 0");
}
}