Class CommandsRegistry


  • public class CommandsRegistry
    extends Object
    A register of commands. This is a singleton. It automatically collects the executed commands when the command is executed by an instrument. The register has a limited size that can be changed.
    Author:
    Arnaud Blouin
    • Constructor Detail

      • CommandsRegistry

        public CommandsRegistry()
        Creates and initialises a register.
    • Method Detail

      • getInstance

        public static CommandsRegistry getInstance()
        Returns:
        The single instance. Cannot be null.
      • setInstance

        public static void setInstance​(CommandsRegistry newInstance)
        Sets the single instance.
        Parameters:
        newInstance - The new single instance. Nothing done if null.
      • commands

        public io.reactivex.Observable<Command> commands()
        An RX observable objects that will provide the commands produced by the binding.
      • getCommands

        public List<Command> getCommands()
        Returns:
        The stored commands. Cannot be null. Because of concurrency, you should not modify this list.
      • unregisterCommand

        public void unregisterCommand​(Command cmd)
        Removes and flushes the commands from the register that use the given command type.
        Parameters:
        cmd - The command that may cancels others.
        See Also:
        ::unregisteredBy
      • addCommand

        public void addCommand​(Command cmd)
        Adds a command to the register. Before being added, the given command is used to cancel commands already added. Handlers are notified of the add of the given command. If Undoable, the cmd is added to the undo collector as well.
        Parameters:
        cmd - The command to add. If null, nothing is done.
      • removeCommand

        public void removeCommand​(Command cmd)
        Removes the command from the register. The cmd is then flushed.
        Parameters:
        cmd - The command to remove.
      • clear

        public void clear()
        Flushes and removes all the stored commands.
      • cancelCmd

        public void cancelCmd​(Command cmd)
        Aborts the given command, i.e. the cmd is cancelled and removed from the register. Handlers are then notified. The command is finally flushed.
        Parameters:
        cmd - The command to cancel.
      • getSizeMax

        public int getSizeMax()
        Returns:
        The maximal number of commands that the register can contain.
      • setSizeMax

        public void setSizeMax​(int newSizeMax)
        Changes the number of commands that the register can contain. In the case that commands have to be removed (because the new size is smaller than the old one), the necessary number of the oldest and cleanable commands (cf. Command::getRegistrationPolicy) are flushed and removed from the register.
        Parameters:
        newSizeMax - The max number of commands that can contain the register. Must be equal or greater than 0.