Browse Source

Architecture info

tags/v0.5.0
Chris Smith 5 years ago
parent
commit
3b1783a2ba
3 changed files with 57 additions and 5 deletions
  1. 37
    5
      README.md
  2. BIN
      docs/sequence.png
  3. 20
    0
      docs/sequence.txt

+ 37
- 5
README.md View File

56
 This is an issue with the Java standard library. You can change its behaviour by
56
 This is an issue with the Java standard library. You can change its behaviour by
57
 defining the system property `java.net.preferIPv6Addresses` to `true`, e.g. by
57
 defining the system property `java.net.preferIPv6Addresses` to `true`, e.g. by
58
 running Java with `-Djava.net.preferIPv6Addresses=true` or calling
58
 running Java with `-Djava.net.preferIPv6Addresses=true` or calling
59
-`System.setProperty("java.net.preferIPv6Addresses","true");` in code. 
60
-
61
-## Contributing
59
+`System.setProperty("java.net.preferIPv6Addresses","true");` in code.
60
+
61
+## Developing KtIrc
62
+
63
+### Lifecycle of a message
64
+
65
+![architecture diagram](docs/sequence.png) 
66
+
67
+The `LineBufferedSocket` class receives bytes from the IRC server. Whenever it
68
+encounters a complete line (terminated by a `CR`, `LF` or `CRLF`), it passes it
69
+to the `IrcClient` as a `ByteArray`. The `MessageParser` breaks up the line
70
+into its component parts (tags, prefixes, commands, and parameters) and returns
71
+them as an `IrcMessage`.
72
+ 
73
+The `IrcMessage` is given to the `MessageHandler`, which tries to find a
74
+processor that can handle the command in the message. The processor's job is
75
+to convert the message into an `IrcEvent` subclass. Processors do not get
76
+given any contextual information or state, their job is simply to convert
77
+the message as received into an event.
78
+
79
+The events are returned to the `MessageHandler` which then passes them on
80
+to all registered event handlers. The job of the event handlers is twofold:
81
+firstly, use the events to update the state of KtIrc (for example, after
82
+receiving a `JOIN` message, the `ChannelStateHandler` will add the user
83
+to the list of users in the channel, while the `UserStateHandler` may update
84
+the user's hostname if we hadn't previously seen it). Secondly, the event
85
+handlers may themselves raise events. This is useful for higher-order
86
+events such as `ServerReady` that depend on a variety of factors and
87
+states.
88
+
89
+All the generated events (from processors or from event handlers) are
90
+passed to the `IrcClient`, which in turn passes them to the library
91
+user via the delegates passed to the `onEvent` method. 
92
+
93
+### Contributing
62
 
94
 
63
 Contributing is welcomed and encouraged! Please try to add unit tests for new features,
95
 Contributing is welcomed and encouraged! Please try to add unit tests for new features,
64
 and maintain a code style consistent with the existing code.
96
 and maintain a code style consistent with the existing code.
65
 
97
 
66
-## Licence
98
+### Licence
67
 
99
 
68
 The code in this repository is released under the MIT licence. See the
100
 The code in this repository is released under the MIT licence. See the
69
-[LICENCE](LICENCE) file for more info.
101
+[LICENCE](LICENCE) file for more info.

BIN
docs/sequence.png View File


+ 20
- 0
docs/sequence.txt View File

1
+title KtIrc internal structure
2
+
3
+participant KtIrc User
4
+participant IrcClient
5
+participant LineBufferedSocket
6
+participant IRC Server
7
+
8
+IRC Server->LineBufferedSocket: Byte*
9
+LineBufferedSocket->IrcClient: ByteArray
10
+IrcClient->+MessageParser: ByteArray
11
+MessageParser-->-IrcClient: IrcMessage
12
+IrcClient->MessageHandler: IrcMessage
13
+MessageHandler->+Processors: IrcMessage
14
+Processors-->-MessageHandler: IrcEvent*
15
+MessageHandler->+Handlers: IrcEvent
16
+Handlers->IrcClient: Update state
17
+note right of Handlers: Handlers update the state held by the client,\nand may raise additional events themselves
18
+Handlers-->-MessageHandler: IrcEvent*
19
+MessageHandler->IrcClient: IrcEvent
20
+IrcClient->KtIrc User: onEvent(IrcEvent)

Loading…
Cancel
Save