Class LoadController

java.lang.Object
com.dna.jopt.member.bucket.route.controller.loadcontroller.LoadController
All Implemented Interfaces:
ILoadController, Serializable

public class LoadController extends Object implements ILoadController
Manages the dynamic per-node INodeDepot state for one entity.

Design — flat one-level COW with on-demand deep isolation

Every instance has two fields:

Only depots with flexible loads and the depots of nodes that are ignored on zero load are kept here. The assessor evaluates any other node depot directly.

Performance

partialCopy() copies the map entries, not the depots: the child's parentMap is a snapshot of the parent's entries and the child gets a fresh empty ownMap. No depot copying happens at clone time. Copying is deferred to getFlexLoadNodeDepot(String): only the specific depot that an operator actually touches is deep-copied at the moment it is first accessed on the clone.

Correctness — why deep copy in lazy isolation

Lazy isolation calls INodeDepot.copy() (deep — ILoad.copy() per item), not partialCopy() (shallow — shared ILoad references). This is essential: FlexLoadOperator calls setLoad() directly on an ILoad object that is already inside the depot's item list. A shallow copy would leave that object shared between the clone and the parent, so mutations on the clone would corrupt the parent's depot state. A deep copy gives the clone fully independent ILoad objects.

Thread safety

Both maps are ConcurrentHashMap instances. get and put are safe under concurrent assessor threads. parentMap is never modified after construction, so reads are always safe. ownMap is iterated with a weakly-consistent iterator in partialCopy() — never throws CME.

See Also:
  • Constructor Details

    • LoadController

      public LoadController()
      Creates a standalone instance with an empty depot map.
  • Method Details

    • getNodeDepotMap

      public Map<String, INodeDepot> getNodeDepotMap()
      Description copied from interface: ILoadController
      Returns a merged view of this instance's map and all ancestors.

      Not on the hot path — used by result-extraction code that needs a complete snapshot. For hot-path reads, use ILoadController.getFlexLoadNodeDepot(String) directly.

      Specified by:
      getNodeDepotMap in interface ILoadController
    • setNodeDepotMap

      public void setNodeDepotMap(Map<String, INodeDepot> m)
      Specified by:
      setNodeDepotMap in interface ILoadController
    • putFlexLoadNodeDepot

      public boolean putFlexLoadNodeDepot(String nodeId, INodeDepot depot)
      Specified by:
      putFlexLoadNodeDepot in interface ILoadController
    • getFlexLoadNodeDepot

      public Optional<INodeDepot> getFlexLoadNodeDepot(String nodeId)
      Returns the depot for nodeId.

      Checks ownMap first (O(1)). On miss, checks parentMap and lazily isolates the depot into ownMap via a deep copy (INodeDepot.copy()) so that the clone owns fully independent ILoad objects. Subsequent accesses for the same node hit ownMap directly (O(1)).

      Specified by:
      getFlexLoadNodeDepot in interface ILoadController
    • partialCopy

      public ILoadController partialCopy()
      Creates a COW child.

      The child's parentMap is a snapshot of the entries this instance can see at this moment. The child gets a fresh empty ownMap. No depots are copied at this point: copying is deferred to the first getFlexLoadNodeDepot(String) call that misses ownMap.

      A standalone instance keeps writing to its ownMap when it is assessed again, so its map is copied as well instead of being shared with the child. If this instance is itself a COW copy (parentMap != null), the complete visible state (parent + own entries, own wins) is merged into the snapshot so the child always sees the full picture.

      Specified by:
      partialCopy in interface ILoadController
    • copy

      public ILoadController copy()
      Specified by:
      copy in interface ILoadController
    • flatten

      public void flatten()
      Promotes this COW copy to a standalone instance by merging parentMap into ownMap and clearing the parent reference.

      Optional but beneficial: makes the next partialCopy() O(1) (Case 1) instead of requiring a merge step (Case 2).