Package org.eclipse.mosaic.lib.util
Class ProcessLoggingThread
java.lang.Object
java.lang.Thread
org.eclipse.mosaic.lib.util.ProcessLoggingThread
- All Implemented Interfaces:
Runnable
A thread which reads lines from a provided
InputStream (e.g., stdout of a process), and
feeds them into a Consumer to print or log the read lines.-
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
ConstructorsConstructorDescriptionProcessLoggingThread(String processName, InputStream stream, Consumer<String> lineConsumer) -
Method Summary
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, 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, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Constructor Details
-
ProcessLoggingThread
-
-
Method Details
-
teeInputStream
AnInputStreamcannot be read twice. Reading it simultaneously results in unexpected results and blocking. Therefore, this method creates a copy of the initially providedInputStreamwhich can be read simultaneously by another thread by using a buffer which is filled by reading the initially provided stream.
Note: If the returnedInputStreamis not processed/read constantly, lines produced by the initial input stream might be lost, since only a limited number of lines are buffered.- Returns:
- an
InputStreamreturning the output produced by the initially provided InputStream
-
close
public void close() -
run
public void run()
-