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 callback, chain, circuit-breaker (iluw…
…atar#1060)

* Reduces checkstyle errors in callback

* Reduces checkstyle errors in chain

* Reduces checkstyle errors in circuit-breaker
  • Loading branch information
anuragagarwal561994 authored and iluwatar committed Nov 9, 2019
commit 31f27a720b3ebc420783bd2ac885a74f6a90c754
14 changes: 6 additions & 8 deletions callback/src/main/java/com/iluwatar/callback/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@

package com.iluwatar.callback;

import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;

import org.slf4j.Logger;

/**
*
* Callback pattern is more native for functional languages where functions are
* treated as first-class citizens. Prior to Java 8 callbacks can be simulated
* using simple (alike command) interfaces.
*
* Callback pattern is more native for functional languages where functions are treated as
* first-class citizens. Prior to Java 8 callbacks can be simulated using simple (alike command)
* interfaces.
*/
public final class App {

Expand All @@ -42,7 +40,7 @@ private App() {
}

/**
* Program entry point
* Program entry point.
*/
public static void main(final String[] args) {
Task task = new SimpleTask();
Expand Down
4 changes: 1 addition & 3 deletions callback/src/main/java/com/iluwatar/callback/Callback.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
package com.iluwatar.callback;

/**
*
* Callback interface
*
* Callback interface.
*/
public interface Callback {

Expand Down
15 changes: 7 additions & 8 deletions callback/src/main/java/com/iluwatar/callback/LambdasApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,23 @@

package com.iluwatar.callback;

import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;

import org.slf4j.Logger;

/**
*
* This example generates the exact same output as {@link App} however the
* callback has been defined as a Lambdas expression.
*
* This example generates the exact same output as {@link App} however the callback has been defined
* as a Lambdas expression.
*/
public final class LambdasApp {

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

private LambdasApp() { }
private LambdasApp() {
}

/**
* Program entry point
* Program entry point.
*/
public static void main(final String[] args) {
Task task = new SimpleTask();
Expand Down
10 changes: 4 additions & 6 deletions callback/src/main/java/com/iluwatar/callback/SimpleTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@

package com.iluwatar.callback;

import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;

import org.slf4j.Logger;

/**
*
* Implementation of task that need to be executed
*
* Implementation of task that need to be executed.
*/
public final class SimpleTask extends Task {

Expand All @@ -39,6 +37,6 @@ public final class SimpleTask extends Task {
@Override
public void execute() {
LOGGER.info("Perform some important activity and after call the"
+ " callback method.");
+ " callback method.");
}
}
6 changes: 2 additions & 4 deletions callback/src/main/java/com/iluwatar/callback/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
package com.iluwatar.callback;

/**
*
* Template-method class for callback hook execution
*
* Template-method class for callback hook execution.
*/
public abstract class Task {

/**
* Execute with callback
* Execute with callback.
*/
final void executeWith(final Callback callback) {
execute();
Expand Down
16 changes: 7 additions & 9 deletions chain/src/main/java/com/iluwatar/chain/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,21 @@
package com.iluwatar.chain;

/**
*
* The Chain of Responsibility pattern is a design pattern consisting of command objects and a
* series of processing objects. Each processing object contains logic that defines the types of
* command objects that it can handle; the rest are passed to the next processing object in the
* chain. A mechanism also exists for adding new processing objects to the end of this chain.
* <p>
* In this example we organize the request handlers ({@link RequestHandler}) into a chain where each
* handler has a chance to act on the request on its turn. Here the king ({@link OrcKing}) makes
* requests and the military orcs ({@link OrcCommander}, {@link OrcOfficer}, {@link OrcSoldier})
* form the handler chain.
*
*
* <p>In this example we organize the request handlers ({@link RequestHandler}) into a chain where
* each handler has a chance to act on the request on its turn. Here the king ({@link OrcKing})
* makes requests and the military orcs ({@link OrcCommander}, {@link OrcOfficer}, {@link
* OrcSoldier}) form the handler chain.
*/
public class App {

/**
* Program entry point
*
* Program entry point.
*
* @param args command line args
*/
public static void main(String[] args) {
Expand Down
4 changes: 1 addition & 3 deletions chain/src/main/java/com/iluwatar/chain/OrcCommander.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
package com.iluwatar.chain;

/**
*
* OrcCommander
*
* OrcCommander.
*/
public class OrcCommander extends RequestHandler {

Expand Down
2 changes: 0 additions & 2 deletions chain/src/main/java/com/iluwatar/chain/OrcKing.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
package com.iluwatar.chain;

/**
*
* OrcKing makes requests that are handled by the chain.
*
*/
public class OrcKing {

Expand Down
4 changes: 1 addition & 3 deletions chain/src/main/java/com/iluwatar/chain/OrcOfficer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
package com.iluwatar.chain;

/**
*
* OrcOfficer
*
* OrcOfficer.
*/
public class OrcOfficer extends RequestHandler {

Expand Down
4 changes: 1 addition & 3 deletions chain/src/main/java/com/iluwatar/chain/OrcSoldier.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
package com.iluwatar.chain;

/**
*
* OrcSoldier
*
* OrcSoldier.
*/
public class OrcSoldier extends RequestHandler {

Expand Down
16 changes: 8 additions & 8 deletions chain/src/main/java/com/iluwatar/chain/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@
import java.util.Objects;

/**
* Request
* Request.
*/
public class Request {

/**
* The type of this request, used by each item in the chain to see if they should or can handle
* this particular request
* this particular request.
*/
private final RequestType requestType;

/**
* A description of the request
* A description of the request.
*/
private final String requestDescription;

/**
* Indicates if the request is handled or not. A request can only switch state from unhandled to
* handled, there's no way to 'unhandle' a request
* handled, there's no way to 'unhandle' a request.
*/
private boolean handled;

Expand All @@ -59,7 +59,7 @@ public Request(final RequestType requestType, final String requestDescription) {
}

/**
* Get a description of the request
* Get a description of the request.
*
* @return A human readable description of the request
*/
Expand All @@ -69,7 +69,7 @@ public String getRequestDescription() {

/**
* Get the type of this request, used by each person in the chain of command to see if they should
* or can handle this particular request
* or can handle this particular request.
*
* @return The request type
*/
Expand All @@ -78,14 +78,14 @@ public RequestType getRequestType() {
}

/**
* Mark the request as handled
* Mark the request as handled.
*/
public void markHandled() {
this.handled = true;
}

/**
* Indicates if this request is handled or not
* Indicates if this request is handled or not.
*
* @return <tt>true</tt> when the request is handled, <tt>false</tt> if not
*/
Expand Down
6 changes: 2 additions & 4 deletions chain/src/main/java/com/iluwatar/chain/RequestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import org.slf4j.LoggerFactory;

/**
*
* RequestHandler
*
* RequestHandler.
*/
public abstract class RequestHandler {

Expand All @@ -42,7 +40,7 @@ public RequestHandler(RequestHandler next) {
}

/**
* Request handler
* Request handler.
*/
public void handleRequest(Request req) {
if (next != null) {
Expand Down
4 changes: 1 addition & 3 deletions chain/src/main/java/com/iluwatar/chain/RequestType.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
package com.iluwatar.chain;

/**
*
* RequestType enumeration
*
* RequestType enumeration.
*/
public enum RequestType {

Expand Down
57 changes: 27 additions & 30 deletions circuit-breaker/src/main/java/com/iluwatar/circuitbreaker/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,57 +28,54 @@

/**
* <p>
* The intention of the Circuit Builder pattern is to handle remote failures
* robustly, which is to mean that if a service is dependant on n number of
* other services, and m of them fail, we should be able to recover from that
* failure by ensuring that the user can still use the services that are actually
* functional, and resources are not tied up by uselessly by the services which
* are not working. However, we should also be able to detect when any of the m
* failing services become operational again, so that we can use it
* The intention of the Circuit Builder pattern is to handle remote failures robustly, which is to
* mean that if a service is dependant on n number of other services, and m of them fail, we should
* be able to recover from that failure by ensuring that the user can still use the services that
* are actually functional, and resources are not tied up by uselessly by the services which are not
* working. However, we should also be able to detect when any of the m failing services become
* operational again, so that we can use it
* </p>
* <p>
* In this example, the circuit breaker pattern is demonstrated by using two services:
* {@link MonitoringService} and {@link DelayedService}. The monitoring service
* is responsible for calling two services: a local service and a remote service {@link DelayedService}
* , and by using the circuit breaker construction we ensure that if the call to
* remote service is going to fail, we are going to save our resources and not make the
* function call at all, by wrapping our call to the remote service in the circuit
* breaker object.
* In this example, the circuit breaker pattern is demonstrated by using two services: {@link
* MonitoringService} and {@link DelayedService}. The monitoring service is responsible for calling
* two services: a local service and a remote service {@link DelayedService} , and by using the
* circuit breaker construction we ensure that if the call to remote service is going to fail, we
* are going to save our resources and not make the function call at all, by wrapping our call to
* the remote service in the circuit breaker object.
* </p>
* <p>
* This works as follows: The {@link CircuitBreaker} object can be in one of three
* states: <b>Open</b>, <b>Closed</b> and <b>Half-Open</b>, which represents the real
* world circuits. If the state is closed (initial), we assume everything is alright
* and perform the function call. However, every time the call fails, we note it
* and once it crosses a threshold, we set the state to Open, preventing any further
* calls to the remote server. Then, after a certain retry period (during which we
* expect thee service to recover), we make another call to the remote server and
* this state is called the Half-Open state, where it stays till the service is down,
* and once it recovers, it goes back to the closed state and the cycle continues.
* This works as follows: The {@link CircuitBreaker} object can be in one of three states:
* <b>Open</b>, <b>Closed</b> and <b>Half-Open</b>, which represents the real world circuits. If the
* state is closed (initial), we assume everything is alright and perform the function call.
* However, every time the call fails, we note it and once it crosses a threshold, we set the state
* to Open, preventing any further calls to the remote server. Then, after a certain retry period
* (during which we expect thee service to recover), we make another call to the remote server and
* this state is called the Half-Open state, where it stays till the service is down, and once it
* recovers, it goes back to the closed state and the cycle continues.
* </p>
*/
public class App {

private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Program entry point
*

/**
* Program entry point.
*
* @param args command line args
*/
@SuppressWarnings("squid:S2189")
public static void main(String[] args) {
//Create an object of monitoring service which makes both local and remote calls
var obj = new MonitoringService();
//Set the circuit Breaker parameters
var circuitBreaker = new CircuitBreaker(3000, 1, 2000 * 1000 * 1000);
var circuitBreaker = new CircuitBreaker(3000, 1, 2000 * 1000 * 1000);
var serverStartTime = System.nanoTime();
while (true) {
LOGGER.info(obj.localResourceResponse());
LOGGER.info(obj.remoteResourceResponse(circuitBreaker, serverStartTime));
LOGGER.info(circuitBreaker.getState());
try {
Thread.sleep(5 * 1000);
Thread.sleep(5 * 1000);
} catch (InterruptedException e) {
LOGGER.error(e.getMessage());
}
Expand Down
Loading