package leigh.reactor;

import leigh.mecha.log.MechaLogger;
import leigh.mecha.log.MechaLoggerFactory;

import java.io.Serializable;
import java.time.Instant;
import java.util.HashMap;

/**
 * Implementation of a tree-based data manifestation.
 */
public class Reactor {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(Reactor.class);
    private final HashMap<String, SymbolValue> symbols = new HashMap<>();

    /**
     * Set a new value into the reactor.
     */
    public void putSymbol(String key, Serializable value) {
        SymbolValue sv = new SymbolValue(value, Instant.now());
        logger.info("Symbol update. [key: {}] [symbol: {}]", key, sv);
        symbols.put(key, sv);
    }

    /**
     * Return the {@link SymbolValue} associated with the given key, if one exists.
     */
    public SymbolValue getValue(String key) {
        return symbols.get(key);
    }
}
