Skip to content

Commit b92eb52

Browse files
anuragagarwal561994iluwatar
authored andcommitted
Resolves checkstyle errors for template-method thread-pool throttling tls tolerant-reader (iluwatar#1073)
* Reduces checkstyle errors in template-method * Reduces checkstyle errors in thread-pool * Reduces checkstyle errors in throttling * Reduces checkstyle errors in tls * Reduces checkstyle errors in tolerant-reader
1 parent 9c8ad44 commit b92eb52

File tree

23 files changed

+175
-222
lines changed

23 files changed

+175
-222
lines changed

template-method/src/main/java/com/iluwatar/templatemethod/App.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,17 @@
2424
package com.iluwatar.templatemethod;
2525

2626
/**
27-
*
2827
* Template Method defines a skeleton for an algorithm. The algorithm subclasses provide
2928
* implementation for the blank parts.
30-
* <p>
31-
* In this example {@link HalflingThief} contains {@link StealingMethod} that can be changed. First
32-
* the thief hits with {@link HitAndRunMethod} and then with {@link SubtleMethod}.
33-
*
29+
*
30+
* <p>In this example {@link HalflingThief} contains {@link StealingMethod} that can be changed.
31+
* First the thief hits with {@link HitAndRunMethod} and then with {@link SubtleMethod}.
3432
*/
3533
public class App {
3634

3735
/**
38-
* Program entry point
39-
*
36+
* Program entry point.
37+
*
4038
* @param args command line args
4139
*/
4240
public static void main(String[] args) {

template-method/src/main/java/com/iluwatar/templatemethod/HalflingThief.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
package com.iluwatar.templatemethod;
2525

2626
/**
27-
*
2827
* Halfling thief uses {@link StealingMethod} to steal.
29-
*
3028
*/
3129
public class HalflingThief {
3230

template-method/src/main/java/com/iluwatar/templatemethod/HitAndRunMethod.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
import org.slf4j.LoggerFactory;
2828

2929
/**
30-
*
3130
* HitAndRunMethod implementation of {@link StealingMethod}.
32-
*
3331
*/
3432
public class HitAndRunMethod extends StealingMethod {
3533

template-method/src/main/java/com/iluwatar/templatemethod/StealingMethod.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
import org.slf4j.LoggerFactory;
2828

2929
/**
30-
*
3130
* StealingMethod defines skeleton for the algorithm.
32-
*
3331
*/
3432
public abstract class StealingMethod {
3533

@@ -42,7 +40,7 @@ public abstract class StealingMethod {
4240
protected abstract void stealTheItem(String target);
4341

4442
/**
45-
* Steal
43+
* Steal.
4644
*/
4745
public void steal() {
4846
var target = pickTarget();

template-method/src/main/java/com/iluwatar/templatemethod/SubtleMethod.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
import org.slf4j.LoggerFactory;
2828

2929
/**
30-
*
3130
* SubtleMethod implementation of {@link StealingMethod}.
32-
*
3331
*/
3432
public class SubtleMethod extends StealingMethod {
3533

thread-pool/src/main/java/com/iluwatar/threadpool/App.java

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,32 @@
2323

2424
package com.iluwatar.threadpool;
2525

26-
import org.slf4j.Logger;
27-
import org.slf4j.LoggerFactory;
28-
29-
import java.util.ArrayList;
3026
import java.util.List;
3127
import java.util.concurrent.ExecutorService;
3228
import java.util.concurrent.Executors;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
3331

3432
/**
35-
*
3633
* Thread Pool pattern is where a number of threads are created to perform a number of tasks, which
3734
* are usually organized in a queue. The results from the tasks being executed might also be placed
3835
* in a queue, or the tasks might return no result. Typically, there are many more tasks than
3936
* threads. As soon as a thread completes its task, it will request the next task from the queue
4037
* until all tasks have been completed. The thread can then terminate, or sleep until there are new
4138
* tasks available.
42-
* <p>
43-
* In this example we create a list of tasks presenting work to be done. Each task is then wrapped
44-
* into a {@link Worker} object that implements {@link Runnable}. We create an
45-
* {@link ExecutorService} with fixed number of threads (Thread Pool) and use them to execute the
46-
* {@link Worker}s.
4739
*
40+
* <p>In this example we create a list of tasks presenting work to be done. Each task is then
41+
* wrapped into a {@link Worker} object that implements {@link Runnable}. We create an {@link
42+
* ExecutorService} with fixed number of threads (Thread Pool) and use them to execute the {@link
43+
* Worker}s.
4844
*/
4945
public class App {
50-
46+
5147
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
5248

5349
/**
54-
* Program entry point
55-
*
50+
* Program entry point.
51+
*
5652
* @param args command line args
5753
*/
5854
public static void main(String[] args) {
@@ -61,21 +57,21 @@ public static void main(String[] args) {
6157

6258
// Create a list of tasks to be executed
6359
List<Task> tasks = List.of(
64-
new PotatoPeelingTask(3),
65-
new PotatoPeelingTask(6),
66-
new CoffeeMakingTask(2),
67-
new CoffeeMakingTask(6),
68-
new PotatoPeelingTask(4),
69-
new CoffeeMakingTask(2),
70-
new PotatoPeelingTask(4),
71-
new CoffeeMakingTask(9),
72-
new PotatoPeelingTask(3),
73-
new CoffeeMakingTask(2),
74-
new PotatoPeelingTask(4),
75-
new CoffeeMakingTask(2),
76-
new CoffeeMakingTask(7),
77-
new PotatoPeelingTask(4),
78-
new PotatoPeelingTask(5));
60+
new PotatoPeelingTask(3),
61+
new PotatoPeelingTask(6),
62+
new CoffeeMakingTask(2),
63+
new CoffeeMakingTask(6),
64+
new PotatoPeelingTask(4),
65+
new CoffeeMakingTask(2),
66+
new PotatoPeelingTask(4),
67+
new CoffeeMakingTask(9),
68+
new PotatoPeelingTask(3),
69+
new CoffeeMakingTask(2),
70+
new PotatoPeelingTask(4),
71+
new CoffeeMakingTask(2),
72+
new CoffeeMakingTask(7),
73+
new PotatoPeelingTask(4),
74+
new PotatoPeelingTask(5));
7975

8076
// Creates a thread pool that reuses a fixed number of threads operating off a shared
8177
// unbounded queue. At any point, at most nThreads threads will be active processing

thread-pool/src/main/java/com/iluwatar/threadpool/CoffeeMakingTask.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
package com.iluwatar.threadpool;
2525

2626
/**
27-
*
28-
* CoffeeMakingTask is a concrete task
29-
*
27+
* CoffeeMakingTask is a concrete task.
3028
*/
3129
public class CoffeeMakingTask extends Task {
3230

thread-pool/src/main/java/com/iluwatar/threadpool/PotatoPeelingTask.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
package com.iluwatar.threadpool;
2525

2626
/**
27-
*
28-
* PotatoPeelingTask is a concrete task
29-
*
27+
* PotatoPeelingTask is a concrete task.
3028
*/
3129
public class PotatoPeelingTask extends Task {
3230

thread-pool/src/main/java/com/iluwatar/threadpool/Task.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
import java.util.concurrent.atomic.AtomicInteger;
2727

2828
/**
29-
*
30-
* Abstract base class for tasks
31-
*
29+
* Abstract base class for tasks.
3230
*/
3331
public abstract class Task {
3432

thread-pool/src/main/java/com/iluwatar/threadpool/Worker.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
import org.slf4j.LoggerFactory;
2828

2929
/**
30-
*
31-
* Worker implements {@link Runnable} and thus can be executed by {@link java.util.concurrent.ExecutorService}
32-
*
30+
* Worker implements {@link Runnable} and thus can be executed by {@link
31+
* java.util.concurrent.ExecutorService}.
3332
*/
3433
public class Worker implements Runnable {
3534

throttling/src/main/java/com/iluwatar/throttling/App.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,30 @@
2323

2424
package com.iluwatar.throttling;
2525

26-
import org.slf4j.Logger;
27-
import org.slf4j.LoggerFactory;
28-
29-
import com.iluwatar.throttling.timer.Throttler;
3026
import com.iluwatar.throttling.timer.ThrottleTimerImpl;
31-
32-
import java.util.concurrent.ExecutorService;
3327
import java.util.concurrent.Executors;
3428
import java.util.concurrent.TimeUnit;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
3531

3632
/**
37-
* Throttling pattern is a design pattern to throttle or limit the use of resources or even a complete service by
38-
* users or a particular tenant. This can allow systems to continue to function and meet service level agreements,
39-
* even when an increase in demand places load on resources.
33+
* Throttling pattern is a design pattern to throttle or limit the use of resources or even a
34+
* complete service by users or a particular tenant. This can allow systems to continue to function
35+
* and meet service level agreements, even when an increase in demand places load on resources.
4036
* <p>
41-
* In this example we have ({@link App}) as the initiating point of the service.
42-
* This is a time based throttling, i.e. only a certain number of calls are allowed per second.
37+
* In this example we have ({@link App}) as the initiating point of the service. This is a time
38+
* based throttling, i.e. only a certain number of calls are allowed per second.
4339
* </p>
44-
* ({@link Tenant}) is the Tenant POJO class with which many tenants can be created
45-
* ({@link B2BService}) is the service which is consumed by the tenants and is throttled.
40+
* ({@link Tenant}) is the Tenant POJO class with which many tenants can be created ({@link
41+
* B2BService}) is the service which is consumed by the tenants and is throttled.
4642
*/
4743
public class App {
4844

4945
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
5046

5147
/**
52-
* Application entry point
48+
* Application entry point.
49+
*
5350
* @param args main arguments
5451
*/
5552
public static void main(String[] args) {
@@ -58,10 +55,10 @@ public static void main(String[] args) {
5855
var nike = new Tenant("Nike", 6, callsCount);
5956

6057
var executorService = Executors.newFixedThreadPool(2);
61-
58+
6259
executorService.execute(() -> makeServiceCalls(adidas, callsCount));
6360
executorService.execute(() -> makeServiceCalls(nike, callsCount));
64-
61+
6562
executorService.shutdown();
6663
try {
6764
executorService.awaitTermination(10, TimeUnit.SECONDS);
@@ -71,14 +68,14 @@ public static void main(String[] args) {
7168
}
7269

7370
/**
74-
* Make calls to the B2BService dummy API
71+
* Make calls to the B2BService dummy API.
7572
*/
7673
private static void makeServiceCalls(Tenant tenant, CallsCount callsCount) {
7774
var timer = new ThrottleTimerImpl(10, callsCount);
7875
var service = new B2BService(timer, callsCount);
7976
for (int i = 0; i < 20; i++) {
8077
service.dummyCustomerApi(tenant);
81-
// Sleep is introduced to keep the output in check and easy to view and analyze the results.
78+
// Sleep is introduced to keep the output in check and easy to view and analyze the results.
8279
try {
8380
Thread.sleep(1);
8481
} catch (InterruptedException e) {

throttling/src/main/java/com/iluwatar/throttling/B2BService.java

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

2424
package com.iluwatar.throttling;
2525

26-
import org.slf4j.Logger;
27-
import org.slf4j.LoggerFactory;
28-
2926
import com.iluwatar.throttling.timer.Throttler;
30-
3127
import java.util.concurrent.ThreadLocalRandom;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
3230

3331
/**
34-
* A service which accepts a tenant and throttles the resource based on the time given to the tenant.
32+
* A service which accepts a tenant and throttles the resource based on the time given to the
33+
* tenant.
3534
*/
3635
class B2BService {
3736

@@ -44,6 +43,7 @@ public B2BService(Throttler timer, CallsCount callsCount) {
4443
}
4544

4645
/**
46+
* Calls dummy customer api.
4747
*
4848
* @return customer id which is randomly generated
4949
*/

throttling/src/main/java/com/iluwatar/throttling/CallsCount.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,17 @@
2323

2424
package com.iluwatar.throttling;
2525

26-
import org.slf4j.Logger;
27-
import org.slf4j.LoggerFactory;
28-
2926
import java.util.Map;
3027
import java.util.Map.Entry;
3128
import java.util.concurrent.ConcurrentHashMap;
3229
import java.util.concurrent.atomic.AtomicLong;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
3332

3433
/**
35-
* A class to keep track of the counter of different Tenants
36-
* @author drastogi
34+
* A class to keep track of the counter of different Tenants.
3735
*
36+
* @author drastogi
3837
*/
3938
public final class CallsCount {
4039

@@ -43,29 +42,32 @@ public final class CallsCount {
4342

4443
/**
4544
* Add a new tenant to the map.
45+
*
4646
* @param tenantName name of the tenant.
4747
*/
4848
public void addTenant(String tenantName) {
4949
tenantCallsCount.putIfAbsent(tenantName, new AtomicLong(0));
5050
}
51-
51+
5252
/**
5353
* Increment the count of the specified tenant.
54+
*
5455
* @param tenantName name of the tenant.
5556
*/
5657
public void incrementCount(String tenantName) {
5758
tenantCallsCount.get(tenantName).incrementAndGet();
5859
}
59-
60+
6061
/**
61-
*
62+
* Get count of tenant based on tenant name.
63+
*
6264
* @param tenantName name of the tenant.
6365
* @return the count of the tenant.
6466
*/
6567
public long getCount(String tenantName) {
6668
return tenantCallsCount.get(tenantName).get();
6769
}
68-
70+
6971
/**
7072
* Resets the count of all the tenants in the map.
7173
*/

throttling/src/main/java/com/iluwatar/throttling/Tenant.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ public class Tenant {
3434
private int allowedCallsPerSecond;
3535

3636
/**
37+
* Constructor.
3738
*
38-
* @param name Name of the tenant
39+
* @param name Name of the tenant
3940
* @param allowedCallsPerSecond The number of calls allowed for a particular tenant.
4041
* @throws InvalidParameterException If number of calls is less than 0, throws exception.
4142
*/

0 commit comments

Comments
 (0)