Package com.yahoo.component
Class AbstractComponent
java.lang.Object
com.yahoo.component.AbstractComponent
- All Implemented Interfaces:
Component
,Deconstructable
,Comparable<Component>
- Direct Known Subclasses:
FreezableComponent
,FreezableSimpleComponent
Superclass of destructible components. Container components to be created via dependency injection
do not have to extend this class unless they need to implement
deconstruct()
.- Author:
- bratseth
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new component which is invalid untilinitId(com.yahoo.component.ComponentId)
is called on it.protected
Creates a new component with an id. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Clones this by returning a new instance which does not have an id.int
Order by id order.void
Implement this to perform any cleanup of structures or resources allocated in the constructor, before this component is removed.final ComponentId
getId()
Do NOT call at construction time.final String
DO NOT CALL, for internal use only,final boolean
DO NOT CALL, for internal use only,final void
initId
(ComponentId id) Initializes this.final boolean
protected boolean
toString()
-
Field Details
-
isDeconstructable
protected final boolean isDeconstructable
-
-
Constructor Details
-
AbstractComponent
protected AbstractComponent()Creates a new component which is invalid untilinitId(com.yahoo.component.ComponentId)
is called on it. The dependency injection framework (DI) will always set the id, so components to be created via DI do not have to implement other constructors, and should not set the id themselves. -
AbstractComponent
Creates a new component with an id. Only for testing and components that are not created via dependency injection.- Throws:
NullPointerException
- if the given id is null
-
-
Method Details
-
initId
Initializes this. Always called from a constructor or the framework. Do not call. -
getId
Do NOT call at construction time. Returns the id of this component. -
hasInitializedId
public final boolean hasInitializedId()DO NOT CALL, for internal use only, -
getIdString
DO NOT CALL, for internal use only, -
getClassName
-
toString
-
clone
Clones this by returning a new instance which does not have an id. An id can subsequently be assigned by callinginitId(com.yahoo.component.ComponentId)
. Note that even though this implements clone, the component subclass may not in fact be clonable.- Overrides:
clone
in classObject
- Throws:
RuntimeException
- if the component is not clonable
-
compareTo
Order by id order. It is permissible to change the order definition in subclasses- Specified by:
compareTo
in interfaceComparable<Component>
-
deconstruct
public void deconstruct()Implement this to perform any cleanup of structures or resources allocated in the constructor, before this component is removed.All other calls to this component is completed before this method is called. It will only be called once. It should block while doing cleanup tasks and return when this class is ready for garbage collection. This method is called in reverse dependency order, so a component will be deconstructed after any other components it is injected into.
This default implementation does nothing.
- Specified by:
deconstruct
in interfaceDeconstructable
-
isDeconstructable
public final boolean isDeconstructable()- Returns:
- true if this component has a non-default implementation of the
deconstruct()
method.
-
setIsDeconstructable
protected boolean setIsDeconstructable()
-