Class Task

    • Field Detail

      • useOnlineResources

        protected boolean useOnlineResources
    • Constructor Detail

      • Task

        public Task()
    • Method Detail

      • addTaskProcessListener

        public void addTaskProcessListener​(TaskProcessListener taskProcessListener)
      • addTaskRunListener

        public void addTaskRunListener​(TaskRunListener taskRunListener)
      • hasSucceeded

        public boolean hasSucceeded()
        Indicates whether processing or running this task succeeded.
        Returns:
        true or false
        See Also:
        setSucceeded(boolean)
      • wasSkipped

        public boolean wasSkipped()
        Returns:
        true or false
        See Also:
        setSkipped(boolean)
      • isAvailable

        public boolean isAvailable()
        Indicate, whether this task is actually available in the current configuration. A task may not be available for non-iTunes libraries.
        Returns:
        true or false
        See Also:
        MediaLibrary.getLibraryDescriptor()
      • setAvailable

        protected void setAvailable​(boolean available)
        Parameters:
        available - available
        See Also:
        isAvailable()
      • createEditor

        public TaskEditor<? extends Task> createEditor()
        By default instantiates a class with the name this.getClass().getName() + "Editor". If that does not work (because the editor class does not exist), an EmptyTaskEditor is created. To create a meaningful editor for a configurable task, you must override this method.
        Returns:
        task editor for this task.
      • isUseOnlineResources

        public boolean isUseOnlineResources()
        Indicates whether this task should use online resources. This persistent flag is typically set in the editor createEditor(). If it is set, its TaskProcessListener.processBefore(Task) method is called once online results are available.
        Returns:
        true or false (defaults to false)
        See Also:
        process()
      • setUseOnlineResources

        public void setUseOnlineResources​(boolean useOnlineResources)
        Determines whether this task should use online resources. This flag is persistent.
        Parameters:
        useOnlineResources - true or false
        See Also:
        isUseOnlineResources()
      • isDeepUseOnlineResources

        public boolean isDeepUseOnlineResources()
        Indicates whether this task or any of its sub-tasks want to use online resources.
        Returns:
        true or false
      • cancel

        public void cancel()
        Asynchronously cancels this and all of its subtasks, if possible.
      • getCurrentOperation

        public Operation getCurrentOperation()
      • setCurrentOperation

        public void setCurrentOperation​(Operation currentOperation)
      • isCancelled

        public boolean isCancelled()
      • isPaused

        public boolean isPaused()
      • setPaused

        public void setPaused​(boolean paused)
        Pauses ot resumes this and all of its sub tasks.
        Parameters:
        paused - true or false
      • getApplication

        public BeaTunes getApplication()
        Returns:
        this task's or its parent's beaTunes instance
      • setApplication

        public void setApplication​(BeaTunes beaTunes)
      • getAnalysisProgress

        public AnalysisProgress getAnalysisProgress()
        Returns:
        this task's or its parent's AnalysisProgress instance
      • setAnalysisProgress

        public void setAnalysisProgress​(AnalysisProgress analysisProgress)
      • isProgressRelevant

        public boolean isProgressRelevant()
        Returns:
        true if this task relevant for overall progress computations.
      • setProgressRelevant

        public void setProgressRelevant​(boolean progressRelevant)
        Parameters:
        progressRelevant - set this to true, if you want this task and its subtasks to be included in overall progress computations.
      • getSong

        public AudioSong getSong()
        Returns:
        this task's or its parent's Song instance
      • setSong

        public void setSong​(AudioSong song)
        Sets the song associated with this task. At the same time the persistent id of this song will be registered using setSongId(Long).
        Parameters:
        song - song
      • setReferenceSong

        public void setReferenceSong​(ReferenceSong referenceSong)
      • getReferenceSong

        public ReferenceSong getReferenceSong()
        Returns:
        this task's or its parent's ReferenceSong instance
      • isFileExistedBeforeStart

        public boolean isFileExistedBeforeStart()
        Indicates whether the file (if any) associated with this song (getSong()) and task existed before processing started.
        Returns:
        true or false
      • fetchCollections

        protected void fetchCollections()
        Fetches any lazily initialized collections, if necessary.
      • getSongId

        public Long getSongId()
      • setSongId

        public void setSongId​(Long id)
      • setAudioFileFormat

        public void setAudioFileFormat​(AudioFileFormat audioFileFormat)
      • getParent

        public Task getParent()
      • setParent

        public void setParent​(Task parent)
      • getTask

        public Task getTask​(int index)
        Parameters:
        index - index
        Returns:
        sub task
      • getTaskCount

        public int getTaskCount()
        Returns:
        number of (sub)tasks contained in this task
      • getDeepTaskCount

        public int getDeepTaskCount​(boolean onlyProgressRelevant)
        Counts this task and all its sub tasks.
        Parameters:
        onlyProgressRelevant - count only tasks relevant for progress computation
        Returns:
        deep count
      • add

        public final void add​(Task task)
        Parameters:
        task - task to add
      • remove

        public boolean remove​(Task task)
        Shallow remove.
        Parameters:
        task - task to remove
        Returns:
        true, if successful
      • deepRemove

        public boolean deepRemove​(Task task)
        Deep remove.
        Parameters:
        task - task to remove
        Returns:
        true, if successful
      • removeDeadLeaves

        public boolean removeDeadLeaves()
        Removes any leaves that have succeeded (hasSucceeded()), were not skipped (!wasSkipped()) and used online resources (useOnlineResources).
        Returns:
        true, if any leaves were removed
      • getTasks

        public Task[] getTasks()
        All subtasks without their subtasks.
        Returns:
        shallow sub tasks
      • getDeepTasks

        public Task[] getDeepTasks()
        All subtasks and their subtasks.
        Returns:
        deep sub tasks
      • getDeepLeafs

        public Task[] getDeepLeafs()
        Returns:
        deep walk to get all leafs
      • isLeaf

        public boolean isLeaf()
      • process

        public void process()
      • processBefore

        public void processBefore​(Task task)
        Process online results with this task before other tasks are invoked. Override this method, if you want to take online resources into account. Note that you will also need to set setUseOnlineResources(boolean) to true, if you want this method to be called at all.

        To avoid having this task processed again by runBefore(Task), you must call setSucceeded(boolean) with the argument true. If, for some reason, you could not take care of this task with just the available online resources, you must call setSucceeded(boolean) with the argument false

        This method is executed before sub tasks are run. When this method is called, the methods getSong() and getReferenceSong() will return meaningful results.

        Specified by:
        processBefore in interface TaskProcessListener
        Parameters:
        task - task
      • maybePause

        protected void maybePause()
        Checks whether the task got paused or cancelled.
      • runFinally

        public void runFinally​(Task task)
        Is executed after sub tasks are run regardless of whether those sub tasks succeeded or not.
        Specified by:
        runFinally in interface TaskRunListener
        Parameters:
        task - task
      • getId

        public long getId()
      • setId

        public void setId​(long id)
      • skip

        public boolean skip()
        Indicates, whether this task can be skipped. Defaults to false.

        Since this task is not necessarily called by beaTunes, but by your own implementation of runBefore(Task), you should call setSkipped(boolean) with whatever value you are returning.

        Returns:
        true or false
      • getDescription

        public String getDescription()
        HTML or plain text description of this task.
        Returns:
        description
      • getName

        public String getName()
        HTML or plaintext name of this task. Defaults to the task's classname.
        Returns:
        name
      • getPropertyNames

        public final Iterator<String> getPropertyNames()
        Names of persistent properties.
        Returns:
        iterator over the property names
      • getProperty

        public String getProperty​(String propertyName)
        Returns property.
        Parameters:
        propertyName - name of the property in question
        Returns:
        value or null if not found
      • setProperty

        public final String setProperty​(String name,
                                        String value)
        Sets persistent property. Properties are not persisted, if this method is called while the task is executed.
        Parameters:
        name - property name
        value - property value
        Returns:
        old property value or null, if none was set
      • clearProperties

        public final void clearProperties()
        Delete all properties.
      • getProperties

        public final Map<String,​String> getProperties()
        Used for XML based persistence by beaTunes. For programmatic getting of properties, use getProperty(String) and getPropertyNames().
        Returns:
        unmodifiable properties map or null, if none was set
      • createDeepCopy

        public Task createDeepCopy()
        This method creates a copy of the Task and its subtasks. If you added any members to your subclass you MUST override this method and provide code that copies your members.
        Returns:
        copy
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getPriority

        public int getPriority()
        Returns:
        priority
      • setPriority

        public void setPriority​(int priority)
        Subtasks with lower priority are executed first.
        Parameters:
        priority - priority
      • getMessagePanel

        protected MessagePanel getMessagePanel()
        Convenience method for getting the analysis queue message panel.
        Returns:
        message panel
        See Also:
        Message