Class PendingInjections

java.lang.Object
de.aristaflow.adept2.util.injection.PendingInjections

public class PendingInjections extends Object
The InjectionAware objects a recording stream met while decoding, waiting for the completion point of the driver to claim them. The recording stream itself neither injects nor needs bindings: at the time it sees an object the surrounding graph is still incomplete and cyclic references may point at half-restored objects, so injection happens after decoding, where the whole graph is available by construction.

A holder is state of one decoded message and is used by one thread at a time: the stream fills it on the IO event loop, the completion point claims it on the thread that goes on to use the objects, and the hand-off carrying the message carries the publication as well.

  • Field Details

    • CALLBACK_BUDGET

      public static final long CALLBACK_BUDGET
      The time in milliseconds an afterInjection may take before the claim reports the class. The callback obtains and arms, so this passes with room to spare while any real work does not.
      See Also:
  • Constructor Details

    • PendingInjections

      public PendingInjections(Collection<InjectionAware> recorded)
      Creates a holder for the designated recorded objects.
      Parameters:
      recorded - The recorded objects in stream order, that is innermost first. This must neither be null nor empty, a message without recorded objects gets no holder at all.
  • Method Details

    • isClaimed

      public boolean isClaimed()
      Gets whether a completion point has run the claim, whatever its outcome. An unclaimed holder on a payload that is being used is a platform programming error, a completion point that did not run.
      Returns:
      Whether a completion point has run the claim.
    • getFailure

      public InjectionException getFailure()
      Gets the failure of the claim or null if the claim did not run or succeeded. This allows the payload to be refused with the very diagnosis instead of a generic one.
      Returns:
      The failure of the claim or null if it did not run or succeeded.
    • claim

      public void claim(BindingContext bindings, Object target, Logger logger) throws InjectionException
      Claims the recorded objects: populates their Injected fields from the designated bindings and then calls afterInjection on each of them in recorded order. The claim runs at most once per object even where a canonicalising readResolve had the stream record the same instance several times – and at most once per holder, whatever the outcome: a second claim is refused.
      Parameters:
      bindings - The resolution surface of the driver claiming the recorded objects or null if the driver has none, which fails the claim.
      target - The target of the invocation carrying the recorded objects or null if the driver resolves none.
      logger - The logger to report a callback overrunning the budget or a class carrying invalid declarations with. This must not be null.
      Throws:
      InjectionException - If the driver has no bindings, a required binding is unavailable, a declaration cannot be honoured or an afterInjection throws, an InjectionException will be thrown. The very same exception is remembered for the payload to be refused with. An unchecked exception of the resolution or of a callback is wrapped into one, so a claim fails the processing that carries the objects and never escapes past it; an Error is remembered as the failure and rethrown as it is.
      IllegalStateException - If this holder has already been claimed, an IllegalStateException will be thrown: a second claim means the driver ran its completion point twice, which is a programming error of the platform – it would silently repopulate the fields and rerun the callbacks with whatever the second caller brings.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • describe

      public static String describe(Collection<InjectionAware> objects)
      Gets a description of the designated objects awaiting injection for a message, naming their classes rather than the objects themselves: the state of an object that is not injected yet is no basis for calling its toString.
      Parameters:
      objects - The objects awaiting injection which to describe.
      Returns:
      A description of the designated objects naming their classes. This will never be null.