Package ai.libs.jaicore.interrupt
Class Interrupter
- java.lang.Object
-
- ai.libs.jaicore.interrupt.Interrupter
-
public class Interrupter extends java.lang.Object
This class is used to conduct managed interrupts, which is essential for organized interrupts. In AILibs, it is generally forbidden to directly interrupt any thread. Instead, the Interrupter should be used, because this enables the interrupted thread to decide how to proceed. Using the Interrupter has several advantages in debugging: 1. the Interrupter tells which thread caused the interrupt 2. the Interrupter tells the time when the thread was interrupted 3. the Interrupter provides a reason for the interrupt
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
avoidInterrupt(java.lang.Thread t, java.lang.Object reason)
static Interrupter
get()
java.util.Collection<Interrupt>
getAllUnresolvedInterrupts()
java.util.Collection<Interrupt>
getAllUnresolvedInterruptsOfThread(java.lang.Thread thread)
java.util.Optional<Interrupt>
getInterruptOfCurrentThreadWithReason(java.lang.Object reason)
java.util.Optional<Interrupt>
getInterruptOfThreadWithReason(java.lang.Thread thread, java.lang.Object reason)
java.util.Optional<Interrupt>
getLatestUnresolvedInterruptOfCurrentThread()
java.util.Optional<Interrupt>
getLatestUnresolvedInterruptOfThread(java.lang.Thread thread)
boolean
hasCurrentThreadBeenInterruptedWithReason(java.lang.Object reason)
boolean
hasCurrentThreadOpenInterrupts()
boolean
hasThreadBeenInterruptedWithReason(java.lang.Thread thread, java.lang.Object reason)
void
interruptThread(java.lang.Thread t, java.lang.Object reason)
void
markInterruptAsResolved(java.lang.Thread t, java.lang.Object reason)
void
markInterruptOnCurrentThreadAsResolved(java.lang.Object reason)
-
-
-
Method Detail
-
get
public static Interrupter get()
-
interruptThread
public void interruptThread(java.lang.Thread t, java.lang.Object reason)
-
hasCurrentThreadBeenInterruptedWithReason
public boolean hasCurrentThreadBeenInterruptedWithReason(java.lang.Object reason)
-
getInterruptOfCurrentThreadWithReason
public java.util.Optional<Interrupt> getInterruptOfCurrentThreadWithReason(java.lang.Object reason)
-
getInterruptOfThreadWithReason
public java.util.Optional<Interrupt> getInterruptOfThreadWithReason(java.lang.Thread thread, java.lang.Object reason)
-
avoidInterrupt
public void avoidInterrupt(java.lang.Thread t, java.lang.Object reason)
-
hasThreadBeenInterruptedWithReason
public boolean hasThreadBeenInterruptedWithReason(java.lang.Thread thread, java.lang.Object reason)
-
getAllUnresolvedInterrupts
public java.util.Collection<Interrupt> getAllUnresolvedInterrupts()
-
getAllUnresolvedInterruptsOfThread
public java.util.Collection<Interrupt> getAllUnresolvedInterruptsOfThread(java.lang.Thread thread)
-
getLatestUnresolvedInterruptOfThread
public java.util.Optional<Interrupt> getLatestUnresolvedInterruptOfThread(java.lang.Thread thread)
-
getLatestUnresolvedInterruptOfCurrentThread
public java.util.Optional<Interrupt> getLatestUnresolvedInterruptOfCurrentThread()
-
hasCurrentThreadOpenInterrupts
public boolean hasCurrentThreadOpenInterrupts()
-
markInterruptOnCurrentThreadAsResolved
public void markInterruptOnCurrentThreadAsResolved(java.lang.Object reason) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
markInterruptAsResolved
public void markInterruptAsResolved(java.lang.Thread t, java.lang.Object reason)
-
-