Class SimpleDataController

java.lang.Object
org.jtrim2.concurrent.query.SimpleDataController
All Implemented Interfaces:
AsyncDataController

public final class SimpleDataController extends Object implements AsyncDataController
An AsyncDataController implementation which stores a volatile reference to an AsyncDataState but otherwise does nothing.

The getDataState method returns the currently set reference to the state of progress.

Note that it is safer to wrap instances of this class in a DelegatedAsyncDataController before sharing it with external code, so the external code will be unable to modify the state of progress.

Thread safety

The methods of this class are safe to be accessed by multiple threads concurrently. Instances of this class cannot be directly modified, only its state of progress if it is mutable. In case the state of progress is immutable (and it is recommended to be so), then the SimpleDataController instance is completely immutable.

Synchronization transparency

The methods of this class are synchronization transparent.
See Also:
  • Constructor Details

    • SimpleDataController

      public SimpleDataController()
      Initializes the SimpleDataController with null as the state of progress.

      Until setDataState has been called, null will be returned by the getDataState method.

    • SimpleDataController

      public SimpleDataController(AsyncDataState firstState)
      Initializes the SimpleDataController with the specified state of progress.
      Parameters:
      firstState - the AsyncDataState which will be returned by the getDataState() method until setDataState has been called. This argument can be null.
  • Method Details

    • setDataState

      public void setDataState(AsyncDataState newState)
      Sets the volatile reference to the stored AsyncDataState to the one specified. Subsequent calls the getDataState() method will return the state specified.
      Parameters:
      newState - the AsyncDataState which is to be returned by the getDataState() method. This argument can be null.
    • controlData

      public void controlData(Object controlArg)
      This method does nothing and returns immediately to the caller.
      Specified by:
      controlData in interface AsyncDataController
      Parameters:
      controlArg - this argument is ignored
    • getDataState

      public AsyncDataState getDataState()
      Returns the AsyncDataState object which was last set by the setDataState() method or the one specified at construction time if there was no setDataState() call yet.
      Specified by:
      getDataState in interface AsyncDataController
      Returns:
      the AsyncDataState which was last set by the setDataState() method or the one specified at construction time if there was no setDataState() call yet. This method may return null if null was set.