mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-19 21:25:38 +00:00
docs: Event-Based Asynchronous explanation + refactor (#2916)
* explation + refactor * update logging
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
@@ -0,0 +1,104 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<class-diagram version="1.2.2" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
|
||||
realizations="true" associations="true" dependencies="false" nesting-relationships="true" router="FAN">
|
||||
<interface id="1" language="java" name="com.iluwatar.event.asynchronous.IEvent" project="java-design-patterns"
|
||||
file="/java-design-patterns/event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/IEvent.java"
|
||||
binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="117" width="151" x="42" y="15"/>
|
||||
<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>
|
||||
</interface>
|
||||
<interface id="2" language="java" name="com.iluwatar.event.asynchronous.ThreadCompleteListener"
|
||||
project="java-design-patterns"
|
||||
file="/java-design-patterns/event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/ThreadCompleteListener.java"
|
||||
binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="326" y="79"/>
|
||||
<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>
|
||||
</interface>
|
||||
<class id="3" language="java" name="com.iluwatar.event.asynchronous.App" project="java-design-patterns"
|
||||
file="/java-design-patterns/event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/App.java"
|
||||
binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="554" y="119"/>
|
||||
<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="4" language="java" name="com.iluwatar.event.asynchronous.EventAsynchronousTest"
|
||||
project="java-design-patterns"
|
||||
file="/java-design-patterns/event-asynchronous/src/test/java/com/iluwatar/event/asynchronous/EventAsynchronousTest.java"
|
||||
binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="207" width="234" x="669" y="16"/>
|
||||
<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="5" language="java" name="com.iluwatar.event.asynchronous.Event" project="java-design-patterns"
|
||||
file="/java-design-patterns/event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/Event.java"
|
||||
binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="141" y="441"/>
|
||||
<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="6" language="java" name="com.iluwatar.event.asynchronous.EventManager" project="java-design-patterns"
|
||||
file="/java-design-patterns/event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/EventManager.java"
|
||||
binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="431" y="439"/>
|
||||
<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="7">
|
||||
<end type="SOURCE" refId="5" navigable="false">
|
||||
<attribute id="8" name="eventListener"/>
|
||||
<multiplicity id="9" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="2" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<realization id="10">
|
||||
<end type="SOURCE" refId="5"/>
|
||||
<end type="TARGET" refId="1"/>
|
||||
</realization>
|
||||
<association id="11">
|
||||
<end type="SOURCE" refId="4" navigable="false">
|
||||
<attribute id="12" name="app"/>
|
||||
<multiplicity id="13" minimum="0" maximum="1"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="3" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<association id="14">
|
||||
<end type="SOURCE" refId="6" navigable="false">
|
||||
<attribute id="15" name="eventPool"/>
|
||||
<multiplicity id="16" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="5" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<realization id="17">
|
||||
<end type="SOURCE" refId="6"/>
|
||||
<end type="TARGET" refId="2"/>
|
||||
</realization>
|
||||
<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>
|
||||
@@ -0,0 +1,70 @@
|
||||
@startuml
|
||||
package com.iluwatar.event.asynchronous {
|
||||
class App {
|
||||
- LOGGER : Logger {static}
|
||||
+ PROP_FILE_NAME : String {static}
|
||||
~ interactiveMode : boolean
|
||||
+ App()
|
||||
+ main(args : String[]) {static}
|
||||
- processOption1(eventManager : EventManager, s : Scanner)
|
||||
- processOption2(eventManager : EventManager, s : Scanner)
|
||||
- processOption3(eventManager : EventManager, s : Scanner)
|
||||
+ quickRun()
|
||||
+ run()
|
||||
+ runInteractiveMode()
|
||||
+ setUp()
|
||||
}
|
||||
class Event {
|
||||
- LOGGER : Logger {static}
|
||||
- eventId : int
|
||||
- eventListener : ThreadCompleteListener
|
||||
- eventTime : int
|
||||
- isComplete : boolean
|
||||
- isSynchronous : boolean
|
||||
- thread : Thread
|
||||
+ Event(eventId : int, eventTime : int, isSynchronous : boolean)
|
||||
+ addListener(listener : ThreadCompleteListener)
|
||||
- completed()
|
||||
+ isSynchronous() : boolean
|
||||
+ removeListener(listener : ThreadCompleteListener)
|
||||
+ run()
|
||||
+ start()
|
||||
+ status()
|
||||
+ stop()
|
||||
}
|
||||
class EventManager {
|
||||
- DOES_NOT_EXIST : String {static}
|
||||
+ MAX_EVENT_TIME : int {static}
|
||||
+ MAX_ID : int {static}
|
||||
+ MAX_RUNNING_EVENTS : int {static}
|
||||
+ MIN_ID : int {static}
|
||||
- currentlyRunningSyncEvent : int
|
||||
- eventPool : Map<Integer, Event>
|
||||
- rand : Random
|
||||
+ EventManager()
|
||||
+ cancel(eventId : int)
|
||||
+ completedEventHandler(eventId : int)
|
||||
+ create(eventTime : int) : int
|
||||
+ createAsync(eventTime : int) : int
|
||||
- createEvent(eventTime : int, isSynchronous : boolean) : int
|
||||
- generateId() : int
|
||||
+ getEventPool() : Map<Integer, Event>
|
||||
+ numOfCurrentlyRunningSyncEvent() : int
|
||||
+ shutdown()
|
||||
+ start(eventId : int)
|
||||
+ status(eventId : int)
|
||||
+ statusOfAllEvents()
|
||||
}
|
||||
interface IEvent {
|
||||
+ start() {abstract}
|
||||
+ status() {abstract}
|
||||
+ stop() {abstract}
|
||||
}
|
||||
interface ThreadCompleteListener {
|
||||
+ completedEventHandler(int) {abstract}
|
||||
}
|
||||
}
|
||||
Event --> "-eventListener" ThreadCompleteListener
|
||||
Event ..|> IEvent
|
||||
EventManager ..|> ThreadCompleteListener
|
||||
@enduml
|
||||
@@ -0,0 +1,70 @@
|
||||
@startuml
|
||||
package com.iluwatar.event.asynchronous {
|
||||
class App {
|
||||
- LOGGER : Logger {static}
|
||||
+ PROP_FILE_NAME : String {static}
|
||||
~ interactiveMode : boolean
|
||||
+ App()
|
||||
+ main(args : String[]) {static}
|
||||
- processOption1(eventManager : EventManager, s : Scanner)
|
||||
- processOption2(eventManager : EventManager, s : Scanner)
|
||||
- processOption3(eventManager : EventManager, s : Scanner)
|
||||
+ quickRun()
|
||||
+ run()
|
||||
+ runInteractiveMode()
|
||||
+ setUp()
|
||||
}
|
||||
class AsyncEvent {
|
||||
- LOGGER : Logger {static}
|
||||
- eventId : int
|
||||
- eventListener : ThreadCompleteListener
|
||||
- eventTime : int
|
||||
- isComplete : AtomicBoolean
|
||||
- synchronous : boolean
|
||||
- thread : Thread
|
||||
+ AsyncEvent(eventId : int, eventTime : int, synchronous : boolean)
|
||||
+ addListener(listener : ThreadCompleteListener)
|
||||
- completed()
|
||||
+ isSynchronous() : boolean
|
||||
+ removeListener()
|
||||
+ run()
|
||||
+ start()
|
||||
+ status()
|
||||
+ stop()
|
||||
}
|
||||
interface Event {
|
||||
+ start() {abstract}
|
||||
+ status() {abstract}
|
||||
+ stop() {abstract}
|
||||
}
|
||||
class EventManager {
|
||||
- DOES_NOT_EXIST : String {static}
|
||||
+ MAX_EVENT_TIME : int {static}
|
||||
+ MAX_ID : int {static}
|
||||
+ MAX_RUNNING_EVENTS : int {static}
|
||||
+ MIN_ID : int {static}
|
||||
- currentlyRunningSyncEvent : int
|
||||
- eventPool : Map<Integer, AsyncEvent>
|
||||
- rand : SecureRandom
|
||||
+ EventManager()
|
||||
+ cancel(eventId : int)
|
||||
+ completedEventHandler(eventId : int)
|
||||
+ create(eventTime : int) : int
|
||||
+ createAsync(eventTime : int) : int
|
||||
- createEvent(eventTime : int, isSynchronous : boolean) : int
|
||||
- generateId() : int
|
||||
+ getEventPool() : Map<Integer, AsyncEvent>
|
||||
+ numOfCurrentlyRunningSyncEvent() : int
|
||||
+ shutdown()
|
||||
+ start(eventId : int)
|
||||
+ status(eventId : int)
|
||||
+ statusOfAllEvents()
|
||||
}
|
||||
interface ThreadCompleteListener {
|
||||
+ completedEventHandler(int) {abstract}
|
||||
}
|
||||
}
|
||||
AsyncEvent --> "-eventListener" ThreadCompleteListener
|
||||
AsyncEvent ..|> Event
|
||||
EventManager ..|> ThreadCompleteListener
|
||||
@enduml
|
||||
Reference in New Issue
Block a user