public static void main()

in aws-iot-device-sdk-java-samples/src/main/java/com/amazonaws/services/iot/client/sample/shadowEcho/ShadowEchoSample.java [71:120]


    public static void main(String args[]) throws IOException, AWSIotException, AWSIotTimeoutException,
            InterruptedException {
        CommandArguments arguments = CommandArguments.parse(args);
        initClient(arguments);

        String thingName = arguments.getNotNull("thingName", SampleUtil.getConfig("thingName"));
        AWSIotDevice device = new AWSIotDevice(thingName);

        awsIotClient.attach(device);
        awsIotClient.connect();

        // Delete existing document if any
        device.delete();

        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        Thing thing = new Thing();

        while (true) {
            long desired = thing.state.desired.counter;
            thing.state.reported.counter = desired;
            thing.state.desired.counter = desired + 1;

            String jsonState = objectMapper.writeValueAsString(thing);

            try {
                // Send updated document to the shadow
                device.update(jsonState);
                System.out.println(System.currentTimeMillis() + ": >>> " + jsonState);
            } catch (AWSIotException e) {
                System.out.println(System.currentTimeMillis() + ": update failed for " + jsonState);
                continue;
            }

            try {
                // Retrieve updated document from the shadow
                String shadowState = device.get();
                System.out.println(System.currentTimeMillis() + ": <<< " + shadowState);

                thing = objectMapper.readValue(shadowState, Thing.class);
            } catch (AWSIotException e) {
                System.out.println(System.currentTimeMillis() + ": get failed for " + jsonState);
                continue;
            }

            Thread.sleep(1000);
        }

    }