Package org.asynchttpclient

Examples of org.asynchttpclient.DefaultAsyncHttpClient


    public void testMultiplePromiseAdapter() throws IOException {
        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicInteger successCount = new AtomicInteger();

        AsyncHttpClient client = new DefaultAsyncHttpClient();

        try {
            Promise<Response, Throwable, HttpProgress> p1 = AsyncHttpDeferredObject.promise(client.prepareGet("http://www.ning.com"));
            Promise<Response, Throwable, HttpProgress> p2 = AsyncHttpDeferredObject.promise(client.prepareGet("http://www.google.com"));
            AsyncHttpDeferredObject deferredRequest = new AsyncHttpDeferredObject(client.prepareGet("http://jdeferred.org"));

            deferredManager.when(p1, p2, deferredRequest).then(new DoneCallback<MultipleResults>() {
                @Override
                public void onDone(MultipleResults result) {
                    try {
                        assertEquals(result.size(), 3);
                        assertEquals(Response.class.cast(result.get(0).getResult()).getStatusCode(), 200);
                        assertEquals(Response.class.cast(result.get(1).getResult()).getStatusCode(), 200);
                        assertEquals(Response.class.cast(result.get(2).getResult()).getStatusCode(), 200);
                        successCount.incrementAndGet();
                    } finally {
                        latch.countDown();
                    }
                }
            });
            latch.await();

        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } finally {
            client.close();
        }
    }
View Full Code Here


    public static AsyncHttpClient nettyProvider(AsyncHttpClientConfig config) {
        if (config == null) {
            config = new AsyncHttpClientConfig.Builder().build();
        }
        return new DefaultAsyncHttpClient(new NettyAsyncHttpProvider(config), config);
    }
View Full Code Here

TOP

Related Classes of org.asynchttpclient.DefaultAsyncHttpClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.