Package com.github.mike10004.xvfbmanager
Class DefaultXvfbController
- java.lang.Object
-
- com.github.mike10004.xvfbmanager.DefaultXvfbController
-
- All Implemented Interfaces:
XvfbController,Closeable,AutoCloseable
public class DefaultXvfbController extends Object implements XvfbController
Default controller implementation. This implementation relies on afutureto listen to the status of theXvfbprocess. It checks for a given window by executingxwininfoinpollForWindow(Predicate, long, int). Most other operations are handled by the service classes provided in the constructor.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceDefaultXvfbController.XLockFileChecker-
Nested classes/interfaces inherited from interface com.github.mike10004.xvfbmanager.XvfbController
XvfbController.XWindow
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAX_NUM_POLLSDefault max number of polls forwaitUntilReady()}.static longDEFAULT_POLL_INTERVAL_MSDefault poll interval forwaitUntilReady()}.protected static longLOCK_FILE_CLEANUP_POLL_INTERVAL_MSprotected static longLOCK_FILE_CLEANUP_TIMEOUT_MS-
Fields inherited from interface com.github.mike10004.xvfbmanager.XvfbController
ENV_DISPLAY
-
-
Constructor Summary
Constructors Modifier Constructor Description DefaultXvfbController(io.github.mike10004.subprocess.ProcessMonitor<?,?> xvfbMonitor, String display, XvfbManager.DisplayReadinessChecker displayReadinessChecker, Screenshooter<?> screenshooter, Sleeper sleeper)protectedDefaultXvfbController(io.github.mike10004.subprocess.ProcessMonitor<?,?> xvfbMonitor, String display, XvfbManager.DisplayReadinessChecker displayReadinessChecker, Screenshooter<?> screenshooter, Sleeper sleeper, DefaultXvfbController.XLockFileChecker lockFileChecker)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Invokesstop().Map<String,String>configureEnvironment(Map<String,String> environment)Sets the display environment variable in the given environment.protected Map<String,String>createEmptyMutableMap()StringgetDisplay()Gets the display number in the format:NwhereNis the display number.static Iterable<String>getRequiredPrograms()Screenshooter<?>getScreenshooter()Captures a screenshot of the virtual framebuffer.Map<String,String>newEnvironment()Creates a new, mutable environment variable map with the display variable set.Optional<TreeNode<XvfbController.XWindow>>pollForWindow(Predicate<XvfbController.XWindow> windowFinder, long intervalMs, int maxPollAttempts)voidstop()Stops the virtual framebuffer process.protected voidwaitForXLockFileCleanup()voidwaitUntilReady()Waits until the display is ready, using default values for the polling interval and maximum polls.voidwaitUntilReady(long pollIntervalMs, int maxNumPolls)Waits until the X display is ready, polling at a given interval until the display is ready or the given number of polls has been executed.
-
-
-
Field Detail
-
DEFAULT_POLL_INTERVAL_MS
public static final long DEFAULT_POLL_INTERVAL_MS
Default poll interval forwaitUntilReady()}.- See Also:
- Constant Field Values
-
DEFAULT_MAX_NUM_POLLS
public static final int DEFAULT_MAX_NUM_POLLS
Default max number of polls forwaitUntilReady()}.- See Also:
- Constant Field Values
-
LOCK_FILE_CLEANUP_POLL_INTERVAL_MS
protected static final long LOCK_FILE_CLEANUP_POLL_INTERVAL_MS
- See Also:
- Constant Field Values
-
LOCK_FILE_CLEANUP_TIMEOUT_MS
protected static final long LOCK_FILE_CLEANUP_TIMEOUT_MS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultXvfbController
public DefaultXvfbController(io.github.mike10004.subprocess.ProcessMonitor<?,?> xvfbMonitor, String display, XvfbManager.DisplayReadinessChecker displayReadinessChecker, Screenshooter<?> screenshooter, Sleeper sleeper)
-
DefaultXvfbController
protected DefaultXvfbController(io.github.mike10004.subprocess.ProcessMonitor<?,?> xvfbMonitor, String display, XvfbManager.DisplayReadinessChecker displayReadinessChecker, Screenshooter<?> screenshooter, Sleeper sleeper, DefaultXvfbController.XLockFileChecker lockFileChecker)
-
-
Method Detail
-
waitUntilReady
public void waitUntilReady() throws InterruptedExceptionDescription copied from interface:XvfbControllerWaits until the display is ready, using default values for the polling interval and maximum polls. Implementations may select the defaults to use.- Specified by:
waitUntilReadyin interfaceXvfbController- Throws:
InterruptedException- if waiting is interrupted- See Also:
XvfbController.waitUntilReady(long, int)
-
getDisplay
public String getDisplay()
Description copied from interface:XvfbControllerGets the display number in the format:NwhereNis the display number.- Specified by:
getDisplayin interfaceXvfbController- Returns:
- the display
-
configureEnvironment
public Map<String,String> configureEnvironment(Map<String,String> environment)
Description copied from interface:XvfbControllerSets the display environment variable in the given environment.- Specified by:
configureEnvironmentin interfaceXvfbController- Parameters:
environment- map of environment variables in which display is to be set- Returns:
- the argument environment object
- See Also:
XvfbController.ENV_DISPLAY
-
newEnvironment
public Map<String,String> newEnvironment()
Description copied from interface:XvfbControllerCreates a new, mutable environment variable map with the display variable set.- Specified by:
newEnvironmentin interfaceXvfbController- Returns:
- the new environment map
- See Also:
XvfbController.configureEnvironment(Map)
-
waitUntilReady
public void waitUntilReady(long pollIntervalMs, int maxNumPolls) throws InterruptedExceptionDescription copied from interface:XvfbControllerWaits until the X display is ready, polling at a given interval until the display is ready or the given number of polls has been executed.- Specified by:
waitUntilReadyin interfaceXvfbController- Parameters:
pollIntervalMs- interval between polls in millisecondsmaxNumPolls- maximum number of polls to execute- Throws:
InterruptedException- if waiting is interrupted
-
stop
public void stop()
Description copied from interface:XvfbControllerStops the virtual framebuffer process.- Specified by:
stopin interfaceXvfbController
-
waitForXLockFileCleanup
protected void waitForXLockFileCleanup()
-
getScreenshooter
public Screenshooter<?> getScreenshooter() throws XvfbException
Description copied from interface:XvfbControllerCaptures a screenshot of the virtual framebuffer.- Specified by:
getScreenshooterin interfaceXvfbController- Returns:
- the screenshot
- Throws:
XvfbException- if screenshooting goes awry
-
close
public void close()
Invokesstop().- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
pollForWindow
public Optional<TreeNode<XvfbController.XWindow>> pollForWindow(Predicate<XvfbController.XWindow> windowFinder, long intervalMs, int maxPollAttempts) throws InterruptedException
- Specified by:
pollForWindowin interfaceXvfbController- Throws:
InterruptedException
-
-