Clone
5
API Reference
Leo Galambos edited this page 2025-08-02 01:18:22 +02:00

API Reference

This page summarizes the key classes in Conflux. For the complete documentation, read Conflux Javadoc.

Ctx

Ctx is a singleton enum that serves as the primary access point for the default application-wide context. It also supports managing multiple independent named contexts.

Default Context Operations

  • put(Key<T>, T value) — store or update a value for a key in the default context
  • get(Key<T>) — retrieve a value from the default context
  • contains(Key<?>) — check if a key is present in the default context
  • remove(Key<?>) — remove a key and its listeners from the default context
  • clear() — clear all keys and listeners from the default context
  • addListener(Key<T>, Listener<T>) — register a weakly referenced listener in the default context
  • removeListener(Key<T>, Listener<T>) — remove a listener from the default context

Managing Multiple Named Contexts

  • getContext(String name) — retrieve or create a named independent context implementing CtxInterface
  • contextNames() — returns the set of existing named context keys

Each named context functions independently with its own keys, values, and listeners, allowing isolated storage scopes within the same application.

Key

A strongly typed key used to identify context entries:

Key<String> nameKey = new Key<>("name", String.class);
  • name() returns the key name
  • type() returns the key type

Keys ensure type consistency and prevent accidental type mismatches.

Listener

An interface for receiving notifications on value changes:

public interface Listener<T> {
    void valueChanged(T newValue);
}

Listeners are weakly referenced to avoid memory leaks and invoked whenever the corresponding key's value changes.


Home | Programming Guide | Design and Architecture | FAQ | Contributing