Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1fa8a60
Sharding Pattern (#1056)
Azureyjt Nov 8, 2019
6d1c0b1
Resolves checkstyle errors for ambassador, async-method-invocation, b…
anuragagarwal561994 Nov 9, 2019
efc17fc
Resolves checkstyle errors for business-delegate, bytecode, caching (…
anuragagarwal561994 Nov 9, 2019
31f27a7
Resolves checkstyle errors for callback, chain, circuit-breaker (#1060)
anuragagarwal561994 Nov 9, 2019
2f49648
Resolves checkstyle errors for collection-pipeline, command, commande…
anuragagarwal561994 Nov 9, 2019
4f9ee01
Resolves checkstyle errors for converter, cqrs (#1063)
anuragagarwal561994 Nov 10, 2019
dda0953
Resolves checkstyle errors for guarded-suspension, half-sync-half-asy…
anuragagarwal561994 Nov 10, 2019
7f06f3b
Resolves checkstyle errors for intercepting-filter, interpreter, iter…
anuragagarwal561994 Nov 10, 2019
eae09fc
Resolves checkstyle errors for api-gateway, lazy-loading, leader-elec…
anuragagarwal561994 Nov 10, 2019
01e489c
Resolves checkstyle errors for dao data-bus data-locality data-mapper…
anuragagarwal561994 Nov 10, 2019
f2c91eb
Resolves checkstyle errors for delegation dependency-injection dirty-…
anuragagarwal561994 Nov 10, 2019
7c888e8
Resolves checkstyle errors for eip-* (#1069)
anuragagarwal561994 Nov 10, 2019
5ae2ce6
Resolves checkstyle errors for event-* (#1070)
anuragagarwal561994 Nov 10, 2019
4dae1fa
Resolves checkstyle errors for execute-around extension-objects (#1071)
anuragagarwal561994 Nov 10, 2019
9c8ad44
Resolves checkstyle errors for patterns starting with letter r (#1072)
anuragagarwal561994 Nov 10, 2019
b92eb52
Resolves checkstyle errors for template-method thread-pool throttling…
anuragagarwal561994 Nov 10, 2019
f0f0143
Resolves checkstyle errors for trampoline twin typeobjectpattern unit…
anuragagarwal561994 Nov 10, 2019
c441831
Java 11 migration: ambassador async-method-invocation balking bridge …
anuragagarwal561994 Nov 11, 2019
329479d
#984 update Ambassador readme
iluwatar Nov 11, 2019
0272d71
#984 update Bridge readme
iluwatar Nov 11, 2019
2628cc0
#984 update Builder readme
iluwatar Nov 11, 2019
c954a43
Resolves checkstyle errors for facade factory-kit spatial-partition s…
anuragagarwal561994 Nov 11, 2019
37599eb
Resolves checkstyle errors for feature-toggle fluentinterface flux fl…
anuragagarwal561994 Nov 11, 2019
3907951
Resolves checkstyle issues for semaphore servant serverless service-l…
anuragagarwal561994 Nov 11, 2019
1e76d91
Resolves checkstyle errors for abstract-document abstract-factory acy…
anuragagarwal561994 Nov 11, 2019
6ef840f
Resolves checkstyle errors for naked-objects null-object object-mothe…
anuragagarwal561994 Nov 12, 2019
33ea733
Java 11 migration: patterns (remaining b-c) (#1081)
anuragagarwal561994 Nov 12, 2019
3c57bf7
#984 #987 update readmes
iluwatar Nov 12, 2019
f04fc3c
Java 11 migration: patterns starting with a (#1084)
anuragagarwal561994 Nov 13, 2019
160b737
Add another real world example for Builder
iluwatar Nov 13, 2019
50467c9
Java 11 migration: patterns (t-v) (#1085)
anuragagarwal561994 Nov 14, 2019
cc571f4
Saga pattern (#1062)
besok Nov 14, 2019
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
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
  • Loading branch information
anuragagarwal561994 authored and iluwatar committed Nov 10, 2019
commit b92eb5229d846694ff021446d5be9a4bfcf23163
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@
package com.iluwatar.templatemethod;

/**
*
* Template Method defines a skeleton for an algorithm. The algorithm subclasses provide
* implementation for the blank parts.
* <p>
* In this example {@link HalflingThief} contains {@link StealingMethod} that can be changed. First
* the thief hits with {@link HitAndRunMethod} and then with {@link SubtleMethod}.
*
*
* <p>In this example {@link HalflingThief} contains {@link StealingMethod} that can be changed.
* First the thief hits with {@link HitAndRunMethod} and then with {@link SubtleMethod}.
*/
public class App {

/**
* Program entry point
*
* Program entry point.
*
* @param args command line args
*/
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
package com.iluwatar.templatemethod;

/**
*
* Halfling thief uses {@link StealingMethod} to steal.
*
*/
public class HalflingThief {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import org.slf4j.LoggerFactory;

/**
*
* HitAndRunMethod implementation of {@link StealingMethod}.
*
*/
public class HitAndRunMethod extends StealingMethod {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import org.slf4j.LoggerFactory;

/**
*
* StealingMethod defines skeleton for the algorithm.
*
*/
public abstract class StealingMethod {

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

/**
* Steal
* Steal.
*/
public void steal() {
var target = pickTarget();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import org.slf4j.LoggerFactory;

/**
*
* SubtleMethod implementation of {@link StealingMethod}.
*
*/
public class SubtleMethod extends StealingMethod {

Expand Down
52 changes: 24 additions & 28 deletions thread-pool/src/main/java/com/iluwatar/threadpool/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,32 @@

package com.iluwatar.threadpool;

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

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
* Thread Pool pattern is where a number of threads are created to perform a number of tasks, which
* are usually organized in a queue. The results from the tasks being executed might also be placed
* in a queue, or the tasks might return no result. Typically, there are many more tasks than
* threads. As soon as a thread completes its task, it will request the next task from the queue
* until all tasks have been completed. The thread can then terminate, or sleep until there are new
* tasks available.
* <p>
* In this example we create a list of tasks presenting work to be done. Each task is then wrapped
* into a {@link Worker} object that implements {@link Runnable}. We create an
* {@link ExecutorService} with fixed number of threads (Thread Pool) and use them to execute the
* {@link Worker}s.
*
* <p>In this example we create a list of tasks presenting work to be done. Each task is then
* wrapped into a {@link Worker} object that implements {@link Runnable}. We create an {@link
* ExecutorService} with fixed number of threads (Thread Pool) and use them to execute the {@link
* Worker}s.
*/
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) {
Expand All @@ -61,21 +57,21 @@ public static void main(String[] args) {

// Create a list of tasks to be executed
List<Task> tasks = List.of(
new PotatoPeelingTask(3),
new PotatoPeelingTask(6),
new CoffeeMakingTask(2),
new CoffeeMakingTask(6),
new PotatoPeelingTask(4),
new CoffeeMakingTask(2),
new PotatoPeelingTask(4),
new CoffeeMakingTask(9),
new PotatoPeelingTask(3),
new CoffeeMakingTask(2),
new PotatoPeelingTask(4),
new CoffeeMakingTask(2),
new CoffeeMakingTask(7),
new PotatoPeelingTask(4),
new PotatoPeelingTask(5));
new PotatoPeelingTask(3),
new PotatoPeelingTask(6),
new CoffeeMakingTask(2),
new CoffeeMakingTask(6),
new PotatoPeelingTask(4),
new CoffeeMakingTask(2),
new PotatoPeelingTask(4),
new CoffeeMakingTask(9),
new PotatoPeelingTask(3),
new CoffeeMakingTask(2),
new PotatoPeelingTask(4),
new CoffeeMakingTask(2),
new CoffeeMakingTask(7),
new PotatoPeelingTask(4),
new PotatoPeelingTask(5));

// Creates a thread pool that reuses a fixed number of threads operating off a shared
// unbounded queue. At any point, at most nThreads threads will be active processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
package com.iluwatar.threadpool;

/**
*
* CoffeeMakingTask is a concrete task
*
* CoffeeMakingTask is a concrete task.
*/
public class CoffeeMakingTask extends Task {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
package com.iluwatar.threadpool;

/**
*
* PotatoPeelingTask is a concrete task
*
* PotatoPeelingTask is a concrete task.
*/
public class PotatoPeelingTask extends Task {

Expand Down
4 changes: 1 addition & 3 deletions thread-pool/src/main/java/com/iluwatar/threadpool/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
import java.util.concurrent.atomic.AtomicInteger;

/**
*
* Abstract base class for tasks
*
* Abstract base class for tasks.
*/
public abstract class Task {

Expand Down
5 changes: 2 additions & 3 deletions thread-pool/src/main/java/com/iluwatar/threadpool/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
import org.slf4j.LoggerFactory;

/**
*
* Worker implements {@link Runnable} and thus can be executed by {@link java.util.concurrent.ExecutorService}
*
* Worker implements {@link Runnable} and thus can be executed by {@link
* java.util.concurrent.ExecutorService}.
*/
public class Worker implements Runnable {

Expand Down
33 changes: 15 additions & 18 deletions throttling/src/main/java/com/iluwatar/throttling/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,30 @@

package com.iluwatar.throttling;

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

import com.iluwatar.throttling.timer.Throttler;
import com.iluwatar.throttling.timer.ThrottleTimerImpl;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

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

/**
* Application entry point
* Application entry point.
*
* @param args main arguments
*/
public static void main(String[] args) {
Expand All @@ -58,10 +55,10 @@ public static void main(String[] args) {
var nike = new Tenant("Nike", 6, callsCount);

var executorService = Executors.newFixedThreadPool(2);

executorService.execute(() -> makeServiceCalls(adidas, callsCount));
executorService.execute(() -> makeServiceCalls(nike, callsCount));

executorService.shutdown();
try {
executorService.awaitTermination(10, TimeUnit.SECONDS);
Expand All @@ -71,14 +68,14 @@ public static void main(String[] args) {
}

/**
* Make calls to the B2BService dummy API
* Make calls to the B2BService dummy API.
*/
private static void makeServiceCalls(Tenant tenant, CallsCount callsCount) {
var timer = new ThrottleTimerImpl(10, callsCount);
var service = new B2BService(timer, callsCount);
for (int i = 0; i < 20; i++) {
service.dummyCustomerApi(tenant);
// Sleep is introduced to keep the output in check and easy to view and analyze the results.
// Sleep is introduced to keep the output in check and easy to view and analyze the results.
try {
Thread.sleep(1);
} catch (InterruptedException e) {
Expand Down
10 changes: 5 additions & 5 deletions throttling/src/main/java/com/iluwatar/throttling/B2BService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@

package com.iluwatar.throttling;

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

import com.iluwatar.throttling.timer.Throttler;

import java.util.concurrent.ThreadLocalRandom;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A service which accepts a tenant and throttles the resource based on the time given to the tenant.
* A service which accepts a tenant and throttles the resource based on the time given to the
* tenant.
*/
class B2BService {

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

/**
* Calls dummy customer api.
*
* @return customer id which is randomly generated
*/
Expand Down
20 changes: 11 additions & 9 deletions throttling/src/main/java/com/iluwatar/throttling/CallsCount.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@

package com.iluwatar.throttling;

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

import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A class to keep track of the counter of different Tenants
* @author drastogi
* A class to keep track of the counter of different Tenants.
*
* @author drastogi
*/
public final class CallsCount {

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

/**
* Add a new tenant to the map.
*
* @param tenantName name of the tenant.
*/
public void addTenant(String tenantName) {
tenantCallsCount.putIfAbsent(tenantName, new AtomicLong(0));
}

/**
* Increment the count of the specified tenant.
*
* @param tenantName name of the tenant.
*/
public void incrementCount(String tenantName) {
tenantCallsCount.get(tenantName).incrementAndGet();
}

/**
*
* Get count of tenant based on tenant name.
*
* @param tenantName name of the tenant.
* @return the count of the tenant.
*/
public long getCount(String tenantName) {
return tenantCallsCount.get(tenantName).get();
}

/**
* Resets the count of all the tenants in the map.
*/
Expand Down
3 changes: 2 additions & 1 deletion throttling/src/main/java/com/iluwatar/throttling/Tenant.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public class Tenant {
private int allowedCallsPerSecond;

/**
* Constructor.
*
* @param name Name of the tenant
* @param name Name of the tenant
* @param allowedCallsPerSecond The number of calls allowed for a particular tenant.
* @throws InvalidParameterException If number of calls is less than 0, throws exception.
*/
Expand Down
Loading