Package org.eclipse.jetty.client.api

Examples of org.eclipse.jetty.client.api.Connection


        return activeConnections;
    }

    public Connection acquire()
    {
        Connection connection = acquireIdleConnection();
        if (connection == null)
            connection = tryCreate();
        return connection;
    }
View Full Code Here


        }
    }

    private Connection acquireIdleConnection()
    {
        Connection connection = idleConnections.pollFirst();
        if (connection == null)
            return null;
        return activate(connection) ? connection : null;
    }
View Full Code Here

    @Test
    public void test_FirstAcquire_WithEmptyQueue() throws Exception
    {
        HttpDestinationOverHTTP destination = new HttpDestinationOverHTTP(client, new Origin("http", "localhost", connector.getLocalPort()));
        Connection connection = destination.acquire();
        if (connection == null)
        {
            // There are no queued requests, so the newly created connection will be idle
            connection = destination.getConnectionPool().getIdleConnections().poll(5, TimeUnit.SECONDS);
        }
View Full Code Here

    @Test
    public void test_SecondAcquire_AfterFirstAcquire_WithEmptyQueue_ReturnsSameConnection() throws Exception
    {
        HttpDestinationOverHTTP destination = new HttpDestinationOverHTTP(client, new Origin("http", "localhost", connector.getLocalPort()));
        Connection connection1 = destination.acquire();
        if (connection1 == null)
        {
            // There are no queued requests, so the newly created connection will be idle
            long start = System.nanoTime();
            while (connection1 == null && TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start) < 5)
            {
                TimeUnit.MILLISECONDS.sleep(50);
                connection1 = destination.getConnectionPool().getIdleConnections().peek();
            }
            Assert.assertNotNull(connection1);

            Connection connection2 = destination.acquire();
            Assert.assertSame(connection1, connection2);
        }
    }
View Full Code Here

                {
                    x.printStackTrace();
                }
            }
        };
        Connection connection1 = destination.acquire();

        // There are no available existing connections, so acquire()
        // returns null because we delayed process() above
        Assert.assertNull(connection1);

        Connection connection2 = destination.acquire();
        Assert.assertNull(connection2);

        latch.countDown();

        // There must be 2 idle connections
        Connection connection = destination.getConnectionPool().getIdleConnections().poll(5, TimeUnit.SECONDS);
        Assert.assertNotNull(connection);
        connection = destination.getConnectionPool().getIdleConnections().poll(5, TimeUnit.SECONDS);
        Assert.assertNotNull(connection);
    }
View Full Code Here

        Assert.assertSame(connection1, destination.acquire());

        destination.process(connection1, false);
        destination.release(connection1);

        Connection connection2 = destination.acquire();
        Assert.assertSame(connection1, connection2);
    }
View Full Code Here

    {
        long idleTimeout = 1000;
        client.setIdleTimeout(idleTimeout);

        HttpDestinationOverHTTP destination = new HttpDestinationOverHTTP(client, new Origin("http", "localhost", connector.getLocalPort()));
        Connection connection1 = destination.acquire();
        if (connection1 == null)
        {
            // There are no queued requests, so the newly created connection will be idle
            long start = System.nanoTime();
            while (connection1 == null && TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start) < 5)
View Full Code Here

        start(new EmptyServerHandler());

        Destination destination = client.getDestination(scheme, "localhost", connector.getLocalPort());
        FuturePromise<Connection> futureConnection = new FuturePromise<>();
        destination.newConnection(futureConnection);
        Connection connection = futureConnection.get(5, TimeUnit.SECONDS);
        Request request = client.newRequest(destination.getHost(), destination.getPort()).scheme(scheme);
        FutureResponseListener listener = new FutureResponseListener(request);
        connection.send(request, listener);
        ContentResponse response = listener.get(5, TimeUnit.SECONDS);

        Assert.assertEquals(200, response.getStatus());

        // Wait some time to have the client is an idle state.
View Full Code Here

        return activeConnections;
    }

    public Connection acquire()
    {
        Connection connection = acquireIdleConnection();
        if (connection == null)
            connection = tryCreate();
        return connection;
    }
View Full Code Here

        }
    }

    private Connection acquireIdleConnection()
    {
        Connection connection = idleConnections.pollFirst();
        if (connection == null)
            return null;
        return activate(connection) ? connection : null;
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.client.api.Connection

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.