Class Dependency<T>
java.lang.Object
org.refcodes.decoupling.Dependency<T>
- Type Parameters:
T- the generic type of theDependency.
- All Implemented Interfaces:
Comparable<Dependency<T>>, ClaimsAccessor, InstanceMetricsAccessor, ProfilesAccessor, TagsAccessor, AliasAccessor, TypeAccessor<T>, Diagnosable, Schemable<DiagnosticOptions>
- Direct Known Subclasses:
DependencyBuilder
public class Dependency<T>
extends Object
implements AliasAccessor, TypeAccessor<T>, ProfilesAccessor, TagsAccessor, InstanceMetricsAccessor, ClaimsAccessor, Comparable<Dependency<T>>, Diagnosable
A
Dependency describes a component wired together by the
Reactor with other components also defined by Dependency
instances.-
Nested Class Summary
Nested classes/interfaces inherited from interface AliasAccessor
AliasAccessor.AliasBuilder<B>, AliasAccessor.AliasMutator, AliasAccessor.AliasPropertyNested classes/interfaces inherited from interface ClaimsAccessor
ClaimsAccessor.ClaimsBuilder<B>, ClaimsAccessor.ClaimsMutator, ClaimsAccessor.ClaimsPropertyNested classes/interfaces inherited from interface InstanceMetricsAccessor
InstanceMetricsAccessor.InstanceMetricsBuilder<B>, InstanceMetricsAccessor.InstanceMetricsMutator, InstanceMetricsAccessor.InstanceMetricsPropertyNested classes/interfaces inherited from interface ProfilesAccessor
ProfilesAccessor.ProfilesBuilder<B>, ProfilesAccessor.ProfilesMutator, ProfilesAccessor.ProfilesPropertyNested classes/interfaces inherited from interface TagsAccessor
TagsAccessor.TagsBuilder<B>, TagsAccessor.TagsMutator, TagsAccessor.TagsPropertyNested classes/interfaces inherited from interface TypeAccessor
TypeAccessor.TypeBuilder<T,B>, TypeAccessor.TypeMutator<T>, TypeAccessor.TypeProperty<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected Dependency<?>[]protected FactoryClaim<?, T> protected InitializerClaim<?, T> protected InstanceMetricsprotected Reactorprotected Tstatic final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(Dependency<T> aDependency) booleangetAlias()Claim[]FactoryClaim<?, T> Retrieves theFactoryClaim, being aClaimdedicated to fabricate (create) the dependency.Retrieves theInitializerClaim, being aClaimdedicated to initialize the dependency after instantiation.Retrieves theInstanceMetricswhich describes how an instance for aDependencyis managed.T[]Retrieves the instances produced by thisDependency(as of theDependency'sInstanceMetricsconfiguration).Object[]Retrieves the profiles assigned to theDependencydeclaration.Object[]getTags()Retrieves the tags assigned to theDependencydeclaration.getType()inthashCode()booleanhasInstance(Object aInstance) Determines whether thisDependencyelement contains the provided instance.booleanDetermines weather thisDependencyelement has at least one instance of its typegetType()being created.booleanhasProfile(Object... aProfiles) Tests whether thisDependencymatches any of the provided profiles.protected THook method to be overwritten by sub-classes in order to decorate new aspects to the produced instance.protected voidsetInstance(T aInstance) Sets the instance for theDependency(the type is derived from the instance if not already set, the alias is derived from type if not already set).Creates theDependency's instance using the preparedDependencydeclarations (theDependencydeclarations are prepared by theReactor'sReactor.createContext()and the like methods and in turn by the underlyingtoInstance()methods).protected TtoInstance(Dependency<?>[] aDependencies, Object... aProfiles) Creates theDependency's instance as of its type using the providedDependencydeclarations.protected TtoInstance(Dependency<?>[] aDependencies, Set<Dependency<?>> aVistedDependencies, Object... aProfiles) Creates theDependency's instance as of its type using the providedDependencydeclarations.toSchema()toString()
-
Field Details
-
DEPENDENCY_STEREOTYPE
- See Also:
-
INSTANCE_STEREOTYPE
- See Also:
-
_singleton
-
_alias
-
_claims
-
_dependencies
-
_instanceMetrics
-
_instances
-
_profiles
-
_tags
-
_type
-
_initializer
-
_factory
-
_reactor
-
-
Constructor Details
-
Dependency
protected Dependency()Instantiates a newDependency.
-
-
Method Details
-
equals
-
getAlias
- Specified by:
getAliasin interfaceAliasAccessor
-
getClaims
-
getInitializer
Retrieves theInitializerClaim, being aClaimdedicated to initialize the dependency after instantiation.- Returns:
- The
InitializerClaimbeing set for thisDependency.
-
getFactory
Retrieves theFactoryClaim, being aClaimdedicated to fabricate (create) the dependency.- Returns:
- The
FactoryClaimbeing set for thisDependency.
-
getInstanceMetrics
Retrieves theInstanceMetricswhich describes how an instance for aDependencyis managed.- Specified by:
getInstanceMetricsin interfaceInstanceMetricsAccessor- Returns:
- The according
InstanceMetrics.
-
getInstances
Retrieves the instances produced by thisDependency(as of theDependency'sInstanceMetricsconfiguration).- Returns:
- The instances fabricated by this
Dependencydeclaration.
-
getProfiles
Retrieves the profiles assigned to theDependencydeclaration.- Specified by:
getProfilesin interfaceProfilesAccessor- Returns:
- The assigned profiles.
-
getTags
Retrieves the tags assigned to theDependencydeclaration.- Specified by:
getTagsin interfaceTagsAccessor- Returns:
- The assigned tags.
-
getType
- Specified by:
getTypein interfaceTypeAccessor<T>
-
hashCode
-
hasInstances
public boolean hasInstances()Determines weather thisDependencyelement has at least one instance of its typegetType()being created.- Returns:
- True in case instances for this
Dependencyhave already been created.
-
hasInstance
Determines whether thisDependencyelement contains the provided instance.- Parameters:
aInstance- The instance which is to be tested.- Returns:
- True in case this
Dependencyelement contains the given instance, else false.
-
hasProfile
Tests whether thisDependencymatches any of the provided profiles.- Parameters:
aProfiles- The profiles (as provided by theReactor) to match against.- Returns:
- True in case this
Dependencymatches at least one of the provided profiles.
-
toInstance
Creates theDependency's instance using the preparedDependencydeclarations (theDependencydeclarations are prepared by theReactor'sReactor.createContext()and the like methods and in turn by the underlyingtoInstance()methods).- Returns:
- The instance retrieved from the
Dependency. - Throws:
DependencyInstanciationException- the dependency instantiation exception
-
toSchema
-
compareTo
- Specified by:
compareToin interfaceComparable<T>
-
toString
-
setInstance
Sets the instance for theDependency(the type is derived from the instance if not already set, the alias is derived from type if not already set).- Parameters:
aInstance- The instance of the dependency;
-
toInstance
protected T toInstance(Dependency<?>[] aDependencies, Object... aProfiles) throws CircularDependencyException, AmbigousDependencyException, UnsatisfiedDependencyException, AmbigousClaimException, AmbigousInitializerException, AmbigousFactoryException, InstallDependencyException Creates theDependency's instance as of its type using the providedDependencydeclarations.- Parameters:
aDependencies- theDependencydeclarations to use.aProfiles- The profiles as provided by theReactorto take into account.- Returns:
- The instance retrieved from the
Dependency. - Throws:
CircularDependencyException- thrown in case there is some (transitive) circular dependency between twoDependencyinstances.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.AmbigousClaimException- is thrown in case oneClaimcan be matched by multiple dependencies.AmbigousInitializerException- is thrown in case oneInitializerClaiminstance can be matched by multiple dependencies.AmbigousFactoryException- is thrown in case oneFactoryClaiminstance can be matched by multiple dependencies.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).
-
toInstance
protected T toInstance(Dependency<?>[] aDependencies, Set<Dependency<?>> aVistedDependencies, Object... aProfiles) throws CircularDependencyException, AmbigousDependencyException, UnsatisfiedDependencyException, AmbigousClaimException, AmbigousInitializerException, AmbigousFactoryException, InstallDependencyException Creates theDependency's instance as of its type using the providedDependencydeclarations.- Parameters:
aDependencies- theDependencydeclarations to use.aVistedDependencies- TheDependencydeclarations already visited in order to detect a circular dependency situation.aProfiles- The profiles as provided by theReactorto take into account.- Returns:
- The instance retrieved from the
Dependency. - Throws:
CircularDependencyException- thrown in case there is some (transitive) circular dependency between twoDependencyinstances.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.AmbigousClaimException- is thrown in case oneClaimcan be matched by multiple dependencies.AmbigousInitializerException- is thrown in case oneInitializerClaiminstance can be matched by multiple dependencies.AmbigousFactoryException- is thrown in case oneFactoryClaiminstance can be matched by multiple dependencies.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).
-
intercept
-