Skip to content

Commit 865d98c

Browse files
committed
docs: update event queue
1 parent 9c30eaa commit 865d98c

File tree

4 files changed

+9
-58
lines changed

4 files changed

+9
-58
lines changed

event-queue/README.md

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@ tag:
1919

2020
The Event Queue pattern is designed to manage tasks in an asynchronous manner, allowing applications to handle operations without blocking user interactions or other processes.
2121

22-
![Event Queue](./etc/event-queue-model.png "Event Queue Visualised")
23-
2422
## Explanation
2523

26-
Real world example
24+
Real-world example
2725

2826
> The modern emailing system is an example of the fundamental process behind the event-queue design pattern. When an email is sent, the sender continues their daily tasks without the necessity of an immediate response from the receiver. Additionally, the receiver has the freedom to access and process the email at their leisure. Therefore, this process decouples the sender and receiver so that they are not required to engage with the queue at the same time.
2927
30-
3128
In plain words
3229

3330
> The buffer between sender and receiver improves maintainability and scalability of a system. Event queues are typically used to organise and carry out interprocess communication (IPC).
@@ -36,16 +33,11 @@ Wikipedia says
3633

3734
> Message queues (also known as event queues) implement an asynchronous communication pattern between two or more processes/threads whereby the sending and receiving party do not need to interact with the queue at the same time.
3835
39-
40-
Key drawback
41-
42-
> As the event queue model decouples the sender-receiver relationship - this means that the event-queue design pattern is unsuitable for scenarios in which the sender requires a response. For example, this is a prominent feature within online multiplayer games, therefore, this approach require thorough consideration.
43-
4436
**Programmatic Example**
4537

4638
This example demonstrates an application using an event queue system to handle audio playback asynchronously.
4739

48-
The App class sets up an instance of Audio, plays two sounds, and waits for user input to exit. It demonstrates how an event queue could be used to manage asynchronous operations in a software application.
40+
The `App` class sets up an instance of `Audio`, plays two sounds, and waits for user input to exit. It demonstrates how an event queue could be used to manage asynchronous operations in a software application.
4941

5042
```java
5143
public class App {
@@ -65,7 +57,7 @@ public class App {
6557
}
6658
```
6759

68-
The Audio class holds the singleton pattern implementation, manages a queue of audio play requests, and controls thread operations for asynchronous processing.
60+
The `Audio` class holds the singleton pattern implementation, manages a queue of audio play requests, and controls thread operations for asynchronous processing.
6961

7062
```java
7163
public class Audio {
@@ -89,7 +81,7 @@ public class Audio {
8981
}
9082
```
9183

92-
These methods manage the lifecycle of the thread used to process the audio events. The init and startThread methods ensure the thread is properly initialized and running.
84+
These methods manage the lifecycle of the thread used to process the audio events. The `init` and `startThread` methods ensure the thread is properly initialized and running.
9385

9486
```java
9587
public synchronized void stopService() throws InterruptedException {
@@ -124,7 +116,7 @@ private synchronized void startThread() {
124116
}
125117
```
126118

127-
The playSound method checks if the audio is already in the queue and either updates the volume or enqueues a new request, demonstrating the management of asynchronous tasks within the event queue.
119+
The `playSound` method checks if the audio is already in the queue and either updates the volume or enqueues a new request, demonstrating the management of asynchronous tasks within the event queue.
128120

129121
```java
130122
public void playSound(AudioInputStream stream, float volume) {
@@ -141,10 +133,6 @@ public void playSound(AudioInputStream stream, float volume) {
141133
}
142134
```
143135

144-
## Class diagram
145-
146-
![alt text](./etc/model.png "Event Queue")
147-
148136
## Applicability
149137

150138
This pattern is applicable in scenarios where tasks can be handled asynchronously outside the main application flow, such as in GUI applications, server-side event handling, or in systems that require task scheduling without immediate execution. In particular:
@@ -182,10 +170,9 @@ Trade-offs:
182170

183171
## Credits
184172

185-
* [Pattern-Oriented Software Architecture, Volume 2: Patterns for Concurrent and Networked Objects](https://amzn.to/3U2hlcy)
173+
* [Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions](https://amzn.to/3xzSlC2)
174+
* [Game Programming Patterns](https://amzn.to/3K96fOn)
186175
* [Java Concurrency in Practice](https://amzn.to/3Ji16mX)
176+
* [Pattern-Oriented Software Architecture, Volume 2: Patterns for Concurrent and Networked Objects](https://amzn.to/3U2hlcy)
187177
* [Patterns of Enterprise Application Architecture](https://amzn.to/3xtVtPJ)
188-
* [Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions](https://amzn.to/3xzSlC2)
189-
* [Mihaly Kuprivecz - Event Queue] (http://gameprogrammingpatterns.com/event-queue.html)
190-
* [Wikipedia - Message Queue] (https://en.wikipedia.org/wiki/Message_queue)
191-
* [AWS - Message Queues] (https://aws.amazon.com/message-queue/)
178+
* [Event Queue (Game Programming Patterns)](http://gameprogrammingpatterns.com/event-queue.html)

event-queue/etc/event-queue-model.png

-47 KB
Binary file not shown.

event-queue/etc/model.png

-22.7 KB
Binary file not shown.

event-queue/etc/model.ucls

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)