Repository navigation
Expand file tree
/
Copy pathreactor.urm.puml
More file actions
151 lines (151 loc) · 5.04 KB
/
Copy pathreactor.urm.puml
File metadata and controls
151 lines (151 loc) · 5.04 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 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
}
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 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 AppClient {
- service : ExecutorService
+ AppClient()
- artificialDelayOf(millis : long) {static}
+ main(args : String[]) {static}
+ start()
+ stop()
}
}
package com.iluwatar.reactor.framework {
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 ChangeKeyOpsCommand {
- interestedOps : int
- key : SelectionKey
+ ChangeKeyOpsCommand(this$0 : SelectionKey, key : int)
+ run()
+ toString() : String
}
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 ThreadPoolDispatcher {
- executorService : ExecutorService
+ ThreadPoolDispatcher(poolSize : int)
+ onChannelReadEvent(channel : AbstractNioChannel, readObject : Object, key : SelectionKey)
+ stop()
}
class NioServerSocketChannel {
- port : int
+ NioServerSocketChannel(port : int, handler : ChannelHandler)
+ bind()
# doWrite(pendingWrite : Object, key : SelectionKey)
+ getInterestedOps() : int
+ getJavaChannel() : ServerSocketChannel
+ read(key : SelectionKey) : ByteBuffer
}
class SameThreadDispatcher {
+ SameThreadDispatcher()
+ onChannelReadEvent(channel : AbstractNioChannel, readObject : Object, key : SelectionKey)
+ stop()
}
interface Dispatcher {
+ onChannelReadEvent(AbstractNioChannel, Object, SelectionKey) {abstract}
+ stop() {abstract}
}
class DatagramPacket {
- data : ByteBuffer
- receiver : SocketAddress
- sender : SocketAddress
+ DatagramPacket(data : ByteBuffer)
+ getData() : ByteBuffer
+ getReceiver() : SocketAddress
+ getSender() : SocketAddress
+ setReceiver(receiver : SocketAddress)
+ setSender(sender : SocketAddress)
}
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()
}
}
AbstractNioChannel --> "-handler" ChannelHandler
UdpLoggingClient ..+ AppClient
TcpLoggingClient ..+ AppClient
AbstractNioChannel --> "-reactor" NioReactor
NioReactor --> "-dispatcher" Dispatcher
App --> "-reactor" NioReactor
App --> "-channels" AbstractNioChannel
DatagramPacket ..+ NioDatagramChannel
LoggingHandler --+ NioDatagramChannel
App --> "-dispatcher" Dispatcher
ChangeKeyOpsCommand --+ NioReactor
NioDatagramChannel --|> AbstractNioChannel
LoggingHandler ..|> ChannelHandler
ThreadPoolDispatcher ..|> Dispatcher
NioServerSocketChannel --|> AbstractNioChannel
SameThreadDispatcher ..|> Dispatcher
@enduml