forked from iluwatar/java-design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreactor.urm.puml
More file actions
151 lines (151 loc) · 5.07 KB
/
reactor.urm.puml
File metadata and controls
151 lines (151 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
@startuml
package com.iluwatar.reactor.app {
~class TcpLoggingClient {
- clientName : String
- serverPort : int
+ TcpLoggingClient(clientName : String, serverPort : int)
+ run()
- sendLogRequests(writer : PrintWriter, inputStream : InputStream)
}
~class UdpLoggingClient {
- clientName : String
- remoteAddress : InetSocketAddress
+ UdpLoggingClient(clientName : String, port : int)
+ run()
}
class LoggingHandler {
- ACK : byte[] {static}
+ LoggingHandler()
- doLogging(data : ByteBuffer) {static}
+ handleChannelRead(channel : AbstractNioChannel, readObject : Object, key : SelectionKey)
- sendReply(channel : AbstractNioChannel, incomingPacket : DatagramPacket, key : SelectionKey) {static}
- sendReply(channel : AbstractNioChannel, key : SelectionKey) {static}
}
class AppClient {
- service : ExecutorService
+ AppClient()
- artificialDelayOf(millis : long) {static}
+ main(args : String[]) {static}
+ start()
+ stop()
}
class App {
- channels : List<AbstractNioChannel>
- dispatcher : Dispatcher
- reactor : NioReactor
+ App(dispatcher : Dispatcher)
+ main(args : String[]) {static}
+ start()
+ stop()
- tcpChannel(port : int, handler : ChannelHandler) : AbstractNioChannel
- udpChannel(port : int, handler : ChannelHandler) : AbstractNioChannel
}
}
package com.iluwatar.reactor.framework {
interface Dispatcher {
+ onChannelReadEvent(AbstractNioChannel, Object, SelectionKey) {abstract}
+ stop() {abstract}
}
class SameThreadDispatcher {
+ SameThreadDispatcher()
+ onChannelReadEvent(channel : AbstractNioChannel, readObject : Object, key : SelectionKey)
+ stop()
}
class ThreadPoolDispatcher {
- executorService : ExecutorService
+ ThreadPoolDispatcher(poolSize : int)
+ onChannelReadEvent(channel : AbstractNioChannel, readObject : Object, key : SelectionKey)
+ stop()
}
interface ChannelHandler {
+ handleChannelRead(AbstractNioChannel, Object, SelectionKey) {abstract}
}
class NioDatagramChannel {
- port : int
+ NioDatagramChannel(port : int, handler : ChannelHandler)
+ bind()
# doWrite(pendingWrite : Object, key : SelectionKey)
+ getInterestedOps() : int
+ getJavaChannel() : DatagramChannel
+ read(key : SelectionKey) : DatagramPacket
+ write(data : Object, key : SelectionKey)
}
class DatagramPacket {
- data : ByteBuffer
- receiver : SocketAddress
- sender : SocketAddress
+ DatagramPacket(data : ByteBuffer)
+ getData() : ByteBuffer
+ getReceiver() : SocketAddress
+ getSender() : SocketAddress
+ setReceiver(receiver : SocketAddress)
+ setSender(sender : SocketAddress)
}
abstract class AbstractNioChannel {
- channel : SelectableChannel
- channelToPendingWrites : Map<SelectableChannel, Queue<Object>>
- handler : ChannelHandler
- reactor : NioReactor
+ AbstractNioChannel(handler : ChannelHandler, channel : SelectableChannel)
+ bind() {abstract}
# doWrite(Object, SelectionKey) {abstract}
~ flush(key : SelectionKey)
+ getHandler() : ChannelHandler
+ getInterestedOps() : int {abstract}
+ getJavaChannel() : SelectableChannel
+ read(SelectionKey) : Object {abstract}
~ setReactor(reactor : NioReactor)
+ write(data : Object, key : SelectionKey)
}
class NioServerSocketChannel {
- port : int
+ NioServerSocketChannel(port : int, handler : ChannelHandler)
+ bind()
# doWrite(pendingWrite : Object, key : SelectionKey)
+ getInterestedOps() : int
+ getJavaChannel() : ServerSocketChannel
+ read(key : SelectionKey) : ByteBuffer
}
class NioReactor {
- dispatcher : Dispatcher
- pendingCommands : Queue<Runnable>
- reactorMain : ExecutorService
- selector : Selector
+ NioReactor(dispatcher : Dispatcher)
+ changeOps(key : SelectionKey, interestedOps : int)
- dispatchReadEvent(key : SelectionKey, readObject : Object)
- eventLoop()
- onChannelAcceptable(key : SelectionKey)
- onChannelReadable(key : SelectionKey)
- onChannelWritable(key : SelectionKey) {static}
- processKey(key : SelectionKey)
- processPendingCommands()
+ registerChannel(channel : AbstractNioChannel) : NioReactor
+ start()
+ stop()
}
~class ChangeKeyOpsCommand {
- interestedOps : int
- key : SelectionKey
+ ChangeKeyOpsCommand(this$0 : NioReactor, key : SelectionKey, interestedOps : int)
+ run()
+ toString() : String
}
}
AbstractNioChannel --> "-handler" ChannelHandler
UdpLoggingClient ..+ AppClient
AbstractNioChannel --> "-reactor" NioReactor
TcpLoggingClient ..+ AppClient
NioReactor --> "-dispatcher" Dispatcher
App --> "-reactor" NioReactor
App --> "-channels" AbstractNioChannel
DatagramPacket ..+ NioDatagramChannel
ChangeKeyOpsCommand --+ NioReactor
App --> "-dispatcher" Dispatcher
LoggingHandler --+ NioDatagramChannel
SameThreadDispatcher ..|> Dispatcher
LoggingHandler ..|> ChannelHandler
ThreadPoolDispatcher ..|> Dispatcher
NioDatagramChannel --|> AbstractNioChannel
NioServerSocketChannel --|> AbstractNioChannel
@enduml