Class Block

java.lang.Object
com.tccc.kos.commons.util.Block
All Implemented Interfaces:
Blockable

public class Block extends Object implements Blockable
Implementation of the Blockable interface. This is typically used by objects that implement Blockable to perform the actual block behavior.

This provides callbacks for onBlocked and onUnblocked which are called when the first block is added or the last block is removed.

Since:
1.0
Version:
2023-02-27
  • Constructor Details

    • Block

      public Block()
  • Method Details

    • setOnBlocked

      public Block setOnBlocked(Runnable callback)
      Set the callback to run when transitioning to a blocked state.
      Parameters:
      callback - the callback to call
    • setOnUnblocked

      public Block setOnUnblocked(Runnable callback)
      Set the callback to run when transitioning to an unblocked state.
      Parameters:
      callback - the callback to call
    • blocked

      public void blocked()
      Called when transitioning to a blocked state. Override as needed or use setOnBlocked() .
    • unblocked

      public void unblocked()
      Called when transitioning to an unblocked state. Override as needed or use setOnUnblocked() .
    • isBlocked

      public boolean isBlocked()
      Description copied from interface: Blockable
      Return true is the object is blocked.
      Specified by:
      isBlocked in interface Blockable
    • block

      public void block(Object reason)
      Description copied from interface: Blockable
      Block the object for the specified reason. The same reason must be used to unblock.
      Specified by:
      block in interface Blockable
      Parameters:
      reason - the reason to block
    • unblock

      public void unblock(Object reason)
      Description copied from interface: Blockable
      Remove a block with the specified reason.
      Specified by:
      unblock in interface Blockable
      Parameters:
      reason - the reason used to block
    • getOnBlocked

      public Runnable getOnBlocked()
    • getOnUnblocked

      public Runnable getOnUnblocked()