Class VSWorkUnit


  • public class VSWorkUnit
    extends java.lang.Object
    Class used to handle manipulation with one or more VS components that in turn may contain others. It is used to postpone other parties that also wishes to process the components and would like to be informed when the others completes their tasks. Typically, this is used by e.g. the Database Connector before it starts to do massive changes to a VS Table. On the consumer side, the UI Grid uses this in order to avoid processing updates to the VS Table until the database has completed its work unit.

    This class is by no means a locking class, but rather a helper class to avoid updating data from a structure that is not yet "stable".

    This class is thread-safe.

    Author:
    Christopher Mindus
    • Constructor Summary

      Constructors 
      ConstructorDescription
      VSWorkUnit​(VirtualSpace virtualSpace)
      Creates a work unit for the entire VirtualSpace.
      VSWorkUnit​(VSComponent component)
      The list of components used in the for the VS update work.
      VSWorkUnit​(VSComponent... components)
      The list of components used in the for the VS update work.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      voidadd​(VSComponent component)
      Adds another component in the work unit.
      booleanareFree​(java.lang.Runnable callback, VSComponent... components)
      Verifies if component(s) is/are included in the work unit.
      voidbeginWork()
      Begins the work unit.
      voidendWork()
      Ends the work unit.
      booleanisFree​(java.lang.Runnable callback, VSComponent component)
      Verifies if a component is included in the work unit.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • VSWorkUnit

        public VSWorkUnit​(VirtualSpace virtualSpace)
        Creates a work unit for the entire VirtualSpace. This is typically done in complex update areas where the components are not know, such as e.g. the rollback of a GyroTransaction.
        Parameters:
        virtualSpace - The VirtualSpace involved in the work.
      • VSWorkUnit

        public VSWorkUnit​(VSComponent component)
        The list of components used in the for the VS update work.
        Parameters:
        component - The VS component involved in the work.
        Throws:
        java.lang.IllegalArgumentException - If the components doesn't have a VirtualSpace.
      • VSWorkUnit

        public VSWorkUnit​(VSComponent... components)
        The list of components used in the for the VS update work.
        Parameters:
        components - The VS components involved in the work.
        Throws:
        java.lang.IllegalArgumentException - If the components doesn't have a VirtualSpace or if the components is of length zero or are in different VirtualSpaces.
    • Method Detail

      • add

        public void add​(VSComponent component)
        Adds another component in the work unit.
        Parameters:
        component - The VS component involved in the work.
        Throws:
        java.lang.IllegalArgumentException - If the component is in a different VirtualSpace.
        java.lang.IllegalStateException - If the work has begun.
      • beginWork

        public void beginWork()
        Begins the work unit. It is VERY important to complete the processing of the work unit with a call to endWork().

        This method registers the work unit with the VirtualSpace in question.

        Throws:
        java.lang.IllegalStateException - If this method is called twice.
      • endWork

        public void endWork()
        Ends the work unit. This call will call all postponed callbacks that have been added during the work unit with the isFree(Runnable, VSComponent) or areFree(Runnable, VSComponent...) methods.
        Throws:
        java.lang.IllegalStateException - If this method is called without prior beginWork or called twice.
      • isFree

        public boolean isFree​(java.lang.Runnable callback,
                              VSComponent component)
        Verifies if a component is included in the work unit.
        Parameters:
        callback - The callback to call when work completes, or null for none.
        component - The component to verify.
        Returns:
        true if it's OK to process, false means the component is included in this work unit and if callback is non-null, it will be called.
      • areFree

        public boolean areFree​(java.lang.Runnable callback,
                               VSComponent... components)
        Verifies if component(s) is/are included in the work unit.
        Parameters:
        callback - The callback to call when work completes, or null for none.
        components - The components to verify.
        Returns:
        true if it's OK to process, false means the component is included in this work unit and if callback is non-null, it will be called.