Java infrastructure · Egothor
conflux
A deliberately small Java library for the cases where independent components need to share a little typed state and react when it changes—without turning that coordination need into a dependency-injection framework or application architecture.
The small problem that often becomes a large dependency graph
A component computes a value. Several unrelated components need the latest value. Some need to react immediately when it changes. The naïve solution is to wire direct references everywhere; the “enterprise” solution can be to import an entire framework. conflux deliberately occupies the space between them.
- Typed keys reduce accidental integration mismatches.
- Current value + eventing covers many UI and infrastructure cases.
- Weak listeners help avoid accidental retention.
- Small scope keeps the library easy to embed inside larger systems.
A type-safe context rather than a stringly typed map
The context uses typed keys so the contract includes both a name and the expected Java type. A key name cannot quietly mean Integer in one component and String in another. That makes the shared state easier to reason about and moves a common class of integration error closer to the point where the key is declared.
Key<Integer> COUNT = Key.of("count", Integer.class);
Ctx.INSTANCE.put(COUNT, 42);
int current = Ctx.INSTANCE.get(COUNT);
Ctx.INSTANCE.addListener(COUNT, value -> refreshView(value));
Shared current state
Components can retrieve the current value without knowing which producer created it or carrying a direct producer reference through the application.
Change notification
Listeners can react to updates, so consumers that need event-driven behaviour do not need to poll the context continuously.
Weak listener references
Subscriptions are designed so a forgotten explicit unsubscribe does not automatically make the event bus the lifetime owner of every listener.
Concurrent use
The implementation uses concurrent collections and copy-on-write listener handling to keep the coordination primitive usable across application threads.
Deliberately not an application framework
conflux does not try to own object construction, configuration, scheduling or business logic. Its value is the opposite: a narrow contract that can be added to an existing system when a few independently developed modules need a common meeting point.
That narrow scope also makes the library suitable as infrastructure inside larger systems: it does one coordination job and leaves architecture decisions to the application.