修订版 | a9e469879f744abd94629bafa82ac94557f8bb55 (tree) |
---|---|
时间 | 2020-03-26 20:17:31 |
作者 | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
PubSub: finisched practice (final draft)
@@ -4,11 +4,14 @@ | ||
4 | 4 | Practice |
5 | 5 | ======== |
6 | 6 | |
7 | +This last section of this :ref:`PubSub` workshop is short. It only contain some practice (ideas). Two are on practicing | |
8 | +your design skills, the other two are more coding-oriented. | |
7 | 9 | |
8 | -Design Analye | |
10 | + | |
11 | +Design Analyse | |
9 | 12 | ============== |
10 | 13 | |
11 | -Given the python implementation, including the shown “Use-Cases”: Analyse the design in detail | |
14 | +Given the python implementation, including the shown “Use-Cases”: Analyse the design in detail: | |
12 | 15 | |
13 | 16 | 1. Make a (quick) static design-analyse. |
14 | 17 |
@@ -19,18 +22,66 @@ | ||
19 | 22 | At least a sequence-diagram for each of the “use-cases” |
20 | 23 | |
21 | 24 | Port to C/C++ |
22 | -============= | |
25 | +-------------- | |
23 | 26 | |
24 | 27 | 3. Can you port (or re-implement) the python examples to C/C++? |
25 | 28 | |
26 | - Surely, you have to change some details; as a generic data-type (“value”) is not available. | |
27 | - | |
28 | - It is fine, to use a *string-type*. And just “print” it in the demo-callbacks (like we do) | |
29 | + Surely, you have to change some details; as a generic data-type (“value”) is not available. It is fine, to use a | |
30 | + *string-type*. And just “print” it in the demo-callbacks (like I did). | |
29 | 31 | |
30 | 32 | Design a cached, distributed one |
31 | 33 | ================================ |
32 | 34 | |
35 | +The shown (conceptional) implementation works for a single process; optional with threads. In this exercise, you are | |
36 | +going to extent that for “network use”; although it will be a simple, conceptional one. Many existing protocols and | |
37 | +frameworks do exist already! The goal is *not* to challenge them, nor to *use* them. | |
33 | 38 | |
34 | -.. todo:: Complete this section | |
39 | +The goal is to practice your design skills! | |
40 | +|BR| | |
41 | +So, this is a (fun) design-exercise. You should be able to make a (full, conceptional) design in about an hour. That does | |
42 | +imply many fancy options should be left-out:-) | |
35 | 43 | |
36 | - * Design a cached, distributed one | |
44 | +4. Extent the current interface to allow pub/sub between multiple processes; optionally running on multiple computers | |
45 | + (on the same network). | |
46 | + | |
47 | + * The current API (:class:`~pubsub.Topic`, :meth:`~pubsub.Topic.publish` & :meth:`~pubsub.Topic.subscribe`) are not | |
48 | + allowed to change. Adding parameters to the class initiation (“the constructor” in C++) is allowed. Adding extra | |
49 | + methods is also allowed (but see below!). | |
50 | + | |
51 | + * All existing Use-Cases **should** keep working (both the shown one, as many others). | |
52 | + | |
53 | + * The main methods (:meth:`~pubsub.Topic.publish` & :meth:`~pubsub.Topic.subscribe`) should remain exactly the | |
54 | + same. No more parameters! | |
55 | + | |
56 | + * The default behavior should be “local” (not distributed). | |
57 | + | |
58 | + * There is no requirement for performance. But it is expected that a second “network-get” will be resolved | |
59 | + locally. So, use a cache to minimize networking | |
60 | + | |
61 | + * The networking should use standard TCP/IP networking (“sockets”). No other network libraries/frameworks are | |
62 | + allowed. | |
63 | + | |
64 | + * A simple “serialise” will do. Assume, all computers/processes use the same endianness and other encodings. | |
65 | + |BR| | |
66 | + Again, use “strings” (only); then this part is easy. | |
67 | + | |
68 | +.. hint:: `Deamon <https://en.wikipedia.org/wiki/Daemon_(computing)>`_ & `lib <https://en.wikipedia.org/wiki/Library_(computing)>`_ | |
69 | + | |
70 | + An easy way to design this is to foresee *one* processes handle all the administration (the core of | |
71 | + :class:`~pubsub.Topic`); including “calling” all the callbacks. | |
72 | + |BR| | |
73 | + This is typically called a **daemon**, or *services* on Windows. | |
74 | + | |
75 | + To hide all the networking stuff, arrange a (small) library, that acts as `facade <https://en.wikipedia.org/wiki/Facade_pattern>`_ | |
76 | + and provides the (extended) :ref:`PubSub_API`. | |
77 | + | |
78 | + | |
79 | +Implement it | |
80 | +------------ | |
81 | + | |
82 | +5. To check your design above is great, now implement it. | |
83 | + | |
84 | + Or better: implement the design of you co-trainee, and ask him to implement yours! | |
85 | + | |
86 | +Remember, a design is a communication-tool: A great design contains exactly those details that your coworker needs to | |
87 | +implement is as it is meant to be, but no more. (S)He should have some freedom to optimize implementation-details. |