Package jmri.jmrit.logixng.util
Class LogixNG_Thread
- java.lang.Object
-
- jmri.jmrit.logixng.util.LogixNG_Thread
-
@ThreadSafe public class LogixNG_Thread extends java.lang.Object
Utilities for handling JMRI's LogixNG threading conventions.For background, see http://jmri.org/help/en/html/doc/Technical/Threads.shtml
This is the ThreadingUtil class for LogixNG.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_LOGIXNG_DEBUG_THREADstatic intDEFAULT_LOGIXNG_THREADstatic intERROR_HANDLING_LOGIXNG_THREAD
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidassertLogixNGThreadNotRunning()voidcheckIsLogixNGThread()Checks if the the current thread is the LogixNG thread.static LogixNG_ThreadcreateNewThread(int threadID, java.lang.String name)static LogixNG_ThreadcreateNewThread(java.lang.String name)static voiddeleteThread(LogixNG_Thread thread)java.lang.ThreadgetThread()static LogixNG_ThreadgetThread(int threadID)intgetThreadId()static intgetThreadID(java.lang.String name)booleangetThreadInUse()java.lang.StringgetThreadName()static java.util.Collection<LogixNG_Thread>getThreads()booleanisLogixNGThread()Check if on the LogixNG-operation thread.booleanisQueueEmpty()voidrunOnLogixNG(ThreadingUtil.ThreadAction ta)Run some LogixNG-specific code before returning.javax.swing.TimerrunOnLogixNGDelayed(ThreadingUtil.ThreadAction ta, int delay)Run some LogixNG-specific code at some later point, at least a known time in the future.voidrunOnLogixNGEventually(ThreadingUtil.ThreadAction ta)Run some LogixNG-specific code at some later point.voidsetThreadInUse()Set the thread to "in use".voidsetThreadName(java.lang.String name)static voidstopAllLogixNGThreads()static booleanvalidateNewThreadName(java.lang.String name)
-
-
-
Field Detail
-
ERROR_HANDLING_LOGIXNG_THREAD
public static final int ERROR_HANDLING_LOGIXNG_THREAD
- See Also:
- Constant Field Values
-
DEFAULT_LOGIXNG_THREAD
public static final int DEFAULT_LOGIXNG_THREAD
- See Also:
- Constant Field Values
-
DEFAULT_LOGIXNG_DEBUG_THREAD
public static final int DEFAULT_LOGIXNG_DEBUG_THREAD
- See Also:
- Constant Field Values
-
-
Method Detail
-
createNewThread
public static LogixNG_Thread createNewThread(@Nonnull java.lang.String name)
-
createNewThread
public static LogixNG_Thread createNewThread(int threadID, @Nonnull java.lang.String name)
-
validateNewThreadName
public static boolean validateNewThreadName(@Nonnull java.lang.String name)
-
getThread
public static LogixNG_Thread getThread(int threadID)
-
getThreadID
public static int getThreadID(java.lang.String name)
-
deleteThread
public static void deleteThread(LogixNG_Thread thread)
-
getThreads
public static java.util.Collection<LogixNG_Thread> getThreads()
-
getThread
public java.lang.Thread getThread()
-
getThreadId
public int getThreadId()
-
getThreadName
public java.lang.String getThreadName()
-
setThreadName
public void setThreadName(@Nonnull java.lang.String name)
-
getThreadInUse
public boolean getThreadInUse()
-
setThreadInUse
public void setThreadInUse()
Set the thread to "in use". If a thread is in use, it cannot be unset as not in use.
-
runOnLogixNG
public void runOnLogixNG(@Nonnull ThreadingUtil.ThreadAction ta)
Run some LogixNG-specific code before returning.Typical uses:
ThreadingUtil.runOnLogixNG(() -> { logixNG.doSomething(value); });- Parameters:
ta- What to run, usually as a lambda expression
-
runOnLogixNGEventually
public void runOnLogixNGEventually(@Nonnull ThreadingUtil.ThreadAction ta)
Run some LogixNG-specific code at some later point.Please note the operation may have happened before this returns. Or later. No long-term guarantees.
Typical uses:
ThreadingUtil.runOnLogixNGEventually(() -> { sensor.setState(value); });- Parameters:
ta- What to run, usually as a lambda expression
-
runOnLogixNGDelayed
@Nonnull public javax.swing.Timer runOnLogixNGDelayed(@Nonnull ThreadingUtil.ThreadAction ta, int delay)
Run some LogixNG-specific code at some later point, at least a known time in the future.There is no long-term guarantee about the accuracy of the interval.
Typical uses:
ThreadingUtil.runOnLogixNGDelayed(() -> { sensor.setState(value); }, 1000);- Parameters:
ta- What to run, usually as a lambda expressiondelay- interval in milliseconds- Returns:
- reference to timer object handling delay so you can cancel if desired; note that operation may have already taken place.
-
isQueueEmpty
public boolean isQueueEmpty()
-
isLogixNGThread
public boolean isLogixNGThread()
Check if on the LogixNG-operation thread.- Returns:
- true if on the LogixNG-operation thread
-
checkIsLogixNGThread
public void checkIsLogixNGThread()
Checks if the the current thread is the LogixNG thread. The check is only done if debug is enabled.
-
stopAllLogixNGThreads
public static void stopAllLogixNGThreads()
-
assertLogixNGThreadNotRunning
public static void assertLogixNGThreadNotRunning()
-
-