/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.messaginghub.amqperative.example;

import java.util.UUID;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.messaginghub.amqperative.Client;
import org.messaginghub.amqperative.ClientOptions;
import org.messaginghub.amqperative.Connection;
import org.messaginghub.amqperative.Delivery;
import org.messaginghub.amqperative.Message;
import org.messaginghub.amqperative.Receiver;
import org.messaginghub.amqperative.Sender;
import org.messaginghub.amqperative.Tracker;

public class HelloWorld {

    public static void main(String[] args) throws Exception {

        try {
            String brokerHost = "localhost";
            int brokerPort = 5672;
            String address = "examples";

            ClientOptions options = new ClientOptions();
            options.containerId(UUID.randomUUID().toString());
            Client client = Client.create(options);

            Connection connection = client.connect(brokerHost, brokerPort);

            Receiver receiver = connection.openReceiver(address);
            receiver.openFuture().get(5, TimeUnit.SECONDS);
            receiver.addCredit(10);

            Sender sender = connection.openSender(address);
            sender.openFuture().get(5, TimeUnit.SECONDS);

            Message<String> message = Message.create("Hello World").durable(true);
            Tracker tracker = sender.send(message);

            tracker.remoteState().get(5, TimeUnit.SECONDS);

            Delivery delivery = receiver.receive();

            if (delivery != null) {
                Message<String> received = delivery.message();

                System.out.println(received.body());
            }

            Future<Receiver> draining = receiver.drain();
            draining.get(5, TimeUnit.SECONDS);

            connection.close().get(5, TimeUnit.SECONDS);
        } catch (Exception exp) {
            System.out.println("Caught exception, exiting.");
            exp.printStackTrace(System.out);
            System.exit(1);
        } finally {
        }
    }
}

@@ -880,82 +880,8 @@
 UID;
-%0Aimport java.util.concurrent.Future;%0Aimport java.util.concurrent.TimeUnit;
 %0A%0Aim
@@ -1205,53 +1205,8 @@
 der;
-%0Aimport org.messaginghub.amqperative.Tracker;
 %0A%0Apu
@@ -1749,514 +1749,191 @@
 s);%0A
-            receiver.openFuture().get(5, TimeUnit.SECONDS);%0A            receiver.addCredit(10);%0A%0A            Sender sender = connection.openSender(address);%0A            sender.openFuture().get(5, TimeUnit.SECONDS);%0A%0A            Message%3CString%3E message = Message.create(%22Hello World%22).durable(true);%0A            Tracker tracker = sender.send(message);%0A%0A            tracker.remoteState().get(5, TimeUnit.SECONDS);%0A%0A            Delivery delivery = receiver.receive();%0A%0A            if (delivery != null) %7B%0A    
+%0A            Sender sender = connection.openSender(address);%0A            sender.send(Message.create(%22Hello World%22));%0A%0A            Delivery delivery = receiver.addCredit(1).receive();%0A
     
@@ -1987,21 +1987,16 @@
 sage();%0A
-%0A    
         
@@ -2039,128 +2039,8 @@
 ());
-%0A            %7D%0A%0A            Future%3CReceiver%3E draining = receiver.drain();%0A            draining.get(5, TimeUnit.SECONDS);
 %0A%0A  
@@ -2076,27 +2076,8 @@
 get(
-5, TimeUnit.SECONDS
 );%0A 

Trim down the hello world to a simpler example of using the API