Package com.yahoo.component
Class AbstractComponent
- java.lang.Object
-
- com.yahoo.component.AbstractComponent
-
- Direct Known Subclasses:
FreezableComponent
,FreezableSimpleComponent
public class AbstractComponent extends java.lang.Object implements Component
Superclass of destructible components. Container components to be created via dependency injection do not have to extend this class unless they need to implementdeconstruct()
.- Author:
- bratseth
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
isDeconstructable
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractComponent()
Creates a new component which is invalid untilinitId(com.yahoo.component.ComponentId)
is called on it.protected
AbstractComponent(ComponentId id)
Creates a new component with an id.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AbstractComponent
clone()
Clones this by returning a new instance which does not have an id.int
compareTo(Component other)
Order by id order.void
deconstruct()
Implement this to perform any cleanup of structures or resources allocated in the constructor, before this component is removed.java.lang.String
getClassName()
ComponentId
getId()
Do NOT call at construction time.java.lang.String
getIdString()
DO NOT CALL, for internal use only,boolean
hasInitializedId()
DO NOT CALL, for internal use only,void
initId(ComponentId id)
Initializes this.boolean
isDeconstructable()
protected boolean
setIsDeconstructable()
java.lang.String
toString()
-
-
-
Constructor Detail
-
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
protected AbstractComponent(ComponentId id)
Creates a new component with an id. Only for testing and components that are not created via dependency injection.- Throws:
java.lang.NullPointerException
- if the given id is null
-
-
Method Detail
-
initId
public final void initId(ComponentId id)
Initializes this. Always called from a constructor or the framework. Do not call.
-
getId
public final ComponentId 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
public final java.lang.String getIdString()
DO NOT CALL, for internal use only,
-
getClassName
public java.lang.String getClassName()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
clone
public AbstractComponent 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 classjava.lang.Object
- Throws:
java.lang.RuntimeException
- if the component is not clonable
-
compareTo
public int compareTo(Component other)
Order by id order. It is permissible to change the order definition in subclasses- Specified by:
compareTo
in interfacejava.lang.Comparable<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 default implementation does nothing.
-
isDeconstructable
public final boolean isDeconstructable()
- Returns:
- true if this component has a non-default implementation of the
deconstruct()
method.
-
setIsDeconstructable
protected boolean setIsDeconstructable()
-
-