Class TaskManager
- java.lang.Object
-
- pulse.util.UpwardsNavigable
-
- pulse.tasks.TaskManager
-
- All Implemented Interfaces:
Serializable,Descriptive
public final class TaskManager extends UpwardsNavigable
The
TaskManageris a high-level class for dealing with operations of creation, removal, storage, and execution ofSearchTasks, as well as with the associatedResults andInterpolationDatasets. Note thatTaskManageradopts aPathSolver.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddExternalDatasetListener(ExternalDatasetListener edl)voidaddSelectionListener(TaskSelectionListener listener)static voidaddSessionListener(SessionListener sl)SearchTaskaddTask(SearchTask t)If a taskequaltothas already been previously loaded, does nothing.voidaddTaskRepositoryListener(TaskRepositoryListener listener)Set<Group>allGrouppedContents()static voidassumeNewState(TaskManager loaded)voidcancelAllTasks()This will terminate all tasks in thisTaskManagerand trigger aSHUTDOWNTaskRepositoryEvent.voidclear()Purges all tasks from thisTaskManager.List<NumericPropertyKeyword>derivableProperties()Creates a list of property keywords that can be derived with help of the loaded data.Stringdescribe()ThisTaskManagerwill be described by the sample name for the experiment.voidevaluate()voidexecute(SearchTask t)Executes tasynchronously using aCompletableFuture.voidexecuteAll()Creates a queue ofSearchTasks based on their readiness and feeds that queue to aForkJoinPoolusing a parallel stream.voidfireTaskSelected(Object source)voidgenerateTask(File file)Generates aSearchTaskassuming that theExperimentalDatais stored in thefile.voidgenerateTasks(List<File> files)Generates multiple tasks from multiplefiles.InterpolationDatasetgetDensityDataset()static TaskManagergetManagerInstance()This class uses a singleton pattern, meaning there is only instance of this class.SampleNamegetSampleName()Uses the first non-nullSearchTaskto retrieve the sample name from theMetadataassociated with itsExperimentalData.SearchTaskgetSelectedTask()List<TaskSelectionListener>getSelectionListeners()InterpolationDatasetgetSpecificHeatDataset()SearchTaskgetTask(int externalId)Finds aSearchTaskusing the external identifier specified in its metadata.SearchTaskgetTask(Identifier id)Finds aSearchTaskwhoseIdentifiermatchesid.List<SearchTask>getTaskList()List<TaskRepositoryListener>getTaskRepositoryListeners()intindexOfTask(SearchTask t)voidinitListeners()booleanisSingleStatement()Checks whether changes in thisPropertyHoldershould automatically be accounted for by other instances of this class.booleanisTaskQueueEmpty()Checks if any of the tasks that thisTaskManagermanages is eitherQUEUEDorIN_PROGRESS.voidnotifyListeners(TaskRepositoryEvent e)Notifies theTaskRepositoryListeners of theeintnumberOfTasks()Gets the current number of tasks in the repository.voidremoveSelectionListeners()static voidremoveSessionListeners()booleanremoveTask(SearchTask t)Iftis found in the local repository, removes it and triggers aTASK_REMOVEDevent.voidremoveTaskRepositoryListener(TaskRepositoryListener trl)voidreset()Clears any progress for all the tasks and resets everything.voidselectFirstTask()voidselectTask(Identifier id, Object src)Selects aSearchTaskwithin this repository with the specifiedid(if present).voidsetDensityDataset(InterpolationDataset dataset)voidsetSingleStatement(boolean singleStatement)Sets the flag to isolate or inter-connects changes in all instances ofPropertyHoldervoidsetSpecificHeatDataset(InterpolationDataset dataset)-
Methods inherited from class pulse.util.UpwardsNavigable
addHierarchyListener, getHierarchyListeners, getParent, identify, removeHierarchyListener, removeHierarchyListeners, setParent, specificAncestor, tellParent
-
-
-
-
Method Detail
-
derivableProperties
public List<NumericPropertyKeyword> derivableProperties()
Creates a list of property keywords that can be derived with help of the loaded data. For example, if heat capacity and density data is available, the returned list will containCONDUCTIVITY.- Returns:
-
initListeners
public void initListeners()
- Overrides:
initListenersin classUpwardsNavigable
-
getManagerInstance
public static TaskManager getManagerInstance()
This class uses a singleton pattern, meaning there is only instance of this class.- Returns:
- the single (static) instance of this class
-
execute
public void execute(SearchTask t)
Executes tasynchronously using aCompletableFuture. When done, creates aResultand puts it into theMap(SearchTask,Result)in thisTaskManager.- Parameters:
t- aSearchTaskthat will be executed
-
notifyListeners
public void notifyListeners(TaskRepositoryEvent e)
Notifies theTaskRepositoryListeners of thee- Parameters:
e- an event
-
executeAll
public void executeAll()
Creates a queue of
SearchTasks based on their readiness and feeds that queue to aForkJoinPoolusing a parallel stream. The size of the pool is usually limited by hardware, e.g. for a 4 core system with 2 independent threads on each core, the limitation will be , etc.
-
isTaskQueueEmpty
public boolean isTaskQueueEmpty()
Checks if any of the tasks that thisTaskManagermanages is eitherQUEUEDorIN_PROGRESS.- Returns:
falseif the status of theSearchTaskis any of the above;falseotherwise.
-
cancelAllTasks
public void cancelAllTasks()
This will terminate all tasks in thisTaskManagerand trigger aSHUTDOWNTaskRepositoryEvent.
-
fireTaskSelected
public void fireTaskSelected(Object source)
-
clear
public void clear()
Purges all tasks from this
TaskManager. Generates aTASK_REMOVEDTaskRepositoryEventfor each of the removed tasks. Clears task selection.
-
getSampleName
public SampleName getSampleName()
Uses the first non-nullSearchTaskto retrieve the sample name from theMetadataassociated with itsExperimentalData.- Returns:
- a
Stringwith the sample name, ornullif no suitable task can be found.
-
reset
public void reset()
Clears any progress for all the tasks and resets everything. Triggers a
TASK_RESETevent.
-
getTask
public SearchTask getTask(Identifier id)
Finds aSearchTaskwhoseIdentifiermatchesid.- Parameters:
id- theIdentifierof the task.- Returns:
- the
SearchTaskassociated with thisIdentifier.
-
getTask
public SearchTask getTask(int externalId)
Finds aSearchTaskusing the external identifier specified in its metadata.- Parameters:
externalId- the external ID of the data.- Returns:
- the
SearchTaskassociated with thisIdentifier.
-
generateTask
public void generateTask(File file)
Generates a
SearchTaskassuming that theExperimentalDatais stored in thefile. This will make theReaderManagerattempt to read thatfile. If successful, invokesaddTask(...)on the createdSearchTask. After the task is generated, checks whether the acquisition time recorded by the experimental setup has been chosen appropriately.- Parameters:
file- the file to load the experimental data from- See Also:
addTask(pulse.tasks.SearchTask)
-
generateTasks
public void generateTasks(List<File> files)
Generates multiple tasks from multiplefiles.- Parameters:
files- a list ofFiles that can be parsed down toExperimentalData.
-
addTask
public SearchTask addTask(SearchTask t)
If a task
equaltothas already been previously loaded, does nothing. Otherwise, adds thistto the task repository and triggers aTASK_ADDEDevent.- Parameters:
t- theSearchTaskthat needs to be added to the internal repository- Returns:
nullif a task likethas already been added previously,totherwise.
-
removeTask
public boolean removeTask(SearchTask t)
Iftis found in the local repository, removes it and triggers aTASK_REMOVEDevent.- Parameters:
t- aSearchTaskthat has been previously loaded to this repository.- Returns:
trueif the operation is successful,falseotherwise.
-
numberOfTasks
public int numberOfTasks()
Gets the current number of tasks in the repository.- Returns:
- the number of available tasks.
-
selectTask
public void selectTask(Identifier id, Object src)
Selects a
SearchTaskwithin this repository with the specifiedid(if present). Informs the listeners this selection has been triggered bysrc.- Parameters:
id- theIdentifierof a task within this repository.src- the source of the selection.
-
selectFirstTask
public void selectFirstTask()
-
addSelectionListener
public final void addSelectionListener(TaskSelectionListener listener)
-
addTaskRepositoryListener
public final void addTaskRepositoryListener(TaskRepositoryListener listener)
-
getSelectionListeners
public List<TaskSelectionListener> getSelectionListeners()
-
removeSelectionListeners
public void removeSelectionListeners()
-
removeTaskRepositoryListener
public void removeTaskRepositoryListener(TaskRepositoryListener trl)
-
indexOfTask
public int indexOfTask(SearchTask t)
-
getTaskList
public List<SearchTask> getTaskList()
-
getSelectedTask
public SearchTask getSelectedTask()
-
getTaskRepositoryListeners
public List<TaskRepositoryListener> getTaskRepositoryListeners()
-
describe
public String describe()
ThisTaskManagerwill be described by the sample name for the experiment.- Specified by:
describein interfaceDescriptive- Overrides:
describein classUpwardsNavigable- Returns:
- the string descriptor
-
evaluate
public void evaluate()
-
isSingleStatement
public boolean isSingleStatement()
Checks whether changes in thisPropertyHoldershould automatically be accounted for by other instances of this class.- Returns:
trueif the user has specified so (set by default),falseotherwise
-
assumeNewState
public static void assumeNewState(TaskManager loaded)
-
addExternalDatasetListener
public void addExternalDatasetListener(ExternalDatasetListener edl)
-
addSessionListener
public static void addSessionListener(SessionListener sl)
-
removeSessionListeners
public static void removeSessionListeners()
-
setSingleStatement
public void setSingleStatement(boolean singleStatement)
Sets the flag to isolate or inter-connects changes in all instances ofPropertyHolder- Parameters:
singleStatement-falseif otherPropertyHoders should disregard changes, which happened to this instances.trueotherwise.
-
getDensityDataset
public InterpolationDataset getDensityDataset()
-
getSpecificHeatDataset
public InterpolationDataset getSpecificHeatDataset()
-
setDensityDataset
public void setDensityDataset(InterpolationDataset dataset)
-
setSpecificHeatDataset
public void setSpecificHeatDataset(InterpolationDataset dataset)
-
-