Class PendingInjections
java.lang.Object
de.aristaflow.adept2.util.injection.PendingInjections
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe time in milliseconds anafterInjectionmay take before the claim reports the class. -
Constructor Summary
ConstructorsConstructorDescriptionPendingInjections(Collection<InjectionAware> recorded) Creates a holder for the designated recorded objects. -
Method Summary
Modifier and TypeMethodDescriptionvoidclaim(BindingContext bindings, Object target, Logger logger) Claims the recorded objects: populates theirInjectedfields from the designated bindings and then callsafterInjectionon each of them in recorded order.static Stringdescribe(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 itstoString.Gets the failure of the claim ornullif the claim did not run or succeeded.booleanGets whether a completion point has run the claim, whatever its outcome.toString()
-
Field Details
-
CALLBACK_BUDGET
public static final long CALLBACK_BUDGETThe time in milliseconds anafterInjectionmay 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
Creates a holder for the designated recorded objects.- Parameters:
recorded- The recorded objects in stream order, that is innermost first. This must neither benullnor 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
Gets the failure of the claim ornullif 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
nullif it did not run or succeeded.
-
claim
Claims the recorded objects: populates theirInjectedfields from the designated bindings and then callsafterInjectionon each of them in recorded order. The claim runs at most once per object even where a canonicalisingreadResolvehad 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 ornullif the driver has none, which fails the claim.target- The target of the invocation carrying the recorded objects ornullif the driver resolves none.logger- The logger to report a callback overrunning the budget or a class carrying invalid declarations with. This must not benull.- Throws:
InjectionException- If the driver has no bindings, arequiredbinding is unavailable, a declaration cannot be honoured or anafterInjectionthrows, anInjectionExceptionwill 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; anErroris remembered as the failure and rethrown as it is.IllegalStateException- If this holder has already been claimed, anIllegalStateExceptionwill 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
-
describe
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 itstoString.- Parameters:
objects- The objects awaiting injection which to describe.- Returns:
- A description of the designated objects naming their classes. This will never be
null.
-