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 int
DEFAULT_LOGIXNG_DEBUG_THREAD
static int
DEFAULT_LOGIXNG_THREAD
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
assertLogixNGThreadNotRunning()
void
checkIsLogixNGThread()
Checks if the the current thread is the LogixNG thread.static LogixNG_Thread
createNewThread(int threadID, java.lang.String name)
static LogixNG_Thread
createNewThread(java.lang.String name)
static void
deleteThread(LogixNG_Thread thread)
java.lang.Thread
getThread()
static LogixNG_Thread
getThread(int threadID)
int
getThreadId()
static int
getThreadID(java.lang.String name)
boolean
getThreadInUse()
java.lang.String
getThreadName()
static java.util.Collection<LogixNG_Thread>
getThreads()
boolean
isLogixNGThread()
Check if on the LogixNG-operation thread.boolean
isQueueEmpty()
void
runOnLogixNG(ThreadingUtil.ThreadAction ta)
Run some LogixNG-specific code before returning.javax.swing.Timer
runOnLogixNGDelayed(ThreadingUtil.ThreadAction ta, int delay)
Run some LogixNG-specific code at some later point, at least a known time in the future.void
runOnLogixNGEventually(ThreadingUtil.ThreadAction ta)
Run some LogixNG-specific code at some later point.void
setThreadInUse()
Set the thread to "in use".void
setThreadName(java.lang.String name)
static void
stopAllLogixNGThreads()
static boolean
validateNewThreadName(java.lang.String name)
-
-
-
Field Detail
-
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()
-
-