Class Reactor
java.lang.Object
org.refcodes.decoupling.Reactor
A
Reactor's instance is used for breaking up dependencies between a
Java software system's components or modules, which enables them to be
developed and tested independently (dependency injection and inversion of
control). The reactor wires components or modules together to form an
interacting application. The Reactor uses dependency injection and inversion
of control, which are two techniques that help achieve decoupling by allowing
components to depend on abstractions instead of concrete implementations.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<DependencyBuilder<?>> protected List<DependencyInterceptor> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> DependencyBuilder<T> addDependency(Class<T> aType) Adds aDependencyto theReactorwhich'sDependencyBuilderis returned for fluently configuring yourDependency.<F extends org.refcodes.factory.Factory<T>,T>
DependencyBuilder<T> addDependency(Class<T> aType, F aFactory) Adds aDependencyfabricated by a factory.<F extends org.refcodes.factory.Factory<T>,T>
DependencyBuilder<T> addDependency(Class<T> aType, Class<F> aFactory) Adds aDependencyfabricated by a factory.<F,T> DependencyBuilder <T> addDependency(Class<T> aType, Class<F> aDependency, Function<F, T> aFactory) Adds aDependencyfabricated from factory's context (Dependency).<T> DependencyBuilder<T> addDependency(T aInstance) Adds aDependencyto theReactorwhich'sDependencyBuilderis returned for fluently configuring yourDependency.booleanaddInterceptor(DependencyInterceptor aInterceptor) Adds the givenDependencyInterceptorinstance.createContext(Object... aProfiles) createContext(String... aProfiles) booleanhasInterceptor(DependencyInterceptor aInterceptor) Tests whether the givenDependencyInterceptorinstance has been added.protected <T> Tintercept(T aInstance, Dependency<T> aDependency) Invokes all registeredDependencyInterceptorinstances for the givenDependencydeclaration's instance for intercepting purposes.booleanremoveInterceptor(DependencyInterceptor aInterceptor) Removes theDependencyInterceptorinstance.protected ContextHook method to create (and prepare) an emptyContext(sub-class).
-
Field Details
-
_dependencies
-
_interceptors
-
-
Constructor Details
-
Reactor
public Reactor()
-
-
Method Details
-
addDependency
Adds aDependencyto theReactorwhich'sDependencyBuilderis returned for fluently configuring yourDependency.- Type Parameters:
T- The type of theDependency.- Parameters:
aType- The type of theDependency.- Returns:
- An instance of the
DependencyBuilderclass which is used to fluently configure yourDependency.
-
addDependency
Adds aDependencyto theReactorwhich'sDependencyBuilderis returned for fluently configuring yourDependency.- Type Parameters:
T- The type of theDependency.- Parameters:
aInstance- The instance of theDependency.- Returns:
- An instance of the
DependencyBuilderclass which is used to fluently configure yourDependency.
-
addDependency
public <F extends org.refcodes.factory.Factory<T>,T> DependencyBuilder<T> addDependency(Class<T> aType, F aFactory) Adds aDependencyfabricated by a factory.- Type Parameters:
F- The type of the factory producing theDependency.T- The type of theDependencyitself.- Parameters:
aType- The type of theDependencyto be fabricated by the factory.aFactory- TheFactoryinstance producing the accordingDependencydeclaration(s).- Returns:
- An instance of the
DependencyBuilderclass which is used to fluently configure yourDependency.
-
addDependency
public <F extends org.refcodes.factory.Factory<T>,T> DependencyBuilder<T> addDependency(Class<T> aType, Class<F> aFactory) Adds aDependencyfabricated by a factory.- Type Parameters:
F- The type of the factory producing theDependency.T- The type of theDependencyitself.- Parameters:
aType- The type of theDependencyto be fabricated by the factory.aFactory- The type of theFactoryproducing the accordingDependencydeclaration(s).- Returns:
- An instance of the
DependencyBuilderclass which is used to fluently configure yourDependency.
-
addDependency
public <F,T> DependencyBuilder<T> addDependency(Class<T> aType, Class<F> aDependency, Function<F, T> aFactory) Adds aDependencyfabricated from factory's context (Dependency).- Type Parameters:
F- The type of the factory's context (Dependency).T- The type of theDependencyitself.- Parameters:
aType- The type of theDependencyto be fabricated by the factory.aDependency- The context (Dependency) used by the factory to produce the resultingDependency.aFactory- The factoryFunctionusing the context to produce the accordingDependencydeclaration(s).- Returns:
- An instance of the
DependencyBuilderclass which is used to fluently configure yourDependency.
-
hasInterceptor
Tests whether the givenDependencyInterceptorinstance has been added.- Parameters:
aInterceptor- TheDependencyInterceptorinstance for which to test if it has been added.- Returns:
- True if the given
DependencyInterceptorinstance has been added already.
-
addInterceptor
Adds the givenDependencyInterceptorinstance. TheDependencyInterceptorinstance itself acts as the handle which is used when removing the givenDependencyInterceptorinstance later.- Parameters:
aInterceptor- TheDependencyInterceptorinstance which is to be added.- Returns:
- True if the
DependencyInterceptorinstance has been added successfully. If theDependencyInterceptorinstance has already been added, false is returned.
-
removeInterceptor
Removes theDependencyInterceptorinstance. In case theDependencyInterceptorinstance has not been added before, then false is returned.- Parameters:
aInterceptor- TheDependencyInterceptorinstance which is to be removed.- Returns:
- True if the
DependencyInterceptorinstance has been removed successfully. If there was none suchDependencyInterceptorinstance or if theDependencyInterceptorinstance has already been removed, then false is returned.
-
createContext
public Context createContext() throws AmbigousDependencyException, UnsatisfiedDependencyException, CircularDependencyException, DuplicateDependencyException, DuplicateClaimException, UnsatisfiedClaimException, AmbigousClaimException, AmbigousInitializerException, UnsatisfiedInitializerException, AmbigousFactoryException, UnsatisfiedFactoryException, InstallDependencyException- Returns:
- The accordingly wired
Contextinstance. - Throws:
AmbigousDependencyException- thrown in case for a requiredDependencythere are more than one matchingDependencycandidates in theReactor.UnsatisfiedDependencyException- thrown in case for a requiredDependencynone matchingDependencycandidates in theReactorhave been found (taking the profiles applied into account) for the constructors of the givenDependency.CircularDependencyException- thrown in case there is some (transitive) circular dependency between twoDependencyinstances.DuplicateDependencyException- is thrown in case there are multiple identical dependencies applicable by theReactor.DuplicateClaimException- is thrown in case there are multiple identical claims declared by aDependency.UnsatisfiedClaimException- is thrown in case aClaiminstance cannot be satisfied by any knownDependencyinstance.AmbigousClaimException- is thrown in case oneClaimcan be matched by multiple dependencies.AmbigousInitializerException- is thrown in case oneInitializerClaiminstance can be matched by multiple dependencies.UnsatisfiedInitializerException- is thrown in case aInitializerClaiminstance cannot be satisfied by any knownDependencydeclaration.AmbigousFactoryException- is thrown in case oneFactoryClaiminstance can be matched by multiple dependencies.UnsatisfiedFactoryException- is thrown in case aFactoryClaiminstance cannot be satisfied by any knownDependencydeclaration.InstallDependencyException- is thrown when trying to install aDependencyinto theContext, though installing failed die to the dependency throwing an exception during the process of installing (e.g. instantiation).
-
createContext
public Context createContext(String... aProfiles) throws AmbigousDependencyException, UnsatisfiedDependencyException, CircularDependencyException, DuplicateDependencyException, DuplicateClaimException, UnsatisfiedClaimException, AmbigousClaimException, AmbigousInitializerException, UnsatisfiedInitializerException, AmbigousFactoryException, UnsatisfiedFactoryException, InstallDependencyException Creates aContext, regarding the provided profiles, which describes the components and modules wired together by thisReactor.- Parameters:
aProfiles- The profiles to take into account when creating theContextinstance.- Returns:
- The accordingly wired
Contextinstance, as of the provided profiles. - Throws:
AmbigousDependencyException- thrown in case for a requiredDependencythere are more than one matchingDependencycandidates in theReactor.UnsatisfiedDependencyException- thrown in case for a requiredDependencynone matchingDependencycandidates in theReactorhave been found (taking the profiles applied into account) for the constructors of the givenDependency.CircularDependencyException- thrown in case there is some (transitive) circular dependency between twoDependencyinstances.DuplicateDependencyException- is thrown in case there are multiple identical dependencies applicable by theReactor.DuplicateClaimException- is thrown in case there are multiple identical claims declared by aDependency.UnsatisfiedClaimException- is thrown in case aClaiminstance cannot be satisfied by any knownDependencyinstance.AmbigousClaimException- is thrown in case oneClaimcan be matched by multiple dependencies.AmbigousInitializerException- is thrown in case oneInitializerClaiminstance can be matched by multiple dependencies.UnsatisfiedInitializerException- is thrown in case aInitializerClaiminstance cannot be satisfied by any knownDependencydeclaration.AmbigousFactoryException- is thrown in case oneFactoryClaiminstance can be matched by multiple dependencies.UnsatisfiedFactoryException- is thrown in case aFactoryClaiminstance cannot be satisfied by any knownDependencydeclaration.InstallDependencyException- is thrown when trying to install aDependencyinto theContext, though installing failed die to the dependency throwing an exception during the process of installing (e.g. instantiation).
-
createContext
public Context createContext(Object... aProfiles) throws AmbigousDependencyException, UnsatisfiedDependencyException, CircularDependencyException, DuplicateDependencyException, DuplicateClaimException, UnsatisfiedClaimException, AmbigousClaimException, AmbigousInitializerException, UnsatisfiedInitializerException, AmbigousFactoryException, UnsatisfiedFactoryException, InstallDependencyException Creates aContext, regarding the provided profiles, which describes the components and modules wired together by thisReactor.- Parameters:
aProfiles- The profiles to take into account when creating theContextinstance.- Returns:
- The accordingly wired
Contextinstance, as of the provided profiles. - Throws:
AmbigousDependencyException- thrown in case for a requiredDependencythere are more than one matchingDependencycandidates in theReactor.UnsatisfiedDependencyException- thrown in case for a requiredDependencynone matchingDependencycandidates in theReactorhave been found (taking the profiles applied into account) for the constructors of the givenDependency.CircularDependencyException- thrown in case there is some (transitive) circular dependency between twoDependencyinstances.DuplicateDependencyException- is thrown in case there are multiple identical dependencies applicable by theReactor.DuplicateClaimException- is thrown in case there are multiple identical claims declared by aDependency.UnsatisfiedClaimException- is thrown in case aClaiminstance cannot be satisfied by any knownDependencyinstance.AmbigousClaimException- is thrown in case oneClaimcan be matched by multiple dependencies.AmbigousInitializerException- is thrown in case oneInitializerClaiminstance can be matched by multiple dependencies.UnsatisfiedInitializerException- is thrown in case aInitializerClaiminstance cannot be satisfied by any knownDependencydeclaration.AmbigousFactoryException- is thrown in case oneFactoryClaiminstance can be matched by multiple dependencies.UnsatisfiedFactoryException- is thrown in case aFactoryClaiminstance cannot be satisfied by any knownDependencydeclaration.InstallDependencyException- is thrown when trying to install aDependencyinto theContext, though installing failed die to the dependency throwing an exception during the process of installing (e.g. instantiation).
-
toContext
-
intercept
Invokes all registeredDependencyInterceptorinstances for the givenDependencydeclaration's instance for intercepting purposes.- Type Parameters:
T- The type of theDependency.- Parameters:
aInstance- The instance created for the providedDependencydeclaration.aDependency- TheDependencydeclaration.- Returns:
- The intercepted instance.
-