docs: add new diagrams for game loop, gateway, guarded suspension, half-sync/half-async, health check

This commit is contained in:
Ilkka Seppälä
2025-04-06 20:55:07 +03:00
parent 9b64cdee98
commit 9d23a234bb
11 changed files with 20 additions and 4 deletions
+4
View File
@@ -34,6 +34,10 @@ Wikipedia says
> The central component of any game, from a programming standpoint, is the game loop. The game loop allows the game to run smoothly regardless of a user's input, or lack thereof.
Flowchart
![Game Loop flowchart](./etc/game-loop-flowchart.png)
## Programmatic Example of Game Loop Pattern in Java
In our Java example, we illustrate a simple game loop controlling a bullet's movement, updating its position, ensuring smooth rendering, and responding to user inputs. The Game Loop is the main process driving all game rendering threads, present in all modern games. It handles input processing, internal status updates, rendering, AI, and other processes. Starting with a simple `Bullet` class, we demonstrate the movement of bullets in our game, focusing on their 1-dimensional position for demonstration purposes.
Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

+4
View File
@@ -35,6 +35,10 @@ Wikipedia says
> A server that acts as an API front-end, receives API requests, enforces throttling and security policies, passes requests to the back-end service and then passes the response back to the requester.
Sequence diagram
![Gateway sequence diagram](./etc/gateway-sequence-diagram.png)
## Programmatic Example of Gateway Pattern in Java
First, we define a `Gateway` interface. This interface represents the contract for our external services. Each service that we want to interact with will implement this interface.
Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

+4
View File
@@ -35,6 +35,10 @@ Wikipedia says
> In concurrent programming, Guarded Suspension manages operations requiring a lock and a precondition, delaying execution until the precondition is met.
Sequence diagram
![Guarded Suspension sequence diagram](./etc/guarded-suspension-sequence-diagram.png)
## Programmatic Example of Guarded Suspension Pattern in Java
The `GuardedQueue` class in Java showcases concurrent programming using the Guarded Suspension pattern. It includes synchronized methods that manage thread management and synchronization, demonstrating how threads wait for the right conditions to execute.
Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

+4
View File
@@ -34,6 +34,10 @@ Wikipedia says
> The Half-Sync/Half-Async design pattern is used to solve situations where one part of the application runs synchronously while another runs asynchronously, and the two modules need to communicate with each other.
Sequence diagram
![Half-Sync/Half-Async sequence diagram](./etc/half-sync-half-async-sequence-diagram.png)
## Programmatic Example of Half-Sync/Half-Async Pattern in Java
The Half-Sync/Half-Async design pattern is a concurrency pattern that separates synchronous and asynchronous processing in a system, simplifying the programming model without affecting performance. It's particularly useful in scenarios where you have a mix of short, mid, and long duration tasks.
Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

+4
View File
@@ -30,6 +30,10 @@ In plain words
> The Health Check Pattern is like a regular doctor's visit for services in a microservices architecture. It helps in early detection of issues and ensures that services are healthy and available.
Sequence diagram
![Health Check sequence diagram](./etc/health-check-sequence-diagram.png)
## Programmatic Example of Health Check Pattern in Java
The Health Check design pattern is particularly useful in distributed systems where the health of individual components can affect the overall health of the system. Using Spring Boot Actuator, developers can easily implement health checks in Java applications.
Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

-4
View File
@@ -173,10 +173,6 @@ Running the main function of App class produces the following output:
In this example, the `LotteryAdministration` and `LotteryService` classes are the core of the application. They interact with external interfaces like `LotteryTicketRepository`, `LotteryEventLog`, and `WireTransfers` through dependency injection, keeping the core business logic decoupled from external concerns. This is a basic example of the Hexagonal Architecture pattern, where the core application is at the center of input/output systems.
## Detailed Explanation of Hexagonal Architecture Pattern with Real-World Examples
![Hexagonal Architecture class diagram](./etc/hexagonal.png)
## When to Use the Hexagonal Architecture Pattern in Java
Hexagonal Architecture is particularly beneficial in scenarios: