Class AbstractComponent

java.lang.Object
com.yahoo.component.AbstractComponent
All Implemented Interfaces:
Component, Deconstructable, Comparable<Component>
Direct Known Subclasses:
FreezableComponent, FreezableSimpleComponent

public class AbstractComponent extends Object implements Component, Deconstructable
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 Details

    • isDeconstructable

      protected final boolean isDeconstructable
  • Constructor Details

    • 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:
      NullPointerException - if the given id is null
  • Method Details

    • 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 String getIdString()
      DO NOT CALL, for internal use only,
    • getClassName

      public String getClassName()
    • toString

      public String toString()
      Overrides:
      toString in class 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 Object
      Throws:
      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 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 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 interface Deconstructable
    • isDeconstructable

      public final boolean isDeconstructable()
      Returns:
      true if this component has a non-default implementation of the deconstruct() method.
    • setIsDeconstructable

      protected boolean setIsDeconstructable()