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.

Typedshared keysone consistent Java type is associated with a context key name
Thread-safecoordinationcontext storage and listener structures are designed for concurrent use
Weaklistenerslistener references can avoid turning subscriptions into accidental object retention
SmallAPI surfacecoordination primitive rather than a replacement application framework

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.

Producerwrites a typed value→ Shared contextstores current state→ Change eventnotifies subscribers→ Consumersreact independently

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.

Conceptual APItype-safe shared state
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.

Use it forsmall shared state · component notifications · cross-module coordination Do not turn it intoa service locator for every dependency · a persistence layer · a distributed message broker

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.

Project resources