/*
 * JBoss, Home of Professional Open Source
 * Copyright Red Hat, Inc., and individual contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jboss.aerogear.webpush;

public class Example {

    public static void main(String[] args) throws Exception {
        WebPushClient webPushClient = new WebPushClient();
        try {
            webPushClient.connect();
            webPushClient.subscribe(subscription -> {
                System.out.println(subscription);
                try {
                    Thread.sleep(10 * 1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                webPushClient.monitor(subscription, true, pushMessage -> {
                    if (pushMessage.isPresent()) {
                        System.out.println(pushMessage.get());
                    } else {
                        System.out.println("204 No Content");
                    }
                });
            });
            Thread.sleep(30 * 1000);
        } finally {
            webPushClient.disconnect();
        }
    }
}

@@ -832,19 +832,49 @@
 hClient(
+%22https://localhost:8443%22, true
 );%0A
-
         
@@ -1040,168 +1040,71 @@
     
-try %7B%0A                    Thread.sleep(10 * 1000);%0A                %7D catch (InterruptedException e) %7B%0A                    e.printStackTrace();%0A                %7D
+//check new push messages and close the stream (nowait == true)
 %0A   
@@ -1317,16 +1317,53 @@
 %7D else %7B
+    //possible only if nowait == true
 %0A       
@@ -1435,24 +1435,24 @@
           %7D%0A
-
             
@@ -1451,32 +1451,154 @@
             %7D);%0A
+                //monitor all new push messages%0A                webPushClient.monitor(subscription, System.out::println);%0A
             %7D);%0A

Update an example