Files
ProcessControl/04-part-iv-rewind.qmd
T
MatsuneMikuroiandClaude Opus 5.5 54338b3ea2 Part III and Part IV chapters as written during the course
The two chapter files are not yet in the profiles' chapter lists, so the
built book does not show them yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 07:10:37 +02:00

162 lines
11 KiB
Plaintext

# [Part IV — Rewind]{.en}[Partie IV — Rembobinage]{.fr}[Teil IV — Zurückspulen]{.de} {#sec-part-iv}
<!-- MULTILINGUAL: see the comment at the top of index.qmd. -->
::: {.en}
Steps 28 to 34 go back to one JVM on purpose. With no replication delay and no five-terminal setup, the only thing that can change is who knows whom — so the idea can be tried in seconds instead of in a distributed debugging session.
:::
::: {.fr}
Les étapes 28 à 34 reviennent volontairement à une seule JVM. Sans délai de réplication ni cinq terminaux, la seule chose qui peut changer est qui connaît qui — l'idée s'essaie donc en quelques secondes plutôt qu'au cours d'une séance de débogage distribué.
:::
::: {.de}
Die Schritte 28 bis 34 kehren absichtlich zu einer JVM zurück. Ohne Replikationsverzögerung und ohne fünf Terminals kann sich nur ändern, wer wen kennt — die Idee lässt sich also in Sekunden ausprobieren statt in einer verteilten Fehlersuche.
:::
## [The obvious shortcut, and its trap]{.en}[Le raccourci évident, et son piège]{.fr}[Die naheliegende Abkürzung und ihre Falle]{.de} {#sec-the-trap}
::: {.en}
If the first mediator only copies messages, delete it and let ROT13 read the source itself:
```java
listen("consoleIn.outbox");
```
The mediator is gone. But ask the recurring question: ROT13 now contains the name of ConsoleIn's mailbox. The topology moved out of the mediator and **into the service**. As the material puts it: "We removed the mediator… and put topology back into the service. *Oops.*"
:::
::: {.fr}
Si le premier médiateur ne fait que copier des messages, supprimons-le et laissons ROT13 lire la source lui-même :
```java
listen("consoleIn.outbox");
```
Le médiateur a disparu. Mais posons la question récurrente : ROT13 contient désormais le nom de la boîte de ConsoleIn. La topologie a quitté le médiateur pour entrer **dans le service**. Comme le dit le matériel : « nous avons supprimé le médiateur… et remis la topologie dans le service. *Oups.* »
:::
::: {.de}
Wenn der erste Vermittler nur Nachrichten kopiert: löschen wir ihn und lassen ROT13 die Quelle selbst lesen:
```java
listen("consoleIn.outbox");
```
Der Vermittler ist weg. Doch die wiederkehrende Frage: ROT13 enthält jetzt den Namen von ConsoleIns Postfach. Die Topologie ist aus dem Vermittler **in den Dienst** gewandert. Im Wortlaut des Materials: „Wir haben den Vermittler entfernt … und die Topologie zurück in den Dienst gelegt. *Hoppla.*"
:::
## [Capability is not topology]{.en}[La capacité n'est pas la topologie]{.fr}[Fähigkeit ist nicht Topologie]{.de} {#sec-capability-vs-topology}
::: {.en}
ROT13 may know two things: *I can transform text*, and *I am capable of listening for compatible text messages*. It may **not** know *my input always comes from consoleIn.outbox* — that is deployment topology.
So the name is not compiled in; it arrives at runtime:
```text
TOPIC consoleIn.outbox
```
ROT13 learns its wiring from data. Note who sends it: in `DynamicQueueRot13.java` it is `main()` that publishes both `TOPIC` messages — a configurator, outside the data path, in the role the orchestrator played before. It cannot be ConsoleIn: if ConsoleIn told ROT13 what to subscribe to, ConsoleIn would have to know ROT13 exists, and the topology would simply have moved into a different capability.
:::
::: {.fr}
ROT13 peut savoir deux choses : *je sais transformer du texte* et *je suis capable d'écouter des messages texte compatibles*. Il ne doit **pas** savoir *mon entrée vient toujours de consoleIn.outbox* — c'est de la topologie de déploiement.
Le nom n'est donc pas compilé ; il arrive à l'exécution :
```text
TOPIC consoleIn.outbox
```
ROT13 apprend son câblage par la donnée. Notez qui l'envoie : dans `DynamicQueueRot13.java`, c'est `main()` qui publie les deux messages `TOPIC` — un configurateur, hors du chemin des données, dans le rôle qu'occupait l'orchestrateur. Ce ne peut pas être ConsoleIn : s'il disait à ROT13 à quoi s'abonner, il devrait savoir que ROT13 existe, et la topologie aurait seulement changé de capacité d'accueil.
:::
::: {.de}
ROT13 darf zwei Dinge wissen: *ich kann Text transformieren* und *ich kann auf kompatible Textnachrichten hören*. Es darf **nicht** wissen: *meine Eingabe kommt immer aus consoleIn.outbox* — das ist Deployment-Topologie.
Der Name ist daher nicht einkompiliert, er kommt zur Laufzeit:
```text
TOPIC consoleIn.outbox
```
ROT13 lernt seine Verdrahtung aus Daten. Wer sie sendet, ist wichtig: in `DynamicQueueRot13.java` veröffentlicht `main()` beide `TOPIC`-Nachrichten — ein Konfigurator ausserhalb des Datenpfads, in der Rolle des früheren Orchestrators. ConsoleIn kann es nicht sein: sagte ConsoleIn ROT13, was es abonnieren soll, müsste es wissen, dass ROT13 existiert — die Topologie wäre nur in eine andere Fähigkeit gewandert.
:::
## [What changes in the code]{.en}[Ce qui change dans le code]{.fr}[Was sich im Code ändert]{.de} {#sec-dynamic-mechanics}
::: {.en}
`listen(...)` is nothing exotic: a virtual thread that repeatedly calls `take()` on one of the same queues. `subscribe(...)` starts one such thread per subscribed name. The consequence is visible in the mailboxes:
- ROT13 takes **straight from `consoleIn.outbox`** — the name it was told;
- `rot13.inbox` is no longer a payload mailbox. It carries control messages, and ROT13's loop reads it to decide whether a message is a `TOPIC` to act on.
Nothing writes into `rot13.inbox` to move data anymore. The mailbox did not disappear; it changed job, from carrying payload to carrying Intent.
One observation from running it: after `Ctrl+D`, output stops but the program stays up. Nothing was interrupted — `runConsoleIn` returns on end of input, so the **producer** is gone, while both subscriber threads sit blocked in `take()` on sources that will never publish again. The JVM stays alive because `main` ends with `Thread.currentThread().join()`. "The flow stopped" always has to be traced to *which* participant stopped.
:::
::: {.fr}
`listen(...)` n'a rien d'exotique : un thread virtuel qui appelle `take()` en boucle sur l'une des mêmes files. `subscribe(...)` démarre un tel thread par nom abonné. La conséquence se voit dans les boîtes :
- ROT13 retire **directement de `consoleIn.outbox`** — le nom qu'on lui a transmis ;
- `rot13.inbox` n'est plus une boîte de charge utile. Elle porte des messages de contrôle, et la boucle de ROT13 la lit pour décider si un message est un `TOPIC` à appliquer.
Plus rien n'écrit dans `rot13.inbox` pour déplacer des données. La boîte n'a pas disparu : elle a changé de métier, de la charge utile vers l'Intent.
Une observation à l'exécution : après `Ctrl+D`, la sortie s'arrête mais le programme reste en vie. Rien n'a été interrompu — `runConsoleIn` retourne à la fin de l'entrée, donc le **producteur** a disparu, tandis que les deux threads abonnés restent bloqués dans `take()` sur des sources qui ne publieront plus. La JVM survit parce que `main` finit par `Thread.currentThread().join()`. « Le flux s'est arrêté » doit toujours être ramené à *quel* participant s'est arrêté.
:::
::: {.de}
`listen(...)` ist nichts Exotisches: ein virtueller Thread, der wiederholt `take()` auf einer derselben Warteschlangen aufruft. `subscribe(...)` startet einen solchen Thread pro abonniertem Namen. Die Folge ist in den Postfächern sichtbar:
- ROT13 nimmt **direkt aus `consoleIn.outbox`** — dem Namen, den es erhalten hat;
- `rot13.inbox` ist kein Nutzlast-Postfach mehr. Es trägt Steuernachrichten, und ROT13s Schleife liest es, um zu entscheiden, ob eine Nachricht ein anzuwendendes `TOPIC` ist.
Nichts schreibt mehr in `rot13.inbox`, um Daten zu bewegen. Das Postfach verschwand nicht; es wechselte die Aufgabe, von Nutzlast zu Intent.
Eine Beobachtung aus dem Lauf: nach `Ctrl+D` endet die Ausgabe, das Programm bleibt aber am Leben. Unterbrochen wurde nichts — `runConsoleIn` kehrt am Eingabeende zurück, der **Produzent** ist also weg, während beide Abonnenten-Threads in `take()` auf Quellen warten, die nie wieder veröffentlichen. Die JVM lebt weiter, weil `main` mit `Thread.currentThread().join()` endet. „Der Fluss stoppte" muss immer darauf zurückgeführt werden, *welcher* Beteiligte stoppte.
:::
## [`ROUTE` and `TOPIC` are Intent]{.en}[`ROUTE` et `TOPIC` sont de l'Intent]{.fr}[`ROUTE` und `TOPIC` sind Intent]{.de} {#sec-route-topic-intent}
::: {.en}
Apply two tests to `TOPIC consoleIn.outbox`. Does it describe something that happened? No. Something currently true? No. It says *please begin listening here* — desired behaviour, which is **Intent**. The mediator's `ROUTE` is the same kind of message: *please forward from here to there*.
One trap worth naming, because it is tempting in a defence: *publishing* an Intent is of course something that happened. Classification follows what the message says, not the fact that it exists.
And one condition, which returns later: the dynamic version is **not** automatically superior. It makes sense only if the consumer actually understands the producer's message contract.
```text
STATIC MEDIATED DYNAMIC DIRECT
Producer → Mediator → Consumer Intent → (Producer ──► Consumer)
```
:::
::: {.fr}
Appliquons deux tests à `TOPIC consoleIn.outbox`. Décrit-il quelque chose qui est arrivé ? Non. Quelque chose actuellement vrai ? Non. Il dit *commence à écouter ici* — un comportement souhaité, donc de l'**Intent**. Le `ROUTE` du médiateur est du même genre : *transmets d'ici à là*.
Un piège à nommer, car il est tentant dans une soutenance : *publier* un Intent est bien sûr quelque chose qui est arrivé. La classification suit ce que dit le message, pas le fait qu'il existe.
Et une condition, qui reviendra : la version dynamique n'est **pas** automatiquement supérieure. Elle n'a de sens que si le consommateur comprend vraiment le contrat de message du producteur.
```text
MÉDIÉ STATIQUE DIRECT DYNAMIQUE
Producteur → Médiateur → Consommateur Intent → (Producteur ──► Consommateur)
```
:::
::: {.de}
Zwei Tests für `TOPIC consoleIn.outbox`. Beschreibt es etwas, das geschehen ist? Nein. Etwas, das gerade gilt? Nein. Es sagt *beginne hier zu hören* — gewünschtes Verhalten, also **Intent**. Das `ROUTE` des Vermittlers ist dieselbe Art Nachricht: *leite von hier nach dort weiter*.
Eine Falle, die benannt gehört, weil sie in einer Verteidigung verlockt: ein Intent zu *veröffentlichen* ist natürlich etwas, das geschehen ist. Die Einordnung folgt dem, was die Nachricht sagt, nicht ihrer Existenz.
Und eine Bedingung, die wiederkommt: die dynamische Fassung ist **nicht** automatisch besser. Sie ergibt nur Sinn, wenn der Konsument den Nachrichtenvertrag des Produzenten wirklich versteht.
```text
STATISCH VERMITTELT DYNAMISCH DIREKT
Produzent → Vermittler → Konsument Intent → (Produzent ──► Konsument)
```
:::