Example usage for com.amazonaws.services.ec2.model GetConsoleScreenshotRequest GetConsoleScreenshotRequest

List of usage examples for com.amazonaws.services.ec2.model GetConsoleScreenshotRequest GetConsoleScreenshotRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model GetConsoleScreenshotRequest GetConsoleScreenshotRequest.

Prototype

GetConsoleScreenshotRequest

Source Link

Usage

From source file:ec2watch.EC2Watch.java

License:Open Source License

public void run() {

    ImageViewer viewer = null;//from   w  ww.  j a  va 2 s  . c o  m
    AmazonEC2Client ec2Client = new AmazonEC2Client(clientConfiguration);

    if (region != null) {
        ec2Client.setRegion(Region.getRegion(Regions.fromName(region)));
    }

    while (true) {
        try {
            GetConsoleScreenshotResult result = ec2Client.getConsoleScreenshot(
                    new GetConsoleScreenshotRequest().withInstanceId(instanceId).withWakeUp(Boolean.TRUE));
            byte[] imageData = Base64.getDecoder().decode(result.getImageData());

            if (viewer == null) {
                viewer = new ImageViewer(instanceId, imageData);
            } else {
                viewer.setImageData(imageData);
                System.out.print(".");
            }

            Thread.sleep(interval * 1000);
        } catch (Exception e) {
            // Ignore it
            System.out.print("x");
        }

    }
}