Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
f01235b
docs: add notification diagram
iseppala Apr 9, 2025
7ed9e39
docs: null object diagram
iseppala Apr 9, 2025
6bae409
docs: object mother diagrams
iseppala Apr 9, 2025
2aaf712
docs: object pool and observer diagrams
iseppala Apr 9, 2025
32dbc7f
docs: optimistic offline lock diagram
iseppala Apr 9, 2025
ecfd944
docs: page object and parameter object diagrams
iseppala Apr 9, 2025
fdd07c7
docs: partial response and pipeline diagrams
iseppala Apr 9, 2025
261da00
docs: poison pill and private class data diagrams
iseppala Apr 9, 2025
3abaa83
docs: producer-consumer and promise diagrams
iseppala Apr 9, 2025
23af67c
docs: property, prototype, proxy diagrams
iseppala Apr 9, 2025
ae737f6
docs: queue-based load leveling diagram
iseppala Apr 9, 2025
6d6638f
docs: reactor diagram
iseppala Apr 9, 2025
09e5313
docs: registry diagram
iseppala Apr 9, 2025
9e5d9e5
docs: repository diagram
iseppala Apr 9, 2025
21fed21
docs: raii diagram
iseppala Apr 9, 2025
44f6ab3
docs: retry and role object diagrams
iseppala Apr 9, 2025
6cadf25
fix: handle awaitTermination result and ensure proper ExecutorService…
2897robo Apr 10, 2025
54048a1
docs: add saga flowchart
iseppala Apr 10, 2025
a97bfec
docs: separated interface diagram
iseppala Apr 10, 2025
30d6875
docs: diagrams for serialized entity and serialized lob
iseppala Apr 10, 2025
b8f3869
docs: diagrams for servant and server session
iseppala Apr 10, 2025
73a5828
docs: service locator and service stub diagrams
iseppala Apr 10, 2025
e5485da
docs: service to worker, session facade, sharding diagrams
iseppala Apr 10, 2025
8e82390
docs: single table inheritance and singleton diagrams
iseppala Apr 10, 2025
cd224ea
docs: add diagrams for spatial partition, special case, specification…
iseppala Apr 10, 2025
0b83b6d
feat: Adding backpressure design pattern #3233 (#3249)
sanurah Apr 12, 2025
ba7be25
docs: diagrams for table module and template method
iseppala Apr 12, 2025
95bfd6c
docs: new diagrams for template view and throttling
iseppala Apr 12, 2025
21914f9
docs: updated diagrams for tolerant reader and trampoline
iseppala Apr 12, 2025
6195d5e
docs: diagrams for transaction script, twin, and type object
iseppala Apr 12, 2025
81ecb56
docs: diagrams for unit of work, update method, and value object
iseppala Apr 12, 2025
32c9031
docs: diagrams for version number, virtual proxy, visitor
iseppala Apr 12, 2025
ce2e5f7
docs: update backpressure description
iseppala Apr 12, 2025
8ca487e
docs: update function composition pattern
iseppala Apr 12, 2025
4b06dc2
docs: updates for MapReduce
iseppala Apr 12, 2025
5241a4a
docs: update client-side ui composition
iseppala Apr 12, 2025
4afabdb
docs: update bloc pattern
iseppala Apr 12, 2025
9de12ea
docs: update clean architecture
iseppala Apr 13, 2025
acb40e1
docs: update microservices distributed tracing
iseppala Apr 14, 2025
076fc21
docs: update microservices idempotent consumer
iseppala Apr 14, 2025
d95c679
docs: update money pattern
iseppala Apr 14, 2025
b8aa775
fix: fix code formatting
iseppala Apr 14, 2025
b95bf24
build(deps): bump org.jacoco:jacoco-maven-plugin from 0.8.12 to 0.8.1…
dependabot[bot] Apr 15, 2025
2e686b2
build(deps): bump io.micrometer:micrometer-tracing-bridge-brave (#3253)
dependabot[bot] Apr 15, 2025
0f37b4e
build(deps): bump com.diffplug.spotless:spotless-maven-plugin (#3254)
dependabot[bot] Apr 15, 2025
1a08b73
docs: update monolithic architecture
iseppala Apr 15, 2025
9f7ce4e
docs: update publish-subscribe
iseppala Apr 15, 2025
bc42e38
docs: update service stub
iseppala Apr 15, 2025
67bc5e3
docs: update session facade
iseppala Apr 15, 2025
cb3853a
docs: update table inheritance
iseppala Apr 15, 2025
d80eca1
docs: update book link
iseppala Apr 16, 2025
1cde704
docs: remove some old diagrams
iseppala Apr 22, 2025
fe522fd
feat: Implement Actor Model pattern
ssrijan-007-sys Apr 22, 2025
e359f1b
docs: add ssrijan-007-sys as a contributor for code (#3263)
allcontributors[bot] Apr 22, 2025
55bef7c
chore: removed duplicated dependency (#3258)
e5LA Apr 22, 2025
e4681e4
docs: add e5LA as a contributor for code (#3264)
allcontributors[bot] Apr 22, 2025
6e20d32
build(deps): bump org.springframework:spring-web (#3262)
dependabot[bot] Apr 22, 2025
ad6bdf8
build(deps): bump org.sonarsource.scanner.maven:sonar-maven-plugin (#…
dependabot[bot] Apr 22, 2025
dae93ad
translation: Translate selected patterns to persian (#3256)
maziyar-gerami Apr 22, 2025
f8f33f5
docs: add maziyar-gerami as a contributor for translation (#3265)
allcontributors[bot] Apr 22, 2025
8a64f4c
docs: update dependency injection
iseppala Apr 26, 2025
7d2e626
build(deps): bump com.mycila:license-maven-plugin from 4.6 to 5.0.0 (…
dependabot[bot] May 1, 2025
a62601a
build(deps): bump com.fasterxml.jackson.core:jackson-core (#3270)
dependabot[bot] May 1, 2025
0da4dcd
docs: update producer-consumer
iseppala May 2, 2025
3ac1a36
docs: update prototype
iseppala May 2, 2025
8529017
feat: Implement Thread-Pool Executor pattern (#3271)
yybmion May 15, 2025
bf16400
docs: add yybmion as a contributor for code (#3279)
allcontributors[bot] May 15, 2025
f6bb515
chore: adding missing license (#3273)
e5LA May 17, 2025
ede37bd
docs: add e5LA as a contributor for doc (#3281)
allcontributors[bot] May 17, 2025
98d3601
docs: Formatted spacing and updated documentation (#3290)
ronodhirSoumik Jan 17, 2026
0ab6019
docs: add ronodhirSoumik as a contributor for doc (#3418)
allcontributors[bot] Jan 17, 2026
08651d0
chore: Update presubmit.ai configuration
iseppala Jan 17, 2026
3ba2560
build(deps-dev): bump org.htmlunit:htmlunit from 4.7.0 to 4.17.0 (#3334)
dependabot[bot] Feb 8, 2026
812e4cd
feat: Microservices pattern : Self-Registration (#3245)
naman-sriv Feb 8, 2026
fecf7e7
build(deps-dev): bump io.projectreactor:reactor-test (#3377)
dependabot[bot] Feb 8, 2026
f92e682
feat: Implement DAO Factory pattern (#3282)
letdtcode Feb 8, 2026
4caa0bf
docs: Persian translation: Abstract Factory (#3280)
maziyar-gerami Feb 8, 2026
7c12643
docs: add naman-sriv as a contributor for code (#3428)
allcontributors[bot] Feb 8, 2026
dc3425d
docs: add letdtcode as a contributor for code (#3429)
allcontributors[bot] Feb 8, 2026
a3fcc63
feat: Implement View Helper pattern (#3278)
e5LA Feb 8, 2026
265e3d0
feat: Rate Limiting Pattern #2973 (#3291)
skamble2 Feb 22, 2026
ce5154e
docs: add skamble2 as a contributor for code (#3437)
allcontributors[bot] Feb 22, 2026
b8f8199
docs: Update README.md (#3298)
Olexandr88 Feb 22, 2026
2d39fe7
docs: add Olexandr88 as a contributor for doc (#3440)
allcontributors[bot] Feb 22, 2026
80e928a
Fixed security hotspots and bugs
Sagar-S-R Apr 14, 2026
ad42f7b
Fix : Security issues
Sagar-S-R Apr 14, 2026
ba6af84
Update special-case/README.md
Sagar-S-R Apr 14, 2026
45aa296
Update microservices-self-registration/greetingservice/src/main/java/…
Sagar-S-R Apr 14, 2026
6d0e071
Update backpressure/src/test/java/com/iluwatar/backpressure/Publisher…
Sagar-S-R Apr 14, 2026
d00936c
Update dao-factory/src/main/java/com/iluwatar/daofactory/DAOFactoryPr…
Sagar-S-R Apr 14, 2026
3f7bfff
Update function-composition/src/main/java/com/iluwatar/function/compo…
Sagar-S-R Apr 14, 2026
6b20179
Update money/README.md
Sagar-S-R Apr 14, 2026
49f248c
Update leader-followers/src/main/java/com/iluwatar/leaderfollowers/Ap…
Sagar-S-R Apr 14, 2026
ffe8b96
Update dao-factory/src/main/java/com/iluwatar/daofactory/MongoDataSou…
Sagar-S-R Apr 14, 2026
ee1689c
Update .github/workflows/presubmit.yml
Sagar-S-R Apr 14, 2026
18b076e
Update dao-factory/src/main/java/com/iluwatar/daofactory/FlatFileData…
Sagar-S-R Apr 14, 2026
29f11b5
Update caching/src/main/java/com/iluwatar/caching/database/MongoDb.java
Sagar-S-R Apr 14, 2026
ec1a6fb
Update backpressure/src/main/java/com/iluwatar/backpressure/App.java
Sagar-S-R Apr 14, 2026
576ecd1
Update rate-limiting-pattern/src/test/java/com/iluwatar/rate/limiting…
Sagar-S-R Apr 14, 2026
5ba7f71
Update rate-limiting-pattern/pom.xml
Sagar-S-R Apr 14, 2026
363a64a
Update backpressure/src/main/java/com/iluwatar/backpressure/App.java
Sagar-S-R Apr 14, 2026
3b197dd
Update backpressure/src/test/java/com/iluwatar/backpressure/Subscribe…
Sagar-S-R Apr 14, 2026
44a1e48
Merge branch 'test-branch' into master
Sagar-S-R Apr 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
82 changes: 82 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -3493,6 +3493,88 @@
"contributions": [
"code"
]
},
{
"login": "ssrijan-007-sys",
"name": "ssrijan-007-sys",
"avatar_url": "https://avatars.githubusercontent.com/u/137605821?v=4",
"profile": "https://github.com/ssrijan-007-sys",
"contributions": [
"code"
]
},
{
"login": "e5LA",
"name": "e5LA",
"avatar_url": "https://avatars.githubusercontent.com/u/208197507?v=4",
"profile": "https://github.com/e5LA",
"contributions": [
"code",
"doc"
]
},
{
"login": "maziyar-gerami",
"name": "Maziyar Gerami",
"avatar_url": "https://avatars.githubusercontent.com/u/122622721?v=4",
"profile": "http://maziyar-gerami.github.io/portfolio/",
"contributions": [
"translation"
]
},
{
"login": "yybmion",
"name": "yoobin_mion",
"avatar_url": "https://avatars.githubusercontent.com/u/113106136?v=4",
"profile": "https://github.com/yybmion",
"contributions": [
"code"
]
},
{
"login": "ronodhirSoumik",
"name": "Soumik Sarker",
"avatar_url": "https://avatars.githubusercontent.com/u/46843689?v=4",
"profile": "https://ronodhirsoumik.github.io",
"contributions": [
"doc"
]
},
{
"login": "naman-sriv",
"name": "Naman Srivastava",
"avatar_url": "https://avatars.githubusercontent.com/u/82610773?v=4",
"profile": "https://github.com/naman-sriv",
"contributions": [
"code"
]
},
{
"login": "letdtcode",
"name": "Thanh Nguyen Duc",
"avatar_url": "https://avatars.githubusercontent.com/u/92111552?v=4",
"profile": "https://github.com/letdtcode",
"contributions": [
"code"
]
},
{
"login": "skamble2",
"name": "Soham Kamble",
"avatar_url": "https://avatars.githubusercontent.com/u/121136639?v=4",
"profile": "https://github.com/skamble2",
"contributions": [
"code"
]
},
{
"login": "Olexandr88",
"name": "Olexandr88",
"avatar_url": "https://avatars.githubusercontent.com/u/93856062?v=4",
"profile": "https://github.com/Olexandr88",
"contributions": [
"doc"
]
}
],
"contributorsPerLine": 6,
Expand Down
49 changes: 21 additions & 28 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
name: Presubmit.ai

permissions:
contents: read
pull-requests: write
issues: write
contents: read
pull-requests: write
issues: write

on:
pull_request_target: # Handle forked repository PRs in the base repository context
types: [opened, synchronize]
pull_request_review_comment: # Handle review comments
types: [created]
pull_request_target:
Comment thread
Sagar-S-R marked this conversation as resolved.
types: [opened, synchronize]
pull_request_review_comment:
types: [created]
Comment thread
Sagar-S-R marked this conversation as resolved.

jobs:
review:
runs-on: ubuntu-latest
steps:
- name: Check required secrets
run: |
if [ -z "${{ secrets.LLM_API_KEY }}" ]; then
echo "Error: LLM_API_KEY secret is not configured"
exit 1
fi

- name: Check out PR code
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Run AI Reviewer
uses: presubmit/ai-reviewer@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
LLM_MODEL: "gemini-1.5-flash"
review:
runs-on: ubuntu-latest
steps:
- name: Check required secrets
run: |
if [ -z "${{ secrets.LLM_API_KEY }}" ]; then
echo "Error: LLM_API_KEY secret is not configured"
exit 1
fi
- uses: presubmit/ai-reviewer@<FULL_40_CHARACTER_COMMIT_SHA>
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
LLM_MODEL: "gpt-5-nano"
Comment thread
Sagar-S-R marked this conversation as resolved.
Comment thread
Sagar-S-R marked this conversation as resolved.
Comment thread
Sagar-S-R marked this conversation as resolved.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Design Patterns Implemented in Java

![Java CI](https://github.com/iluwatar/java-design-patterns/workflows/Java%20CI/badge.svg)
[![Java CI](https://github.com/iluwatar/java-design-patterns/workflows/Java%20CI/badge.svg)](https://github.com/iluwatar/java-design-patterns/actions/workflows/maven-ci.yml)
[![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/iluwatar/java-design-patterns/master/LICENSE.md)
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=iluwatar_java-design-patterns&metric=ncloc)](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=iluwatar_java-design-patterns&metric=coverage)](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns)
[![Join the chat at https://gitter.im/iluwatar/java-design-patterns](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-383-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-392-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

<br/>
Expand Down Expand Up @@ -45,7 +45,7 @@ If you are willing to contribute to the project you will find the relevant infor

# The Book

The design patterns are now available as an e-book. Find out more about "Open Source Java Design Patterns" here: https://payhip.com/b/kcaF9
The design patterns are now available as an e-book. Find out more about "Open Source Java Design Patterns" here: https://payhip.com/b/bNQFX

The project contributors can get the book for free. Contact the maintainer via [Gitter chatroom](https://gitter.im/iluwatar/java-design-patterns) or email (iluwatar (at) gmail (dot) com ). Send a message that contains your email address, Github username, and a link to an accepted pull request.

Expand Down Expand Up @@ -570,6 +570,19 @@ This project is licensed under the terms of the MIT license.
<td align="center" valign="top" width="16.66%"><a href="https://github.com/sanurah"><img src="https://avatars.githubusercontent.com/u/16178588?v=4?s=100" width="100px;" alt="Sanura Hettiarachchi"/><br /><sub><b>Sanura Hettiarachchi</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=sanurah" title="Code">💻</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/2897robo"><img src="https://avatars.githubusercontent.com/u/31699375?v=4?s=100" width="100px;" alt="Kim Gi Uk"/><br /><sub><b>Kim Gi Uk</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=2897robo" title="Code">💻</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/Suchismita-Deb"><img src="https://avatars.githubusercontent.com/u/68535074?v=4?s=100" width="100px;" alt="Suchismita Deb"/><br /><sub><b>Suchismita Deb</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=Suchismita-Deb" title="Code">💻</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/ssrijan-007-sys"><img src="https://avatars.githubusercontent.com/u/137605821?v=4?s=100" width="100px;" alt="ssrijan-007-sys"/><br /><sub><b>ssrijan-007-sys</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=ssrijan-007-sys" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/e5LA"><img src="https://avatars.githubusercontent.com/u/208197507?v=4?s=100" width="100px;" alt="e5LA"/><br /><sub><b>e5LA</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=e5LA" title="Code">💻</a> <a href="https://github.com/iluwatar/java-design-patterns/commits?author=e5LA" title="Documentation">📖</a></td>
<td align="center" valign="top" width="16.66%"><a href="http://maziyar-gerami.github.io/portfolio/"><img src="https://avatars.githubusercontent.com/u/122622721?v=4?s=100" width="100px;" alt="Maziyar Gerami"/><br /><sub><b>Maziyar Gerami</b></sub></a><br /><a href="#translation-maziyar-gerami" title="Translation">🌍</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/yybmion"><img src="https://avatars.githubusercontent.com/u/113106136?v=4?s=100" width="100px;" alt="yoobin_mion"/><br /><sub><b>yoobin_mion</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=yybmion" title="Code">💻</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://ronodhirsoumik.github.io"><img src="https://avatars.githubusercontent.com/u/46843689?v=4?s=100" width="100px;" alt="Soumik Sarker"/><br /><sub><b>Soumik Sarker</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=ronodhirSoumik" title="Documentation">📖</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/naman-sriv"><img src="https://avatars.githubusercontent.com/u/82610773?v=4?s=100" width="100px;" alt="Naman Srivastava"/><br /><sub><b>Naman Srivastava</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=naman-sriv" title="Code">💻</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/letdtcode"><img src="https://avatars.githubusercontent.com/u/92111552?v=4?s=100" width="100px;" alt="Thanh Nguyen Duc"/><br /><sub><b>Thanh Nguyen Duc</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=letdtcode" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/skamble2"><img src="https://avatars.githubusercontent.com/u/121136639?v=4?s=100" width="100px;" alt="Soham Kamble"/><br /><sub><b>Soham Kamble</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=skamble2" title="Code">💻</a></td>
<td align="center" valign="top" width="16.66%"><a href="https://github.com/Olexandr88"><img src="https://avatars.githubusercontent.com/u/93856062?v=4?s=100" width="100px;" alt="Olexandr88"/><br /><sub><b>Olexandr88</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=Olexandr88" title="Documentation">📖</a></td>
</tr>
</tbody>
</table>
Expand Down
201 changes: 201 additions & 0 deletions actor-model/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
---
title: "Actor Model Pattern in Java: Building Concurrent Systems with Elegance"
shortTitle: Actor Model
description: "Explore the Actor Model pattern in Java with real-world examples and practical implementation. Learn how to build scalable, message-driven systems using actors, messages, and asynchronous communication."
category: Concurrency
language: en
tag:
- Concurrency
- Messaging
- Isolation
- Asynchronous
- Distributed Systems
- Actor Model
---

## Also Known As

- Message-passing concurrency
- Actor-based concurrency

---

## Intent of Actor Model Pattern

The Actor Model pattern enables the construction of highly concurrent, distributed, and fault-tolerant systems by using isolated components (actors) that interact exclusively through asynchronous message passing.

---

## Detailed Explanation of Actor Model Pattern with Real-World Examples

### 📦 Real-world Example

Imagine a customer service system:
- Each **customer support agent** is an **actor**.
- Customers **send questions (messages)** to agents.
- Each agent handles one request at a time and can **respond asynchronously** without interfering with other agents.

---

### 🧠 In Plain Words

> "Actors are like independent workers that never share memory and only communicate through messages."

---

### 📖 Wikipedia Says

> [Actor model](https://en.wikipedia.org/wiki/Actor_model) is a mathematical model of concurrent computation that treats "actors" as the universal primitives of concurrent computation.

---

### 🧹 Architecture Diagram

![UML Class Diagram](./etc/Actor_Model_UML_Class_Diagram.png)

---

## Programmatic Example of Actor Model Pattern in Java

### Actor.java

```java
public abstract class Actor implements Runnable {

@Setter @Getter private String actorId;
private final BlockingQueue<Message> mailbox = new LinkedBlockingQueue<>();
private volatile boolean active = true;


public void send(Message message) {
mailbox.add(message);
}

public void stop() {
active = false;
}

@Override
public void run() {

}

protected abstract void onReceive(Message message);
}

```

### Message.java

```java

@AllArgsConstructor
@Getter
@Setter
public class Message {
private final String content;
private final String senderId;
}
```

### ActorSystem.java

```java
public class ActorSystem {
public void startActor(Actor actor) {
String actorId = "actor-" + idCounter.incrementAndGet(); // Generate a new and unique ID
actor.setActorId(actorId); // assign the actor it's ID
actorRegister.put(actorId, actor); // Register and save the actor with it's ID
executor.submit(actor); // Run the actor in a thread
}
public Actor getActorById(String actorId) {
return actorRegister.get(actorId); // Find by Id
}

public void shutdown() {
executor.shutdownNow(); // Stop all threads
}
}
```

### App.java

```java
public class App {
public static void main(String[] args) {
ActorSystem system = new ActorSystem();
Actor srijan = new ExampleActor(system);
Actor ansh = new ExampleActor2(system);

system.startActor(srijan);
system.startActor(ansh);
ansh.send(new Message("Hello ansh", srijan.getActorId()));
srijan.send(new Message("Hello srijan!", ansh.getActorId()));

Thread.sleep(1000); // Give time for messages to process

srijan.stop(); // Stop the actor gracefully
ansh.stop();
system.shutdown(); // Stop the actor system
}
}
```

---

## When to Use the Actor Model Pattern in Java

- When building **concurrent or distributed systems**
- When you want **no shared mutable state**
- When you need **asynchronous, message-driven communication**
- When components should be **isolated and loosely coupled**

---

## Actor Model Pattern Java Tutorials

- [Baeldung – Akka with Java](https://www.baeldung.com/java-akka)
- [Vaughn Vernon – Reactive Messaging Patterns](https://vaughnvernon.co/?p=1143)

---

## Real-World Applications of Actor Model Pattern in Java

- [Akka Framework](https://akka.io/)
- [Erlang and Elixir concurrency](https://www.erlang.org/)
- [Microsoft Orleans](https://learn.microsoft.com/en-us/dotnet/orleans/)
- JVM-based game engines and simulators

---

## Benefits and Trade-offs of Actor Model Pattern

### ✅ Benefits
- High concurrency support
- Easy scaling across threads or machines
- Fault isolation and recovery
- Message ordering within actors

### ⚠️ Trade-offs
- Harder to debug due to asynchronous behavior
- Slight performance overhead due to message queues
- More complex to design than simple method calls

---

## Related Java Design Patterns

- [Command Pattern](../command)
- [Mediator Pattern](../mediator)
- [Event-Driven Architecture](../event-driven-architecture)
- [Observer Pattern](../observer)

---

## References and Credits

- *Programming Erlang*, Joe Armstrong
- *Reactive Design Patterns*, Roland Kuhn
- *The Actor Model in 10 Minutes*, [InfoQ Article](https://www.infoq.com/articles/actor-model/)
- [Akka Documentation](https://doc.akka.io/docs/akka/current/index.html)

Binary file added actor-model/etc/Actor_Model_UML_Class_Diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading