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 api-gateway, lazy-loading, leader-elec…
…tion (iluwatar#1066)

* Reduces checkstyle errors in lazy-loading

* Reduces checkstyle errors in leader-election

* Reduces checkstyle errors in api-gateway
  • Loading branch information
anuragagarwal561994 authored and iluwatar committed Nov 10, 2019
commit eae09fc07eb96e66b8227a23b9a09b3382943c95
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@

package com.iluwatar.api.gateway;

import javax.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
* The ApiGateway aggregates calls to microservices based on the needs of the individual clients.
*/
Expand All @@ -42,7 +41,8 @@ public class ApiGateway {
private PriceClient priceClient;

/**
* Retrieves product information that desktop clients need
* Retrieves product information that desktop clients need.
*
* @return Product information for clients on a desktop
*/
@RequestMapping(path = "/desktop", method = RequestMethod.GET)
Expand All @@ -54,7 +54,8 @@ public DesktopProduct getProductDesktop() {
}

/**
* Retrieves product information that mobile clients need
* Retrieves product information that mobile clients need.
*
* @return Product information for clients on a mobile device
*/
@RequestMapping(path = "/mobile", method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,36 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* With the Microservices pattern, a client may need data from multiple different microservices.
* If the client called each microservice directly, that could contribute to longer load times,
* since the client would have to make a network request for each microservice called. Moreover,
* having the client call each microservice directly ties the client to that microservice - if the
* internal implementations of the microservices change (for example, if two microservices are
* combined sometime in the future) or if the location (host and port) of a microservice changes,
* then every client that makes use of those microservices must be updated.
* With the Microservices pattern, a client may need data from multiple different microservices. If
* the client called each microservice directly, that could contribute to longer load times, since
* the client would have to make a network request for each microservice called. Moreover, having
* the client call each microservice directly ties the client to that microservice - if the internal
* implementations of the microservices change (for example, if two microservices are combined
* sometime in the future) or if the location (host and port) of a microservice changes, then every
* client that makes use of those microservices must be updated.
*
* <p>
* The intent of the API Gateway pattern is to alleviate some of these issues. In the API Gateway
* pattern, an additional entity (the API Gateway) is placed between the client and the
* microservices. The job of the API Gateway is to aggregate the calls to the microservices.
* Rather than the client calling each microservice individually, the client calls the API Gateway
* a single time. The API Gateway then calls each of the microservices that the client needs.
* <p>The intent of the API Gateway pattern is to alleviate some of these issues. In the API
* Gateway pattern, an additional entity (the API Gateway) is placed between the client and the
* microservices. The job of the API Gateway is to aggregate the calls to the microservices. Rather
* than the client calling each microservice individually, the client calls the API Gateway a single
* time. The API Gateway then calls each of the microservices that the client needs.
*
* <p>
* This implementation shows what the API Gateway pattern could look like for an e-commerce site.
* The {@link ApiGateway} makes calls to the Image and Price microservices using the
* {@link ImageClientImpl} and {@link PriceClientImpl} respectively. Customers viewing the site on a
* desktop device can see both price information and an image of a product, so the {@link ApiGateway}
* calls both of the microservices and aggregates the data in the {@link DesktopProduct} model.
* However, mobile users only see price information; they do not see a product image. For mobile
* users, the {@link ApiGateway} only retrieves price information, which it uses to populate the
* {@link MobileProduct}.
* <p>This implementation shows what the API Gateway pattern could look like for an e-commerce
* site. The {@link ApiGateway} makes calls to the Image and Price microservices using the {@link
* ImageClientImpl} and {@link PriceClientImpl} respectively. Customers viewing the site on a
* desktop device can see both price information and an image of a product, so the {@link
* ApiGateway} calls both of the microservices and aggregates the data in the {@link DesktopProduct}
* model. However, mobile users only see price information; they do not see a product image. For
* mobile users, the {@link ApiGateway} only retrieves price information, which it uses to populate
* the {@link MobileProduct}.
*/
@SpringBootApplication
public class App {

/**
* Program entry point
* Program entry point.
*
* @param args
* command line args
* @param args command line args
*/
public static void main(String[] args) {
SpringApplication.run(App.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
*/
public class DesktopProduct {
/**
* The price of the product
* The price of the product.
*/
private String price;

/**
* The path to the image of the product
* The path to the image of the product.
*/
private String imagePath;

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

/**
* An interface used to communicate with the Image microservice
* An interface used to communicate with the Image microservice.
*/
public interface ImageClient {
String getImagePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;

import org.springframework.stereotype.Component;

/**
* An adapter to communicate with the Image microservice
* An adapter to communicate with the Image microservice.
*/
@Component
public class ImageClientImpl implements ImageClient {
/**
* Makes a simple HTTP Get request to the Image microservice
*
* Makes a simple HTTP Get request to the Image microservice.
*
* @return The path to the image
*/
@Override
public String getImagePath() {
String response = null;

HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest httpGet = HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:50005/image-path")).build();
HttpRequest httpGet =
HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:50005/image-path")).build();

try {
HttpResponse<String> httpResponse = httpClient.send(httpGet, BodyHandlers.ofString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
public class MobileProduct {
/**
* The price of the product
* The price of the product.
*/
private String price;

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

/**
* An interface used to communicate with the Price microservice
* An interface used to communicate with the Price microservice.
*/
public interface PriceClient {
String getPrice();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;

import org.springframework.stereotype.Component;

/**
* An adapter to communicate with the Price microservice
* An adapter to communicate with the Price microservice.
*/
@Component
public class PriceClientImpl implements PriceClient {
/**
* Makes a simple HTTP Get request to the Price microservice
*
* Makes a simple HTTP Get request to the Price microservice.
*
* @return The price of the product
*/
@Override
Expand All @@ -48,7 +47,8 @@ public String getPrice() {
String response = null;

HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest httpGet = HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:50006/price")).build();
HttpRequest httpGet =
HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:50006/price")).build();

try {
HttpResponse<String> httpResponse = httpClient.send(httpGet, BodyHandlers.ofString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

server.port=50004
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* ImageApplication starts up Spring Boot, exposing endpoints for the Image microservice through
* the {@link ImageController}.
* ImageApplication starts up Spring Boot, exposing endpoints for the Image microservice through the
* {@link ImageController}.
*/
@SpringBootApplication
public class ImageApplication {

/**
* Microservice entry point
* @param args
* command line args
* Microservice entry point.
*
* @param args command line args
*/
public static void main(String[] args) {
SpringApplication.run(ImageApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
import org.springframework.web.bind.annotation.RestController;

/**
* Exposes the Image microservice's endpoints
* Exposes the Image microservice's endpoints.
*/
@RestController
public class ImageController {

/**
* An endpoint for a user to retrieve an image path
* An endpoint for a user to retrieve an image path.
*
* @return An image path
*/
@RequestMapping(value = "/image-path", method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* PriceApplication starts up Spring Boot, exposing endpoints for the Price microservice through
* the {@link PriceController}.
* PriceApplication starts up Spring Boot, exposing endpoints for the Price microservice through the
* {@link PriceController}.
*/
@SpringBootApplication
public class PriceApplication {

/**
* Microservice entry point
* @param args
* command line args
* Microservice entry point.
*
* @param args command line args
*/
public static void main(String[] args) {
SpringApplication.run(PriceApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
import org.springframework.web.bind.annotation.RestController;

/**
* Exposes the Price microservice's endpoints
* Exposes the Price microservice's endpoints.
*/
@RestController
public class PriceController {

/**
* An endpoint for a user to retrieve a product's price
* An endpoint for a user to retrieve a product's price.
*
* @return A product's price
*/
@RequestMapping(value = "/price", method = RequestMethod.GET)
Expand Down
14 changes: 6 additions & 8 deletions lazy-loading/src/main/java/com/iluwatar/lazy/loading/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,20 @@
import org.slf4j.LoggerFactory;

/**
*
* Lazy loading idiom defers object creation until needed.
* <p>
* This example shows different implementations of the pattern with increasing sophistication.
* <p>
* Additional information and lazy loading flavours are described in
* http://martinfowler.com/eaaCatalog/lazyLoad.html
*
* <p>This example shows different implementations of the pattern with increasing sophistication.
*
* <p>Additional information and lazy loading flavours are described in
* http://martinfowler.com/eaaCatalog/lazyLoad.html
*/
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@
import org.slf4j.LoggerFactory;

/**
*
* Heavy objects are expensive to create.
*
*/
public class Heavy {

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

/**
* Constructor
* Constructor.
*/
public Heavy() {
LOGGER.info("Creating Heavy ...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import org.slf4j.LoggerFactory;

/**
*
* Simple implementation of the lazy loading idiom. However, this is not thread safe.
*
*/
public class HolderNaive {

Expand All @@ -38,14 +36,14 @@ public class HolderNaive {
private Heavy heavy;

/**
* Constructor
* Constructor.
*/
public HolderNaive() {
LOGGER.info("HolderNaive created");
}

/**
* Get heavy object
* Get heavy object.
*/
public Heavy getHeavy() {
if (heavy == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
import org.slf4j.LoggerFactory;

/**
*
* Same as HolderNaive but with added synchronization. This implementation is thread safe, but each
* {@link #getHeavy()} call costs additional synchronization overhead.
*
*/
public class HolderThreadSafe {

Expand All @@ -39,14 +37,14 @@ public class HolderThreadSafe {
private Heavy heavy;

/**
* Constructor
* Constructor.
*/
public HolderThreadSafe() {
LOGGER.info("HolderThreadSafe created");
}

/**
* Get heavy object
* Get heavy object.
*/
public synchronized Heavy getHeavy() {
if (heavy == null) {
Expand Down
Loading