Interface SmartObject

All Known Implementing Classes:
CompressedSmartObject, Extractor, Group, HealingTurret, InfernoTurret, KeyedKingdomsObject, Kingdom, KingdomBlock, KingdomBuilding, KingdomPlayer, KingdomsObject, Land, Mail, MineTurret, Nation, Outpost, ProtectionSign, RangedTurret, Rank, Regulator, SiegeCannon, SoldierTurret, Structure, TargetedRangedTurret, Turret, WarpPad

public interface SmartObject
An object that is intended to be saved in a database. This object implements a system that notifies it when the instance is being replaced by a new one loaded from the database (ensureValidObject()) and also implements a system that knows whether this object is updated and needs to be saved to the database or not (shouldSave()).
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
     
    boolean
     
    void
    Mark this object as a phantom object.
    default boolean
    Checks whether this data is absolutely empty and can be deleted from the database.
    boolean
     
    void
    saveObjectState(boolean forceSave)
    Should be called after a data is either fully loaded from the database or loaded into the manager by other means.
    boolean
    Should this data be saved to the database?
  • Method Details

    • invalidateObject

      @Internal void invalidateObject(String reason)
      Mark this object as a phantom object. No reference should access this object, and it's expected to be garbage collected since it no longer exists in the cache. Implementations must try to guard most access to this object with ensureValidObject().
      See Also:
    • hasObjectExpired

      @Internal boolean hasObjectExpired()
      See Also:
    • ensureValidObject

      @Internal default void ensureValidObject()
      See Also:
    • isDataEmpty

      @Internal default boolean isDataEmpty()
      Checks whether this data is absolutely empty and can be deleted from the database. The definition of "empty" depends on the implementation.
      Returns:
      true if the data is empty and should be deleted, otherwise false
    • saveObjectState

      @Internal void saveObjectState(boolean forceSave)
      Should be called after a data is either fully loaded from the database or loaded into the manager by other means.
      Parameters:
      forceSave - true if this data should be saved regardless if it was changed or not. This is used when this data never existed in the database or certain operations that guarantee that the object will be changed. Using this can result in huge performance gain.
      Throws:
      IllegalStateException - If forceSave is false and the object state is already set.
      See Also:
    • isObjectStateSaved

      @Internal boolean isObjectStateSaved()
      See Also:
    • shouldSave

      @Internal boolean shouldSave()
      Should this data be saved to the database?