7
Home
Leo Galambos edited this page 2025-08-28 18:54:19 +02:00

Conflux

Conflux is a lightweight, type-safe, generic application-wide context for Java, providing strongly-typed key/value storage, listener support, and thread-safe sharing of data. It helps coordinate shared state across otherwise decoupled classes.

Features

  • Strongly typed keys - no unsafe casting
  • Type-consistent storage - values always match their declared key type
  • Change notifications - listeners (held via weak references) react to updates without memory leaks
  • Thread-safe - built on concurrent data structures
  • Simple singleton API - provided via an enum instance
  • Ephemeral named contexts - create multiple independent, short-lived contexts for modular scoping (per user, per request, per transaction)

Example

Key<Integer> counterKey = Key.of("counter", Integer.class);
Ctx.INSTANCE.put(counterKey, 42);

// Working with multiple named contexts
CtxInterface orderCtx = Ctx.INSTANCE.getContext("order");
Key<String> orderIdKey = Key.of("orderId", String.class);
orderCtx.put(orderIdKey, "ORD123");

Enjoy consistent, simple context management!