Package nzilbb.labbcat.server.task
Class Task
- java.lang.Object
-
- java.lang.Thread
-
- nzilbb.labbcat.server.task.Task
-
- All Implemented Interfaces:
Runnable
,nzilbb.util.MonitorableTask
- Direct Known Subclasses:
ProcessWithPraat
,SearchTask
,SerializeFragmentsTask
public class Task extends Thread implements nzilbb.util.MonitorableTask
Base class for all long-running server-side tasks.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
-
Field Summary
-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description Task()
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
Cancels the task.String
defaultThreadName()
A default unique name for the thread.static Task
findTask(long id)
Finds the named task.static Task
findTask(String sName)
Finds the named thread.Date
getCreationTime()
The creation time of the task.long
getDuration()
The duration of the tasks execution so far.Throwable
getLastException()
Gets the last exception that occurred during the task.Date
getLastKeepAlive()
LastKeepAlive accessorString
getLog()
Provides a timestamped log of activity.int
getMaxLogSize()
Getter formaxLogSize
: Maximum size of the task's log, in characters.Integer
getPercentComplete()
Determines how far through the task is is.ResourceBundle
getResources()
Getter forresources
: Localization resource bundle.String
getResultTarget()
Getter forsResultTarget
: The target HTML frame/window for the results to open in.String
getResultText()
ResultText accessorString
getResultUrl()
ResultUrl accessorboolean
getRunning()
Reveals whether the task is still running or not.String
getStatus()
The current status of the thread.SqlGraphStore
getStore()
Getter forstore
: Graph store.StoreCache
getStoreCache()
Getter forstoreCache
: A supplier/consumer of graph stores, so that a store can be obtained if necessary, and resources can be shared/closed when appropriate.static ThreadGroup
getTaskThreadGroup()
Access the Task thread grouplong
getWaitToDieMilliseconds()
Getter forwaitToDieMilliseconds
: Time to wait after finishing or the last keepalive, before dying.String
getWho()
Gets the user associated with the task, if any.void
keepAlive()
Somebody is still interested in the thread, so keep it from dying.void
release()
Allows the finished-and-waiting thread to exit.void
setLastException(Throwable ex)
Sets the last exception that occurred during the task.void
setLastKeepAlive(Date dtNewLastKeepAlive)
LastKeepAlive mutatorTask
setMaxLogSize(int newMaxLogSize)
Setter formaxLogSize
: Maximum size of the task's log, in characters.Task
setResources(ResourceBundle newResources)
Setter forresources
: Localization resource bundle.void
setResultTarget(String sNewResultTarget)
Setter forsResultTarget
: The target HTML frame/window for the results to open in.void
setResultText(String sNewResultText)
ResultText mutatorvoid
setResultUrl(String sNewResultUrl)
ResultUrl mutatorvoid
setStatus(String sMessage)
Sets the thread status.Task
setStore(SqlGraphStore newStore)
Setter forstore
: Graph store.Task
setStoreCache(StoreCache newStoreCache)
Setter forstoreCache
: A supplier/consumer of graph stores, so that a store can be obtained if necessary, and resources can be shared/closed when appropriate.void
setWaitToDieMilliseconds(long newWaitToDieMilliseconds)
Setter forwaitToDieMilliseconds
: Time to wait after finishing or the last keepalive, before dying.void
setWho(String who)
Sets the user associated with the task.void
waitToDie()
Called at the end of the task's run() method, this method blocks until there is nobody interested in the thread any more - i.e.void
waitToDie(long lDelay)
Called at the end of the task's run() method, this method blocks until there is nobody interested in the thread any more - i.e.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Method Detail
-
getTaskThreadGroup
public static ThreadGroup getTaskThreadGroup()
Access the Task thread group
-
getPercentComplete
public Integer getPercentComplete()
Determines how far through the task is is.- Specified by:
getPercentComplete
in interfacenzilbb.util.MonitorableTask
- Returns:
- An integer between 0 and 100 (inclusive), or null if progress can not be calculated.
-
cancel
public void cancel()
Cancels the task.- Specified by:
cancel
in interfacenzilbb.util.MonitorableTask
-
getRunning
public boolean getRunning()
Reveals whether the task is still running or not.- Specified by:
getRunning
in interfacenzilbb.util.MonitorableTask
- Returns:
- true if the task is currently running, false otherwise.
-
getStatus
public String getStatus()
The current status of the thread.- Specified by:
getStatus
in interfacenzilbb.util.MonitorableTask
- Returns:
- a description of the current status of the task.
-
setStatus
public void setStatus(String sMessage)
Sets the thread status.- Parameters:
sMessage
- a status message to display to anyone who's watching the thread.
-
getWho
public String getWho()
Gets the user associated with the task, if any.- Returns:
- the username or hostname of the person who started the task, if available.
-
setWho
public void setWho(String who)
Sets the user associated with the task.- Parameters:
who
- the username or hostname of the person who started the task
-
getLastException
public Throwable getLastException()
Gets the last exception that occurred during the task.- Returns:
- the last task exception, or null if no exception has occurred.
-
setLastException
public void setLastException(Throwable ex)
Sets the last exception that occurred during the task.- Parameters:
ex
- the last task exception, or null if no exception has occurred.
-
getResultUrl
public String getResultUrl()
ResultUrl accessor- Returns:
- Full URL to the final results of the task, or null if the task isn't finished or has no URL for final results.
-
setResultUrl
public void setResultUrl(String sNewResultUrl)
ResultUrl mutator- Parameters:
sNewResultUrl
- Full URL to the final results of the task, or null if the task isn't finished or has no URL for final results. Instances of "+" in the string will be replaced with "%20".
-
getResultText
public String getResultText()
ResultText accessor- Returns:
- Text to describe the link to the ResultUrl. This will be the contents of the <a> tag if ResultUrl is set.
-
setResultText
public void setResultText(String sNewResultText)
ResultText mutator- Parameters:
sNewResultText
- Text to describe the link to the ResultUrl. This will be the contents of the <a> tag if ResultUrl is set.
-
getResultTarget
public String getResultTarget()
Getter forsResultTarget
: The target HTML frame/window for the results to open in.- Returns:
- The target HTML frame/window for the results to open in.
-
setResultTarget
public void setResultTarget(String sNewResultTarget)
Setter forsResultTarget
: The target HTML frame/window for the results to open in.- Parameters:
sNewResultTarget
- The target HTML frame/window for the results to open in.
-
getLastKeepAlive
public Date getLastKeepAlive()
LastKeepAlive accessor- Returns:
- Last time keepAlive() was called.
-
setLastKeepAlive
public void setLastKeepAlive(Date dtNewLastKeepAlive)
LastKeepAlive mutator- Parameters:
dtNewLastKeepAlive
- Last time keepAlive() was called.
-
getWaitToDieMilliseconds
public long getWaitToDieMilliseconds()
Getter forwaitToDieMilliseconds
: Time to wait after finishing or the last keepalive, before dying.- Returns:
- Time to wait after finishing or the last keepalive, before dying.
-
setWaitToDieMilliseconds
public void setWaitToDieMilliseconds(long newWaitToDieMilliseconds)
Setter forwaitToDieMilliseconds
: Time to wait after finishing or the last keepalive, before dying.- Parameters:
newWaitToDieMilliseconds
- Time to wait after finishing or the last keepalive, before dying.
-
getStore
public SqlGraphStore getStore()
Getter forstore
: Graph store.- Returns:
- Graph store.
-
setStore
public Task setStore(SqlGraphStore newStore)
Setter forstore
: Graph store.- Parameters:
newStore
- Graph store.
-
getStoreCache
public StoreCache getStoreCache()
Getter forstoreCache
: A supplier/consumer of graph stores, so that a store can be obtained if necessary, and resources can be shared/closed when appropriate.- Returns:
- A supplier/consumer of graph stores, so that a store can be obtained if necessary, and resources can be shared/closed when appropriate.
-
setStoreCache
public Task setStoreCache(StoreCache newStoreCache)
Setter forstoreCache
: A supplier/consumer of graph stores, so that a store can be obtained if necessary, and resources can be shared/closed when appropriate.- Parameters:
newStoreCache
- A supplier/consumer of graph stores, so that a store can be obtained if necessary, and resources can be shared/closed when appropriate.
-
getLog
public String getLog()
Provides a timestamped log of activity.- Returns:
- a string containing all of the values that setStatus has had since the task started.
- Throws:
Exception
-
getMaxLogSize
public int getMaxLogSize()
Getter formaxLogSize
: Maximum size of the task's log, in characters.- Returns:
- Maximum size of the task's log, in characters.
-
setMaxLogSize
public Task setMaxLogSize(int newMaxLogSize)
Setter formaxLogSize
: Maximum size of the task's log, in characters.- Parameters:
newMaxLogSize
- Maximum size of the task's log, in characters.
-
getResources
public ResourceBundle getResources()
Getter forresources
: Localization resource bundle.- Returns:
- Localization resource bundle.
-
setResources
public Task setResources(ResourceBundle newResources)
Setter forresources
: Localization resource bundle.- Parameters:
newResources
- Localization resource bundle.
-
defaultThreadName
public String defaultThreadName()
A default unique name for the thread. Implementors can use or add this this as they like.
-
release
public void release()
Allows the finished-and-waiting thread to exit.
-
findTask
public static Task findTask(String sName)
Finds the named thread.- Parameters:
sName
- the thread's name- Returns:
- the named thread, or null if it can't be found.
-
findTask
public static Task findTask(long id)
Finds the named task.- Parameters:
id
- the thread's ID- Returns:
- The identified thread, or null if it can't be found.
-
keepAlive
public void keepAlive()
Somebody is still interested in the thread, so keep it from dying.
-
waitToDie
public void waitToDie()
Called at the end of the task's run() method, this method blocks until there is nobody interested in the thread any more - i.e. there have been no recent calls to keepAlive(). The default delay is 120000ms, i.e. 2 minutes;
-
waitToDie
public void waitToDie(long lDelay)
Called at the end of the task's run() method, this method blocks until there is nobody interested in the thread any more - i.e. there have been no recent calls to keepAlive()- Parameters:
lDelay
- Delay time - i.e. the minimum amount of time to wait before dying.
-
getCreationTime
public Date getCreationTime()
The creation time of the task.- Returns:
- the creation time of the task
-
getDuration
public long getDuration()
The duration of the tasks execution so far.- Returns:
- the number of millisecond that the thread ran for if it is finished, or the amount of time the thread has been running for so far, if it is still executing.
-
-