Class OutputStreamConnector
- java.lang.Object
-
- java.lang.Thread
-
- com.oracle.bedrock.runtime.remote.windows.winrm.OutputStreamConnector
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Runnable
public class OutputStreamConnector extends Thread implements Closeable
An implementation of aThreadthat polls a remote WinRM shell command for the contents of its output streams and then pipes that data to correspondingOutputStreams.Copyright (c) 2015. All Rights Reserved. Oracle Corporation.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.- Author:
- Jonathan Knight
-
-
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 Modifier Constructor Description protectedOutputStreamConnector(WindowsSession session, OutputStream stdOut, OutputStream stdErr)Create anOutputStreamConnectorto link the output streams of the remote process controlled by theWindowsSession.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes thisOutputStreamConnectorand stops the run loop.OutputStreamgetErrorStream()Obtain theOutputStreamthis connector pipes the remote process stderr to.intgetExitCode()Obtain the exit value of the remote process or -1 if the process has not yet terminated.OutputStreamgetOutputStream()Obtain theOutputStreamthis connector pipes the remote process stdout to.WindowsSessiongetSession()Obtain theWindowsSessionrunning the remote process.booleanpollOutput()Poll for the current process output from the remote command.voidrun()The run loop for thisThread.IntegerwaitFor(com.oracle.bedrock.Option... options)Causes the current thread to wait, if necessary, until the remote command has terminated.-
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 Detail
-
OutputStreamConnector
protected OutputStreamConnector(WindowsSession session, OutputStream stdOut, OutputStream stdErr)
Create anOutputStreamConnectorto link the output streams of the remote process controlled by theWindowsSession.- Parameters:
session- theWindowsSessionrunning the remote processstdOut- theOutputStreamto write the process stdout stream tostdErr- theOutputStreamto write the process stderr stream to
-
-
Method Detail
-
getOutputStream
public OutputStream getOutputStream()
Obtain theOutputStreamthis connector pipes the remote process stdout to.- Returns:
- the
OutputStreamthis connector pipes the remote process stdout to
-
getErrorStream
public OutputStream getErrorStream()
Obtain theOutputStreamthis connector pipes the remote process stderr to.- Returns:
- the
OutputStreamthis connector pipes the remote process stderr to
-
getSession
public WindowsSession getSession()
Obtain theWindowsSessionrunning the remote process.- Returns:
- the
WindowsSessionrunning the remote process
-
close
public void close()
Closes thisOutputStreamConnectorand stops the run loop.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
waitFor
public Integer waitFor(com.oracle.bedrock.Option... options)
Causes the current thread to wait, if necessary, until the remote command has terminated.- Parameters:
options- theOptions for waiting, includingTimeout- Returns:
- the exit code of the remote command. By convention, the value 0 indicates normal termination
- Throws:
RuntimeException- if there was a problem waiting for termination
-
getExitCode
public int getExitCode()
Obtain the exit value of the remote process or -1 if the process has not yet terminated.- Returns:
- the exit value of the remote process or -1 if the process has not yet terminated
-
pollOutput
public boolean pollOutput() throws IOExceptionPoll for the current process output from the remote command.- Returns:
- true if the process is still running otherwise false.
- Throws:
IOException- if an error occurs.
-
-