-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb36470
commit 961fb46
Showing
35 changed files
with
2,462 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
Submodule async-java-gradle
deleted from
1f7913
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# Create .gitignore file | ||
cat > .gitignore << 'EOL' | ||
# Gradle specific | ||
.gradle/ | ||
build/ | ||
out/ | ||
bin/ | ||
|
||
# Compiled class files | ||
*.class | ||
|
||
# Log files | ||
*.log | ||
logs/ | ||
|
||
# Package Files | ||
*.jar | ||
*.war | ||
*.ear | ||
*.nar | ||
|
||
# Virtual machine crash logs | ||
hs_err_pid* | ||
|
||
# IDE specific files | ||
.idea/ | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.vscode/ | ||
*.code-workspace | ||
|
||
# macOS specific | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Eclipse specific | ||
.classpath | ||
.project | ||
.settings/ | ||
.metadata/ | ||
|
||
# NetBeans specific | ||
nbproject/private/ | ||
build/ | ||
nbbuild/ | ||
dist/ | ||
nbdist/ | ||
nbactions.xml | ||
nb-configuration.xml | ||
|
||
# Temporary files | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
|
||
# Dependency directories | ||
node_modules/ | ||
|
||
# Sensitive or local configuration | ||
*.env | ||
local.properties | ||
|
||
# Compiled Python files | ||
*.pyc | ||
|
||
# Backup files | ||
*.bak | ||
*.gho | ||
*.ori | ||
*.orig | ||
*.tmp | ||
|
||
# Gradle build cache | ||
.gradle-build-cache/ | ||
|
||
# JVM crash logs | ||
hs_err_pid* | ||
|
||
# Compiled bytecode | ||
*.class | ||
|
||
# Log backup files | ||
*.log.* | ||
|
||
# Compiled native libraries | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Compiled static libraries | ||
*.a | ||
*.lib | ||
|
||
# Profiler and performance analysis files | ||
*.hprof | ||
EOL | ||
|
||
# Set appropriate permissions | ||
chmod 644 .gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
# Concurrent Producer-Consumer Message Processing System | ||
|
||
## 🚀 Project Overview | ||
|
||
This Java-based application demonstrates a sophisticated concurrent message processing system using the producer-consumer design pattern. It showcases advanced concurrent programming techniques, thread management, and configurable message processing. | ||
|
||
## 🔧 System Architecture | ||
|
||
### Architectural Diagram | ||
``` | ||
+-------------------+ +-------------------+ | ||
| Producers | | Consumers | | ||
+-------------------+ +-------------------+ | ||
| - Generate msgs | | - Process msgs | | ||
| - Put in channel | --> | - Consume from | | ||
+-------------------+ | shared channel | | ||
+-------------------+ | ||
| Blocking Queue | | ||
+-------------------+ | ||
``` | ||
|
||
### Message Flow Diagram | ||
``` | ||
Producer 1 Producer 2 Producer N | ||
| | | | ||
v v v | ||
+--------------------+ +--------------------+ +--------------------+ | ||
| Generate Message | | Generate Message | | Generate Message | | ||
+--------------------+ +--------------------+ +--------------------+ | ||
| | | | ||
| | | | ||
v v v | ||
+------------------------------------------------------------+ | ||
| Blocking Message Queue | | ||
| [Message 1] [Message 2] [Message 3] ... [Message N] | | ||
+------------------------------------------------------------+ | ||
| | | | ||
| Concurrent | | | ||
| Consumption | | | ||
v v v | ||
+--------------------+ +--------------------+ +--------------------+ | ||
| Consumer 1 | | Consumer 2 | | Consumer N | | ||
| - Process Message | | - Process Message | | - Process Message | | ||
| - Track Duration | | - Track Duration | | - Track Duration | | ||
+--------------------+ +--------------------+ +--------------------+ | ||
| | | | ||
v v v | ||
+------------------------------------------------------------+ | ||
| Processed Message Results | | ||
| [Processed Msg] [Processed Msg] [Processed Msg] | | ||
+------------------------------------------------------------+ | ||
``` | ||
|
||
|
||
### Key Components | ||
|
||
1. **Producers**: | ||
- Generate unique messages | ||
- Add messages to a shared blocking queue | ||
- Simulate variable message creation time | ||
|
||
2. **Consumers**: | ||
- Remove messages from the shared queue | ||
- Process messages with variable processing time | ||
- Track message processing duration | ||
|
||
3. **Shared Channel**: | ||
- Thread-safe `ArrayBlockingQueue` | ||
- Manages message transfer between producers and consumers | ||
|
||
## 🌟 Features | ||
|
||
- Configurable number of producers and consumers | ||
- Dynamic thread pool management | ||
- Message processing time tracking | ||
- Graceful thread shutdown | ||
- Comprehensive logging | ||
- Command-line configuration | ||
|
||
## 🛠 Technical Details | ||
|
||
### Core Classes | ||
|
||
- `MessageProcessor`: Orchestrates message processing | ||
- `Message`: Immutable message representation | ||
- `Duration`: Processing time tracking | ||
- `ProducerConsumerApp`: CLI entry point | ||
|
||
### Concurrency Mechanisms | ||
|
||
- `ExecutorService` for thread management | ||
- `ConcurrentHashMap` for thread-safe tracking | ||
- `BlockingQueue` for inter-thread communication | ||
- Configurable queue capacity | ||
|
||
## 📦 Technology Stack | ||
|
||
- **Language**: Java 17 | ||
- **Concurrency**: Java Concurrent APIs | ||
- **CLI**: Picocli | ||
- **Logging**: SLF4J | ||
- **Testing**: JUnit 5 | ||
|
||
## 🚀 Getting Started | ||
|
||
### Prerequisites | ||
|
||
- Java 17 or higher | ||
- Gradle 8.x | ||
|
||
### Installation | ||
|
||
1. Clone the repository | ||
```bash | ||
git clone https://github.com/yourusername/producer-consumer-app.git | ||
cd producer-consumer-app | ||
``` | ||
2. Build the project | ||
```bash | ||
./gradlew clean build | ||
``` | ||
3. Run the application | ||
```bash | ||
# Default configuration | ||
./gradlew run | ||
``` | ||
|
||
```bash | ||
./gradlew run --args="--numProducers 5 --numConsumers 5 --queueCapacity 100 --messageCreationDelay 1000 --messageProcessingDelay 500" | ||
``` | ||
|
||
### Command-line Options | ||
|
||
- `-p, --producers`: Number of producers (default: 10) | ||
- `-c, --consumers`: Number of consumers (default: 5) | ||
- `-m, --messages`: Messages per producer (default: 5) | ||
|
||
## 🧪 Testing | ||
|
||
Run comprehensive test suite: | ||
```bash | ||
./gradlew test | ||
``` | ||
|
||
|
||
## 📊 Performance Characteristics | ||
|
||
- Dynamic thread pool scaling | ||
- Non-blocking message processing | ||
- Configurable processing delays | ||
- Detailed performance logging | ||
|
||
## 🔍 Logging | ||
|
||
Utilizes SLF4J for comprehensive logging: | ||
- INFO level for system events | ||
- DEBUG level for detailed message tracking | ||
- ERROR level for exception handling | ||
|
||
## 🚧 Potential Improvements | ||
|
||
- Advanced metrics collection | ||
- Configurable backoff strategies | ||
- Enhanced error handling | ||
- Prometheus/Micrometer integration for monitoring | ||
|
||
## 📜 License | ||
|
||
MIT License | ||
|
||
## 🤝 Contributing | ||
|
||
1. Fork the repository | ||
2. Create your feature branch | ||
3. Commit your changes | ||
4. Push to the branch | ||
5. Create a new Pull Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
plugins { | ||
id 'java' | ||
id 'application' | ||
} | ||
|
||
group 'com.example' | ||
version '1.0-SNAPSHOT' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'com.google.guava:guava:31.1-jre' | ||
implementation 'info.picocli:picocli:4.7.5' | ||
implementation 'org.slf4j:slf4j-api:2.0.9' | ||
implementation 'ch.qos.logback:logback-classic:1.4.11' | ||
|
||
annotationProcessor 'info.picocli:picocli-codegen:4.7.5' | ||
|
||
// Test dependencies | ||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' | ||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' | ||
} | ||
|
||
application { | ||
mainClass = 'com.example.ProducerConsumerApp' | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.