Class CosIdIdentifierFactory
IdentifierFactory on a runtime generator (07-runtime-and-spring.md ยง5).
The one static state of CosId. Axon loads its identifier factory through ServiceLoader
(this module's META-INF/services entry) into a JVM-wide static, so the factory it creates cannot be given a
runtime. It uses the runtime bound most recently and not yet unbound instead:
the Spring Boot auto-configuration binds the context's runtime once it is started and unbinds it before it is closed;
other code binds with try (var binding = CosIdIdentifierFactory.bind(runtime, null)) { ... }. Closing one of
several runtimes unbinds only its own binding. With nothing bound, generating an identifier throws an
IllegalStateException: having this module means Axon's identifiers come from CosId (as in 4.x).
The generator is the one a binding names, else the one of the ID_KEY system property, else
default. A factory created with a runtime ignores the bindings.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA runtime bound bybind(CosIdRuntime, String); closing it unbinds it. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionThe factoryServiceLoadercreates: the ids of the bound runtime, failing without one.CosIdIdentifierFactory(me.ahoo.cosid.runtime.CosIdRuntime runtime, String generator) A factory of one runtime, regardless of the bindings. -
Method Summary
Modifier and TypeMethodDescriptionBinds a runtime for the factoryServiceLoadercreates; the most recent binding wins.static booleanunbind(CosIdIdentifierFactory.Binding binding) Removes exactly this binding, leaving the others in place.Methods inherited from class org.axonframework.common.IdentifierFactory
getInstance
-
Field Details
-
ID_KEY
The system property of the generator name.- See Also:
-
DEFAULT_GENERATOR
The generator when neither a binding nor the system property names one.- See Also:
-
-
Constructor Details
-
CosIdIdentifierFactory
public CosIdIdentifierFactory()The factoryServiceLoadercreates: the ids of the bound runtime, failing without one. -
CosIdIdentifierFactory
A factory of one runtime, regardless of the bindings.- Parameters:
runtime- the runtimegenerator- the generator name; blank ornullfor theID_KEYsystem property's
-
-
Method Details
-
bind
public static CosIdIdentifierFactory.Binding bind(me.ahoo.cosid.runtime.CosIdRuntime runtime, String generator) Binds a runtime for the factoryServiceLoadercreates; the most recent binding wins.- Parameters:
runtime- the runtimegenerator- the generator name; blank ornullfor theID_KEYsystem property's- Returns:
- the binding; close it to unbind
-
unbind
Removes exactly this binding, leaving the others in place.- Parameters:
binding- the binding- Returns:
trueif it was bound,falseif it was already unbound
-
generateIdentifier
- Specified by:
generateIdentifierin classorg.axonframework.common.IdentifierFactory
-