Class AbstractComponent

  • All Implemented Interfaces:
    Component, java.lang.Comparable<Component>
    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 implement deconstruct().
    Author:
    bratseth
    • Field Detail

      • isDeconstructable

        protected final boolean isDeconstructable
    • Constructor Detail

      • AbstractComponent

        protected AbstractComponent()
        Creates a new component which is invalid until initId(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.
        Specified by:
        initId in interface Component
      • getId

        public final ComponentId getId()
        Do NOT call at construction time. Returns the id of this component.
        Specified by:
        getId in interface 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 class java.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 calling initId(com.yahoo.component.ComponentId). Note that even though this implements clone, the component subclass may not in fact be clonable.
        Overrides:
        clone in class java.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 interface java.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()