java.lang.Object
org.jtrim2.concurrent.query.SimpleDataController
- All Implemented Interfaces:
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 itsstate 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 Summary
ConstructorsConstructorDescriptionSimpleDataController(AsyncDataState firstState) Initializes theSimpleDataControllerwith the specifiedstate of progress. -
Method Summary
Modifier and TypeMethodDescriptionvoidcontrolData(Object controlArg) This method does nothing and returns immediately to the caller.Returns theAsyncDataStateobject which was last set by thesetDataState()method or the one specified at construction time if there was nosetDataState()call yet.voidsetDataState(AsyncDataState newState) Sets the volatile reference to the storedAsyncDataStateto the one specified.
-
Constructor Details
-
SimpleDataController
public SimpleDataController()Initializes theSimpleDataControllerwithnullas thestate of progress.Until
setDataStatehas been called,nullwill be returned by thegetDataStatemethod. -
SimpleDataController
Initializes theSimpleDataControllerwith the specifiedstate of progress.- Parameters:
firstState- theAsyncDataStatewhich will be returned by thegetDataState()method untilsetDataStatehas been called. This argument can benull.
-
-
Method Details
-
setDataState
Sets the volatile reference to the storedAsyncDataStateto the one specified. Subsequent calls thegetDataState()method will return the state specified.- Parameters:
newState- theAsyncDataStatewhich is to be returned by thegetDataState()method. This argument can benull.
-
controlData
This method does nothing and returns immediately to the caller.- Specified by:
controlDatain interfaceAsyncDataController- Parameters:
controlArg- this argument is ignored
-
getDataState
Returns theAsyncDataStateobject which was last set by thesetDataState()method or the one specified at construction time if there was nosetDataState()call yet.- Specified by:
getDataStatein interfaceAsyncDataController- Returns:
- the
AsyncDataStatewhich was last set by thesetDataState()method or the one specified at construction time if there was nosetDataState()call yet. This method may returnnullifnullwas set.
-