forked from iluwatar/java-design-patterns
-
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
Showing
6 changed files
with
93 additions
and
7 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,29 @@ | ||
--- | ||
layout: pattern | ||
title: Event Queue | ||
folder: event-queue | ||
permalink: /patterns/event-queue/ | ||
categories: Concurrency | ||
tags: | ||
- Java | ||
- Difficulty Intermediate | ||
- Queue | ||
--- | ||
|
||
## Intent | ||
Event Queue is a good pattern if You have a limited accesibility resource (for example: | ||
Audio or Database), but You need to handle all the requests that want to use that. | ||
It puts all the requests in a queue and process them asynchronously. | ||
Gives the resource for the event when it is the next in the queue and in same time | ||
removes it from the queue. | ||
|
||
![alt text](./etc/model.png "Event Queue") | ||
|
||
## Applicability | ||
Use the Event Queue pattern when | ||
|
||
* You have a limited accesibility resource and the asynchronous process is acceptable to reach that | ||
|
||
## Credits | ||
|
||
* [Mihály Kuprivecz - Event Queue] |
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,26 @@ | ||
@startuml | ||
package com.iluwatar.event.queue { | ||
class App { | ||
+ App() | ||
+ getAudioStream(filePath : String) : AudioInputStream {static} | ||
+ main(args : String[]) {static} | ||
} | ||
class Audio { | ||
- MAX_PENDING : int {static} | ||
- headIndex : int {static} | ||
- pendingAudio : PlayMessage[] {static} | ||
- tailIndex : int {static} | ||
- updateThread : Thread {static} | ||
+ Audio() | ||
+ init() {static} | ||
+ playSound(stream : AudioInputStream, volume : float) {static} | ||
+ stopService() {static} | ||
+ update() {static} | ||
} | ||
class PlayMessage { | ||
~ stream : AudioInputStream | ||
~ volume : float | ||
+ PlayMessage() | ||
} | ||
} | ||
@enduml |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<class-diagram version="1.2.0" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true" | ||
realizations="true" associations="true" dependencies="false" nesting-relationships="true" router="FAN"> | ||
<class id="1" language="java" name="com.iluwatar.event.queue.Audio" project="event-queue" | ||
file="/event-queue/src/main/java/com/iluwatar/event/queue/Audio.java" binary="false" corner="BOTTOM_RIGHT"> | ||
<position height="-1" width="-1" x="285" y="179"/> | ||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" | ||
sort-features="false" accessors="true" visibility="true"> | ||
<attributes public="true" package="true" protected="true" private="true" static="true"/> | ||
<operations public="true" package="true" protected="true" private="true" static="true"/> | ||
</display> | ||
</class> | ||
<class id="2" language="java" name="com.iluwatar.event.queue.PlayMessage" project="event-queue" | ||
file="/event-queue/src/main/java/com/iluwatar/event/queue/PlayMessage.java" binary="false" corner="BOTTOM_RIGHT"> | ||
<position height="-1" width="-1" x="633" y="179"/> | ||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" | ||
sort-features="false" accessors="true" visibility="true"> | ||
<attributes public="true" package="true" protected="true" private="true" static="true"/> | ||
<operations public="true" package="true" protected="true" private="true" static="true"/> | ||
</display> | ||
</class> | ||
<association id="3"> | ||
<end type="SOURCE" refId="1" navigable="false"> | ||
<attribute id="4" name="pendingAudio"/> | ||
<multiplicity id="5" minimum="0" maximum="2147483647"/> | ||
</end> | ||
<end type="TARGET" refId="2" navigable="true"/> | ||
<display labels="true" multiplicity="true"/> | ||
</association> | ||
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" | ||
sort-features="false" accessors="true" visibility="true"> | ||
<attributes public="true" package="true" protected="true" private="true" static="true"/> | ||
<operations public="true" package="true" protected="true" private="true" static="true"/> | ||
</classifier-display> | ||
<association-display labels="true" multiplicity="true"/> | ||
</class-diagram> |
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